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