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