Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions notebook/static/notebook/js/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,30 @@ 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.restart_kernel().then(function() {
notebook.execute_all_cells();
});
}
},
'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',
Expand Down
4 changes: 4 additions & 0 deletions notebook/static/notebook/js/menubar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
});
Expand Down
40 changes: 27 additions & 13 deletions notebook/static/notebook/js/notebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -667,11 +667,11 @@ define(function (require) {
}
var current_selection = this.get_selected_cells();
for (var i=0; i<current_selection.length; i++) {
current_selection[i].unselect()
current_selection[i].unselect();
}

var cell = this._select(index);
cell.selection_anchor = true
cell.selection_anchor = true;
}
return this;
};
Expand Down Expand Up @@ -738,7 +738,7 @@ define(function (require) {
var current_selection = this.get_selected_cells();
for (var i=0; i<current_selection.length; i++) {
if (!current_selection[i].selected) {
current_selection[i].unselect()
current_selection[i].unselect();
}
}
};
Expand Down Expand Up @@ -821,7 +821,7 @@ define(function (require) {
var cell = this.get_selected_cell();
if (cell === null) {return;} // No cell is selected
cell.ensure_focused();
}
};

/**
* Focus the currently selected cell.
Expand Down Expand Up @@ -1465,9 +1465,9 @@ define(function (require) {
contents.push(this.get_cell(indices[i]).get_text());
}
if (into_last) {
contents.push(target.get_text())
contents.push(target.get_text());
} else {
contents.unshift(target.get_text())
contents.unshift(target.get_text());
}

// Update the contents of the target cell
Expand Down Expand Up @@ -1502,15 +1502,15 @@ define(function (require) {
*/
Notebook.prototype.merge_cell_above = function () {
var index = this.get_selected_index();
this.merge_cells([index-1, index], true)
this.merge_cells([index-1, index], true);
};

/**
* Merge the selected cell into the cell below it.
*/
Notebook.prototype.merge_cell_below = function () {
var index = this.get_selected_index();
this.merge_cells([index, index+1], false)
this.merge_cells([index, index+1], false);
};


Expand Down Expand Up @@ -1793,9 +1793,22 @@ define(function (require) {
*/
Notebook.prototype.restart_kernel = function () {
var that = this;
var resolve_promise, reject_promise;
var promise = new Promise(function (resolve, reject){
resolve_promise = resolve;
reject_promise = reject;
});

function restart_and_resolve () {
that.kernel.restart(function () {
// resolve when the kernel is *ready* not just started
that.events.one('kernel_ready.Kernel', resolve_promise);
}, reject_promise);
}

dialog.modal({
notebook: this,
keyboard_manager: this.keyboard_manager,
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.'
Expand All @@ -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;
};

/**
Expand Down
4 changes: 4 additions & 0 deletions notebook/templates/notebook.html
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@
title="Restart the Kernel">
<a href="#">Restart</a>
</li>
<li id="restart_run_all"
title="Restart the Kernel and re-run the notebook">
<a href="#">Restart &amp; Run All</a>
</li>
<li id="reconnect_kernel"
title="Reconnect to the Kernel">
<a href="#">Reconnect</a>
Expand Down