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