Show More
@@ -33,6 +33,9 b' define([' | |||
|
33 | 33 | KernelSelector.prototype._got_kernelspecs = function(data) { |
|
34 | 34 | this.kernelspecs = data.kernelspecs; |
|
35 | 35 | var change_kernel_submenu = $("#menu-change-kernel-submenu"); |
|
36 | var new_notebook_submenu = $("#menu-new-notebook-submenu"); | |
|
37 | ||
|
38 | // Create the change kernel submenu | |
|
36 | 39 | var keys = Object.keys(data.kernelspecs).sort(function (a, b) { |
|
37 | 40 | // sort by display_name |
|
38 | 41 | var da = data.kernelspecs[a].spec.display_name; |
@@ -53,6 +56,41 b' define([' | |||
|
53 | 56 | .text(ks.spec.display_name)); |
|
54 | 57 | change_kernel_submenu.append(ks_submenu_entry); |
|
55 | 58 | } |
|
59 | ||
|
60 | // Create the new notebook submenu | |
|
61 | /** This code is supposed to put the current kernel at the top of the submenu | |
|
62 | * but at the time _got_kernelspecs gets called, this.notebook.kernel is null | |
|
63 | * | |
|
64 | * var current_kernel_name = this.notebook.kernel.name | |
|
65 | * var keys = Object.keys(data.kernelspecs).sort(function (a, b) { | |
|
66 | * // sort by display_name, putting the current kernel on top | |
|
67 | * var da = data.kernelspecs[a].spec.display_name; | |
|
68 | * var db = data.kernelspecs[b].spec.display_name; | |
|
69 | * if (da === db) { | |
|
70 | * return 0; | |
|
71 | * } else if (db == current_kernel_name || da > db) { | |
|
72 | * return 1; | |
|
73 | * } else { | |
|
74 | * return -1; | |
|
75 | * } | |
|
76 | * }); | |
|
77 | */ | |
|
78 | ||
|
79 | /** Uncomment to add header the the new notebook submenu | |
|
80 | * | |
|
81 | * new_notebook_submenu.append($("<li>").attr("id","notebook-kernels") | |
|
82 | * .attr("class","dropdown-header") | |
|
83 | * .attr("role","presentation") | |
|
84 | * .text("Notebook")) | |
|
85 | */ | |
|
86 | for (var i = 0; i < keys.length; i++) { | |
|
87 | var ks = this.kernelspecs[keys[i]]; | |
|
88 | var ks_submenu_entry = $("<li>").attr("id", "new-notebook-submenu-"+ks.name).append($('<a>') | |
|
89 | .attr('href', '#') | |
|
90 | .click($.proxy(this.new_notebook, this, ks.name)) | |
|
91 | .text(ks.spec.display_name)); | |
|
92 | new_notebook_submenu.append(ks_submenu_entry); | |
|
93 | } | |
|
56 | 94 | }; |
|
57 | 95 | |
|
58 | 96 | KernelSelector.prototype._spec_changed = function (event, ks) { |
@@ -122,6 +160,32 b' define([' | |||
|
122 | 160 | this.events.trigger('spec_changed.Kernel', ks); |
|
123 | 161 | }; |
|
124 | 162 | |
|
163 | KernelSelector.prototype.new_notebook = function (kernel_name) { | |
|
164 | ||
|
165 | var w = window.open(); | |
|
166 | // Create a new notebook in the same path as the current | |
|
167 | // notebook's path. | |
|
168 | var that = this; | |
|
169 | var parent = utils.url_path_split(that.notebook.notebook_path)[0]; | |
|
170 | that.notebook.contents.new_untitled(parent, {type: "notebook"}).then( | |
|
171 | function (data) { | |
|
172 | var url = utils.url_join_encode( | |
|
173 | that.notebook.base_url, 'notebooks', data.path | |
|
174 | ); | |
|
175 | url += "?kernel_name=" + kernel_name; | |
|
176 | w.location = url; | |
|
177 | }, | |
|
178 | function(error) { | |
|
179 | w.close(); | |
|
180 | dialog.modal({ | |
|
181 | title : 'Creating Notebook Failed', | |
|
182 | body : "The error was: " + error.message, | |
|
183 | buttons : {'OK' : {'class' : 'btn-primary'}} | |
|
184 | }); | |
|
185 | } | |
|
186 | ); | |
|
187 | }; | |
|
188 | ||
|
125 | 189 | KernelSelector.prototype.lock_switch = function() { |
|
126 | 190 | // should set a flag and display warning+reload if user want to |
|
127 | 191 | // re-change kernel. As UI discussion never finish |
@@ -98,7 +98,13 b' define([' | |||
|
98 | 98 | * File |
|
99 | 99 | */ |
|
100 | 100 | var that = this; |
|
101 | this.element.find('#new_notebook').click(function () { | |
|
101 | /*var new_buttons = new newnotebook.NewNotebookWidget("#new-buttons", | |
|
102 | $.extend( | |
|
103 | {contents: contents}, | |
|
104 | common_options | |
|
105 | ) | |
|
106 | );*/ | |
|
107 | /*this.element.find('#new_notebook').click(function () { | |
|
102 | 108 | var w = window.open(); |
|
103 | 109 | // Create a new notebook in the same path as the current |
|
104 | 110 | // notebook's path. |
@@ -120,7 +126,7 b' define([' | |||
|
120 | 126 | }); |
|
121 | 127 | } |
|
122 | 128 | ); |
|
123 | }); | |
|
129 | });*/ | |
|
124 | 130 | this.element.find('#open_notebook').click(function () { |
|
125 | 131 | var parent = utils.url_path_split(that.notebook.notebook_path)[0]; |
|
126 | 132 | window.open(utils.url_join_encode(that.base_url, 'tree', parent)); |
@@ -67,9 +67,10 b' class="notebook_app"' | |||
|
67 | 67 | <ul class="nav navbar-nav"> |
|
68 | 68 | <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">File</a> |
|
69 | 69 | <ul id="file_menu" class="dropdown-menu"> |
|
70 | <li id="new_notebook" | |
|
71 |
|
|
|
72 | <a href="#">New</a></li> | |
|
70 | <li id="new_notebook" class="dropdown-submenu"> | |
|
71 | <a href="#">New Notebook</a> | |
|
72 | <ul class="dropdown-menu" id="menu-new-notebook-submenu"></ul> | |
|
73 | </li> | |
|
73 | 74 | <li id="open_notebook" |
|
74 | 75 | title="Opens a new window with the Dashboard view"> |
|
75 | 76 | <a href="#">Open...</a></li> |
General Comments 0
You need to be logged in to leave comments.
Login now