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