From 0615c251f28b92bf821f085d6356e98d6799d34c Mon Sep 17 00:00:00 2001 From: Min RK Date: Sun, 6 Sep 2015 15:51:20 +0200 Subject: [PATCH 1/3] add restart-run-all action and constituent restart, run-all actions --- notebook/static/notebook/js/actions.js | 25 +++++++++++++++++++++++++ notebook/static/notebook/js/menubar.js | 4 ++++ 2 files changed, 29 insertions(+) diff --git a/notebook/static/notebook/js/actions.js b/notebook/static/notebook/js/actions.js index 4f7aeb882..d387c17ee 100644 --- a/notebook/static/notebook/js/actions.js +++ b/notebook/static/notebook/js/actions.js @@ -59,6 +59,31 @@ 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.events.one('kernel_ready.Kernel', function () { + notebook.execute_all_cells(); + }); + notebook.restart_kernel(); + } + }, + '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', diff --git a/notebook/static/notebook/js/menubar.js b/notebook/static/notebook/js/menubar.js index a53ecaf81..914990849 100644 --- a/notebook/static/notebook/js/menubar.js +++ b/notebook/static/notebook/js/menubar.js @@ -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(); }); From 31f0ef480b708a3084bc893467c9e73f5e4d77b9 Mon Sep 17 00:00:00 2001 From: Min RK Date: Sun, 6 Sep 2015 15:51:34 +0200 Subject: [PATCH 2/3] add Restart & Run All to Kernel Menu --- notebook/templates/notebook.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/notebook/templates/notebook.html b/notebook/templates/notebook.html index c9b024f08..649e300ab 100644 --- a/notebook/templates/notebook.html +++ b/notebook/templates/notebook.html @@ -239,6 +239,10 @@ data-notebook-path="{{notebook_path}}" title="Restart the Kernel"> Restart +
  • + Restart & Run All +
  • Reconnect From 17499ebb49f1361244cb476292adea6f7871f938 Mon Sep 17 00:00:00 2001 From: Min RK Date: Sun, 6 Sep 2015 17:57:58 +0200 Subject: [PATCH 3/3] Notebook.restart_kernel returns a promise --- notebook/static/notebook/js/actions.js | 3 +- notebook/static/notebook/js/notebook.js | 40 +++++++++++++++++-------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/notebook/static/notebook/js/actions.js b/notebook/static/notebook/js/actions.js index d387c17ee..b0990a622 100644 --- a/notebook/static/notebook/js/actions.js +++ b/notebook/static/notebook/js/actions.js @@ -71,10 +71,9 @@ define(function(require){ help_index: 'be', handler: function (env) { var notebook = env.notebook; - notebook.events.one('kernel_ready.Kernel', function () { + notebook.restart_kernel().then(function() { notebook.execute_all_cells(); }); - notebook.restart_kernel(); } }, 'restart': { diff --git a/notebook/static/notebook/js/notebook.js b/notebook/static/notebook/js/notebook.js index 2a02c5e17..22d2a5eb1 100644 --- a/notebook/static/notebook/js/notebook.js +++ b/notebook/static/notebook/js/notebook.js @@ -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").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; }; /**