mirror of
https://github.com/jupyter/notebook.git
synced 2025-03-07 13:07:22 +08:00
Merge pull request #465 from minrk/restart-run-all-dialog-laziness
rework restart-run-all dialog
This commit is contained in:
commit
8224a9d7cd
@ -10,6 +10,7 @@ define(function(require){
|
||||
Object.seal(this);
|
||||
};
|
||||
|
||||
var $ = require('jquery');
|
||||
var events = require('base/js/events');
|
||||
|
||||
/**
|
||||
@ -83,23 +84,43 @@ define(function(require){
|
||||
env.notebook.execute_all_cells();
|
||||
}
|
||||
},
|
||||
'restart-run-all': {
|
||||
help: 'restart the kernel, then re-run the whole notebook',
|
||||
help_index: 'be',
|
||||
'restart-run-all-dialog': {
|
||||
help: 'restart the kernel, then re-run the whole notebook (with dialog)',
|
||||
handler: function (env) {
|
||||
var notebook = env.notebook;
|
||||
notebook.restart_kernel().then(function() {
|
||||
notebook.execute_all_cells();
|
||||
});
|
||||
env.notebook.restart_run_all();
|
||||
}
|
||||
},
|
||||
'restart': {
|
||||
help: 'restart the kernel',
|
||||
'restart-clear-output-dialog': {
|
||||
help: 'restart the kernel and clear all output (with dialog)',
|
||||
handler: function (env) {
|
||||
env.notebook.restart_clear_output();
|
||||
}
|
||||
},
|
||||
'restart-dialog': {
|
||||
help: 'restart the kernel (with dialog)',
|
||||
help_index: 'bf',
|
||||
handler: function (env) {
|
||||
env.notebook.restart_kernel();
|
||||
},
|
||||
},
|
||||
'restart-run-all': {
|
||||
help: 'restart the kernel, then re-run the whole notebook (no confirmation dialog)',
|
||||
handler: function (env) {
|
||||
env.notebook.restart_run_all({confirm: false});
|
||||
}
|
||||
},
|
||||
'restart-clear-output': {
|
||||
help: 'restart the kernel and clear all output (no confirmation dialog)',
|
||||
handler: function (env) {
|
||||
env.notebook.restart_clear_output({confirm: false});
|
||||
}
|
||||
},
|
||||
'restart': {
|
||||
help: 'restart the kernel (no confirmation dialog)',
|
||||
handler: function (env) {
|
||||
env.notebook.restart_kernel({confirm: false});
|
||||
},
|
||||
},
|
||||
'run-all-cells-above':{
|
||||
handler : function (env) {
|
||||
env.notebook.execute_cells_above();
|
||||
@ -507,7 +528,7 @@ define(function(require){
|
||||
'rename-notebook':{
|
||||
help: "Rename current notebook",
|
||||
handler : function (env, event) {
|
||||
env.notebook.save_widget.rename_notebook({notebook: env.notebook})
|
||||
env.notebook.save_widget.rename_notebook({notebook: env.notebook});
|
||||
}
|
||||
},
|
||||
'save-notebook':{
|
||||
|
@ -201,7 +201,9 @@ define([
|
||||
var id_actions_dict = {
|
||||
'#find_and_replace' : 'ipython.find-and-replace-dialog',
|
||||
'#save_checkpoint': 'ipython.save-notebook',
|
||||
'#restart_kernel': 'ipython.restart-kernel',
|
||||
'#restart_kernel': 'ipython.restart-kernel-dialog',
|
||||
'#restart_clear_output': 'ipython.restart-clear-output-dialog',
|
||||
'#restart_run_all': 'ipython.restart-run-all-dialog',
|
||||
'#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();
|
||||
});
|
||||
|
@ -1456,7 +1456,7 @@ define(function (require) {
|
||||
|
||||
// Check if trying to merge above on topmost cell or wrap around
|
||||
// when merging above, see #330
|
||||
if (indices.filter(function(item) {return item < 0}).length > 0) {
|
||||
if (indices.filter(function(item) {return item < 0;}).length > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1480,7 +1480,7 @@ define(function (require) {
|
||||
|
||||
// Update the contents of the target cell
|
||||
if (target instanceof codecell.CodeCell) {
|
||||
target.set_text(contents.join('\n\n'))
|
||||
target.set_text(contents.join('\n\n'));
|
||||
} else {
|
||||
var was_rendered = target.rendered;
|
||||
target.unrender(); // Must unrender before we set_text.
|
||||
@ -1797,10 +1797,86 @@ define(function (require) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Prompt the user to restart the Jupyter kernel.
|
||||
* Prompt the user to restart the kernel and re-run everything.
|
||||
* if options.confirm === false, no confirmation dialog is shown.
|
||||
*/
|
||||
Notebook.prototype.restart_kernel = function () {
|
||||
Notebook.prototype.restart_run_all = function (options) {
|
||||
var that = this;
|
||||
var restart_options = {};
|
||||
restart_options.confirm = (options || {}).confirm;
|
||||
restart_options.dialog = {
|
||||
notebook: that,
|
||||
keyboard_manager: that.keyboard_manager,
|
||||
title : "Restart kernel and re-run the whole notebook?",
|
||||
body : $("<p/>").text(
|
||||
'Are you sure you want to restart the current kernel and re-execute the whole notebook? All variables and outputs will be lost.'
|
||||
),
|
||||
buttons : {
|
||||
"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 and clear output.
|
||||
* if options.confirm === false, no confirmation dialog is shown.
|
||||
*/
|
||||
Notebook.prototype.restart_clear_output = function (options) {
|
||||
var that = this;
|
||||
var restart_options = {};
|
||||
restart_options.confirm = (options || {}).confirm;
|
||||
restart_options.dialog = {
|
||||
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 and clear all output? All variables and outputs will be lost.'
|
||||
),
|
||||
buttons : {
|
||||
"Restart & clear all outputs" : {
|
||||
"class" : "btn-danger",
|
||||
"click" : function (){
|
||||
that.clear_all_output();
|
||||
},
|
||||
},
|
||||
}
|
||||
};
|
||||
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 () {},
|
||||
},
|
||||
}
|
||||
};
|
||||
return this._restart_kernel(restart_options);
|
||||
};
|
||||
|
||||
// inner implementation of restart dialog & promise
|
||||
Notebook.prototype._restart_kernel = function (options) {
|
||||
var that = this;
|
||||
options = options || {};
|
||||
var resolve_promise, reject_promise;
|
||||
var promise = new Promise(function (resolve, reject){
|
||||
resolve_promise = resolve;
|
||||
@ -1813,31 +1889,30 @@ define(function (require) {
|
||||
that.events.one('kernel_ready.Kernel', resolve_promise);
|
||||
}, reject_promise);
|
||||
}
|
||||
|
||||
dialog.modal({
|
||||
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.'
|
||||
),
|
||||
buttons : {
|
||||
"Continue running" : {},
|
||||
"Clear all outputs & restart" : {
|
||||
"class" : "btn-danger",
|
||||
"click" : function(){
|
||||
that.clear_all_output();
|
||||
restart_and_resolve();
|
||||
},
|
||||
},
|
||||
"Restart" : {
|
||||
"class" : "btn-warning",
|
||||
"click" : function() {
|
||||
restart_and_resolve();
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
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 = 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 & Clear Output</a>
|
||||
</li>
|
||||
<li id="restart_run_all"
|
||||
title="Restart the Kernel and re-run the notebook">
|
||||
<a href="#">Restart & Run All</a>
|
||||
|
Loading…
Reference in New Issue
Block a user