Show More
@@ -1,171 +1,171 b'' | |||||
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 | //============================================================================ |
|
4 | //============================================================================ | |
5 | // QuickHelp button |
|
5 | // QuickHelp button | |
6 | //============================================================================ |
|
6 | //============================================================================ | |
7 |
|
7 | |||
8 | var IPython = (function (IPython) { |
|
8 | var IPython = (function (IPython) { | |
9 | "use strict"; |
|
9 | "use strict"; | |
10 |
|
10 | |||
11 | var platform = IPython.utils.platform; |
|
11 | var platform = IPython.utils.platform; | |
12 |
|
12 | |||
13 | var QuickHelp = function (selector) { |
|
13 | var QuickHelp = function (selector) { | |
14 | }; |
|
14 | }; | |
15 |
|
15 | |||
16 | var cmd_ctrl = 'Ctrl-'; |
|
16 | var cmd_ctrl = 'Ctrl-'; | |
17 | var platform_specific; |
|
17 | var platform_specific; | |
18 |
|
18 | |||
19 | if (platform === 'MacOS') { |
|
19 | if (platform === 'MacOS') { | |
20 | // Mac OS X specific |
|
20 | // Mac OS X specific | |
21 | cmd_ctrl = 'Cmd-'; |
|
21 | cmd_ctrl = 'Cmd-'; | |
22 | platform_specific = [ |
|
22 | platform_specific = [ | |
23 | { shortcut: "Cmd-Up", help:"go to cell start" }, |
|
23 | { shortcut: "Cmd-Up", help:"go to cell start" }, | |
24 | { shortcut: "Cmd-Down", help:"go to cell end" }, |
|
24 | { shortcut: "Cmd-Down", help:"go to cell end" }, | |
25 | { shortcut: "Opt-Left", help:"go one word left" }, |
|
25 | { shortcut: "Opt-Left", help:"go one word left" }, | |
26 | { shortcut: "Opt-Right", help:"go one word right" }, |
|
26 | { shortcut: "Opt-Right", help:"go one word right" }, | |
27 | { shortcut: "Opt-Backspace", help:"del word before" }, |
|
27 | { shortcut: "Opt-Backspace", help:"del word before" }, | |
28 | { shortcut: "Opt-Delete", help:"del word after" }, |
|
28 | { shortcut: "Opt-Delete", help:"del word after" }, | |
29 | ]; |
|
29 | ]; | |
30 | } else { |
|
30 | } else { | |
31 | // PC specific |
|
31 | // PC specific | |
32 | platform_specific = [ |
|
32 | platform_specific = [ | |
33 | { shortcut: "Ctrl-Home", help:"go to cell start" }, |
|
33 | { shortcut: "Ctrl-Home", help:"go to cell start" }, | |
34 | { shortcut: "Ctrl-Up", help:"go to cell start" }, |
|
34 | { shortcut: "Ctrl-Up", help:"go to cell start" }, | |
35 | { shortcut: "Ctrl-End", help:"go to cell end" }, |
|
35 | { shortcut: "Ctrl-End", help:"go to cell end" }, | |
36 | { shortcut: "Ctrl-Down", help:"go to cell end" }, |
|
36 | { shortcut: "Ctrl-Down", help:"go to cell end" }, | |
37 | { shortcut: "Ctrl-Left", help:"go one word left" }, |
|
37 | { shortcut: "Ctrl-Left", help:"go one word left" }, | |
38 | { shortcut: "Ctrl-Right", help:"go one word right" }, |
|
38 | { shortcut: "Ctrl-Right", help:"go one word right" }, | |
39 | { shortcut: "Ctrl-Backspace", help:"del word before" }, |
|
39 | { shortcut: "Ctrl-Backspace", help:"del word before" }, | |
40 | { shortcut: "Ctrl-Delete", help:"del word after" }, |
|
40 | { shortcut: "Ctrl-Delete", help:"del word after" }, | |
41 | ]; |
|
41 | ]; | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | var cm_shortcuts = [ |
|
44 | var cm_shortcuts = [ | |
45 | { shortcut:"Tab", help:"code completion or indent" }, |
|
45 | { shortcut:"Tab", help:"code completion or indent" }, | |
46 | { shortcut:"Shift-Tab", help:"tooltip" }, |
|
46 | { shortcut:"Shift-Tab", help:"tooltip" }, | |
47 | { shortcut: cmd_ctrl + "]", help:"indent" }, |
|
47 | { shortcut: cmd_ctrl + "]", help:"indent" }, | |
48 | { shortcut: cmd_ctrl + "[", help:"dedent" }, |
|
48 | { shortcut: cmd_ctrl + "[", help:"dedent" }, | |
49 | { shortcut: cmd_ctrl + "a", help:"select all" }, |
|
49 | { shortcut: cmd_ctrl + "a", help:"select all" }, | |
50 | { shortcut: cmd_ctrl + "z", help:"undo" }, |
|
50 | { shortcut: cmd_ctrl + "z", help:"undo" }, | |
51 | { shortcut: cmd_ctrl + "Shift-z", help:"redo" }, |
|
51 | { shortcut: cmd_ctrl + "Shift-z", help:"redo" }, | |
52 | { shortcut: cmd_ctrl + "y", help:"redo" }, |
|
52 | { shortcut: cmd_ctrl + "y", help:"redo" }, | |
53 | ].concat( platform_specific ); |
|
53 | ].concat( platform_specific ); | |
54 |
|
54 | |||
55 |
|
55 | |||
56 |
|
56 | |||
57 |
|
57 | |||
58 |
|
58 | |||
59 |
|
59 | |||
60 | QuickHelp.prototype.show_keyboard_shortcuts = function () { |
|
60 | QuickHelp.prototype.show_keyboard_shortcuts = function () { | |
61 | // toggles display of keyboard shortcut dialog |
|
61 | // toggles display of keyboard shortcut dialog | |
62 | var that = this; |
|
62 | var that = this; | |
63 | if ( this.force_rebuild ) { |
|
63 | if ( this.force_rebuild ) { | |
64 | this.shortcut_dialog.remove(); |
|
64 | this.shortcut_dialog.remove(); | |
65 | delete(this.shortcut_dialog); |
|
65 | delete(this.shortcut_dialog); | |
66 | this.force_rebuild = false; |
|
66 | this.force_rebuild = false; | |
67 | } |
|
67 | } | |
68 | if ( this.shortcut_dialog ){ |
|
68 | if ( this.shortcut_dialog ){ | |
69 | // if dialog is already shown, close it |
|
69 | // if dialog is already shown, close it | |
70 | $(this.shortcut_dialog).modal("toggle"); |
|
70 | $(this.shortcut_dialog).modal("toggle"); | |
71 | return; |
|
71 | return; | |
72 | } |
|
72 | } | |
73 | var command_shortcuts = IPython.keyboard_manager.command_shortcuts.help(); |
|
73 | var command_shortcuts = IPython.keyboard_manager.command_shortcuts.help(); | |
74 | var edit_shortcuts = IPython.keyboard_manager.edit_shortcuts.help(); |
|
74 | var edit_shortcuts = IPython.keyboard_manager.edit_shortcuts.help(); | |
75 | var help, shortcut; |
|
75 | var help, shortcut; | |
76 | var i, half, n; |
|
76 | var i, half, n; | |
77 | var element = $('<div/>'); |
|
77 | var element = $('<div/>'); | |
78 |
|
78 | |||
79 | // The documentation |
|
79 | // The documentation | |
80 | var doc = $('<div/>').addClass('alert'); |
|
80 | var doc = $('<div/>').addClass('alert'); | |
81 | doc.append( |
|
81 | doc.append( | |
82 | $('<button/>').addClass('close').attr('data-dismiss','alert').html('×') |
|
82 | $('<button/>').addClass('close').attr('data-dismiss','alert').html('×') | |
83 | ).append( |
|
83 | ).append( | |
84 | 'The IPython Notebook has two different keyboard input modes. <b>Edit mode</b> '+ |
|
84 | 'The IPython Notebook has two different keyboard input modes. <b>Edit mode</b> '+ | |
85 | 'allows you to type code/text into a cell and is indicated by a green cell '+ |
|
85 | 'allows you to type code/text into a cell and is indicated by a green cell '+ | |
86 | 'border. <b>Command mode</b> binds the keyboard to notebook level actions '+ |
|
86 | 'border. <b>Command mode</b> binds the keyboard to notebook level actions '+ | |
87 | 'and is indicated by a grey cell border.' |
|
87 | 'and is indicated by a grey cell border.' | |
88 | ); |
|
88 | ); | |
89 | element.append(doc); |
|
89 | element.append(doc); | |
90 |
|
90 | |||
91 | // Command mode |
|
91 | // Command mode | |
92 | var cmd_div = this.build_command_help(); |
|
92 | var cmd_div = this.build_command_help(); | |
93 | element.append(cmd_div); |
|
93 | element.append(cmd_div); | |
94 |
|
94 | |||
95 | // Edit mode |
|
95 | // Edit mode | |
96 | var edit_div = this.build_edit_help(cm_shortcuts); |
|
96 | var edit_div = this.build_edit_help(cm_shortcuts); | |
97 | element.append(edit_div); |
|
97 | element.append(edit_div); | |
98 |
|
98 | |||
99 | this.shortcut_dialog = IPython.dialog.modal({ |
|
99 | this.shortcut_dialog = IPython.dialog.modal({ | |
100 | title : "Keyboard shortcuts", |
|
100 | title : "Keyboard shortcuts", | |
101 | body : element, |
|
101 | body : element, | |
102 | destroy : false, |
|
102 | destroy : false, | |
103 | buttons : { |
|
103 | buttons : { | |
104 | Close : {} |
|
104 | Close : {} | |
105 | } |
|
105 | } | |
106 | }); |
|
106 | }); | |
107 | this.shortcut_dialog.addClass("modal_stretch"); |
|
107 | this.shortcut_dialog.addClass("modal_stretch"); | |
108 |
|
108 | |||
109 | $([IPython.events]).on('rebuild.QuickHelp', function() { that.force_rebuild = true;}); |
|
109 | $([IPython.events]).on('rebuild.QuickHelp', function() { that.force_rebuild = true;}); | |
110 | }; |
|
110 | }; | |
111 |
|
111 | |||
112 | QuickHelp.prototype.build_command_help = function () { |
|
112 | QuickHelp.prototype.build_command_help = function () { | |
113 | var command_shortcuts = IPython.keyboard_manager.command_shortcuts.help(); |
|
113 | var command_shortcuts = IPython.keyboard_manager.command_shortcuts.help(); | |
114 | return build_div('<h4>Command Mode (press <code>Esc</code> to enable)</h4>', command_shortcuts); |
|
114 | return build_div('<h4>Command Mode (press <code>Esc</code> to enable)</h4>', command_shortcuts); | |
115 | }; |
|
115 | }; | |
116 |
|
116 | |||
117 | var special_case = { pageup: "PageUp", pagedown: "Page Down", 'minus': '-' }; |
|
117 | var special_case = { pageup: "PageUp", pagedown: "Page Down", 'minus': '-' }; | |
118 | var prettify = function (s) { |
|
118 | var prettify = function (s) { | |
119 | s = s.replace(/-$/, 'minus'); // catch shortcuts using '-' key |
|
119 | s = s.replace(/-$/, 'minus'); // catch shortcuts using '-' key | |
120 | var keys = s.split('-'); |
|
120 | var keys = s.split('-'); | |
121 | var k, i; |
|
121 | var k, i; | |
122 | for (i=0; i < keys.length; i++) { |
|
122 | for (i=0; i < keys.length; i++) { | |
123 | k = keys[i]; |
|
123 | k = keys[i]; | |
124 | if ( k.length == 1 ) { |
|
124 | if ( k.length == 1 ) { | |
125 | keys[i] = "<code><strong>" + k + "</strong></code>"; |
|
125 | keys[i] = "<code><strong>" + k + "</strong></code>"; | |
126 | continue; // leave individual keys lower-cased |
|
126 | continue; // leave individual keys lower-cased | |
127 | } |
|
127 | } | |
128 | keys[i] = ( special_case[k] ? special_case[k] : k.charAt(0).toUpperCase() + k.slice(1) ); |
|
128 | keys[i] = ( special_case[k] ? special_case[k] : k.charAt(0).toUpperCase() + k.slice(1) ); | |
129 | keys[i] = "<code><strong>" + keys[i] + "</strong></code>"; |
|
129 | keys[i] = "<code><strong>" + keys[i] + "</strong></code>"; | |
130 | } |
|
130 | } | |
131 | return keys.join('-'); |
|
131 | return keys.join('-'); | |
132 |
|
132 | |||
133 |
|
133 | |||
134 | }; |
|
134 | }; | |
135 |
|
135 | |||
136 | QuickHelp.prototype.build_edit_help = function (cm_shortcuts) { |
|
136 | QuickHelp.prototype.build_edit_help = function (cm_shortcuts) { | |
137 | var edit_shortcuts = IPython.keyboard_manager.edit_shortcuts.help(); |
|
137 | var edit_shortcuts = IPython.keyboard_manager.edit_shortcuts.help(); | |
138 |
jQuery. |
|
138 | jQuery.merge(cm_shortcuts, edit_shortcuts); | |
139 | return build_div('<h4>Edit Mode (press <code>Enter</code> to enable)</h4>', cm_shortcuts); |
|
139 | return build_div('<h4>Edit Mode (press <code>Enter</code> to enable)</h4>', cm_shortcuts); | |
140 | }; |
|
140 | }; | |
141 |
|
141 | |||
142 | var build_one = function (s) { |
|
142 | var build_one = function (s) { | |
143 | var help = s.help; |
|
143 | var help = s.help; | |
144 | var shortcut = prettify(s.shortcut); |
|
144 | var shortcut = prettify(s.shortcut); | |
145 | return $('<div>').addClass('quickhelp'). |
|
145 | return $('<div>').addClass('quickhelp'). | |
146 | append($('<span/>').addClass('shortcut_key').append($(shortcut))). |
|
146 | append($('<span/>').addClass('shortcut_key').append($(shortcut))). | |
147 | append($('<span/>').addClass('shortcut_descr').text(' : ' + help)); |
|
147 | append($('<span/>').addClass('shortcut_descr').text(' : ' + help)); | |
148 |
|
148 | |||
149 | }; |
|
149 | }; | |
150 |
|
150 | |||
151 | var build_div = function (title, shortcuts) { |
|
151 | var build_div = function (title, shortcuts) { | |
152 | var i, half, n; |
|
152 | var i, half, n; | |
153 | var div = $('<div/>').append($(title)); |
|
153 | var div = $('<div/>').append($(title)); | |
154 | var sub_div = $('<div/>').addClass('hbox'); |
|
154 | var sub_div = $('<div/>').addClass('hbox'); | |
155 | var col1 = $('<div/>').addClass('box-flex1'); |
|
155 | var col1 = $('<div/>').addClass('box-flex1'); | |
156 | var col2 = $('<div/>').addClass('box-flex1'); |
|
156 | var col2 = $('<div/>').addClass('box-flex1'); | |
157 | n = shortcuts.length; |
|
157 | n = shortcuts.length; | |
158 | half = ~~(n/2); // Truncate :) |
|
158 | half = ~~(n/2); // Truncate :) | |
159 | for (i=0; i<half; i++) { col1.append( build_one(shortcuts[i]) ); } |
|
159 | for (i=0; i<half; i++) { col1.append( build_one(shortcuts[i]) ); } | |
160 | for (i=half; i<n; i++) { col2.append( build_one(shortcuts[i]) ); } |
|
160 | for (i=half; i<n; i++) { col2.append( build_one(shortcuts[i]) ); } | |
161 | sub_div.append(col1).append(col2); |
|
161 | sub_div.append(col1).append(col2); | |
162 | div.append(sub_div); |
|
162 | div.append(sub_div); | |
163 | return div; |
|
163 | return div; | |
164 | }; |
|
164 | }; | |
165 |
|
165 | |||
166 | // Set module variables |
|
166 | // Set module variables | |
167 | IPython.QuickHelp = QuickHelp; |
|
167 | IPython.QuickHelp = QuickHelp; | |
168 |
|
168 | |||
169 | return IPython; |
|
169 | return IPython; | |
170 |
|
170 | |||
171 | }(IPython)); |
|
171 | }(IPython)); |
General Comments 0
You need to be logged in to leave comments.
Login now