add choice of kernel for new notebook

Mathieu 11 years ago
parent 0eb340b3e2
commit 4e5839dde4

@ -33,6 +33,9 @@ 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");
// Create the change kernel submenu
var keys = Object.keys(data.kernelspecs).sort(function (a, b) {
// sort by display_name
var da = data.kernelspecs[a].spec.display_name;
@ -53,6 +56,41 @@ define([
.text(ks.spec.display_name));
change_kernel_submenu.append(ks_submenu_entry);
}
// Create the new notebook submenu
/** This code is supposed to put the current kernel at the top of the submenu
* but at the time _got_kernelspecs gets called, this.notebook.kernel is null
*
* var current_kernel_name = this.notebook.kernel.name
* var keys = Object.keys(data.kernelspecs).sort(function (a, b) {
* // sort by display_name, putting the current kernel on top
* var da = data.kernelspecs[a].spec.display_name;
* var db = data.kernelspecs[b].spec.display_name;
* if (da === db) {
* return 0;
* } else if (db == current_kernel_name || da > db) {
* return 1;
* } else {
* return -1;
* }
* });
*/
/** Uncomment to add header the the new notebook submenu
*
* new_notebook_submenu.append($("<li>").attr("id","notebook-kernels")
* .attr("class","dropdown-header")
* .attr("role","presentation")
* .text("Notebook"))
*/
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) {
@ -122,6 +160,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,7 +98,13 @@ define([
* File
*/
var that = this;
this.element.find('#new_notebook').click(function () {
/*var new_buttons = new newnotebook.NewNotebookWidget("#new-buttons",
$.extend(
{contents: contents},
common_options
)
);*/
/*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.
@ -120,7 +126,7 @@ define([
});
}
);
});
});*/
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));

@ -67,9 +67,10 @@ class="notebook_app"
<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