Skip to content

Commit 8cc9d79

Browse files
committed
[various] ensure actions have names and prefixes, and buttons keep correct ids
1 parent a993df3 commit 8cc9d79

File tree

24 files changed

+176
-153
lines changed

24 files changed

+176
-153
lines changed

src/jupyter_contrib_nbextensions/nbextensions/addbefore/main.js

Lines changed: 4 additions & 4 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-
Jupyter.actions.register ({
12+
Jupyter.keyboard_manager.actions.register ({
1313
'help' : 'Insert Cell Above',
1414
'icon' : 'fa-arrow-circle-o-up',
1515
'handler': function () {
1616
Jupyter.notebook.insert_cell_above('code');
1717
Jupyter.notebook.select_prev();
1818
Jupyter.notebook.focus_cell();
1919
}
20-
}),
21-
Jupyter.actions.register ({
20+
}, 'insert-cell-above', 'addbefore'),
21+
Jupyter.keyboard_manager.actions.register ({
2222
'help' : 'Insert Cell Below',
2323
'icon' : 'fa-arrow-circle-o-down',
2424
'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: 4 additions & 4 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-
Jupyter.actions.register ({
50+
Jupyter.keyboard_manager.actions.register ({
5151
'help' : 'Increase code font size',
5252
'icon' : 'fa-search-plus',
5353
'handler': function () {
5454
$( document ).ready(code_change_fontsize(true));
5555
}
56-
}),
57-
Jupyter.actions.register ({
56+
}, 'increase-code-font-size', 'code_font_size'),
57+
Jupyter.keyboard_manager.actions.register ({
5858
'help' : 'Decrease code font size',
5959
'icon' : 'fa-search-minus',
6060
'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 & 38 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,46 +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-
Jupyter.actions.register ({
839-
help : 'toggle heading',
840-
icon : 'fa-angle-double-up',
841-
handler: function () {
842-
/**
843-
* Collapse the closest uncollapsed heading above the
844-
* currently selected cell.
845-
*/
846-
var heading_cell = find_header_cell(Jupyter.notebook.get_selected_cell(), function (cell) {
847-
return cell.element.is(':visible') && !_is_collapsed(cell);
848-
});
849-
if (is_heading(heading_cell)) {
850-
toggle_heading(heading_cell, true);
851-
Jupyter.notebook.select(Jupyter.notebook.find_cell_index(heading_cell));
852-
}
853-
}
854-
})
855-
]);
870+
Jupyter.toolbar.add_buttons_group([action_names.toggle]);
856871
}
857872
if (params.add_all_cells_button) {
858-
Jupyter.toolbar.add_buttons_group([
859-
Jupyter.actions.register ({
860-
help : 'toggle all headings',
861-
icon : 'fa-angle-double-up',
862-
handler: function () {
863-
/**
864-
* Collapse/uncollapse all heading cells based on status of first
865-
*/
866-
var cells = Jupyter.notebook.get_cells();
867-
for (var ii = 0; ii < cells.length; ii++) {
868-
if (is_heading(cells[ii])) {
869-
Jupyter.keyboard_manager.actions.call(action_names[
870-
is_collapsed_heading(cells[ii]) ? 'uncollapse_all' : 'collapse_all']);
871-
return;
872-
}
873-
}
874-
}
875-
})
876-
]);
873+
Jupyter.toolbar.add_buttons_group([action_names.toggle_all]);
877874
}
878875
if (params.add_insert_header_buttons) {
879876
Jupyter.toolbar.add_buttons_group([

src/jupyter_contrib_nbextensions/nbextensions/datestamper/main.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ define([
2626
};
2727

2828
var load_ipython_extension = function () {
29-
IPython.toolbar.add_buttons_group([
30-
Jupyter.actions.register ({
29+
IPython.toolbar.add_buttons_group([{
30+
id: 'datestamp',
31+
action: IPython.keyboard_manager.actions.register ({
3132
help : 'insert datestamp',
3233
icon : 'fa-calendar',
3334
handler: datestamp
34-
}, 'datestamp')
35-
]);
35+
}, 'insert-datestamp', 'datestamp')
36+
}]);
3637
};
3738

3839
var extension = {

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ 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-
Jupyter.actions.register ({
16+
Jupyter.toolbar.add_buttons_group([{
17+
id: 'reset_numbering',
18+
action: Jupyter.keyboard_manager.actions.register ({
1619
help : 'Reset equation numbering',
1720
icon : 'fa-sort-numeric-asc',
1821
handler: function () {
@@ -23,8 +26,8 @@ define([
2326
);
2427
$('#reset_numbering').blur();
2528
}
26-
}, 'reset_numbering')
27-
]);
29+
}, 'reset-numbering', 'equation_numbering')
30+
}]);
2831
MathJax.Hub.Config({
2932
TeX: { equationNumbers: { autoNumber: "AMS" } }
3033
});

src/jupyter_contrib_nbextensions/nbextensions/exercise/main.js

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

133133
function load_ipython_extension(){
134-
IPython.toolbar.add_buttons_group([
135-
Jupyter.actions.register ({
134+
IPython.toolbar.add_buttons_group([{
135+
id: 'hide_solutions',
136+
action: IPython.keyboard_manager.actions.register ({
136137
help : 'Exercise: Create/Remove solutions',
137138
icon : 'fa-mortar-board',
138139
handler : function () {
139140
//console.log(IPython.notebook.get_selected_cells())
140141
hide_solutions();
141142
}
142-
}, 'hide_solutions')
143-
]);
143+
}, 'hide_solutions', 'exercise')
144+
}]);
144145

145146
/**
146147
* load css file and append to document

src/jupyter_contrib_nbextensions/nbextensions/exercise2/main.js

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

129129
function load_ipython_extension(){
130-
IPython.toolbar.add_buttons_group([
131-
Jupyter.actions.register ({
130+
IPython.toolbar.add_buttons_group([{
131+
id: 'process_solution',
132+
action: IPython.keyboard_manager.actions.register ({
132133
help : 'Exercise2: Create/Remove solution',
133134
icon : 'fa-toggle-on',
134135
handler : function () {
135136
process_solution();
136137
}
137-
}, 'process_solution')
138-
]);
138+
}, 'process_solution', 'exercise2')
139+
}]);
139140

140141

141142

src/jupyter_contrib_nbextensions/nbextensions/export_embedded/main.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@ define([
3333

3434
/* Add also a Button, currently disabled */
3535
/*
36-
Jupyter.toolbar.add_buttons_group([
37-
Jupyter.actions.register ({
38-
help : 'Embedded HTML Export',
39-
icon : 'fa-save',
40-
handler: function() {
41-
Jupyter.menubar._nbconvert('html_embed', true);
42-
}
43-
}, 'export_embeddedhtml')
44-
]);
36+
Jupyter.toolbar.add_buttons_group([{
37+
id: 'export_embeddedhtml',
38+
action: Jupyter.keyboard_manager.actions.register ({
39+
help : 'Embedded HTML Export',
40+
icon : 'fa-save',
41+
handler: function() {
42+
Jupyter.menubar._nbconvert('html_embed', true);
43+
}
44+
}, 'export-embedded-html', 'export_embedded')
45+
}]);
4546
*/
4647
if (Jupyter.notebook !== undefined && Jupyter.notebook._fully_loaded) {
4748
// notebook_loaded.Notebook event has already happened

src/jupyter_contrib_nbextensions/nbextensions/freeze/main.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,23 +160,28 @@ define([
160160
}
161161

162162
function load_extension () {
163-
Jupyter.toolbar.add_buttons_group([
164-
Jupyter.actions.register ({
163+
Jupyter.toolbar.add_buttons_group([{
164+
id: 'make_normal',
165+
action: Jupyter.keyboard_manager.actions.register ({
165166
help : 'lift restrictions from selected cells',
166167
icon : 'fa-unlock-alt',
167168
handler : make_normal_selected
168-
},'make_normal'),
169-
Jupyter.actions.register({
169+
}, 'make-cells-normal', mod_name)
170+
}, {
171+
id: 'make_read_only',
172+
action: Jupyter.keyboard_manager.actions.register({
170173
help : 'make selected cells read-only',
171174
icon: 'fa-lock',
172175
handler : make_read_only_selected
173-
},'make_read_only'),
174-
Jupyter.actions.register({
176+
}, 'make-cells-read-only', mod_name),
177+
}, {
178+
id: 'freeze_cells',
179+
action: Jupyter.keyboard_manager.actions.register({
175180
help : 'freeze selected cells',
176181
icon : 'fa-asterisk',
177182
handler : make_frozen_selected
178-
},'freeze_cells')
179-
]);
183+
}, 'freeze-cells', mod_name)
184+
}]);
180185

181186
patch_CodeCell_execute();
182187
patch_MarkdownCell_unrender();

src/jupyter_contrib_nbextensions/nbextensions/gist_it/main.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ define([
4444
var initialize = function () {
4545
update_params();
4646
Jupyter.toolbar.add_buttons_group([
47-
Jupyter.actions.register ({
48-
help : 'Create/Edit Gist of Notebook',
47+
Jupyter.keyboard_manager.actions.register ({
48+
help : 'Create/Edit Gist of Notebook',
4949
icon : 'fa-github',
5050
handler: show_gist_editor_modal
51-
})
51+
}, 'create-gist-from-notebook', 'gist_it')
5252
]);
5353
};
5454

0 commit comments

Comments
 (0)