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