Skip to content

Commit 44bb24a

Browse files
authored
Merge pull request #1123 from jcb91/Sukneet-master
[various] ensure actions have names and prefixes, and buttons keep correct ids
2 parents 7046b76 + 8cc9d79 commit 44bb24a

File tree

24 files changed

+232
-206
lines changed

24 files changed

+232
-206
lines changed

src/jupyter_contrib_nbextensions/nbextensions/addbefore/main.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@ define([
99

1010
var load_extension = function() {
1111
Jupyter.toolbar.add_buttons_group([
12-
{
13-
'label' : 'Insert Cell Above',
14-
'icon' : 'fa-arrow-circle-o-up',
15-
'callback': function () {
12+
Jupyter.keyboard_manager.actions.register ({
13+
'help' : 'Insert Cell Above',
14+
'icon' : 'fa-arrow-circle-o-up',
15+
'handler': function () {
1616
Jupyter.notebook.insert_cell_above('code');
1717
Jupyter.notebook.select_prev();
1818
Jupyter.notebook.focus_cell();
1919
}
20-
},
21-
{
22-
'label' : 'Insert Cell Below',
23-
'icon' : 'fa-arrow-circle-o-down',
24-
'callback': function () {
20+
}, 'insert-cell-above', 'addbefore'),
21+
Jupyter.keyboard_manager.actions.register ({
22+
'help' : 'Insert Cell Below',
23+
'icon' : 'fa-arrow-circle-o-down',
24+
'handler': function () {
2525
Jupyter.notebook.insert_cell_below('code');
2626
Jupyter.notebook.select_next();
2727
Jupyter.notebook.focus_cell();
2828
}
29-
}
29+
}, 'insert-cell-below', 'addbefore'),
3030
]);
3131
$('#insert_above_below').remove()
3232

src/jupyter_contrib_nbextensions/nbextensions/code_font_size/code_font_size.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,20 @@ define([
4747
/*
4848
* Buttons to increase/decrease code font size
4949
*/
50-
{
51-
'label' : 'Increase code font size',
52-
'icon' : 'fa-search-plus',
53-
'callback': function () {
50+
Jupyter.keyboard_manager.actions.register ({
51+
'help' : 'Increase code font size',
52+
'icon' : 'fa-search-plus',
53+
'handler': function () {
5454
$( document ).ready(code_change_fontsize(true));
5555
}
56-
},
57-
{
58-
'label' : 'Decrease code font size',
59-
'icon' : 'fa-search-minus',
60-
'callback': function () {
56+
}, 'increase-code-font-size', 'code_font_size'),
57+
Jupyter.keyboard_manager.actions.register ({
58+
'help' : 'Decrease code font size',
59+
'icon' : 'fa-search-minus',
60+
'handler': function () {
6161
$( document ).ready(code_change_fontsize(false));
6262
}
63-
}
63+
}, 'decrease-code-font-size', 'code_font_size'),
6464

6565
]);
6666
};

src/jupyter_contrib_nbextensions/nbextensions/collapsible_headings/main.js

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,39 @@
736736
'uncollapse_all_headings', mod_name
737737
);
738738

739+
action_names.toggle = Jupyter.keyboard_manager.actions.register ({
740+
handler: function () {
741+
var heading_cell = find_header_cell(Jupyter.notebook.get_selected_cell(), function (cell) {
742+
return cell.element.is(':visible') && !_is_collapsed(cell);
743+
});
744+
if (is_heading(heading_cell)) {
745+
toggle_heading(heading_cell, true);
746+
Jupyter.notebook.select(Jupyter.notebook.find_cell_index(heading_cell));
747+
}
748+
},
749+
help : "Toggle closest heading's collapsed status",
750+
icon : 'fa-angle-double-up',
751+
},
752+
'toggle_collapse_heading', mod_name
753+
);
754+
755+
action_names.toggle_all = Jupyter.keyboard_manager.actions.register ({
756+
handler: function () {
757+
var cells = Jupyter.notebook.get_cells();
758+
for (var ii = 0; ii < cells.length; ii++) {
759+
if (is_heading(cells[ii])) {
760+
Jupyter.keyboard_manager.actions.call(action_names[
761+
is_collapsed_heading(cells[ii]) ? 'uncollapse_all' : 'collapse_all']);
762+
return;
763+
}
764+
}
765+
},
766+
help : 'Collapse/uncollapse all headings based on the status of the first',
767+
icon : 'fa-angle-double-up',
768+
},
769+
'toggle_collapse_all_headings', mod_name
770+
);
771+
739772
action_names.select = Jupyter.keyboard_manager.actions.register({
740773
handler : function (env) {
741774
var cell = env.notebook.get_selected_cell();
@@ -834,42 +867,10 @@
834867
function add_buttons_and_shortcuts () {
835868
// (Maybe) add buttons to the toolbar
836869
if (params.add_button) {
837-
Jupyter.toolbar.add_buttons_group([{
838-
label: 'toggle heading',
839-
icon: 'fa-angle-double-up',
840-
callback: function () {
841-
/**
842-
* Collapse the closest uncollapsed heading above the
843-
* currently selected cell.
844-
*/
845-
var heading_cell = find_header_cell(Jupyter.notebook.get_selected_cell(), function (cell) {
846-
return cell.element.is(':visible') && !_is_collapsed(cell);
847-
});
848-
if (is_heading(heading_cell)) {
849-
toggle_heading(heading_cell, true);
850-
Jupyter.notebook.select(Jupyter.notebook.find_cell_index(heading_cell));
851-
}
852-
}
853-
}]);
870+
Jupyter.toolbar.add_buttons_group([action_names.toggle]);
854871
}
855872
if (params.add_all_cells_button) {
856-
Jupyter.toolbar.add_buttons_group([{
857-
label: 'toggle all headings',
858-
icon: 'fa-angle-double-up',
859-
callback: function () {
860-
/**
861-
* Collapse/uncollapse all heading cells based on status of first
862-
*/
863-
var cells = Jupyter.notebook.get_cells();
864-
for (var ii = 0; ii < cells.length; ii++) {
865-
if (is_heading(cells[ii])) {
866-
Jupyter.keyboard_manager.actions.call(action_names[
867-
is_collapsed_heading(cells[ii]) ? 'uncollapse_all' : 'collapse_all']);
868-
return;
869-
}
870-
}
871-
}
872-
}]);
873+
Jupyter.toolbar.add_buttons_group([action_names.toggle_all]);
873874
}
874875
if (params.add_insert_header_buttons) {
875876
Jupyter.toolbar.add_buttons_group([

src/jupyter_contrib_nbextensions/nbextensions/datestamper/main.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ define([
2626
};
2727

2828
var load_ipython_extension = function () {
29-
IPython.toolbar.add_buttons_group([
30-
{
31-
id : 'datestamp',
32-
label : 'insert datestamp',
33-
icon : 'fa-calendar',
34-
callback : datestamp
35-
}
36-
]);
29+
IPython.toolbar.add_buttons_group([{
30+
id: 'datestamp',
31+
action: IPython.keyboard_manager.actions.register ({
32+
help : 'insert datestamp',
33+
icon : 'fa-calendar',
34+
handler: datestamp
35+
}, 'insert-datestamp', 'datestamp')
36+
}]);
3737
};
3838

3939
var extension = {
4040
load_ipython_extension : load_ipython_extension,
4141
};
4242
return extension;
43-
});
43+
});

src/jupyter_contrib_nbextensions/nbextensions/equation-numbering/main.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,27 @@ define([
77
'require',
88
'notebook/js/textcell',
99
'base/js/utils',
10-
], function(IPython, $, require, textcell, utils) {
10+
], function(Jupyter, $, require, textcell, utils) {
1111
"use strict";
1212

13+
var MathJax = window.MathJax;
14+
1315
var load_ipython_extension = function() {
14-
IPython.toolbar.add_buttons_group([
15-
{
16-
id: 'reset_numbering',
17-
label: 'Reset equation numbering',
18-
icon: 'fa-sort-numeric-asc',
19-
callback: function () {
16+
Jupyter.toolbar.add_buttons_group([{
17+
id: 'reset_numbering',
18+
action: Jupyter.keyboard_manager.actions.register ({
19+
help : 'Reset equation numbering',
20+
icon : 'fa-sort-numeric-asc',
21+
handler: function () {
2022
MathJax.Hub.Queue(
2123
["resetEquationNumbers", MathJax.InputJax.TeX],
2224
["PreProcess", MathJax.Hub],
2325
["Reprocess", MathJax.Hub]
2426
);
2527
$('#reset_numbering').blur();
2628
}
27-
}
28-
]);
29+
}, 'reset-numbering', 'equation_numbering')
30+
}]);
2931
MathJax.Hub.Config({
3032
TeX: { equationNumbers: { autoNumber: "AMS" } }
3133
});

src/jupyter_contrib_nbextensions/nbextensions/exercise/main.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,17 @@ define([
131131
}
132132

133133
function load_ipython_extension(){
134-
IPython.toolbar.add_buttons_group([
135-
{
136-
id : 'hide_solutions',
137-
label : 'Exercise: Create/Remove solutions',
138-
icon : 'fa-mortar-board',
139-
callback : function () {
134+
IPython.toolbar.add_buttons_group([{
135+
id: 'hide_solutions',
136+
action: IPython.keyboard_manager.actions.register ({
137+
help : 'Exercise: Create/Remove solutions',
138+
icon : 'fa-mortar-board',
139+
handler : function () {
140140
//console.log(IPython.notebook.get_selected_cells())
141141
hide_solutions();
142142
}
143-
}
144-
]);
143+
}, 'hide_solutions', 'exercise')
144+
}]);
145145

146146
/**
147147
* load css file and append to document

src/jupyter_contrib_nbextensions/nbextensions/exercise2/main.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,16 @@ id=\"myCheck' + cbx + '\" >\
127127
}
128128

129129
function load_ipython_extension(){
130-
IPython.toolbar.add_buttons_group([
131-
{
132-
id : 'process_solution',
133-
label : 'Exercise2: Create/Remove solution',
134-
icon : 'fa-toggle-on',
135-
callback : function () {
130+
IPython.toolbar.add_buttons_group([{
131+
id: 'process_solution',
132+
action: IPython.keyboard_manager.actions.register ({
133+
help : 'Exercise2: Create/Remove solution',
134+
icon : 'fa-toggle-on',
135+
handler : function () {
136136
process_solution();
137137
}
138-
}
139-
]);
138+
}, 'process_solution', 'exercise2')
139+
}]);
140140

141141

142142

src/jupyter_contrib_nbextensions/nbextensions/export_embedded/main.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ define([
3434
/* Add also a Button, currently disabled */
3535
/*
3636
Jupyter.toolbar.add_buttons_group([{
37-
id : 'export_embeddedhtml',
38-
label : 'Embedded HTML Export',
39-
icon : 'fa-save',
40-
callback : function() {
37+
id: 'export_embeddedhtml',
38+
action: Jupyter.keyboard_manager.actions.register ({
39+
help : 'Embedded HTML Export',
40+
icon : 'fa-save',
41+
handler: function() {
4142
Jupyter.menubar._nbconvert('html_embed', true);
4243
}
44+
}, 'export-embedded-html', 'export_embedded')
4345
}]);
4446
*/
4547
if (Jupyter.notebook !== undefined && Jupyter.notebook._fully_loaded) {

src/jupyter_contrib_nbextensions/nbextensions/freeze/main.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -160,26 +160,28 @@ define([
160160
}
161161

162162
function load_extension () {
163-
Jupyter.toolbar.add_buttons_group([
164-
{
165-
id : 'make_normal',
166-
label : 'lift restrictions from selected cells',
163+
Jupyter.toolbar.add_buttons_group([{
164+
id: 'make_normal',
165+
action: Jupyter.keyboard_manager.actions.register ({
166+
help : 'lift restrictions from selected cells',
167167
icon : 'fa-unlock-alt',
168-
callback : make_normal_selected
169-
},
170-
{
171-
id : 'make_read_only',
172-
label : 'make selected cells read-only',
168+
handler : make_normal_selected
169+
}, 'make-cells-normal', mod_name)
170+
}, {
171+
id: 'make_read_only',
172+
action: Jupyter.keyboard_manager.actions.register({
173+
help : 'make selected cells read-only',
173174
icon: 'fa-lock',
174-
callback : make_read_only_selected
175-
},
176-
{
177-
id : 'freeze_cells',
178-
label : 'freeze selected cells',
175+
handler : make_read_only_selected
176+
}, 'make-cells-read-only', mod_name),
177+
}, {
178+
id: 'freeze_cells',
179+
action: Jupyter.keyboard_manager.actions.register({
180+
help : 'freeze selected cells',
179181
icon : 'fa-asterisk',
180-
callback : make_frozen_selected
181-
}
182-
]);
182+
handler : make_frozen_selected
183+
}, 'freeze-cells', mod_name)
184+
}]);
183185

184186
patch_CodeCell_execute();
185187
patch_MarkdownCell_unrender();

src/jupyter_contrib_nbextensions/nbextensions/gist_it/main.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ define([
4343

4444
var initialize = function () {
4545
update_params();
46-
Jupyter.toolbar.add_buttons_group([{
47-
label : 'Create/Edit Gist of Notebook',
48-
icon : 'fa-github',
49-
callback: show_gist_editor_modal
50-
}]);
46+
Jupyter.toolbar.add_buttons_group([
47+
Jupyter.keyboard_manager.actions.register ({
48+
help : 'Create/Edit Gist of Notebook',
49+
icon : 'fa-github',
50+
handler: show_gist_editor_modal
51+
}, 'create-gist-from-notebook', 'gist_it')
52+
]);
5153
};
5254

5355
// update params with any specified in the server's config file

0 commit comments

Comments
 (0)