make restart-clear-output a discrete action

- no more multi-button restart dialog
- Restart & Clear Output added to Kernel menu
Min RK 11 years ago
parent 1c786d74ee
commit ef64f743c4

@ -86,11 +86,16 @@ define(function(require){
},
'restart-run-all': {
help: 'restart the kernel, then re-run the whole notebook',
help_index: 'be',
handler: function (env) {
env.notebook.restart_run_all();
}
},
'restart-clear-output': {
help: 'restart the kernel and clear all output',
handler: function (env) {
env.notebook.restart_clear_output();
}
},
'restart': {
help: 'restart the kernel',
help_index: 'bf',
@ -104,6 +109,12 @@ define(function(require){
env.notebook.restart_run_all({confirm: false});
}
},
'restart-clear-output-no-confirm': {
help: 'restart the kernel and clear all output (no confirmation dialog)',
handler: function (env) {
env.notebook.restart_clear_output({confirm: false});
}
},
'restart-no-confirm': {
help: 'restart the kernel (no confirmation dialog)',
handler: function (env) {

@ -202,6 +202,8 @@ define([
'#find_and_replace' : 'ipython.find-and-replace-dialog',
'#save_checkpoint': 'ipython.save-notebook',
'#restart_kernel': 'ipython.restart-kernel',
'#restart_clear_output': 'ipython.restart-clear-output',
'#restart_run_all': 'ipython.restart-run-all',
'#int_kernel': 'ipython.interrupt-kernel',
'#cut_cell': 'ipython.cut-selected-cell',
'#copy_cell': 'ipython.copy-selected-cell',
@ -258,9 +260,6 @@ define([
});
// 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();
});

@ -1812,7 +1812,6 @@ define(function (require) {
'Are you sure you want to restart the current kernel and re-execute the whole notebook? All variables and outputs will be lost.'
),
buttons : {
"Continue running" : {},
"Restart & run all cells" : {
"class" : "btn-danger",
"click" : function () {
@ -1825,32 +1824,46 @@ define(function (require) {
};
/**
* Prompt the user to restart the kernel.
* Prompt the user to restart the kernel and clear output.
* if options.confirm === false, no confirmation dialog is shown.
*/
Notebook.prototype.restart_kernel = function (options) {
Notebook.prototype.restart_clear_output = function (options) {
var that = this;
var restart_options = {};
restart_options.confirm = (options || {}).confirm;
restart_options.dialog = {
title : "Restart kernel or continue running?",
notebook: that,
keyboard_manager: that.keyboard_manager,
title : "Restart kernel and clear all output?",
body : $("<p/>").text(
'Do you want to restart the current kernel? You will lose all variables defined in it.'
'Do you want to restart the current kernel and clear all output? All variables and outputs will be lost.'
),
buttons : {
"Continue running" : {},
"Restart & clear all outputs" : {
"class" : "btn-danger",
"click" : function (){
that.clear_all_output();
},
},
"Restart & run all cells" : {
"class" : "btn-danger",
"click" : function (){
that.execute_all_cells();
},
},
}
};
return this._restart_kernel(restart_options);
};
/**
* Prompt the user to restart the kernel.
* if options.confirm === false, no confirmation dialog is shown.
*/
Notebook.prototype.restart_kernel = function (options) {
var that = this;
var restart_options = {};
restart_options.confirm = (options || {}).confirm;
restart_options.dialog = {
title : "Restart kernel?",
body : $("<p/>").text(
'Do you want to restart the current kernel? All variables will be lost.'
),
buttons : {
"Restart" : {
"class" : "btn-warning",
"click" : function () {},
@ -1878,21 +1891,27 @@ define(function (require) {
}
if (options.confirm === false) {
var default_button = options.dialog.buttons[Object.keys(options.dialog.buttons)[0]];
promise.then(default_button.click);
restart_and_resolve();
return promise;
}
options.dialog.notebook = this;
options.dialog.keyboard_manager = this.keyboard_manager;
// add 'Continue running' cancel button
var buttons = {
"Continue running": {},
};
// hook up button.click actions after restart promise resolves
Object.keys(options.dialog.buttons).map(function (key) {
var button = options.dialog.buttons[key];
if (button.click) {
var click = button.click;
button.click = function () {
promise.then(click);
restart_and_resolve();
};
}
var button = buttons[key] = options.dialog.buttons[key];
var click = button.click;
button.click = function () {
promise.then(click);
restart_and_resolve();
};
});
options.dialog.buttons = buttons;
dialog.modal(options.dialog);
return promise;
};

@ -240,6 +240,10 @@ data-notebook-path="{{notebook_path | urlencode}}"
title="Restart the Kernel">
<a href="#">Restart</a>
</li>
<li id="restart_clear_output"
title="Restart the Kernel and clear all output">
<a href="#">Restart &amp; Clear Output</a>
</li>
<li id="restart_run_all"
title="Restart the Kernel and re-run the notebook">
<a href="#">Restart &amp; Run All</a>

Loading…
Cancel
Save