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