##// END OF EJS Templates
Merge pull request #4962 from ptone/help-typo...
Thomas Kluyver -
r14950:b240b051 merge
parent child Browse files
Show More
@@ -1,133 +1,133 b''
1 //----------------------------------------------------------------------------
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
3 //
4 // Distributed under the terms of the BSD License. The full license is in
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
6 //----------------------------------------------------------------------------
7
7
8 //============================================================================
8 //============================================================================
9 // QuickHelp button
9 // QuickHelp button
10 //============================================================================
10 //============================================================================
11
11
12 var IPython = (function (IPython) {
12 var IPython = (function (IPython) {
13 "use strict";
13 "use strict";
14
14
15 var QuickHelp = function (selector) {
15 var QuickHelp = function (selector) {
16 };
16 };
17
17
18 QuickHelp.prototype.show_keyboard_shortcuts = function () {
18 QuickHelp.prototype.show_keyboard_shortcuts = function () {
19 // toggles display of keyboard shortcut dialog
19 // toggles display of keyboard shortcut dialog
20 var that = this;
20 var that = this;
21 if ( this.shortcut_dialog ){
21 if ( this.shortcut_dialog ){
22 // if dialog is already shown, close it
22 // if dialog is already shown, close it
23 $(this.shortcut_dialog).modal("toggle");
23 $(this.shortcut_dialog).modal("toggle");
24 return;
24 return;
25 }
25 }
26 var command_shortcuts = IPython.keyboard_manager.command_shortcuts.help();
26 var command_shortcuts = IPython.keyboard_manager.command_shortcuts.help();
27 var edit_shortcuts = IPython.keyboard_manager.edit_shortcuts.help();
27 var edit_shortcuts = IPython.keyboard_manager.edit_shortcuts.help();
28 var help, shortcut;
28 var help, shortcut;
29 var i, half, n;
29 var i, half, n;
30 var element = $('<div/>');
30 var element = $('<div/>');
31
31
32 // The documentation
32 // The documentation
33 var doc = $('<div/>').addClass('alert');
33 var doc = $('<div/>').addClass('alert');
34 doc.append(
34 doc.append(
35 $('<button/>').addClass('close').attr('data-dismiss','alert').html('&times;')
35 $('<button/>').addClass('close').attr('data-dismiss','alert').html('&times;')
36 ).append(
36 ).append(
37 'The IPython Notebook has two different keyboard input modes. <b>Edit mode</b> '+
37 'The IPython Notebook has two different keyboard input modes. <b>Edit mode</b> '+
38 'allow you the type code/text into a cell and is indicated by a green cell '+
38 'allows you to type code/text into a cell and is indicated by a green cell '+
39 'border. <b>Command mode</b> binds the keyboard to notebook level actions '+
39 'border. <b>Command mode</b> binds the keyboard to notebook level actions '+
40 'and is indicated by a grey cell border.'
40 'and is indicated by a grey cell border.'
41 )
41 )
42 element.append(doc);
42 element.append(doc);
43
43
44 // Command mode
44 // Command mode
45 var cmd_div = this.build_command_help();
45 var cmd_div = this.build_command_help();
46 element.append(cmd_div);
46 element.append(cmd_div);
47
47
48 // Edit mode
48 // Edit mode
49 var edit_div = this.build_edit_help();
49 var edit_div = this.build_edit_help();
50 element.append(edit_div);
50 element.append(edit_div);
51
51
52 this.shortcut_dialog = IPython.dialog.modal({
52 this.shortcut_dialog = IPython.dialog.modal({
53 title : "Keyboard shortcuts",
53 title : "Keyboard shortcuts",
54 body : element,
54 body : element,
55 destroy : false,
55 destroy : false,
56 buttons : {
56 buttons : {
57 Close : {}
57 Close : {}
58 }
58 }
59 });
59 });
60 };
60 };
61
61
62 QuickHelp.prototype.build_command_help = function () {
62 QuickHelp.prototype.build_command_help = function () {
63 var command_shortcuts = IPython.keyboard_manager.command_shortcuts.help();
63 var command_shortcuts = IPython.keyboard_manager.command_shortcuts.help();
64 var help, shortcut;
64 var help, shortcut;
65 var i, half, n;
65 var i, half, n;
66
66
67 // Command mode
67 // Command mode
68 var cmd_div = $('<div/>').append($('<h4>Command Mode (press ESC to enable)</h4>'));
68 var cmd_div = $('<div/>').append($('<h4>Command Mode (press ESC to enable)</h4>'));
69 var cmd_sub_div = $('<div/>').addClass('hbox');
69 var cmd_sub_div = $('<div/>').addClass('hbox');
70 var cmd_col1 = $('<div/>').addClass('box-flex0');
70 var cmd_col1 = $('<div/>').addClass('box-flex0');
71 var cmd_col2 = $('<div/>').addClass('box-flex0');
71 var cmd_col2 = $('<div/>').addClass('box-flex0');
72 n = command_shortcuts.length;
72 n = command_shortcuts.length;
73 half = ~~(n/2); // Truncate :)
73 half = ~~(n/2); // Truncate :)
74 for (i=0; i<half; i++) {
74 for (i=0; i<half; i++) {
75 help = command_shortcuts[i]['help'];
75 help = command_shortcuts[i]['help'];
76 shortcut = command_shortcuts[i]['shortcut'];
76 shortcut = command_shortcuts[i]['shortcut'];
77 cmd_col1.append($('<div>').addClass('quickhelp').
77 cmd_col1.append($('<div>').addClass('quickhelp').
78 append($('<span/>').addClass('shortcut_key').text(shortcut)).
78 append($('<span/>').addClass('shortcut_key').text(shortcut)).
79 append($('<span/>').addClass('shortcut_descr').text(' : ' + help))
79 append($('<span/>').addClass('shortcut_descr').text(' : ' + help))
80 );
80 );
81 };
81 };
82 for (i=half; i<n; i++) {
82 for (i=half; i<n; i++) {
83 help = command_shortcuts[i]['help'];
83 help = command_shortcuts[i]['help'];
84 shortcut = command_shortcuts[i]['shortcut'];
84 shortcut = command_shortcuts[i]['shortcut'];
85 cmd_col2.append($('<div>').addClass('quickhelp').
85 cmd_col2.append($('<div>').addClass('quickhelp').
86 append($('<span/>').addClass('shortcut_key').text(shortcut)).
86 append($('<span/>').addClass('shortcut_key').text(shortcut)).
87 append($('<span/>').addClass('shortcut_descr').text(' : ' + help))
87 append($('<span/>').addClass('shortcut_descr').text(' : ' + help))
88 );
88 );
89 };
89 };
90 cmd_sub_div.append(cmd_col1).append(cmd_col2);
90 cmd_sub_div.append(cmd_col1).append(cmd_col2);
91 cmd_div.append(cmd_sub_div);
91 cmd_div.append(cmd_sub_div);
92 return cmd_div;
92 return cmd_div;
93 }
93 }
94
94
95 QuickHelp.prototype.build_edit_help = function () {
95 QuickHelp.prototype.build_edit_help = function () {
96 var edit_shortcuts = IPython.keyboard_manager.edit_shortcuts.help();
96 var edit_shortcuts = IPython.keyboard_manager.edit_shortcuts.help();
97 var help, shortcut;
97 var help, shortcut;
98 var i, half, n;
98 var i, half, n;
99
99
100 // Edit mode
100 // Edit mode
101 var edit_div = $('<div/>').append($('<h4>Edit Mode (press ENTER to enable)</h4>'));
101 var edit_div = $('<div/>').append($('<h4>Edit Mode (press ENTER to enable)</h4>'));
102 var edit_sub_div = $('<div/>').addClass('hbox');
102 var edit_sub_div = $('<div/>').addClass('hbox');
103 var edit_col1 = $('<div/>').addClass('box-flex0');
103 var edit_col1 = $('<div/>').addClass('box-flex0');
104 var edit_col2 = $('<div/>').addClass('box-flex0');
104 var edit_col2 = $('<div/>').addClass('box-flex0');
105 n = edit_shortcuts.length;
105 n = edit_shortcuts.length;
106 half = ~~(n/2); // Truncate :)
106 half = ~~(n/2); // Truncate :)
107 for (i=0; i<half; i++) {
107 for (i=0; i<half; i++) {
108 help = edit_shortcuts[i]['help'];
108 help = edit_shortcuts[i]['help'];
109 shortcut = edit_shortcuts[i]['shortcut'];
109 shortcut = edit_shortcuts[i]['shortcut'];
110 edit_col1.append($('<div>').addClass('quickhelp').
110 edit_col1.append($('<div>').addClass('quickhelp').
111 append($('<span/>').addClass('shortcut_key').text(shortcut)).
111 append($('<span/>').addClass('shortcut_key').text(shortcut)).
112 append($('<span/>').addClass('shortcut_descr').text(' : ' + help))
112 append($('<span/>').addClass('shortcut_descr').text(' : ' + help))
113 );
113 );
114 };
114 };
115 for (i=half; i<n; i++) {
115 for (i=half; i<n; i++) {
116 help = edit_shortcuts[i]['help'];
116 help = edit_shortcuts[i]['help'];
117 shortcut = edit_shortcuts[i]['shortcut'];
117 shortcut = edit_shortcuts[i]['shortcut'];
118 edit_col2.append($('<div>').addClass('quickhelp').
118 edit_col2.append($('<div>').addClass('quickhelp').
119 append($('<span/>').addClass('shortcut_key').text(shortcut)).
119 append($('<span/>').addClass('shortcut_key').text(shortcut)).
120 append($('<span/>').addClass('shortcut_descr').text(' : ' + help))
120 append($('<span/>').addClass('shortcut_descr').text(' : ' + help))
121 );
121 );
122 };
122 };
123 edit_sub_div.append(edit_col1).append(edit_col2);
123 edit_sub_div.append(edit_col1).append(edit_col2);
124 edit_div.append(edit_sub_div);
124 edit_div.append(edit_sub_div);
125 return edit_div;
125 return edit_div;
126 }
126 }
127
127
128 // Set module variables
128 // Set module variables
129 IPython.QuickHelp = QuickHelp;
129 IPython.QuickHelp = QuickHelp;
130
130
131 return IPython;
131 return IPython;
132
132
133 }(IPython));
133 }(IPython));
General Comments 0
You need to be logged in to leave comments. Login now