Show More
@@ -459,6 +459,20 b' IPython.utils = (function (IPython) {' | |||||
459 | return M; |
|
459 | return M; | |
460 | })(); |
|
460 | })(); | |
461 |
|
461 | |||
|
462 | // http://stackoverflow.com/questions/11219582/how-to-detect-my-browser-version-and-operating-system-using-javascript | |||
|
463 | var platform = (function () { | |||
|
464 | if (typeof navigator === 'undefined') { | |||
|
465 | // navigator undefined in node | |||
|
466 | return 'None'; | |||
|
467 | } | |||
|
468 | var OSName="None"; | |||
|
469 | if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows"; | |||
|
470 | if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS"; | |||
|
471 | if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX"; | |||
|
472 | if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux"; | |||
|
473 | return OSName | |||
|
474 | })(); | |||
|
475 | ||||
462 | var is_or_has = function (a, b) { |
|
476 | var is_or_has = function (a, b) { | |
463 | // Is b a child of a or a itself? |
|
477 | // Is b a child of a or a itself? | |
464 | return a.has(b).length !==0 || a.is(b); |
|
478 | return a.has(b).length !==0 || a.is(b); | |
@@ -500,6 +514,7 b' IPython.utils = (function (IPython) {' | |||||
500 | splitext : splitext, |
|
514 | splitext : splitext, | |
501 | always_new : always_new, |
|
515 | always_new : always_new, | |
502 | browser : browser, |
|
516 | browser : browser, | |
|
517 | platform: platform, | |||
503 | is_or_has : is_or_has, |
|
518 | is_or_has : is_or_has, | |
504 | is_focused : is_focused |
|
519 | is_focused : is_focused | |
505 | }; |
|
520 | }; |
@@ -50,6 +50,7 b' var IPython = (function (IPython) {' | |||||
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | var browser = IPython.utils.browser[0]; |
|
52 | var browser = IPython.utils.browser[0]; | |
|
53 | var platform = IPython.utils.platform; | |||
53 |
|
54 | |||
54 | if (browser === 'Firefox' || browser === 'Opera') { |
|
55 | if (browser === 'Firefox' || browser === 'Opera') { | |
55 | $.extend(_keycodes, _mozilla_keycodes); |
|
56 | $.extend(_keycodes, _mozilla_keycodes); | |
@@ -78,24 +79,6 b' var IPython = (function (IPython) {' | |||||
78 | // Default keyboard shortcuts |
|
79 | // Default keyboard shortcuts | |
79 |
|
80 | |||
80 | var default_common_shortcuts = { |
|
81 | var default_common_shortcuts = { | |
81 | 'meta+s' : { |
|
|||
82 | help : 'save notebook', |
|
|||
83 | help_index : 'fb', |
|
|||
84 | handler : function (event) { |
|
|||
85 | IPython.notebook.save_checkpoint(); |
|
|||
86 | event.preventDefault(); |
|
|||
87 | return false; |
|
|||
88 | } |
|
|||
89 | }, |
|
|||
90 | 'ctrl+s' : { |
|
|||
91 | help : 'save notebook', |
|
|||
92 | help_index : 'fc', |
|
|||
93 | handler : function (event) { |
|
|||
94 | IPython.notebook.save_checkpoint(); |
|
|||
95 | event.preventDefault(); |
|
|||
96 | return false; |
|
|||
97 | } |
|
|||
98 | }, |
|
|||
99 | 'shift' : { |
|
82 | 'shift' : { | |
100 | help : '', |
|
83 | help : '', | |
101 | help_index : '', |
|
84 | help_index : '', | |
@@ -130,6 +113,30 b' var IPython = (function (IPython) {' | |||||
130 | } |
|
113 | } | |
131 | } |
|
114 | } | |
132 |
|
115 | |||
|
116 | if (platform === 'MacOS') { | |||
|
117 | default_common_shortcuts['cmd+s'] = | |||
|
118 | { | |||
|
119 | help : 'save notebook', | |||
|
120 | help_index : 'fb', | |||
|
121 | handler : function (event) { | |||
|
122 | IPython.notebook.save_checkpoint(); | |||
|
123 | event.preventDefault(); | |||
|
124 | return false; | |||
|
125 | } | |||
|
126 | }; | |||
|
127 | } else { | |||
|
128 | default_common_shortcuts['ctrl+s'] = | |||
|
129 | { | |||
|
130 | help : 'save notebook', | |||
|
131 | help_index : 'fb', | |||
|
132 | handler : function (event) { | |||
|
133 | IPython.notebook.save_checkpoint(); | |||
|
134 | event.preventDefault(); | |||
|
135 | return false; | |||
|
136 | } | |||
|
137 | }; | |||
|
138 | } | |||
|
139 | ||||
133 | // Edit mode defaults |
|
140 | // Edit mode defaults | |
134 |
|
141 | |||
135 | var default_edit_shortcuts = { |
|
142 | var default_edit_shortcuts = { | |
@@ -195,6 +202,48 b' var IPython = (function (IPython) {' | |||||
195 | return false; |
|
202 | return false; | |
196 | } |
|
203 | } | |
197 | }, |
|
204 | }, | |
|
205 | 'tab' : { | |||
|
206 | help : 'indent or complete', | |||
|
207 | help_index : 'ec', | |||
|
208 | }, | |||
|
209 | 'shift+tab' : { | |||
|
210 | help : 'tooltip', | |||
|
211 | help_index : 'ed', | |||
|
212 | }, | |||
|
213 | } | |||
|
214 | ||||
|
215 | if (platform === 'MacOS') { | |||
|
216 | default_edit_shortcuts['cmd+/'] = | |||
|
217 | { | |||
|
218 | help : 'toggle comment', | |||
|
219 | help_index : 'ee' | |||
|
220 | }; | |||
|
221 | default_edit_shortcuts['cmd+]'] = | |||
|
222 | { | |||
|
223 | help : 'indent', | |||
|
224 | help_index : 'ef' | |||
|
225 | }; | |||
|
226 | default_edit_shortcuts['cmd+['] = | |||
|
227 | { | |||
|
228 | help : 'dedent', | |||
|
229 | help_index : 'eg' | |||
|
230 | }; | |||
|
231 | } else { | |||
|
232 | default_edit_shortcuts['ctrl+/'] = | |||
|
233 | { | |||
|
234 | help : 'toggle comment', | |||
|
235 | help_index : 'ee' | |||
|
236 | }; | |||
|
237 | default_edit_shortcuts['ctrl+]'] = | |||
|
238 | { | |||
|
239 | help : 'indent', | |||
|
240 | help_index : 'ef' | |||
|
241 | }; | |||
|
242 | default_edit_shortcuts['ctrl+['] = | |||
|
243 | { | |||
|
244 | help : 'dedent', | |||
|
245 | help_index : 'eg' | |||
|
246 | }; | |||
198 | } |
|
247 | } | |
199 |
|
248 | |||
200 | // Command mode defaults |
|
249 | // Command mode defaults | |
@@ -276,9 +325,17 b' var IPython = (function (IPython) {' | |||||
276 | return false; |
|
325 | return false; | |
277 | } |
|
326 | } | |
278 | }, |
|
327 | }, | |
|
328 | 'shift+v' : { | |||
|
329 | help : 'paste cell above', | |||
|
330 | help_index : 'eg', | |||
|
331 | handler : function (event) { | |||
|
332 | IPython.notebook.paste_cell_above(); | |||
|
333 | return false; | |||
|
334 | } | |||
|
335 | }, | |||
279 | 'v' : { |
|
336 | 'v' : { | |
280 | help : 'paste cell below', |
|
337 | help : 'paste cell below', | |
281 |
help_index : 'e |
|
338 | help_index : 'eh', | |
282 | handler : function (event) { |
|
339 | handler : function (event) { | |
283 | IPython.notebook.paste_cell_below(); |
|
340 | IPython.notebook.paste_cell_below(); | |
284 | return false; |
|
341 | return false; | |
@@ -286,18 +343,10 b' var IPython = (function (IPython) {' | |||||
286 | }, |
|
343 | }, | |
287 | 'd' : { |
|
344 | 'd' : { | |
288 | help : 'delete cell (press twice)', |
|
345 | help : 'delete cell (press twice)', | |
289 |
help_index : 'e |
|
346 | help_index : 'ej', | |
|
347 | count: 2, | |||
290 | handler : function (event) { |
|
348 | handler : function (event) { | |
291 |
|
|
349 | IPython.notebook.delete_cell(); | |
292 | if (dc === 0) { |
|
|||
293 | IPython.keyboard_manager._delete_count = 1; |
|
|||
294 | setTimeout(function () { |
|
|||
295 | IPython.keyboard_manager._delete_count = 0; |
|
|||
296 | }, 800); |
|
|||
297 | } else if (dc === 1) { |
|
|||
298 | IPython.notebook.delete_cell(); |
|
|||
299 | IPython.keyboard_manager._delete_count = 0; |
|
|||
300 | } |
|
|||
301 | return false; |
|
350 | return false; | |
302 | } |
|
351 | } | |
303 | }, |
|
352 | }, | |
@@ -337,7 +386,7 b' var IPython = (function (IPython) {' | |||||
337 | return false; |
|
386 | return false; | |
338 | } |
|
387 | } | |
339 | }, |
|
388 | }, | |
340 |
' |
|
389 | 'r' : { | |
341 | help : 'to raw', |
|
390 | help : 'to raw', | |
342 | help_index : 'cc', |
|
391 | help_index : 'cc', | |
343 | handler : function (event) { |
|
392 | handler : function (event) { | |
@@ -402,7 +451,7 b' var IPython = (function (IPython) {' | |||||
402 | } |
|
451 | } | |
403 | }, |
|
452 | }, | |
404 | 'shift+o' : { |
|
453 | 'shift+o' : { | |
405 | help : 'toggle output', |
|
454 | help : 'toggle output scroll', | |
406 | help_index : 'gc', |
|
455 | help_index : 'gc', | |
407 | handler : function (event) { |
|
456 | handler : function (event) { | |
408 | IPython.notebook.toggle_output_scroll(); |
|
457 | IPython.notebook.toggle_output_scroll(); | |
@@ -442,16 +491,18 b' var IPython = (function (IPython) {' | |||||
442 | } |
|
491 | } | |
443 | }, |
|
492 | }, | |
444 | 'i' : { |
|
493 | 'i' : { | |
445 | help : 'interrupt kernel', |
|
494 | help : 'interrupt kernel (press twice)', | |
446 | help_index : 'ha', |
|
495 | help_index : 'ha', | |
|
496 | count: 2, | |||
447 | handler : function (event) { |
|
497 | handler : function (event) { | |
448 | IPython.notebook.kernel.interrupt(); |
|
498 | IPython.notebook.kernel.interrupt(); | |
449 | return false; |
|
499 | return false; | |
450 | } |
|
500 | } | |
451 | }, |
|
501 | }, | |
452 |
' |
|
502 | '0' : { | |
453 | help : 'restart kernel', |
|
503 | help : 'restart kernel (press twice)', | |
454 | help_index : 'hb', |
|
504 | help_index : 'hb', | |
|
505 | count: 2, | |||
455 | handler : function (event) { |
|
506 | handler : function (event) { | |
456 | IPython.notebook.restart_kernel(); |
|
507 | IPython.notebook.restart_kernel(); | |
457 | return false; |
|
508 | return false; | |
@@ -467,7 +518,7 b' var IPython = (function (IPython) {' | |||||
467 | }, |
|
518 | }, | |
468 | 'z' : { |
|
519 | 'z' : { | |
469 | help : 'undo last delete', |
|
520 | help : 'undo last delete', | |
470 |
help_index : 'e |
|
521 | help_index : 'ei', | |
471 | handler : function (event) { |
|
522 | handler : function (event) { | |
472 | IPython.notebook.undelete_cell(); |
|
523 | IPython.notebook.undelete_cell(); | |
473 | return false; |
|
524 | return false; | |
@@ -475,7 +526,15 b' var IPython = (function (IPython) {' | |||||
475 | }, |
|
526 | }, | |
476 | 'shift+=' : { |
|
527 | 'shift+=' : { | |
477 | help : 'merge cell below', |
|
528 | help : 'merge cell below', | |
478 |
help_index : 'e |
|
529 | help_index : 'ek', | |
|
530 | handler : function (event) { | |||
|
531 | IPython.notebook.merge_cell_below(); | |||
|
532 | return false; | |||
|
533 | } | |||
|
534 | }, | |||
|
535 | 'shift+m' : { | |||
|
536 | help : 'merge cell below', | |||
|
537 | help_index : 'ek', | |||
479 | handler : function (event) { |
|
538 | handler : function (event) { | |
480 | IPython.notebook.merge_cell_below(); |
|
539 | IPython.notebook.merge_cell_below(); | |
481 | return false; |
|
540 | return false; | |
@@ -486,8 +545,10 b' var IPython = (function (IPython) {' | |||||
486 |
|
545 | |||
487 | // Shortcut manager class |
|
546 | // Shortcut manager class | |
488 |
|
547 | |||
489 | var ShortcutManager = function () { |
|
548 | var ShortcutManager = function (delay) { | |
490 | this._shortcuts = {} |
|
549 | this._shortcuts = {} | |
|
550 | this._counts = {} | |||
|
551 | this.delay = delay || 800; // delay in milliseconds | |||
491 | } |
|
552 | } | |
492 |
|
553 | |||
493 | ShortcutManager.prototype.help = function () { |
|
554 | ShortcutManager.prototype.help = function () { | |
@@ -496,6 +557,9 b' var IPython = (function (IPython) {' | |||||
496 | var help_string = this._shortcuts[shortcut]['help']; |
|
557 | var help_string = this._shortcuts[shortcut]['help']; | |
497 | var help_index = this._shortcuts[shortcut]['help_index']; |
|
558 | var help_index = this._shortcuts[shortcut]['help_index']; | |
498 | if (help_string) { |
|
559 | if (help_string) { | |
|
560 | if (platform === 'MacOS') { | |||
|
561 | shortcut = shortcut.replace('meta', 'cmd'); | |||
|
562 | } | |||
499 | help.push({ |
|
563 | help.push({ | |
500 | shortcut: shortcut, |
|
564 | shortcut: shortcut, | |
501 | help: help_string, |
|
565 | help: help_string, | |
@@ -519,6 +583,7 b' var IPython = (function (IPython) {' | |||||
519 |
|
583 | |||
520 | ShortcutManager.prototype.normalize_shortcut = function (shortcut) { |
|
584 | ShortcutManager.prototype.normalize_shortcut = function (shortcut) { | |
521 | // Sort a sequence of + separated modifiers into the order alt+ctrl+meta+shift |
|
585 | // Sort a sequence of + separated modifiers into the order alt+ctrl+meta+shift | |
|
586 | shortcut = shortcut.replace('cmd', 'meta').toLowerCase(); | |||
522 | var values = shortcut.split("+"); |
|
587 | var values = shortcut.split("+"); | |
523 | if (values.length === 1) { |
|
588 | if (values.length === 1) { | |
524 | return this.normalize_key(values[0]) |
|
589 | return this.normalize_key(values[0]) | |
@@ -552,10 +617,12 b' var IPython = (function (IPython) {' | |||||
552 | } |
|
617 | } | |
553 | data.help_index = data.help_index || ''; |
|
618 | data.help_index = data.help_index || ''; | |
554 | data.help = data.help || ''; |
|
619 | data.help = data.help || ''; | |
|
620 | data.count = data.count || 1; | |||
555 | if (data.help_index === '') { |
|
621 | if (data.help_index === '') { | |
556 | data.help_index = 'zz'; |
|
622 | data.help_index = 'zz'; | |
557 | } |
|
623 | } | |
558 | shortcut = this.normalize_shortcut(shortcut); |
|
624 | shortcut = this.normalize_shortcut(shortcut); | |
|
625 | this._counts[shortcut] = 0; | |||
559 | this._shortcuts[shortcut] = data; |
|
626 | this._shortcuts[shortcut] = data; | |
560 | } |
|
627 | } | |
561 |
|
628 | |||
@@ -567,16 +634,37 b' var IPython = (function (IPython) {' | |||||
567 |
|
634 | |||
568 | ShortcutManager.prototype.remove_shortcut = function (shortcut) { |
|
635 | ShortcutManager.prototype.remove_shortcut = function (shortcut) { | |
569 | shortcut = this.normalize_shortcut(shortcut); |
|
636 | shortcut = this.normalize_shortcut(shortcut); | |
|
637 | delete this._counts[shortcut]; | |||
570 | delete this._shortcuts[shortcut]; |
|
638 | delete this._shortcuts[shortcut]; | |
571 | } |
|
639 | } | |
572 |
|
640 | |||
|
641 | ShortcutManager.prototype.count_handler = function (shortcut, event, data) { | |||
|
642 | var that = this; | |||
|
643 | var c = this._counts; | |||
|
644 | if (c[shortcut] === data.count-1) { | |||
|
645 | c[shortcut] = 0; | |||
|
646 | return data.handler(event); | |||
|
647 | } else { | |||
|
648 | c[shortcut] = c[shortcut] + 1; | |||
|
649 | setTimeout(function () { | |||
|
650 | c[shortcut] = 0; | |||
|
651 | }, that.delay); | |||
|
652 | } | |||
|
653 | return false; | |||
|
654 | ||||
|
655 | } | |||
|
656 | ||||
573 | ShortcutManager.prototype.call_handler = function (event) { |
|
657 | ShortcutManager.prototype.call_handler = function (event) { | |
574 | var shortcut = this.event_to_shortcut(event); |
|
658 | var shortcut = this.event_to_shortcut(event); | |
575 | var data = this._shortcuts[shortcut]; |
|
659 | var data = this._shortcuts[shortcut]; | |
576 |
if (data |
|
660 | if (data) { | |
577 | var handler = data['handler']; |
|
661 | var handler = data['handler']; | |
578 |
if (handler |
|
662 | if (handler) { | |
579 | return handler(event); |
|
663 | if (data.count === 1) { | |
|
664 | return handler(event); | |||
|
665 | } else if (data.count > 1) { | |||
|
666 | return this.count_handler(shortcut, event, data); | |||
|
667 | } | |||
580 | } |
|
668 | } | |
581 | } |
|
669 | } | |
582 | return true; |
|
670 | return true; | |
@@ -589,7 +677,6 b' var IPython = (function (IPython) {' | |||||
589 | var KeyboardManager = function () { |
|
677 | var KeyboardManager = function () { | |
590 | this.mode = 'command'; |
|
678 | this.mode = 'command'; | |
591 | this.enabled = true; |
|
679 | this.enabled = true; | |
592 | this._delete_count = 0; |
|
|||
593 | this.bind_events(); |
|
680 | this.bind_events(); | |
594 | this.command_shortcuts = new ShortcutManager(); |
|
681 | this.command_shortcuts = new ShortcutManager(); | |
595 | this.command_shortcuts.add_shortcuts(default_common_shortcuts); |
|
682 | this.command_shortcuts.add_shortcuts(default_common_shortcuts); |
@@ -88,7 +88,7 b' var IPython = (function (IPython) {' | |||||
88 | }); |
|
88 | }); | |
89 |
|
89 | |||
90 | $([IPython.events]).on('status_interrupting.Kernel',function () { |
|
90 | $([IPython.events]).on('status_interrupting.Kernel',function () { | |
91 | knw.set_message("Interrupting kernel"); |
|
91 | knw.set_message("Interrupting kernel", 2000); | |
92 | }); |
|
92 | }); | |
93 |
|
93 | |||
94 | $([IPython.events]).on('status_dead.Kernel',function () { |
|
94 | $([IPython.events]).on('status_dead.Kernel',function () { |
General Comments 0
You need to be logged in to leave comments.
Login now