diff --git a/notebook/static/notebook/js/actions.js b/notebook/static/notebook/js/actions.js index 1eb0cad85..15346dbe4 100644 --- a/notebook/static/notebook/js/actions.js +++ b/notebook/static/notebook/js/actions.js @@ -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) { diff --git a/notebook/static/notebook/js/menubar.js b/notebook/static/notebook/js/menubar.js index eb77a01a5..f4241c822 100644 --- a/notebook/static/notebook/js/menubar.js +++ b/notebook/static/notebook/js/menubar.js @@ -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(); }); diff --git a/notebook/static/notebook/js/notebook.js b/notebook/static/notebook/js/notebook.js index b7f910007..92e3a0e0e 100644 --- a/notebook/static/notebook/js/notebook.js +++ b/notebook/static/notebook/js/notebook.js @@ -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 : $("
").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 : $("").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; }; diff --git a/notebook/templates/notebook.html b/notebook/templates/notebook.html index 0ed2deb75..32d8459ff 100644 --- a/notebook/templates/notebook.html +++ b/notebook/templates/notebook.html @@ -240,6 +240,10 @@ data-notebook-path="{{notebook_path | urlencode}}" title="Restart the Kernel"> Restart +