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