##// END OF EJS Templates
Merge pull request #3513 from minrk/nocp...
Matthias Bussonnier -
r11182:6124d342 merge
parent child Browse files
Show More
@@ -1,263 +1,270
1 1 //----------------------------------------------------------------------------
2 2 // Copyright (C) 2008-2011 The IPython Development Team
3 3 //
4 4 // Distributed under the terms of the BSD License. The full license is in
5 5 // the file COPYING, distributed as part of this software.
6 6 //----------------------------------------------------------------------------
7 7
8 8 //============================================================================
9 9 // MenuBar
10 10 //============================================================================
11 11
12 12 /**
13 13 * @module IPython
14 14 * @namespace IPython
15 15 * @submodule MenuBar
16 16 */
17 17
18 18
19 19 var IPython = (function (IPython) {
20 20
21 21 /**
22 22 * A MenuBar Class to generate the menubar of IPython noteboko
23 23 * @Class MenuBar
24 24 *
25 25 * @constructor
26 26 *
27 27 *
28 28 * @param selector {string} selector for the menubar element in DOM
29 29 * @param {object} [options]
30 30 * @param [options.baseProjectUrl] {String} String to use for the
31 31 * Base Project url, default would be to inspect
32 32 * $('body').data('baseProjectUrl');
33 33 * does not support change for now is set through this option
34 34 */
35 35 var MenuBar = function (selector, options) {
36 36 var options = options || {};
37 37 if(options.baseProjectUrl!= undefined){
38 38 this._baseProjectUrl = options.baseProjectUrl;
39 39 }
40 40 this.selector = selector;
41 41 if (this.selector !== undefined) {
42 42 this.element = $(selector);
43 43 this.style();
44 44 this.bind_events();
45 45 }
46 46 };
47 47
48 48 MenuBar.prototype.baseProjectUrl = function(){
49 49 return this._baseProjectUrl || $('body').data('baseProjectUrl');
50 50 };
51 51
52 52
53 53 MenuBar.prototype.style = function () {
54 54 this.element.addClass('border-box-sizing');
55 55 this.element.find("li").click(function (event, ui) {
56 56 // The selected cell loses focus when the menu is entered, so we
57 57 // re-select it upon selection.
58 58 var i = IPython.notebook.get_selected_index();
59 59 IPython.notebook.select(i);
60 60 }
61 61 );
62 62 };
63 63
64 64
65 65 MenuBar.prototype.bind_events = function () {
66 66 // File
67 67 var that = this;
68 68 this.element.find('#new_notebook').click(function () {
69 69 window.open(that.baseProjectUrl()+'new');
70 70 });
71 71 this.element.find('#open_notebook').click(function () {
72 72 window.open(that.baseProjectUrl());
73 73 });
74 74 this.element.find('#rename_notebook').click(function () {
75 75 IPython.save_widget.rename_notebook();
76 76 });
77 77 this.element.find('#copy_notebook').click(function () {
78 78 var notebook_id = IPython.notebook.get_notebook_id();
79 79 var url = that.baseProjectUrl() + notebook_id + '/copy';
80 80 window.open(url,'_blank');
81 81 return false;
82 82 });
83 83 this.element.find('#save_checkpoint').click(function () {
84 84 IPython.notebook.save_checkpoint();
85 85 });
86 86 this.element.find('#restore_checkpoint').click(function () {
87 87 });
88 88 this.element.find('#download_ipynb').click(function () {
89 89 var notebook_id = IPython.notebook.get_notebook_id();
90 90 var url = that.baseProjectUrl() + 'notebooks/' +
91 91 notebook_id + '?format=json';
92 92 window.location.assign(url);
93 93 });
94 94 this.element.find('#download_py').click(function () {
95 95 var notebook_id = IPython.notebook.get_notebook_id();
96 96 var url = that.baseProjectUrl() + 'notebooks/' +
97 97 notebook_id + '?format=py';
98 98 window.location.assign(url);
99 99 });
100 100 this.element.find('#kill_and_exit').click(function () {
101 101 IPython.notebook.kernel.kill();
102 102 setTimeout(function(){window.close();}, 200);
103 103 });
104 104 // Edit
105 105 this.element.find('#cut_cell').click(function () {
106 106 IPython.notebook.cut_cell();
107 107 });
108 108 this.element.find('#copy_cell').click(function () {
109 109 IPython.notebook.copy_cell();
110 110 });
111 111 this.element.find('#delete_cell').click(function () {
112 112 IPython.notebook.delete_cell();
113 113 });
114 114 this.element.find('#undelete_cell').click(function () {
115 115 IPython.notebook.undelete();
116 116 });
117 117 this.element.find('#split_cell').click(function () {
118 118 IPython.notebook.split_cell();
119 119 });
120 120 this.element.find('#merge_cell_above').click(function () {
121 121 IPython.notebook.merge_cell_above();
122 122 });
123 123 this.element.find('#merge_cell_below').click(function () {
124 124 IPython.notebook.merge_cell_below();
125 125 });
126 126 this.element.find('#move_cell_up').click(function () {
127 127 IPython.notebook.move_cell_up();
128 128 });
129 129 this.element.find('#move_cell_down').click(function () {
130 130 IPython.notebook.move_cell_down();
131 131 });
132 132 this.element.find('#select_previous').click(function () {
133 133 IPython.notebook.select_prev();
134 134 });
135 135 this.element.find('#select_next').click(function () {
136 136 IPython.notebook.select_next();
137 137 });
138 138 // View
139 139 this.element.find('#toggle_header').click(function () {
140 140 $('div#header').toggle();
141 141 IPython.layout_manager.do_resize();
142 142 });
143 143 this.element.find('#toggle_toolbar').click(function () {
144 144 $('div#maintoolbar').toggle();
145 145 IPython.layout_manager.do_resize();
146 146 });
147 147 // Insert
148 148 this.element.find('#insert_cell_above').click(function () {
149 149 IPython.notebook.insert_cell_above('code');
150 150 });
151 151 this.element.find('#insert_cell_below').click(function () {
152 152 IPython.notebook.insert_cell_below('code');
153 153 });
154 154 // Cell
155 155 this.element.find('#run_cell').click(function () {
156 156 IPython.notebook.execute_selected_cell();
157 157 });
158 158 this.element.find('#run_cell_in_place').click(function () {
159 159 IPython.notebook.execute_selected_cell({terminal:true});
160 160 });
161 161 this.element.find('#run_all_cells').click(function () {
162 162 IPython.notebook.execute_all_cells();
163 163 }).attr('title', 'Run all cells in the notebook');
164 164 this.element.find('#run_all_cells_above').click(function () {
165 165 IPython.notebook.execute_cells_above();
166 166 }).attr('title', 'Run all cells above (but not including) this cell');
167 167 this.element.find('#run_all_cells_below').click(function () {
168 168 IPython.notebook.execute_cells_below();
169 169 }).attr('title', 'Run this cell and all cells below it');
170 170 this.element.find('#to_code').click(function () {
171 171 IPython.notebook.to_code();
172 172 });
173 173 this.element.find('#to_markdown').click(function () {
174 174 IPython.notebook.to_markdown();
175 175 });
176 176 this.element.find('#to_raw').click(function () {
177 177 IPython.notebook.to_raw();
178 178 });
179 179 this.element.find('#to_heading1').click(function () {
180 180 IPython.notebook.to_heading(undefined, 1);
181 181 });
182 182 this.element.find('#to_heading2').click(function () {
183 183 IPython.notebook.to_heading(undefined, 2);
184 184 });
185 185 this.element.find('#to_heading3').click(function () {
186 186 IPython.notebook.to_heading(undefined, 3);
187 187 });
188 188 this.element.find('#to_heading4').click(function () {
189 189 IPython.notebook.to_heading(undefined, 4);
190 190 });
191 191 this.element.find('#to_heading5').click(function () {
192 192 IPython.notebook.to_heading(undefined, 5);
193 193 });
194 194 this.element.find('#to_heading6').click(function () {
195 195 IPython.notebook.to_heading(undefined, 6);
196 196 });
197 197 this.element.find('#toggle_output').click(function () {
198 198 IPython.notebook.toggle_output();
199 199 });
200 200 this.element.find('#collapse_all_output').click(function () {
201 201 IPython.notebook.collapse_all_output();
202 202 });
203 203 this.element.find('#scroll_all_output').click(function () {
204 204 IPython.notebook.scroll_all_output();
205 205 });
206 206 this.element.find('#expand_all_output').click(function () {
207 207 IPython.notebook.expand_all_output();
208 208 });
209 209 this.element.find('#clear_all_output').click(function () {
210 210 IPython.notebook.clear_all_output();
211 211 });
212 212 // Kernel
213 213 this.element.find('#int_kernel').click(function () {
214 214 IPython.notebook.kernel.interrupt();
215 215 });
216 216 this.element.find('#restart_kernel').click(function () {
217 217 IPython.notebook.restart_kernel();
218 218 });
219 219 // Help
220 220 this.element.find('#keyboard_shortcuts').click(function () {
221 221 IPython.quick_help.show_keyboard_shortcuts();
222 222 });
223 223
224 224 this.update_restore_checkpoint(null);
225 225
226 226 $([IPython.events]).on('checkpoints_listed.Notebook', function (event, data) {
227 227 that.update_restore_checkpoint(data);
228 228 });
229 229
230 230 $([IPython.events]).on('checkpoint_created.Notebook', function (event, data) {
231 231 that.update_restore_checkpoint([data]);
232 232 });
233 233 };
234 234
235 235 MenuBar.prototype.update_restore_checkpoint = function(checkpoints) {
236 if (! checkpoints) {
237 checkpoints = [];
236 var ul = this.element.find("#restore_checkpoint").find("ul");
237 ul.empty();
238 if (! checkpoints || checkpoints.length == 0) {
239 ul.append(
240 $("<li/>")
241 .addClass("disabled")
242 .append(
243 $("<a/>")
244 .text("No checkpoints")
245 )
246 );
247 return;
238 248 };
239 this.element.find("#restore_checkpoint").find("ul").find("li").each(function(i) {
240 var li = $(this);
241 var a = li.find("a");
242 a.off("click");
243 if (checkpoints.length <= i) {
244 li.hide();
245 return;
246 } else {
247 li.show();
248 };
249
250 for (var i = 0; i < checkpoints.length; i++) {
249 251 var checkpoint = checkpoints[i];
250 252 var d = new Date(checkpoint.last_modified);
251 li.find('a').text(
252 d.format("mmm dd HH:MM:ss")
253 ).click(function () {
254 IPython.notebook.restore_checkpoint_dialog(checkpoint);
255 });
256 });
253 ul.append(
254 $("<li/>").append(
255 $("<a/>")
256 .attr("href", "#")
257 .text(d.format("mmm dd HH:MM:ss"))
258 .click(function () {
259 IPython.notebook.restore_checkpoint_dialog(checkpoint);
260 })
261 )
262 );
263 };
257 264 };
258 265
259 266 IPython.MenuBar = MenuBar;
260 267
261 268 return IPython;
262 269
263 270 }(IPython));
General Comments 0
You need to be logged in to leave comments. Login now