From 6162ca9570d1f5f95503d8dd0d611ba10c86d22c Mon Sep 17 00:00:00 2001 From: Mac Knight Date: Wed, 7 Feb 2018 11:20:26 -0500 Subject: [PATCH 1/4] Added close and halt to the action menu and exposed function --- notebook/static/notebook/js/actions.js | 7 +++++++ notebook/static/notebook/js/menubar.js | 12 ++---------- notebook/static/notebook/js/notebook.js | 18 +++++++++++++++++- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/notebook/static/notebook/js/actions.js b/notebook/static/notebook/js/actions.js index a7c1d974e..46338900f 100644 --- a/notebook/static/notebook/js/actions.js +++ b/notebook/static/notebook/js/actions.js @@ -694,6 +694,13 @@ define([ // Execute a CM command selected_cell.code_mirror.execCommand('indentAuto'); } + }, + 'close-and-halt': { + cmd: i18n.msg._('shutdown kernel and close window'), + help : i18n.msg._('shutdown kernel and close window'), + handler : function(env) { + env.notebook.close_and_halt(); + } } }; diff --git a/notebook/static/notebook/js/menubar.js b/notebook/static/notebook/js/menubar.js index cd75b36c8..12538e98f 100644 --- a/notebook/static/notebook/js/menubar.js +++ b/notebook/static/notebook/js/menubar.js @@ -232,15 +232,7 @@ define([ }); this.element.find('#kill_and_exit').click(function () { - var close_window = function () { - /** - * allow closing of new tabs in Chromium, impossible in FF - */ - window.open('', '_self', ''); - window.close(); - }; - // finish with close on success or failure - that.notebook.session.delete(close_window, close_window); + that.notebook.close_and_halt(); }); // View @@ -252,7 +244,7 @@ define([ notebook: that.notebook, keyboard_manager: that.notebook.keyboard_manager}); }); - + var id_actions_dict = { '#trust_notebook' : 'trust-notebook', '#rename_notebook' : 'rename-notebook', diff --git a/notebook/static/notebook/js/notebook.js b/notebook/static/notebook/js/notebook.js index df7dc8559..98ceb2bcd 100644 --- a/notebook/static/notebook/js/notebook.js +++ b/notebook/static/notebook/js/notebook.js @@ -2392,13 +2392,29 @@ define([ button.click = function () { promise.then(click); do_kernel_action(); - }; + } }); options.dialog.buttons = buttons; dialog.modal(options.dialog); return promise; }; + /** + * + * Halt the kernel and close the notebook window + */ + Notebook.prototype.close_and_halt = function () { + var close_window = function () { + /** + * allow closing of new tabs in Chromium, impossible in FF + */ + window.open('', '_self', ''); + window.close(); + }; + // finish with close on success or failure + this.session.delete(close_window, close_window); + }; + /** * Execute cells corresponding to the given indices. * From 8888fa4e078ae2568def569d4a4ce346c9bf97ce Mon Sep 17 00:00:00 2001 From: Mac Knight Date: Wed, 7 Feb 2018 11:23:33 -0500 Subject: [PATCH 2/4] fixed removed ';' --- notebook/static/notebook/js/notebook.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notebook/static/notebook/js/notebook.js b/notebook/static/notebook/js/notebook.js index 98ceb2bcd..1d3d61584 100644 --- a/notebook/static/notebook/js/notebook.js +++ b/notebook/static/notebook/js/notebook.js @@ -2392,7 +2392,7 @@ define([ button.click = function () { promise.then(click); do_kernel_action(); - } + }; }); options.dialog.buttons = buttons; dialog.modal(options.dialog); From f5d59ca004bd458b0018830f1081e71da952a697 Mon Sep 17 00:00:00 2001 From: Mac Knight Date: Wed, 7 Feb 2018 11:56:40 -0500 Subject: [PATCH 3/4] connect close_and_halt via id_actions_dict --- notebook/static/notebook/js/menubar.js | 5 +---- notebook/templates/notebook.html | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/notebook/static/notebook/js/menubar.js b/notebook/static/notebook/js/menubar.js index 12538e98f..17a6945a2 100644 --- a/notebook/static/notebook/js/menubar.js +++ b/notebook/static/notebook/js/menubar.js @@ -231,10 +231,6 @@ define([ } }); - this.element.find('#kill_and_exit').click(function () { - that.notebook.close_and_halt(); - }); - // View this._add_celltoolbar_list(); @@ -254,6 +250,7 @@ define([ '#restart_kernel': 'confirm-restart-kernel', '#restart_clear_output': 'confirm-restart-kernel-and-clear-output', '#restart_run_all': 'confirm-restart-kernel-and-run-all-cells', + '#close_and_halt': 'close-and-halt', '#int_kernel': 'interrupt-kernel', '#cut_cell': 'cut-cell', '#copy_cell': 'copy-cell', diff --git a/notebook/templates/notebook.html b/notebook/templates/notebook.html index 19603642c..589efdd47 100644 --- a/notebook/templates/notebook.html +++ b/notebook/templates/notebook.html @@ -124,7 +124,7 @@ data-notebook-path="{{notebook_path | urlencode}}" title="{% trans %}Trust the output of this notebook{% endtrans %}"> {% trans %}Trust Notebook{% endtrans %}
  • -
  • {% trans %}Close and Halt{% endtrans %}
  • From 9b9c19186dbb877483e445bc30fe8ca55760d30d Mon Sep 17 00:00:00 2001 From: Mac Knight Date: Wed, 7 Feb 2018 17:59:18 -0500 Subject: [PATCH 4/4] changed test to reflect new id --- notebook/tests/notebook/shutdown.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notebook/tests/notebook/shutdown.js b/notebook/tests/notebook/shutdown.js index 3bdd38fb0..dfa62d24b 100644 --- a/notebook/tests/notebook/shutdown.js +++ b/notebook/tests/notebook/shutdown.js @@ -25,7 +25,7 @@ casper.notebook_test(function () { this.waitForPopup(''); this.withPopup('', function () { this.thenEvaluate(function () { - $('#kill_and_exit').click(); + $('#close_and_halt').click(); }); this.thenEvaluate(function () {