Merge pull request #7401 from mathieu1/new-notebook-same-kernel

create new notebook with same kernel
Brian E. Granger 11 years ago
commit db10980a8f

@ -33,6 +33,8 @@ define([
KernelSelector.prototype._got_kernelspecs = function(data) {
this.kernelspecs = data.kernelspecs;
var change_kernel_submenu = $("#menu-change-kernel-submenu");
var new_notebook_submenu = $("#menu-new-notebook-submenu");
var keys = Object.keys(data.kernelspecs).sort(function (a, b) {
// sort by display_name
var da = data.kernelspecs[a].spec.display_name;
@ -45,6 +47,8 @@ define([
return -1;
}
});
// Create the Kernel > Change kernel submenu
for (var i = 0; i < keys.length; i++) {
var ks = this.kernelspecs[keys[i]];
var ks_submenu_entry = $("<li>").attr("id", "kernel-submenu-"+ks.name).append($('<a>')
@ -53,6 +57,16 @@ define([
.text(ks.spec.display_name));
change_kernel_submenu.append(ks_submenu_entry);
}
// Create the File > New Notebook submenu
for (var i = 0; i < keys.length; i++) {
var ks = this.kernelspecs[keys[i]];
var ks_submenu_entry = $("<li>").attr("id", "new-notebook-submenu-"+ks.name).append($('<a>')
.attr('href', '#')
.click($.proxy(this.new_notebook, this, ks.name))
.text(ks.spec.display_name));
new_notebook_submenu.append(ks_submenu_entry);
}
};
KernelSelector.prototype._spec_changed = function (event, ks) {
@ -61,6 +75,13 @@ define([
// update selection
this.current_selection = ks.name;
// put the current kernel at the top of File > New Notebook
var cur_kernel_entry = $("#new-notebook-submenu-" + ks.name);
if (cur_kernel_entry.length) {
cur_kernel_entry.parent().prepend($("<li>").attr("class","divider"))
.prepend(cur_kernel_entry);
};
// load logo
var logo_img = this.element.find("img.current_kernel_logo");
$("#kernel_indicator").find('.kernel_indicator_name').text(ks.spec.display_name);
@ -122,6 +143,32 @@ define([
this.events.trigger('spec_changed.Kernel', ks);
};
KernelSelector.prototype.new_notebook = function (kernel_name) {
var w = window.open();
// Create a new notebook in the same path as the current
// notebook's path.
var that = this;
var parent = utils.url_path_split(that.notebook.notebook_path)[0];
that.notebook.contents.new_untitled(parent, {type: "notebook"}).then(
function (data) {
var url = utils.url_join_encode(
that.notebook.base_url, 'notebooks', data.path
);
url += "?kernel_name=" + kernel_name;
w.location = url;
},
function(error) {
w.close();
dialog.modal({
title : 'Creating Notebook Failed',
body : "The error was: " + error.message,
buttons : {'OK' : {'class' : 'btn-primary'}}
});
}
);
};
KernelSelector.prototype.lock_switch = function() {
// should set a flag and display warning+reload if user want to
// re-change kernel. As UI discussion never finish

@ -98,27 +98,7 @@ define([
* File
*/
var that = this;
this.element.find('#new_notebook').click(function () {
var w = window.open();
// Create a new notebook in the same path as the current
// notebook's path.
var parent = utils.url_path_split(that.notebook.notebook_path)[0];
that.contents.new_untitled(parent, {type: "notebook"}).then(
function (data) {
w.location = utils.url_join_encode(
that.base_url, 'notebooks', data.path
);
},
function(error) {
w.close();
dialog.modal({
title : 'Creating Notebook Failed',
body : "The error was: " + error.message,
buttons : {'OK' : {'class' : 'btn-primary'}}
});
}
);
});
this.element.find('#open_notebook').click(function () {
var parent = utils.url_path_split(that.notebook.notebook_path)[0];
window.open(utils.url_join_encode(that.base_url, 'tree', parent));

@ -68,9 +68,10 @@ data-notebook-path="{{notebook_path}}"
<ul class="nav navbar-nav">
<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">File</a>
<ul id="file_menu" class="dropdown-menu">
<li id="new_notebook"
title="Make a new notebook (Opens a new window)">
<a href="#">New</a></li>
<li id="new_notebook" class="dropdown-submenu">
<a href="#">New Notebook</a>
<ul class="dropdown-menu" id="menu-new-notebook-submenu"></ul>
</li>
<li id="open_notebook"
title="Opens a new window with the Dashboard view">
<a href="#">Open...</a></li>

Loading…
Cancel
Save