Merge pull request #400 from minrk/restart-run-all

add Restart & Run All action
Matthias Bussonnier 11 years ago
commit 806cd1f989

@ -59,6 +59,30 @@ define(function(require){
env.notebook.execute_cell_and_insert_below();
}
},
'run-all': {
help: 'run all cells',
help_index: 'bd',
handler: function (env) {
env.notebook.execute_all_cells();
}
},
'restart-run-all': {
help: 'restart the kernel, then re-run the whole notebook',
help_index: 'be',
handler: function (env) {
var notebook = env.notebook;
notebook.restart_kernel().then(function() {
notebook.execute_all_cells();
});
}
},
'restart': {
help: 'restart the kernel',
help_index: 'bf',
handler: function (env) {
env.notebook.restart_kernel();
}
},
'go-to-command-mode': {
help : 'command mode',
help_index : 'aa',

@ -35,6 +35,7 @@ define([
this.base_url = options.base_url || utils.get_body_data("baseUrl");
this.selector = selector;
this.notebook = options.notebook;
this.actions = this.notebook.keyboard_manager.actions;
this.contents = options.contents;
this.events = options.events;
this.save_widget = options.save_widget;
@ -298,6 +299,9 @@ define([
this.element.find('#restart_kernel').click(function () {
that.notebook.restart_kernel();
});
this.element.find('#restart_run_all').click(function () {
that.actions.call('ipython.restart-run-all');
});
this.element.find('#reconnect_kernel').click(function () {
that.notebook.kernel.reconnect();
});

@ -323,7 +323,7 @@ define(function (require) {
Notebook.prototype.show_command_palette = function() {
var x = new commandpalette.CommandPalette(this);
}
};
/**
* Trigger a warning dialog about missing functionality from newer minor versions
@ -667,11 +667,11 @@ define(function (require) {
}
var current_selection = this.get_selected_cells();
for (var i=0; i<current_selection.length; i++) {
current_selection[i].unselect()
current_selection[i].unselect();
}
var cell = this._select(index);
cell.selection_anchor = true
cell.selection_anchor = true;
}
return this;
};
@ -738,7 +738,7 @@ define(function (require) {
var current_selection = this.get_selected_cells();
for (var i=0; i<current_selection.length; i++) {
if (!current_selection[i].selected) {
current_selection[i].unselect()
current_selection[i].unselect();
}
}
};
@ -821,7 +821,7 @@ define(function (require) {
var cell = this.get_selected_cell();
if (cell === null) {return;} // No cell is selected
cell.ensure_focused();
}
};
/**
* Focus the currently selected cell.
@ -1465,9 +1465,9 @@ define(function (require) {
contents.push(this.get_cell(indices[i]).get_text());
}
if (into_last) {
contents.push(target.get_text())
contents.push(target.get_text());
} else {
contents.unshift(target.get_text())
contents.unshift(target.get_text());
}
// Update the contents of the target cell
@ -1502,7 +1502,7 @@ define(function (require) {
*/
Notebook.prototype.merge_cell_above = function () {
var index = this.get_selected_index();
this.merge_cells([index-1, index], true)
this.merge_cells([index-1, index], true);
};
/**
@ -1510,7 +1510,7 @@ define(function (require) {
*/
Notebook.prototype.merge_cell_below = function () {
var index = this.get_selected_index();
this.merge_cells([index, index+1], false)
this.merge_cells([index, index+1], false);
};
@ -1793,9 +1793,22 @@ define(function (require) {
*/
Notebook.prototype.restart_kernel = function () {
var that = this;
var resolve_promise, reject_promise;
var promise = new Promise(function (resolve, reject){
resolve_promise = resolve;
reject_promise = reject;
});
function restart_and_resolve () {
that.kernel.restart(function () {
// resolve when the kernel is *ready* not just started
that.events.one('kernel_ready.Kernel', resolve_promise);
}, reject_promise);
}
dialog.modal({
notebook: this,
keyboard_manager: this.keyboard_manager,
notebook: that,
keyboard_manager: that.keyboard_manager,
title : "Restart kernel or continue running?",
body : $("<p/>").text(
'Do you want to restart the current kernel? You will lose all variables defined in it.'
@ -1806,17 +1819,18 @@ define(function (require) {
"class" : "btn-danger",
"click" : function(){
that.clear_all_output();
that.kernel.restart();
restart_and_resolve();
},
},
"Restart" : {
"class" : "btn-warning",
"click" : function() {
that.kernel.restart();
restart_and_resolve();
}
},
}
});
return promise;
};
/**

@ -239,6 +239,10 @@ data-notebook-path="{{notebook_path}}"
title="Restart the Kernel">
<a href="#">Restart</a>
</li>
<li id="restart_run_all"
title="Restart the Kernel and re-run the notebook">
<a href="#">Restart &amp; Run All</a>
</li>
<li id="reconnect_kernel"
title="Reconnect to the Kernel">
<a href="#">Reconnect</a>

Loading…
Cancel
Save