##// END OF EJS Templates
complete unicode mac symbol
Bussonnier Matthias -
Show More
@@ -1,267 +1,271 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 define([
4 define([
5 'base/js/namespace',
5 'base/js/namespace',
6 'jquery',
6 'jquery',
7 'base/js/utils',
7 'base/js/utils',
8 'base/js/dialog',
8 'base/js/dialog',
9 ], function(IPython, $, utils, dialog) {
9 ], function(IPython, $, utils, dialog) {
10 "use strict";
10 "use strict";
11 var platform = utils.platform;
11 var platform = utils.platform;
12
12
13 var QuickHelp = function (options) {
13 var QuickHelp = function (options) {
14 /**
14 /**
15 * Constructor
15 * Constructor
16 *
16 *
17 * Parameters:
17 * Parameters:
18 * options: dictionary
18 * options: dictionary
19 * Dictionary of keyword arguments.
19 * Dictionary of keyword arguments.
20 * events: $(Events) instance
20 * events: $(Events) instance
21 * keyboard_manager: KeyboardManager instance
21 * keyboard_manager: KeyboardManager instance
22 * notebook: Notebook instance
22 * notebook: Notebook instance
23 */
23 */
24 this.keyboard_manager = options.keyboard_manager;
24 this.keyboard_manager = options.keyboard_manager;
25 this.notebook = options.notebook;
25 this.notebook = options.notebook;
26 this.keyboard_manager.quick_help = this;
26 this.keyboard_manager.quick_help = this;
27 this.events = options.events;
27 this.events = options.events;
28 };
28 };
29
29
30 var cmd_ctrl = 'Ctrl-';
30 var cmd_ctrl = 'Ctrl-';
31 var platform_specific;
31 var platform_specific;
32
32
33 if (platform === 'MacOS') {
33 if (platform === 'MacOS') {
34 // Mac OS X specific
34 // Mac OS X specific
35 cmd_ctrl = 'Cmd-';
35 cmd_ctrl = 'Cmd-';
36 platform_specific = [
36 platform_specific = [
37 { shortcut: "Cmd-Up", help:"go to cell start" },
37 { shortcut: "Cmd-Up", help:"go to cell start" },
38 { shortcut: "Cmd-Down", help:"go to cell end" },
38 { shortcut: "Cmd-Down", help:"go to cell end" },
39 { shortcut: "Alt-Left", help:"go one word left" },
39 { shortcut: "Alt-Left", help:"go one word left" },
40 { shortcut: "Alt-Right", help:"go one word right" },
40 { shortcut: "Alt-Right", help:"go one word right" },
41 { shortcut: "Alt-Backspace", help:"del word before" },
41 { shortcut: "Alt-Backspace", help:"del word before" },
42 { shortcut: "Alt-Delete", help:"del word after" },
42 { shortcut: "Alt-Delete", help:"del word after" },
43 ];
43 ];
44 } else {
44 } else {
45 // PC specific
45 // PC specific
46 platform_specific = [
46 platform_specific = [
47 { shortcut: "Ctrl-Home", help:"go to cell start" },
47 { shortcut: "Ctrl-Home", help:"go to cell start" },
48 { shortcut: "Ctrl-Up", help:"go to cell start" },
48 { shortcut: "Ctrl-Up", help:"go to cell start" },
49 { shortcut: "Ctrl-End", help:"go to cell end" },
49 { shortcut: "Ctrl-End", help:"go to cell end" },
50 { shortcut: "Ctrl-Down", help:"go to cell end" },
50 { shortcut: "Ctrl-Down", help:"go to cell end" },
51 { shortcut: "Ctrl-Left", help:"go one word left" },
51 { shortcut: "Ctrl-Left", help:"go one word left" },
52 { shortcut: "Ctrl-Right", help:"go one word right" },
52 { shortcut: "Ctrl-Right", help:"go one word right" },
53 { shortcut: "Ctrl-Backspace", help:"del word before" },
53 { shortcut: "Ctrl-Backspace", help:"del word before" },
54 { shortcut: "Ctrl-Delete", help:"del word after" },
54 { shortcut: "Ctrl-Delete", help:"del word after" },
55 ];
55 ];
56 }
56 }
57
57
58 var cm_shortcuts = [
58 var cm_shortcuts = [
59 { shortcut:"Tab", help:"code completion or indent" },
59 { shortcut:"Tab", help:"code completion or indent" },
60 { shortcut:"Shift-Tab", help:"tooltip" },
60 { shortcut:"Shift-Tab", help:"tooltip" },
61 { shortcut: cmd_ctrl + "]", help:"indent" },
61 { shortcut: cmd_ctrl + "]", help:"indent" },
62 { shortcut: cmd_ctrl + "[", help:"dedent" },
62 { shortcut: cmd_ctrl + "[", help:"dedent" },
63 { shortcut: cmd_ctrl + "a", help:"select all" },
63 { shortcut: cmd_ctrl + "a", help:"select all" },
64 { shortcut: cmd_ctrl + "z", help:"undo" },
64 { shortcut: cmd_ctrl + "z", help:"undo" },
65 { shortcut: cmd_ctrl + "Shift-z", help:"redo" },
65 { shortcut: cmd_ctrl + "Shift-z", help:"redo" },
66 { shortcut: cmd_ctrl + "y", help:"redo" },
66 { shortcut: cmd_ctrl + "y", help:"redo" },
67 ].concat( platform_specific );
67 ].concat( platform_specific );
68
68
69 var mac_humanize_map = {
69 var mac_humanize_map = {
70 // all these are unicode, will probably display badly on anything except macs.
70 // all these are unicode, will probably display badly on anything except macs.
71 // these are the standard symbol that are used in MacOS native menus
71 // these are the standard symbol that are used in MacOS native menus
72 // cf http://apple.stackexchange.com/questions/55727/
73 // for htmlentities and/or unicode value
72 'cmd':'⌘',
74 'cmd':'⌘',
73 'shift':'⇧',
75 'shift':'⇧',
74 'alt':'βŒ₯',
76 'alt':'βŒ₯',
75 'up':'↑',
77 'up':'↑',
76 'down':'↓',
78 'down':'↓',
77 'left':'←',
79 'left':'←',
78 'right':'β†’',
80 'right':'β†’',
79 'eject':'⏏',
81 'eject':'⏏',
80 'tab':'β‡₯',
82 'tab':'β‡₯',
81 'capslock':'⇧',
83 'backtab':'⇀',
84 'capslock':'β‡ͺ',
82 'esc':'βŽ‹',
85 'esc':'βŽ‹',
83 'ctrl':'βŒƒ',
86 'ctrl':'βŒƒ',
84 'enter':'↩',
87 'enter':'↩',
85 'pageup':'β‡ž',
88 'pageup':'β‡ž',
86 'pagedown':'β‡Ÿ',
89 'pagedown':'β‡Ÿ',
87 'home':'β†–',
90 'home':'β†–',
88 'end':'β†˜',
91 'end':'β†˜',
89 'altenter':'⌀',
92 'altenter':'⌀',
90 'space':'␣',
93 'space':'␣',
91 'backspace':'⇀',
94 'delete':'⌦',
95 'backspace':'⌫',
92 'apple':'ο£Ώ',
96 'apple':'ο£Ώ',
93 };
97 };
94
98
95 var default_humanize_map = {
99 var default_humanize_map = {
96 'shift':'Shift',
100 'shift':'Shift',
97 'alt':'Alt',
101 'alt':'Alt',
98 'up':'Up',
102 'up':'Up',
99 'down':'Down',
103 'down':'Down',
100 'left':'Left',
104 'left':'Left',
101 'right':'Right',
105 'right':'Right',
102 'tab':'Tab',
106 'tab':'Tab',
103 'capslock':'Caps Lock',
107 'capslock':'Caps Lock',
104 'esc':'Esc',
108 'esc':'Esc',
105 'ctrl':'Ctrl',
109 'ctrl':'Ctrl',
106 'enter':'Enter',
110 'enter':'Enter',
107 'pageup':'Page Up',
111 'pageup':'Page Up',
108 'pagedown':'Page Down',
112 'pagedown':'Page Down',
109 'home':'Home',
113 'home':'Home',
110 'end':'End',
114 'end':'End',
111 'space':'Space',
115 'space':'Space',
112 'backspace,':'Backaspace',
116 'backspace,':'Backspace',
113 };
117 };
114
118
115 var humanize_map;
119 var humanize_map;
116
120
117 if (platform === 'MacOS'){
121 if (platform === 'MacOS'){
118 humanize_map = mac_humanize_map;
122 humanize_map = mac_humanize_map;
119 } else {
123 } else {
120 humanize_map = default_humanize_map;
124 humanize_map = default_humanize_map;
121 }
125 }
122
126
123 function humanize_key(key){
127 function humanize_key(key){
124 if (key.length === 1){
128 if (key.length === 1){
125 key = key.toUpperCase();
129 key = key.toUpperCase();
126 }
130 }
127 return humanize_map[key.toLowerCase()]||key;
131 return humanize_map[key.toLowerCase()]||key;
128 }
132 }
129
133
130 function humanize_sequence(sequence){
134 function humanize_sequence(sequence){
131 var joinchar = ',';
135 var joinchar = ',';
132 var hum = _.map(sequence.replace(/meta/g, 'cmd').split(','), humanize_shortcut).join(joinchar);
136 var hum = _.map(sequence.replace(/meta/g, 'cmd').split(','), humanize_shortcut).join(joinchar);
133 return hum;
137 return hum;
134 }
138 }
135
139
136 function humanize_shortcut(shortcut){
140 function humanize_shortcut(shortcut){
137 var joinchar = '-';
141 var joinchar = '-';
138 if (platform === 'MacOS'){
142 if (platform === 'MacOS'){
139 joinchar = '';
143 joinchar = '';
140 }
144 }
141 var sh = _.map(shortcut.split('-'), humanize_key ).join(joinchar);
145 var sh = _.map(shortcut.split('-'), humanize_key ).join(joinchar);
142 return sh;
146 return sh;
143 }
147 }
144
148
145
149
146 QuickHelp.prototype.show_keyboard_shortcuts = function () {
150 QuickHelp.prototype.show_keyboard_shortcuts = function () {
147 /**
151 /**
148 * toggles display of keyboard shortcut dialog
152 * toggles display of keyboard shortcut dialog
149 */
153 */
150 var that = this;
154 var that = this;
151 if ( this.force_rebuild ) {
155 if ( this.force_rebuild ) {
152 this.shortcut_dialog.remove();
156 this.shortcut_dialog.remove();
153 delete(this.shortcut_dialog);
157 delete(this.shortcut_dialog);
154 this.force_rebuild = false;
158 this.force_rebuild = false;
155 }
159 }
156 if ( this.shortcut_dialog ){
160 if ( this.shortcut_dialog ){
157 // if dialog is already shown, close it
161 // if dialog is already shown, close it
158 $(this.shortcut_dialog).modal("toggle");
162 $(this.shortcut_dialog).modal("toggle");
159 return;
163 return;
160 }
164 }
161 var command_shortcuts = this.keyboard_manager.command_shortcuts.help();
165 var command_shortcuts = this.keyboard_manager.command_shortcuts.help();
162 var edit_shortcuts = this.keyboard_manager.edit_shortcuts.help();
166 var edit_shortcuts = this.keyboard_manager.edit_shortcuts.help();
163 var help, shortcut;
167 var help, shortcut;
164 var i, half, n;
168 var i, half, n;
165 var element = $('<div/>');
169 var element = $('<div/>');
166
170
167 // The documentation
171 // The documentation
168 var doc = $('<div/>').addClass('alert alert-warning');
172 var doc = $('<div/>').addClass('alert alert-warning');
169 doc.append(
173 doc.append(
170 $('<button/>').addClass('close').attr('data-dismiss','alert').html('&times;')
174 $('<button/>').addClass('close').attr('data-dismiss','alert').html('&times;')
171 ).append(
175 ).append(
172 'The IPython Notebook has two different keyboard input modes. <b>Edit mode</b> '+
176 'The IPython Notebook has two different keyboard input modes. <b>Edit mode</b> '+
173 'allows you to type code/text into a cell and is indicated by a green cell '+
177 'allows you to type code/text into a cell and is indicated by a green cell '+
174 'border. <b>Command mode</b> binds the keyboard to notebook level actions '+
178 'border. <b>Command mode</b> binds the keyboard to notebook level actions '+
175 'and is indicated by a grey cell border.'
179 'and is indicated by a grey cell border.'
176 );
180 );
177 element.append(doc);
181 element.append(doc);
178
182
179 // Command mode
183 // Command mode
180 var cmd_div = this.build_command_help();
184 var cmd_div = this.build_command_help();
181 element.append(cmd_div);
185 element.append(cmd_div);
182
186
183 // Edit mode
187 // Edit mode
184 var edit_div = this.build_edit_help(cm_shortcuts);
188 var edit_div = this.build_edit_help(cm_shortcuts);
185 element.append(edit_div);
189 element.append(edit_div);
186
190
187 this.shortcut_dialog = dialog.modal({
191 this.shortcut_dialog = dialog.modal({
188 title : "Keyboard shortcuts",
192 title : "Keyboard shortcuts",
189 body : element,
193 body : element,
190 destroy : false,
194 destroy : false,
191 buttons : {
195 buttons : {
192 Close : {}
196 Close : {}
193 },
197 },
194 notebook: this.notebook,
198 notebook: this.notebook,
195 keyboard_manager: this.keyboard_manager,
199 keyboard_manager: this.keyboard_manager,
196 });
200 });
197 this.shortcut_dialog.addClass("modal_stretch");
201 this.shortcut_dialog.addClass("modal_stretch");
198
202
199 this.events.on('rebuild.QuickHelp', function() { that.force_rebuild = true;});
203 this.events.on('rebuild.QuickHelp', function() { that.force_rebuild = true;});
200 };
204 };
201
205
202 QuickHelp.prototype.build_command_help = function () {
206 QuickHelp.prototype.build_command_help = function () {
203 var command_shortcuts = this.keyboard_manager.command_shortcuts.help();
207 var command_shortcuts = this.keyboard_manager.command_shortcuts.help();
204 return build_div('<h4>Command Mode (press <code>Esc</code> to enable)</h4>', command_shortcuts);
208 return build_div('<h4>Command Mode (press <code>Esc</code> to enable)</h4>', command_shortcuts);
205 };
209 };
206
210
207 var special_case = { pageup: "PageUp", pagedown: "Page Down", 'minus': '-' };
211 var special_case = { pageup: "PageUp", pagedown: "Page Down", 'minus': '-' };
208 var prettify = function (s) {
212 var prettify = function (s) {
209 s = s.replace(/-$/, 'minus'); // catch shortcuts using '-' key
213 s = s.replace(/-$/, 'minus'); // catch shortcuts using '-' key
210 var keys = s.split('-');
214 var keys = s.split('-');
211 var k, i;
215 var k, i;
212 for (i=0; i < keys.length; i++) {
216 for (i=0; i < keys.length; i++) {
213 k = keys[i];
217 k = keys[i];
214 if ( k.length == 1 ) {
218 if ( k.length == 1 ) {
215 keys[i] = "<code><strong>" + k + "</strong></code>";
219 keys[i] = "<code><strong>" + k + "</strong></code>";
216 continue; // leave individual keys lower-cased
220 continue; // leave individual keys lower-cased
217 }
221 }
218 if (k.indexOf(',') === -1){
222 if (k.indexOf(',') === -1){
219 keys[i] = ( special_case[k] ? special_case[k] : k.charAt(0).toUpperCase() + k.slice(1) );
223 keys[i] = ( special_case[k] ? special_case[k] : k.charAt(0).toUpperCase() + k.slice(1) );
220 }
224 }
221 keys[i] = "<code><strong>" + keys[i] + "</strong></code>";
225 keys[i] = "<code><strong>" + keys[i] + "</strong></code>";
222 }
226 }
223 return keys.join('-');
227 return keys.join('-');
224
228
225
229
226 };
230 };
227
231
228 QuickHelp.prototype.build_edit_help = function (cm_shortcuts) {
232 QuickHelp.prototype.build_edit_help = function (cm_shortcuts) {
229 var edit_shortcuts = this.keyboard_manager.edit_shortcuts.help();
233 var edit_shortcuts = this.keyboard_manager.edit_shortcuts.help();
230 jQuery.merge(cm_shortcuts, edit_shortcuts);
234 jQuery.merge(cm_shortcuts, edit_shortcuts);
231 return build_div('<h4>Edit Mode (press <code>Enter</code> to enable)</h4>', cm_shortcuts);
235 return build_div('<h4>Edit Mode (press <code>Enter</code> to enable)</h4>', cm_shortcuts);
232 };
236 };
233
237
234 var build_one = function (s) {
238 var build_one = function (s) {
235 var help = s.help;
239 var help = s.help;
236 var shortcut = '';
240 var shortcut = '';
237 if(s.shortcut){
241 if(s.shortcut){
238 shortcut = prettify(humanize_sequence(s.shortcut));
242 shortcut = prettify(humanize_sequence(s.shortcut));
239 } else {
243 } else {
240 console.error('[debug] - nothing for', s)
244 console.error('[debug] - nothing for', s)
241 }
245 }
242 return $('<div>').addClass('quickhelp').
246 return $('<div>').addClass('quickhelp').
243 append($('<span/>').addClass('shortcut_key').append($(shortcut))).
247 append($('<span/>').addClass('shortcut_key').append($(shortcut))).
244 append($('<span/>').addClass('shortcut_descr').text(' : ' + help));
248 append($('<span/>').addClass('shortcut_descr').text(' : ' + help));
245
249
246 };
250 };
247
251
248 var build_div = function (title, shortcuts) {
252 var build_div = function (title, shortcuts) {
249 var i, half, n;
253 var i, half, n;
250 var div = $('<div/>').append($(title));
254 var div = $('<div/>').append($(title));
251 var sub_div = $('<div/>').addClass('hbox');
255 var sub_div = $('<div/>').addClass('hbox');
252 var col1 = $('<div/>').addClass('box-flex1');
256 var col1 = $('<div/>').addClass('box-flex1');
253 var col2 = $('<div/>').addClass('box-flex1');
257 var col2 = $('<div/>').addClass('box-flex1');
254 n = shortcuts.length;
258 n = shortcuts.length;
255 half = ~~(n/2); // Truncate :)
259 half = ~~(n/2); // Truncate :)
256 for (i=0; i<half; i++) { col1.append( build_one(shortcuts[i]) ); }
260 for (i=0; i<half; i++) { col1.append( build_one(shortcuts[i]) ); }
257 for (i=half; i<n; i++) { col2.append( build_one(shortcuts[i]) ); }
261 for (i=half; i<n; i++) { col2.append( build_one(shortcuts[i]) ); }
258 sub_div.append(col1).append(col2);
262 sub_div.append(col1).append(col2);
259 div.append(sub_div);
263 div.append(sub_div);
260 return div;
264 return div;
261 };
265 };
262
266
263 // Backwards compatability.
267 // Backwards compatability.
264 IPython.QuickHelp = QuickHelp;
268 IPython.QuickHelp = QuickHelp;
265
269
266 return {'QuickHelp': QuickHelp};
270 return {'QuickHelp': QuickHelp};
267 });
271 });
General Comments 0
You need to be logged in to leave comments. Login now