Show More
@@ -1,351 +1,350 | |||
|
1 | 1 | // Copyright (c) IPython Development Team. |
|
2 | 2 | // Distributed under the terms of the Modified BSD License. |
|
3 | 3 | |
|
4 | 4 | define([ |
|
5 | 5 | 'base/js/namespace', |
|
6 | 6 | 'jquery', |
|
7 | 7 | 'base/js/utils', |
|
8 | 8 | 'notebook/js/tour', |
|
9 | 9 | 'bootstrap', |
|
10 | 10 | ], function(IPython, $, utils, tour) { |
|
11 | 11 | "use strict"; |
|
12 | 12 | |
|
13 | 13 | var MenuBar = function (selector, options) { |
|
14 | 14 | // Constructor |
|
15 | 15 | // |
|
16 | 16 | // A MenuBar Class to generate the menubar of IPython notebook |
|
17 | 17 | // |
|
18 | 18 | // Parameters: |
|
19 | 19 | // selector: string |
|
20 | 20 | // options: dictionary |
|
21 | 21 | // Dictionary of keyword arguments. |
|
22 | 22 | // notebook: Notebook instance |
|
23 | 23 | // layout_manager: LayoutManager instance |
|
24 | 24 | // events: $(Events) instance |
|
25 | 25 | // save_widget: SaveWidget instance |
|
26 | 26 | // quick_help: QuickHelp instance |
|
27 | 27 | // base_url : string |
|
28 | 28 | // notebook_path : string |
|
29 | 29 | // notebook_name : string |
|
30 | 30 | options = options || {}; |
|
31 | 31 | this.base_url = options.base_url || utils.get_body_data("baseUrl"); |
|
32 | 32 | this.selector = selector; |
|
33 | 33 | this.notebook = options.notebook; |
|
34 | 34 | this.layout_manager = options.layout_manager; |
|
35 | 35 | this.events = options.events; |
|
36 | 36 | this.save_widget = options.save_widget; |
|
37 | 37 | this.quick_help = options.quick_help; |
|
38 | 38 | |
|
39 | 39 | try { |
|
40 | 40 | this.tour = new tour.Tour(this.notebook, this.events); |
|
41 | 41 | } catch (e) { |
|
42 | 42 | this.tour = undefined; |
|
43 | 43 | console.log("Failed to instantiate Notebook Tour", e); |
|
44 | 44 | } |
|
45 | 45 | |
|
46 | 46 | if (this.selector !== undefined) { |
|
47 | 47 | this.element = $(selector); |
|
48 | 48 | this.style(); |
|
49 | 49 | this.bind_events(); |
|
50 | 50 | } |
|
51 | 51 | }; |
|
52 | 52 | |
|
53 | 53 | MenuBar.prototype.style = function () { |
|
54 | 54 | var that = this; |
|
55 | this.element.addClass('border-box-sizing'); | |
|
56 | 55 | this.element.find("li").click(function (event, ui) { |
|
57 | 56 | // The selected cell loses focus when the menu is entered, so we |
|
58 | 57 | // re-select it upon selection. |
|
59 | 58 | var i = that.notebook.get_selected_index(); |
|
60 | 59 | that.notebook.select(i); |
|
61 | 60 | } |
|
62 | 61 | ); |
|
63 | 62 | }; |
|
64 | 63 | |
|
65 | 64 | MenuBar.prototype._nbconvert = function (format, download) { |
|
66 | 65 | download = download || false; |
|
67 | 66 | var notebook_path = this.notebook.notebook_path; |
|
68 | 67 | var notebook_name = this.notebook.notebook_name; |
|
69 | 68 | if (this.notebook.dirty) { |
|
70 | 69 | this.notebook.save_notebook({async : false}); |
|
71 | 70 | } |
|
72 | 71 | var url = utils.url_join_encode( |
|
73 | 72 | this.base_url, |
|
74 | 73 | 'nbconvert', |
|
75 | 74 | format, |
|
76 | 75 | notebook_path, |
|
77 | 76 | notebook_name |
|
78 | 77 | ) + "?download=" + download.toString(); |
|
79 | 78 | |
|
80 | 79 | window.open(url); |
|
81 | 80 | }; |
|
82 | 81 | |
|
83 | 82 | MenuBar.prototype.bind_events = function () { |
|
84 | 83 | // File |
|
85 | 84 | var that = this; |
|
86 | 85 | this.element.find('#new_notebook').click(function () { |
|
87 | 86 | that.notebook.new_notebook(); |
|
88 | 87 | }); |
|
89 | 88 | this.element.find('#open_notebook').click(function () { |
|
90 | 89 | window.open(utils.url_join_encode( |
|
91 | 90 | that.notebook.base_url, |
|
92 | 91 | 'tree', |
|
93 | 92 | that.notebook.notebook_path |
|
94 | 93 | )); |
|
95 | 94 | }); |
|
96 | 95 | this.element.find('#copy_notebook').click(function () { |
|
97 | 96 | that.notebook.copy_notebook(); |
|
98 | 97 | return false; |
|
99 | 98 | }); |
|
100 | 99 | this.element.find('#download_ipynb').click(function () { |
|
101 | 100 | var base_url = that.notebook.base_url; |
|
102 | 101 | var notebook_path = that.notebook.notebook_path; |
|
103 | 102 | var notebook_name = that.notebook.notebook_name; |
|
104 | 103 | if (that.notebook.dirty) { |
|
105 | 104 | that.notebook.save_notebook({async : false}); |
|
106 | 105 | } |
|
107 | 106 | |
|
108 | 107 | var url = utils.url_join_encode( |
|
109 | 108 | base_url, |
|
110 | 109 | 'files', |
|
111 | 110 | notebook_path, |
|
112 | 111 | notebook_name |
|
113 | 112 | ); |
|
114 | 113 | window.location.assign(url); |
|
115 | 114 | }); |
|
116 | 115 | |
|
117 | 116 | this.element.find('#print_preview').click(function () { |
|
118 | 117 | that._nbconvert('html', false); |
|
119 | 118 | }); |
|
120 | 119 | |
|
121 | 120 | this.element.find('#download_py').click(function () { |
|
122 | 121 | that._nbconvert('python', true); |
|
123 | 122 | }); |
|
124 | 123 | |
|
125 | 124 | this.element.find('#download_html').click(function () { |
|
126 | 125 | that._nbconvert('html', true); |
|
127 | 126 | }); |
|
128 | 127 | |
|
129 | 128 | this.element.find('#download_rst').click(function () { |
|
130 | 129 | that._nbconvert('rst', true); |
|
131 | 130 | }); |
|
132 | 131 | |
|
133 | 132 | this.element.find('#download_pdf').click(function () { |
|
134 | 133 | that._nbconvert('pdf', true); |
|
135 | 134 | }); |
|
136 | 135 | |
|
137 | 136 | this.element.find('#rename_notebook').click(function () { |
|
138 | 137 | that.save_widget.rename_notebook({notebook: that.notebook}); |
|
139 | 138 | }); |
|
140 | 139 | this.element.find('#save_checkpoint').click(function () { |
|
141 | 140 | that.notebook.save_checkpoint(); |
|
142 | 141 | }); |
|
143 | 142 | this.element.find('#restore_checkpoint').click(function () { |
|
144 | 143 | }); |
|
145 | 144 | this.element.find('#trust_notebook').click(function () { |
|
146 | 145 | that.notebook.trust_notebook(); |
|
147 | 146 | }); |
|
148 | 147 | this.events.on('trust_changed.Notebook', function (event, trusted) { |
|
149 | 148 | if (trusted) { |
|
150 | 149 | that.element.find('#trust_notebook') |
|
151 | 150 | .addClass("disabled") |
|
152 | 151 | .find("a").text("Trusted Notebook"); |
|
153 | 152 | } else { |
|
154 | 153 | that.element.find('#trust_notebook') |
|
155 | 154 | .removeClass("disabled") |
|
156 | 155 | .find("a").text("Trust Notebook"); |
|
157 | 156 | } |
|
158 | 157 | }); |
|
159 | 158 | this.element.find('#kill_and_exit').click(function () { |
|
160 | 159 | that.notebook.session.delete(); |
|
161 | 160 | setTimeout(function(){ |
|
162 | 161 | // allow closing of new tabs in Chromium, impossible in FF |
|
163 | 162 | window.open('', '_self', ''); |
|
164 | 163 | window.close(); |
|
165 | 164 | }, 500); |
|
166 | 165 | }); |
|
167 | 166 | // Edit |
|
168 | 167 | this.element.find('#cut_cell').click(function () { |
|
169 | 168 | that.notebook.cut_cell(); |
|
170 | 169 | }); |
|
171 | 170 | this.element.find('#copy_cell').click(function () { |
|
172 | 171 | that.notebook.copy_cell(); |
|
173 | 172 | }); |
|
174 | 173 | this.element.find('#delete_cell').click(function () { |
|
175 | 174 | that.notebook.delete_cell(); |
|
176 | 175 | }); |
|
177 | 176 | this.element.find('#undelete_cell').click(function () { |
|
178 | 177 | that.notebook.undelete_cell(); |
|
179 | 178 | }); |
|
180 | 179 | this.element.find('#split_cell').click(function () { |
|
181 | 180 | that.notebook.split_cell(); |
|
182 | 181 | }); |
|
183 | 182 | this.element.find('#merge_cell_above').click(function () { |
|
184 | 183 | that.notebook.merge_cell_above(); |
|
185 | 184 | }); |
|
186 | 185 | this.element.find('#merge_cell_below').click(function () { |
|
187 | 186 | that.notebook.merge_cell_below(); |
|
188 | 187 | }); |
|
189 | 188 | this.element.find('#move_cell_up').click(function () { |
|
190 | 189 | that.notebook.move_cell_up(); |
|
191 | 190 | }); |
|
192 | 191 | this.element.find('#move_cell_down').click(function () { |
|
193 | 192 | that.notebook.move_cell_down(); |
|
194 | 193 | }); |
|
195 | 194 | this.element.find('#edit_nb_metadata').click(function () { |
|
196 | 195 | that.notebook.edit_metadata({ |
|
197 | 196 | notebook: that.notebook, |
|
198 | 197 | keyboard_manager: that.notebook.keyboard_manager}); |
|
199 | 198 | }); |
|
200 | 199 | |
|
201 | 200 | // View |
|
202 | 201 | this.element.find('#toggle_header').click(function () { |
|
203 | 202 | $('div#header').toggle(); |
|
204 | 203 | that.layout_manager.do_resize(); |
|
205 | 204 | }); |
|
206 | 205 | this.element.find('#toggle_toolbar').click(function () { |
|
207 | 206 | $('div#maintoolbar').toggle(); |
|
208 | 207 | that.layout_manager.do_resize(); |
|
209 | 208 | }); |
|
210 | 209 | // Insert |
|
211 | 210 | this.element.find('#insert_cell_above').click(function () { |
|
212 | 211 | that.notebook.insert_cell_above('code'); |
|
213 | 212 | that.notebook.select_prev(); |
|
214 | 213 | }); |
|
215 | 214 | this.element.find('#insert_cell_below').click(function () { |
|
216 | 215 | that.notebook.insert_cell_below('code'); |
|
217 | 216 | that.notebook.select_next(); |
|
218 | 217 | }); |
|
219 | 218 | // Cell |
|
220 | 219 | this.element.find('#run_cell').click(function () { |
|
221 | 220 | that.notebook.execute_cell(); |
|
222 | 221 | }); |
|
223 | 222 | this.element.find('#run_cell_select_below').click(function () { |
|
224 | 223 | that.notebook.execute_cell_and_select_below(); |
|
225 | 224 | }); |
|
226 | 225 | this.element.find('#run_cell_insert_below').click(function () { |
|
227 | 226 | that.notebook.execute_cell_and_insert_below(); |
|
228 | 227 | }); |
|
229 | 228 | this.element.find('#run_all_cells').click(function () { |
|
230 | 229 | that.notebook.execute_all_cells(); |
|
231 | 230 | }); |
|
232 | 231 | this.element.find('#run_all_cells_above').click(function () { |
|
233 | 232 | that.notebook.execute_cells_above(); |
|
234 | 233 | }); |
|
235 | 234 | this.element.find('#run_all_cells_below').click(function () { |
|
236 | 235 | that.notebook.execute_cells_below(); |
|
237 | 236 | }); |
|
238 | 237 | this.element.find('#to_code').click(function () { |
|
239 | 238 | that.notebook.to_code(); |
|
240 | 239 | }); |
|
241 | 240 | this.element.find('#to_markdown').click(function () { |
|
242 | 241 | that.notebook.to_markdown(); |
|
243 | 242 | }); |
|
244 | 243 | this.element.find('#to_raw').click(function () { |
|
245 | 244 | that.notebook.to_raw(); |
|
246 | 245 | }); |
|
247 | 246 | this.element.find('#to_heading1').click(function () { |
|
248 | 247 | that.notebook.to_heading(undefined, 1); |
|
249 | 248 | }); |
|
250 | 249 | this.element.find('#to_heading2').click(function () { |
|
251 | 250 | that.notebook.to_heading(undefined, 2); |
|
252 | 251 | }); |
|
253 | 252 | this.element.find('#to_heading3').click(function () { |
|
254 | 253 | that.notebook.to_heading(undefined, 3); |
|
255 | 254 | }); |
|
256 | 255 | this.element.find('#to_heading4').click(function () { |
|
257 | 256 | that.notebook.to_heading(undefined, 4); |
|
258 | 257 | }); |
|
259 | 258 | this.element.find('#to_heading5').click(function () { |
|
260 | 259 | that.notebook.to_heading(undefined, 5); |
|
261 | 260 | }); |
|
262 | 261 | this.element.find('#to_heading6').click(function () { |
|
263 | 262 | that.notebook.to_heading(undefined, 6); |
|
264 | 263 | }); |
|
265 | 264 | |
|
266 | 265 | this.element.find('#toggle_current_output').click(function () { |
|
267 | 266 | that.notebook.toggle_output(); |
|
268 | 267 | }); |
|
269 | 268 | this.element.find('#toggle_current_output_scroll').click(function () { |
|
270 | 269 | that.notebook.toggle_output_scroll(); |
|
271 | 270 | }); |
|
272 | 271 | this.element.find('#clear_current_output').click(function () { |
|
273 | 272 | that.notebook.clear_output(); |
|
274 | 273 | }); |
|
275 | 274 | |
|
276 | 275 | this.element.find('#toggle_all_output').click(function () { |
|
277 | 276 | that.notebook.toggle_all_output(); |
|
278 | 277 | }); |
|
279 | 278 | this.element.find('#toggle_all_output_scroll').click(function () { |
|
280 | 279 | that.notebook.toggle_all_output_scroll(); |
|
281 | 280 | }); |
|
282 | 281 | this.element.find('#clear_all_output').click(function () { |
|
283 | 282 | that.notebook.clear_all_output(); |
|
284 | 283 | }); |
|
285 | 284 | |
|
286 | 285 | // Kernel |
|
287 | 286 | this.element.find('#int_kernel').click(function () { |
|
288 | 287 | that.notebook.session.interrupt_kernel(); |
|
289 | 288 | }); |
|
290 | 289 | this.element.find('#restart_kernel').click(function () { |
|
291 | 290 | that.notebook.restart_kernel(); |
|
292 | 291 | }); |
|
293 | 292 | // Help |
|
294 | 293 | if (this.tour) { |
|
295 | 294 | this.element.find('#notebook_tour').click(function () { |
|
296 | 295 | that.tour.start(); |
|
297 | 296 | }); |
|
298 | 297 | } else { |
|
299 | 298 | this.element.find('#notebook_tour').addClass("disabled"); |
|
300 | 299 | } |
|
301 | 300 | this.element.find('#keyboard_shortcuts').click(function () { |
|
302 | 301 | that.quick_help.show_keyboard_shortcuts(); |
|
303 | 302 | }); |
|
304 | 303 | |
|
305 | 304 | this.update_restore_checkpoint(null); |
|
306 | 305 | |
|
307 | 306 | this.events.on('checkpoints_listed.Notebook', function (event, data) { |
|
308 | 307 | that.update_restore_checkpoint(that.notebook.checkpoints); |
|
309 | 308 | }); |
|
310 | 309 | |
|
311 | 310 | this.events.on('checkpoint_created.Notebook', function (event, data) { |
|
312 | 311 | that.update_restore_checkpoint(that.notebook.checkpoints); |
|
313 | 312 | }); |
|
314 | 313 | }; |
|
315 | 314 | |
|
316 | 315 | MenuBar.prototype.update_restore_checkpoint = function(checkpoints) { |
|
317 | 316 | var ul = this.element.find("#restore_checkpoint").find("ul"); |
|
318 | 317 | ul.empty(); |
|
319 | 318 | if (!checkpoints || checkpoints.length === 0) { |
|
320 | 319 | ul.append( |
|
321 | 320 | $("<li/>") |
|
322 | 321 | .addClass("disabled") |
|
323 | 322 | .append( |
|
324 | 323 | $("<a/>") |
|
325 | 324 | .text("No checkpoints") |
|
326 | 325 | ) |
|
327 | 326 | ); |
|
328 | 327 | return; |
|
329 | 328 | } |
|
330 | 329 | |
|
331 | 330 | var that = this; |
|
332 | 331 | checkpoints.map(function (checkpoint) { |
|
333 | 332 | var d = new Date(checkpoint.last_modified); |
|
334 | 333 | ul.append( |
|
335 | 334 | $("<li/>").append( |
|
336 | 335 | $("<a/>") |
|
337 | 336 | .attr("href", "#") |
|
338 | 337 | .text(d.format("mmm dd HH:MM:ss")) |
|
339 | 338 | .click(function () { |
|
340 | 339 | that.notebook.restore_checkpoint_dialog(checkpoint); |
|
341 | 340 | }) |
|
342 | 341 | ) |
|
343 | 342 | ); |
|
344 | 343 | }); |
|
345 | 344 | }; |
|
346 | 345 | |
|
347 | 346 | // Backwards compatability. |
|
348 | 347 | IPython.MenuBar = MenuBar; |
|
349 | 348 | |
|
350 | 349 | return {'MenuBar': MenuBar}; |
|
351 | 350 | }); |
@@ -1,54 +1,55 | |||
|
1 | 1 | #menubar { |
|
2 | 2 | margin-top: 0px; |
|
3 | 3 | margin-bottom: -19px; |
|
4 | 4 | position: relative; |
|
5 | .border-box-sizing(); | |
|
5 | 6 | |
|
6 | 7 | .navbar { |
|
7 | 8 | border-top: 1px; |
|
8 | 9 | border-radius: 0px 0px @border-radius-base @border-radius-base; |
|
9 | 10 | } |
|
10 | 11 | |
|
11 | 12 | |
|
12 | 13 | li.dropdown { |
|
13 | 14 | line-height: 12px; |
|
14 | 15 | |
|
15 | 16 | a { |
|
16 | 17 | padding-top: 6px; |
|
17 | 18 | padding-bottom: 5px; |
|
18 | 19 | } |
|
19 | 20 | } |
|
20 | 21 | |
|
21 | 22 | ul.navbar-right { |
|
22 | 23 | padding-top: 2px; |
|
23 | 24 | } |
|
24 | 25 | } |
|
25 | 26 | |
|
26 | 27 | .nav-wrapper { |
|
27 | 28 | border-bottom: 1px solid @navbar-default-border; |
|
28 | 29 | } |
|
29 | 30 | |
|
30 | 31 | i.menu-icon { |
|
31 | 32 | // add padding to account for float-right |
|
32 | 33 | padding-top: 4px; |
|
33 | 34 | } |
|
34 | 35 | |
|
35 | 36 | ul#help_menu li a{ |
|
36 | 37 | overflow: hidden; |
|
37 | 38 | padding-right: 2.2em; |
|
38 | 39 | i { |
|
39 | 40 | margin-right: -1.2em; |
|
40 | 41 | } |
|
41 | 42 | } |
|
42 | 43 | |
|
43 | 44 | #menus { |
|
44 | 45 | min-height: 30px; |
|
45 | 46 | } |
|
46 | 47 | |
|
47 | 48 | // Make sub menus work in BS3. |
|
48 | 49 | // Credit: http://www.bootply.com/86684 |
|
49 | 50 | .dropdown-submenu{position:relative;} |
|
50 | 51 | .dropdown-submenu>.dropdown-menu{top:0;left:100%;margin-top:-6px;margin-left:-1px;-webkit-border-radius:0 6px 6px 6px;-moz-border-radius:0 6px 6px 6px;border-radius:0 6px 6px 6px;} |
|
51 | 52 | .dropdown-submenu:hover>.dropdown-menu{display:block;} |
|
52 | 53 | .dropdown-submenu>a:after{display:block;content:" ";float:right;width:0;height:0;border-color:transparent;border-style:solid;border-width:5px 0 5px 5px;border-left-color:#cccccc;margin-top:5px;margin-right:-10px;} |
|
53 | 54 | .dropdown-submenu:hover>a:after{border-left-color:#ffffff;} |
|
54 | 55 | .dropdown-submenu.pull-left{float:none;}.dropdown-submenu.pull-left>.dropdown-menu{left:-100%;margin-left:10px;-webkit-border-radius:6px 0 6px 6px;-moz-border-radius:6px 0 6px 6px;border-radius:6px 0 6px 6px;} |
General Comments 0
You need to be logged in to leave comments.
Login now