Show More
@@ -1,424 +1,426 | |||||
1 | // Copyright (c) IPython Development Team. |
|
1 | // Copyright (c) IPython Development Team. | |
2 | // Distributed under the terms of the Modified BSD License. |
|
2 | // Distributed under the terms of the Modified BSD License. | |
3 |
|
3 | |||
4 | define([ |
|
4 | define([ | |
5 | 'jquery', |
|
5 | 'jquery', | |
6 | 'base/js/namespace', |
|
6 | 'base/js/namespace', | |
7 | 'base/js/dialog', |
|
7 | 'base/js/dialog', | |
8 | 'base/js/utils', |
|
8 | 'base/js/utils', | |
9 | 'notebook/js/tour', |
|
9 | 'notebook/js/tour', | |
10 | 'bootstrap', |
|
10 | 'bootstrap', | |
11 | 'moment', |
|
11 | 'moment', | |
12 | ], function($, IPython, dialog, utils, tour, bootstrap, moment) { |
|
12 | ], function($, IPython, dialog, utils, tour, bootstrap, moment) { | |
13 | "use strict"; |
|
13 | "use strict"; | |
14 |
|
14 | |||
15 | var MenuBar = function (selector, options) { |
|
15 | var MenuBar = function (selector, options) { | |
16 | /** |
|
16 | /** | |
17 | * Constructor |
|
17 | * Constructor | |
18 | * |
|
18 | * | |
19 | * A MenuBar Class to generate the menubar of IPython notebook |
|
19 | * A MenuBar Class to generate the menubar of IPython notebook | |
20 | * |
|
20 | * | |
21 | * Parameters: |
|
21 | * Parameters: | |
22 | * selector: string |
|
22 | * selector: string | |
23 | * options: dictionary |
|
23 | * options: dictionary | |
24 | * Dictionary of keyword arguments. |
|
24 | * Dictionary of keyword arguments. | |
25 | * notebook: Notebook instance |
|
25 | * notebook: Notebook instance | |
26 | * contents: ContentManager instance |
|
26 | * contents: ContentManager instance | |
27 | * events: $(Events) instance |
|
27 | * events: $(Events) instance | |
28 | * save_widget: SaveWidget instance |
|
28 | * save_widget: SaveWidget instance | |
29 | * quick_help: QuickHelp instance |
|
29 | * quick_help: QuickHelp instance | |
30 | * base_url : string |
|
30 | * base_url : string | |
31 | * notebook_path : string |
|
31 | * notebook_path : string | |
32 | * notebook_name : string |
|
32 | * notebook_name : string | |
33 | */ |
|
33 | */ | |
34 | options = options || {}; |
|
34 | options = options || {}; | |
35 | this.base_url = options.base_url || utils.get_body_data("baseUrl"); |
|
35 | this.base_url = options.base_url || utils.get_body_data("baseUrl"); | |
36 | this.selector = selector; |
|
36 | this.selector = selector; | |
37 | this.notebook = options.notebook; |
|
37 | this.notebook = options.notebook; | |
38 | this.contents = options.contents; |
|
38 | this.contents = options.contents; | |
39 | this.events = options.events; |
|
39 | this.events = options.events; | |
40 | this.save_widget = options.save_widget; |
|
40 | this.save_widget = options.save_widget; | |
41 | this.quick_help = options.quick_help; |
|
41 | this.quick_help = options.quick_help; | |
42 |
|
42 | |||
43 | try { |
|
43 | try { | |
44 | this.tour = new tour.Tour(this.notebook, this.events); |
|
44 | this.tour = new tour.Tour(this.notebook, this.events); | |
45 | } catch (e) { |
|
45 | } catch (e) { | |
46 | this.tour = undefined; |
|
46 | this.tour = undefined; | |
47 | console.log("Failed to instantiate Notebook Tour", e); |
|
47 | console.log("Failed to instantiate Notebook Tour", e); | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | if (this.selector !== undefined) { |
|
50 | if (this.selector !== undefined) { | |
51 | this.element = $(selector); |
|
51 | this.element = $(selector); | |
52 | this.style(); |
|
52 | this.style(); | |
53 | this.bind_events(); |
|
53 | this.bind_events(); | |
54 | } |
|
54 | } | |
55 | }; |
|
55 | }; | |
56 |
|
56 | |||
57 | // TODO: This has definitively nothing to do with style ... |
|
57 | // TODO: This has definitively nothing to do with style ... | |
58 | MenuBar.prototype.style = function () { |
|
58 | MenuBar.prototype.style = function () { | |
59 | var that = this; |
|
59 | var that = this; | |
60 | this.element.find("li").click(function (event, ui) { |
|
60 | this.element.find("li").click(function (event, ui) { | |
61 | // The selected cell loses focus when the menu is entered, so we |
|
61 | // The selected cell loses focus when the menu is entered, so we | |
62 | // re-select it upon selection. |
|
62 | // re-select it upon selection. | |
63 | var i = that.notebook.get_selected_index(); |
|
63 | var i = that.notebook.get_selected_index(); | |
64 | that.notebook.select(i); |
|
64 | that.notebook.select(i); | |
65 | } |
|
65 | } | |
66 | ); |
|
66 | ); | |
67 | }; |
|
67 | }; | |
68 |
|
68 | |||
69 | MenuBar.prototype._nbconvert = function (format, download) { |
|
69 | MenuBar.prototype._nbconvert = function (format, download) { | |
70 | download = download || false; |
|
70 | download = download || false; | |
71 | var notebook_path = this.notebook.notebook_path; |
|
71 | var notebook_path = this.notebook.notebook_path; | |
72 | var url = utils.url_join_encode( |
|
72 | var url = utils.url_join_encode( | |
73 | this.base_url, |
|
73 | this.base_url, | |
74 | 'nbconvert', |
|
74 | 'nbconvert', | |
75 | format, |
|
75 | format, | |
76 | notebook_path |
|
76 | notebook_path | |
77 | ) + "?download=" + download.toString(); |
|
77 | ) + "?download=" + download.toString(); | |
78 |
|
78 | |||
79 | var w = window.open(); |
|
79 | var w = window.open(); | |
80 | if (this.notebook.dirty) { |
|
80 | if (this.notebook.dirty) { | |
81 | this.notebook.save_notebook().then(function() { |
|
81 | this.notebook.save_notebook().then(function() { | |
82 | w.location = url; |
|
82 | w.location = url; | |
83 | }); |
|
83 | }); | |
84 | } else { |
|
84 | } else { | |
85 | w.location = url; |
|
85 | w.location = url; | |
86 | } |
|
86 | } | |
87 | }; |
|
87 | }; | |
88 |
|
88 | |||
89 | MenuBar.prototype._size_header = function() { |
|
89 | MenuBar.prototype._size_header = function() { | |
90 | /** |
|
90 | /** | |
91 | * Update header spacer size. |
|
91 | * Update header spacer size. | |
92 | */ |
|
92 | */ | |
93 | this.events.trigger('resize-header.Page'); |
|
93 | this.events.trigger('resize-header.Page'); | |
94 | }; |
|
94 | }; | |
95 |
|
95 | |||
96 | MenuBar.prototype.bind_events = function () { |
|
96 | MenuBar.prototype.bind_events = function () { | |
97 | /** |
|
97 | /** | |
98 | * File |
|
98 | * File | |
99 | */ |
|
99 | */ | |
100 | var that = this; |
|
100 | var that = this; | |
101 | this.element.find('#new_notebook').click(function () { |
|
101 | this.element.find('#new_notebook').click(function () { | |
102 | var w = window.open(); |
|
102 | var w = window.open(); | |
103 | // Create a new notebook in the same path as the current |
|
103 | // Create a new notebook in the same path as the current | |
104 | // notebook's path. |
|
104 | // notebook's path. | |
105 | var parent = utils.url_path_split(that.notebook.notebook_path)[0]; |
|
105 | var parent = utils.url_path_split(that.notebook.notebook_path)[0]; | |
106 | that.contents.new_untitled(parent, {type: "notebook"}).then( |
|
106 | that.contents.new_untitled(parent, {type: "notebook"}).then( | |
107 | function (data) { |
|
107 | function (data) { | |
108 |
|
|
108 | var url = utils.url_join_encode( | |
109 |
|
|
109 | that.base_url, 'notebooks', data.path | |
110 |
|
|
110 | ); | |
|
111 | url += "?kernel_name=" + that.notebook.kernel.name; | |||
|
112 | w.location = url; | |||
111 | }, |
|
113 | }, | |
112 | function(error) { |
|
114 | function(error) { | |
113 | w.close(); |
|
115 | w.close(); | |
114 | dialog.modal({ |
|
116 | dialog.modal({ | |
115 | title : 'Creating Notebook Failed', |
|
117 | title : 'Creating Notebook Failed', | |
116 | body : "The error was: " + error.message, |
|
118 | body : "The error was: " + error.message, | |
117 | buttons : {'OK' : {'class' : 'btn-primary'}} |
|
119 | buttons : {'OK' : {'class' : 'btn-primary'}} | |
118 | }); |
|
120 | }); | |
119 | } |
|
121 | } | |
120 | ); |
|
122 | ); | |
121 | }); |
|
123 | }); | |
122 | this.element.find('#open_notebook').click(function () { |
|
124 | this.element.find('#open_notebook').click(function () { | |
123 | var parent = utils.url_path_split(that.notebook.notebook_path)[0]; |
|
125 | var parent = utils.url_path_split(that.notebook.notebook_path)[0]; | |
124 | window.open(utils.url_join_encode(that.base_url, 'tree', parent)); |
|
126 | window.open(utils.url_join_encode(that.base_url, 'tree', parent)); | |
125 | }); |
|
127 | }); | |
126 | this.element.find('#copy_notebook').click(function () { |
|
128 | this.element.find('#copy_notebook').click(function () { | |
127 | that.notebook.copy_notebook(); |
|
129 | that.notebook.copy_notebook(); | |
128 | return false; |
|
130 | return false; | |
129 | }); |
|
131 | }); | |
130 | this.element.find('#download_ipynb').click(function () { |
|
132 | this.element.find('#download_ipynb').click(function () { | |
131 | var base_url = that.notebook.base_url; |
|
133 | var base_url = that.notebook.base_url; | |
132 | var notebook_path = that.notebook.notebook_path; |
|
134 | var notebook_path = that.notebook.notebook_path; | |
133 | if (that.notebook.dirty) { |
|
135 | if (that.notebook.dirty) { | |
134 | that.notebook.save_notebook({async : false}); |
|
136 | that.notebook.save_notebook({async : false}); | |
135 | } |
|
137 | } | |
136 |
|
138 | |||
137 | var url = utils.url_join_encode(base_url, 'files', notebook_path); |
|
139 | var url = utils.url_join_encode(base_url, 'files', notebook_path); | |
138 | window.open(url + '?download=1'); |
|
140 | window.open(url + '?download=1'); | |
139 | }); |
|
141 | }); | |
140 |
|
142 | |||
141 | this.element.find('#print_preview').click(function () { |
|
143 | this.element.find('#print_preview').click(function () { | |
142 | that._nbconvert('html', false); |
|
144 | that._nbconvert('html', false); | |
143 | }); |
|
145 | }); | |
144 |
|
146 | |||
145 | this.element.find('#download_html').click(function () { |
|
147 | this.element.find('#download_html').click(function () { | |
146 | that._nbconvert('html', true); |
|
148 | that._nbconvert('html', true); | |
147 | }); |
|
149 | }); | |
148 |
|
150 | |||
149 | this.element.find('#download_rst').click(function () { |
|
151 | this.element.find('#download_rst').click(function () { | |
150 | that._nbconvert('rst', true); |
|
152 | that._nbconvert('rst', true); | |
151 | }); |
|
153 | }); | |
152 |
|
154 | |||
153 | this.element.find('#download_pdf').click(function () { |
|
155 | this.element.find('#download_pdf').click(function () { | |
154 | that._nbconvert('pdf', true); |
|
156 | that._nbconvert('pdf', true); | |
155 | }); |
|
157 | }); | |
156 |
|
158 | |||
157 | this.element.find('#download_script').click(function () { |
|
159 | this.element.find('#download_script').click(function () { | |
158 | that._nbconvert('script', true); |
|
160 | that._nbconvert('script', true); | |
159 | }); |
|
161 | }); | |
160 |
|
162 | |||
161 | this.element.find('#rename_notebook').click(function () { |
|
163 | this.element.find('#rename_notebook').click(function () { | |
162 | that.save_widget.rename_notebook({notebook: that.notebook}); |
|
164 | that.save_widget.rename_notebook({notebook: that.notebook}); | |
163 | }); |
|
165 | }); | |
164 | this.element.find('#save_checkpoint').click(function () { |
|
166 | this.element.find('#save_checkpoint').click(function () { | |
165 | that.notebook.save_checkpoint(); |
|
167 | that.notebook.save_checkpoint(); | |
166 | }); |
|
168 | }); | |
167 | this.element.find('#restore_checkpoint').click(function () { |
|
169 | this.element.find('#restore_checkpoint').click(function () { | |
168 | }); |
|
170 | }); | |
169 | this.element.find('#trust_notebook').click(function () { |
|
171 | this.element.find('#trust_notebook').click(function () { | |
170 | that.notebook.trust_notebook(); |
|
172 | that.notebook.trust_notebook(); | |
171 | }); |
|
173 | }); | |
172 | this.events.on('trust_changed.Notebook', function (event, trusted) { |
|
174 | this.events.on('trust_changed.Notebook', function (event, trusted) { | |
173 | if (trusted) { |
|
175 | if (trusted) { | |
174 | that.element.find('#trust_notebook') |
|
176 | that.element.find('#trust_notebook') | |
175 | .addClass("disabled") |
|
177 | .addClass("disabled") | |
176 | .find("a").text("Trusted Notebook"); |
|
178 | .find("a").text("Trusted Notebook"); | |
177 | } else { |
|
179 | } else { | |
178 | that.element.find('#trust_notebook') |
|
180 | that.element.find('#trust_notebook') | |
179 | .removeClass("disabled") |
|
181 | .removeClass("disabled") | |
180 | .find("a").text("Trust Notebook"); |
|
182 | .find("a").text("Trust Notebook"); | |
181 | } |
|
183 | } | |
182 | }); |
|
184 | }); | |
183 | this.element.find('#kill_and_exit').click(function () { |
|
185 | this.element.find('#kill_and_exit').click(function () { | |
184 | var close_window = function () { |
|
186 | var close_window = function () { | |
185 | /** |
|
187 | /** | |
186 | * allow closing of new tabs in Chromium, impossible in FF |
|
188 | * allow closing of new tabs in Chromium, impossible in FF | |
187 | */ |
|
189 | */ | |
188 | window.open('', '_self', ''); |
|
190 | window.open('', '_self', ''); | |
189 | window.close(); |
|
191 | window.close(); | |
190 | }; |
|
192 | }; | |
191 | // finish with close on success or failure |
|
193 | // finish with close on success or failure | |
192 | that.notebook.session.delete(close_window, close_window); |
|
194 | that.notebook.session.delete(close_window, close_window); | |
193 | }); |
|
195 | }); | |
194 | // Edit |
|
196 | // Edit | |
195 | this.element.find('#cut_cell').click(function () { |
|
197 | this.element.find('#cut_cell').click(function () { | |
196 | that.notebook.cut_cell(); |
|
198 | that.notebook.cut_cell(); | |
197 | }); |
|
199 | }); | |
198 | this.element.find('#copy_cell').click(function () { |
|
200 | this.element.find('#copy_cell').click(function () { | |
199 | that.notebook.copy_cell(); |
|
201 | that.notebook.copy_cell(); | |
200 | }); |
|
202 | }); | |
201 | this.element.find('#delete_cell').click(function () { |
|
203 | this.element.find('#delete_cell').click(function () { | |
202 | that.notebook.delete_cell(); |
|
204 | that.notebook.delete_cell(); | |
203 | }); |
|
205 | }); | |
204 | this.element.find('#undelete_cell').click(function () { |
|
206 | this.element.find('#undelete_cell').click(function () { | |
205 | that.notebook.undelete_cell(); |
|
207 | that.notebook.undelete_cell(); | |
206 | }); |
|
208 | }); | |
207 | this.element.find('#split_cell').click(function () { |
|
209 | this.element.find('#split_cell').click(function () { | |
208 | that.notebook.split_cell(); |
|
210 | that.notebook.split_cell(); | |
209 | }); |
|
211 | }); | |
210 | this.element.find('#merge_cell_above').click(function () { |
|
212 | this.element.find('#merge_cell_above').click(function () { | |
211 | that.notebook.merge_cell_above(); |
|
213 | that.notebook.merge_cell_above(); | |
212 | }); |
|
214 | }); | |
213 | this.element.find('#merge_cell_below').click(function () { |
|
215 | this.element.find('#merge_cell_below').click(function () { | |
214 | that.notebook.merge_cell_below(); |
|
216 | that.notebook.merge_cell_below(); | |
215 | }); |
|
217 | }); | |
216 | this.element.find('#move_cell_up').click(function () { |
|
218 | this.element.find('#move_cell_up').click(function () { | |
217 | that.notebook.move_cell_up(); |
|
219 | that.notebook.move_cell_up(); | |
218 | }); |
|
220 | }); | |
219 | this.element.find('#move_cell_down').click(function () { |
|
221 | this.element.find('#move_cell_down').click(function () { | |
220 | that.notebook.move_cell_down(); |
|
222 | that.notebook.move_cell_down(); | |
221 | }); |
|
223 | }); | |
222 | this.element.find('#edit_nb_metadata').click(function () { |
|
224 | this.element.find('#edit_nb_metadata').click(function () { | |
223 | that.notebook.edit_metadata({ |
|
225 | that.notebook.edit_metadata({ | |
224 | notebook: that.notebook, |
|
226 | notebook: that.notebook, | |
225 | keyboard_manager: that.notebook.keyboard_manager}); |
|
227 | keyboard_manager: that.notebook.keyboard_manager}); | |
226 | }); |
|
228 | }); | |
227 |
|
229 | |||
228 | // View |
|
230 | // View | |
229 | this.element.find('#toggle_header').click(function () { |
|
231 | this.element.find('#toggle_header').click(function () { | |
230 | $('div#header-container').toggle(); |
|
232 | $('div#header-container').toggle(); | |
231 | that._size_header(); |
|
233 | that._size_header(); | |
232 | }); |
|
234 | }); | |
233 | this.element.find('#toggle_toolbar').click(function () { |
|
235 | this.element.find('#toggle_toolbar').click(function () { | |
234 | $('div#maintoolbar').toggle(); |
|
236 | $('div#maintoolbar').toggle(); | |
235 | that._size_header(); |
|
237 | that._size_header(); | |
236 | }); |
|
238 | }); | |
237 | // Insert |
|
239 | // Insert | |
238 | this.element.find('#insert_cell_above').click(function () { |
|
240 | this.element.find('#insert_cell_above').click(function () { | |
239 | that.notebook.insert_cell_above('code'); |
|
241 | that.notebook.insert_cell_above('code'); | |
240 | that.notebook.select_prev(); |
|
242 | that.notebook.select_prev(); | |
241 | }); |
|
243 | }); | |
242 | this.element.find('#insert_cell_below').click(function () { |
|
244 | this.element.find('#insert_cell_below').click(function () { | |
243 | that.notebook.insert_cell_below('code'); |
|
245 | that.notebook.insert_cell_below('code'); | |
244 | that.notebook.select_next(); |
|
246 | that.notebook.select_next(); | |
245 | }); |
|
247 | }); | |
246 | // Cell |
|
248 | // Cell | |
247 | this.element.find('#run_cell').click(function () { |
|
249 | this.element.find('#run_cell').click(function () { | |
248 | that.notebook.execute_cell(); |
|
250 | that.notebook.execute_cell(); | |
249 | }); |
|
251 | }); | |
250 | this.element.find('#run_cell_select_below').click(function () { |
|
252 | this.element.find('#run_cell_select_below').click(function () { | |
251 | that.notebook.execute_cell_and_select_below(); |
|
253 | that.notebook.execute_cell_and_select_below(); | |
252 | }); |
|
254 | }); | |
253 | this.element.find('#run_cell_insert_below').click(function () { |
|
255 | this.element.find('#run_cell_insert_below').click(function () { | |
254 | that.notebook.execute_cell_and_insert_below(); |
|
256 | that.notebook.execute_cell_and_insert_below(); | |
255 | }); |
|
257 | }); | |
256 | this.element.find('#run_all_cells').click(function () { |
|
258 | this.element.find('#run_all_cells').click(function () { | |
257 | that.notebook.execute_all_cells(); |
|
259 | that.notebook.execute_all_cells(); | |
258 | }); |
|
260 | }); | |
259 | this.element.find('#run_all_cells_above').click(function () { |
|
261 | this.element.find('#run_all_cells_above').click(function () { | |
260 | that.notebook.execute_cells_above(); |
|
262 | that.notebook.execute_cells_above(); | |
261 | }); |
|
263 | }); | |
262 | this.element.find('#run_all_cells_below').click(function () { |
|
264 | this.element.find('#run_all_cells_below').click(function () { | |
263 | that.notebook.execute_cells_below(); |
|
265 | that.notebook.execute_cells_below(); | |
264 | }); |
|
266 | }); | |
265 | this.element.find('#to_code').click(function () { |
|
267 | this.element.find('#to_code').click(function () { | |
266 | that.notebook.to_code(); |
|
268 | that.notebook.to_code(); | |
267 | }); |
|
269 | }); | |
268 | this.element.find('#to_markdown').click(function () { |
|
270 | this.element.find('#to_markdown').click(function () { | |
269 | that.notebook.to_markdown(); |
|
271 | that.notebook.to_markdown(); | |
270 | }); |
|
272 | }); | |
271 | this.element.find('#to_raw').click(function () { |
|
273 | this.element.find('#to_raw').click(function () { | |
272 | that.notebook.to_raw(); |
|
274 | that.notebook.to_raw(); | |
273 | }); |
|
275 | }); | |
274 |
|
276 | |||
275 | this.element.find('#toggle_current_output').click(function () { |
|
277 | this.element.find('#toggle_current_output').click(function () { | |
276 | that.notebook.toggle_output(); |
|
278 | that.notebook.toggle_output(); | |
277 | }); |
|
279 | }); | |
278 | this.element.find('#toggle_current_output_scroll').click(function () { |
|
280 | this.element.find('#toggle_current_output_scroll').click(function () { | |
279 | that.notebook.toggle_output_scroll(); |
|
281 | that.notebook.toggle_output_scroll(); | |
280 | }); |
|
282 | }); | |
281 | this.element.find('#clear_current_output').click(function () { |
|
283 | this.element.find('#clear_current_output').click(function () { | |
282 | that.notebook.clear_output(); |
|
284 | that.notebook.clear_output(); | |
283 | }); |
|
285 | }); | |
284 |
|
286 | |||
285 | this.element.find('#toggle_all_output').click(function () { |
|
287 | this.element.find('#toggle_all_output').click(function () { | |
286 | that.notebook.toggle_all_output(); |
|
288 | that.notebook.toggle_all_output(); | |
287 | }); |
|
289 | }); | |
288 | this.element.find('#toggle_all_output_scroll').click(function () { |
|
290 | this.element.find('#toggle_all_output_scroll').click(function () { | |
289 | that.notebook.toggle_all_output_scroll(); |
|
291 | that.notebook.toggle_all_output_scroll(); | |
290 | }); |
|
292 | }); | |
291 | this.element.find('#clear_all_output').click(function () { |
|
293 | this.element.find('#clear_all_output').click(function () { | |
292 | that.notebook.clear_all_output(); |
|
294 | that.notebook.clear_all_output(); | |
293 | }); |
|
295 | }); | |
294 |
|
296 | |||
295 | // Kernel |
|
297 | // Kernel | |
296 | this.element.find('#int_kernel').click(function () { |
|
298 | this.element.find('#int_kernel').click(function () { | |
297 | that.notebook.kernel.interrupt(); |
|
299 | that.notebook.kernel.interrupt(); | |
298 | }); |
|
300 | }); | |
299 | this.element.find('#restart_kernel').click(function () { |
|
301 | this.element.find('#restart_kernel').click(function () { | |
300 | that.notebook.restart_kernel(); |
|
302 | that.notebook.restart_kernel(); | |
301 | }); |
|
303 | }); | |
302 | this.element.find('#reconnect_kernel').click(function () { |
|
304 | this.element.find('#reconnect_kernel').click(function () { | |
303 | that.notebook.kernel.reconnect(); |
|
305 | that.notebook.kernel.reconnect(); | |
304 | }); |
|
306 | }); | |
305 | // Help |
|
307 | // Help | |
306 | if (this.tour) { |
|
308 | if (this.tour) { | |
307 | this.element.find('#notebook_tour').click(function () { |
|
309 | this.element.find('#notebook_tour').click(function () { | |
308 | that.tour.start(); |
|
310 | that.tour.start(); | |
309 | }); |
|
311 | }); | |
310 | } else { |
|
312 | } else { | |
311 | this.element.find('#notebook_tour').addClass("disabled"); |
|
313 | this.element.find('#notebook_tour').addClass("disabled"); | |
312 | } |
|
314 | } | |
313 | this.element.find('#keyboard_shortcuts').click(function () { |
|
315 | this.element.find('#keyboard_shortcuts').click(function () { | |
314 | that.quick_help.show_keyboard_shortcuts(); |
|
316 | that.quick_help.show_keyboard_shortcuts(); | |
315 | }); |
|
317 | }); | |
316 |
|
318 | |||
317 | this.update_restore_checkpoint(null); |
|
319 | this.update_restore_checkpoint(null); | |
318 |
|
320 | |||
319 | this.events.on('checkpoints_listed.Notebook', function (event, data) { |
|
321 | this.events.on('checkpoints_listed.Notebook', function (event, data) { | |
320 | that.update_restore_checkpoint(that.notebook.checkpoints); |
|
322 | that.update_restore_checkpoint(that.notebook.checkpoints); | |
321 | }); |
|
323 | }); | |
322 |
|
324 | |||
323 | this.events.on('checkpoint_created.Notebook', function (event, data) { |
|
325 | this.events.on('checkpoint_created.Notebook', function (event, data) { | |
324 | that.update_restore_checkpoint(that.notebook.checkpoints); |
|
326 | that.update_restore_checkpoint(that.notebook.checkpoints); | |
325 | }); |
|
327 | }); | |
326 |
|
328 | |||
327 | this.events.on('notebook_loaded.Notebook', function() { |
|
329 | this.events.on('notebook_loaded.Notebook', function() { | |
328 | var langinfo = that.notebook.metadata.language_info || {}; |
|
330 | var langinfo = that.notebook.metadata.language_info || {}; | |
329 | that.update_nbconvert_script(langinfo); |
|
331 | that.update_nbconvert_script(langinfo); | |
330 | }); |
|
332 | }); | |
331 |
|
333 | |||
332 | this.events.on('kernel_ready.Kernel', function(event, data) { |
|
334 | this.events.on('kernel_ready.Kernel', function(event, data) { | |
333 | var langinfo = data.kernel.info_reply.language_info || {}; |
|
335 | var langinfo = data.kernel.info_reply.language_info || {}; | |
334 | that.update_nbconvert_script(langinfo); |
|
336 | that.update_nbconvert_script(langinfo); | |
335 | that.add_kernel_help_links(data.kernel.info_reply.help_links || []); |
|
337 | that.add_kernel_help_links(data.kernel.info_reply.help_links || []); | |
336 | }); |
|
338 | }); | |
337 | }; |
|
339 | }; | |
338 |
|
340 | |||
339 | MenuBar.prototype.update_restore_checkpoint = function(checkpoints) { |
|
341 | MenuBar.prototype.update_restore_checkpoint = function(checkpoints) { | |
340 | var ul = this.element.find("#restore_checkpoint").find("ul"); |
|
342 | var ul = this.element.find("#restore_checkpoint").find("ul"); | |
341 | ul.empty(); |
|
343 | ul.empty(); | |
342 | if (!checkpoints || checkpoints.length === 0) { |
|
344 | if (!checkpoints || checkpoints.length === 0) { | |
343 | ul.append( |
|
345 | ul.append( | |
344 | $("<li/>") |
|
346 | $("<li/>") | |
345 | .addClass("disabled") |
|
347 | .addClass("disabled") | |
346 | .append( |
|
348 | .append( | |
347 | $("<a/>") |
|
349 | $("<a/>") | |
348 | .text("No checkpoints") |
|
350 | .text("No checkpoints") | |
349 | ) |
|
351 | ) | |
350 | ); |
|
352 | ); | |
351 | return; |
|
353 | return; | |
352 | } |
|
354 | } | |
353 |
|
355 | |||
354 | var that = this; |
|
356 | var that = this; | |
355 | checkpoints.map(function (checkpoint) { |
|
357 | checkpoints.map(function (checkpoint) { | |
356 | var d = new Date(checkpoint.last_modified); |
|
358 | var d = new Date(checkpoint.last_modified); | |
357 | ul.append( |
|
359 | ul.append( | |
358 | $("<li/>").append( |
|
360 | $("<li/>").append( | |
359 | $("<a/>") |
|
361 | $("<a/>") | |
360 | .attr("href", "#") |
|
362 | .attr("href", "#") | |
361 | .text(moment(d).format("LLLL")) |
|
363 | .text(moment(d).format("LLLL")) | |
362 | .click(function () { |
|
364 | .click(function () { | |
363 | that.notebook.restore_checkpoint_dialog(checkpoint); |
|
365 | that.notebook.restore_checkpoint_dialog(checkpoint); | |
364 | }) |
|
366 | }) | |
365 | ) |
|
367 | ) | |
366 | ); |
|
368 | ); | |
367 | }); |
|
369 | }); | |
368 | }; |
|
370 | }; | |
369 |
|
371 | |||
370 | MenuBar.prototype.update_nbconvert_script = function(langinfo) { |
|
372 | MenuBar.prototype.update_nbconvert_script = function(langinfo) { | |
371 | /** |
|
373 | /** | |
372 | * Set the 'Download as foo' menu option for the relevant language. |
|
374 | * Set the 'Download as foo' menu option for the relevant language. | |
373 | */ |
|
375 | */ | |
374 | var el = this.element.find('#download_script'); |
|
376 | var el = this.element.find('#download_script'); | |
375 |
|
377 | |||
376 | // Set menu entry text to e.g. "Python (.py)" |
|
378 | // Set menu entry text to e.g. "Python (.py)" | |
377 | var langname = (langinfo.name || 'Script'); |
|
379 | var langname = (langinfo.name || 'Script'); | |
378 | langname = langname.charAt(0).toUpperCase()+langname.substr(1); // Capitalise |
|
380 | langname = langname.charAt(0).toUpperCase()+langname.substr(1); // Capitalise | |
379 | el.find('a').text(langname + ' ('+(langinfo.file_extension || 'txt')+')'); |
|
381 | el.find('a').text(langname + ' ('+(langinfo.file_extension || 'txt')+')'); | |
380 | }; |
|
382 | }; | |
381 |
|
383 | |||
382 | MenuBar.prototype.add_kernel_help_links = function(help_links) { |
|
384 | MenuBar.prototype.add_kernel_help_links = function(help_links) { | |
383 | /** add links from kernel_info to the help menu */ |
|
385 | /** add links from kernel_info to the help menu */ | |
384 | var divider = $("#kernel-help-links"); |
|
386 | var divider = $("#kernel-help-links"); | |
385 | if (divider.length === 0) { |
|
387 | if (divider.length === 0) { | |
386 | // insert kernel help section above about link |
|
388 | // insert kernel help section above about link | |
387 | var about = $("#notebook_about").parent(); |
|
389 | var about = $("#notebook_about").parent(); | |
388 | divider = $("<li>") |
|
390 | divider = $("<li>") | |
389 | .attr('id', "kernel-help-links") |
|
391 | .attr('id', "kernel-help-links") | |
390 | .addClass('divider'); |
|
392 | .addClass('divider'); | |
391 | about.prev().before(divider); |
|
393 | about.prev().before(divider); | |
392 | } |
|
394 | } | |
393 | // remove previous entries |
|
395 | // remove previous entries | |
394 | while (!divider.next().hasClass('divider')) { |
|
396 | while (!divider.next().hasClass('divider')) { | |
395 | divider.next().remove(); |
|
397 | divider.next().remove(); | |
396 | } |
|
398 | } | |
397 | if (help_links.length === 0) { |
|
399 | if (help_links.length === 0) { | |
398 | // no help links, remove the divider |
|
400 | // no help links, remove the divider | |
399 | divider.remove(); |
|
401 | divider.remove(); | |
400 | return; |
|
402 | return; | |
401 | } |
|
403 | } | |
402 | var cursor = divider; |
|
404 | var cursor = divider; | |
403 | help_links.map(function (link) { |
|
405 | help_links.map(function (link) { | |
404 | cursor.after($("<li>") |
|
406 | cursor.after($("<li>") | |
405 | .append($("<a>") |
|
407 | .append($("<a>") | |
406 | .attr('target', '_blank') |
|
408 | .attr('target', '_blank') | |
407 | .attr('title', 'Opens in a new window') |
|
409 | .attr('title', 'Opens in a new window') | |
408 | .attr('href', link.url) |
|
410 | .attr('href', link.url) | |
409 | .text(link.text) |
|
411 | .text(link.text) | |
410 | .append($("<i>") |
|
412 | .append($("<i>") | |
411 | .addClass("fa fa-external-link menu-icon pull-right") |
|
413 | .addClass("fa fa-external-link menu-icon pull-right") | |
412 | ) |
|
414 | ) | |
413 | ) |
|
415 | ) | |
414 | ); |
|
416 | ); | |
415 | cursor = cursor.next(); |
|
417 | cursor = cursor.next(); | |
416 | }); |
|
418 | }); | |
417 |
|
419 | |||
418 | }; |
|
420 | }; | |
419 |
|
421 | |||
420 | // Backwards compatability. |
|
422 | // Backwards compatability. | |
421 | IPython.MenuBar = MenuBar; |
|
423 | IPython.MenuBar = MenuBar; | |
422 |
|
424 | |||
423 | return {'MenuBar': MenuBar}; |
|
425 | return {'MenuBar': MenuBar}; | |
424 | }); |
|
426 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now