Skip to content

Commit

Permalink
update add_buttons_group to use action instead of button
Browse files Browse the repository at this point in the history
  • Loading branch information
Sukneet committed Sep 21, 2017
1 parent 1547b3e commit 4b06a54
Show file tree
Hide file tree
Showing 23 changed files with 171 additions and 167 deletions.
20 changes: 10 additions & 10 deletions src/jupyter_contrib_nbextensions/nbextensions/addbefore/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ define([

var load_extension = function() {
Jupyter.toolbar.add_buttons_group([
{
'label' : 'Insert Cell Above',
'icon' : 'fa-arrow-circle-o-up',
'callback': function () {
Jupyter.actions.register ({
'help' : 'Insert Cell Above',
'icon' : 'fa-arrow-circle-o-up',
'handler': function () {
Jupyter.notebook.insert_cell_above('code');
Jupyter.notebook.select_prev();
Jupyter.notebook.focus_cell();
}
},
{
'label' : 'Insert Cell Below',
'icon' : 'fa-arrow-circle-o-down',
'callback': function () {
}),
Jupyter.actions.register ({
'help' : 'Insert Cell Below',
'icon' : 'fa-arrow-circle-o-down',
'handler': function () {
Jupyter.notebook.insert_cell_below('code');
Jupyter.notebook.select_next();
Jupyter.notebook.focus_cell();
}
}
})
]);
$('#insert_above_below').remove()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ define([
/*
* Buttons to increase/decrease code font size
*/
{
'label' : 'Increase code font size',
'icon' : 'fa-search-plus',
'callback': function () {
Jupyter.actions.register ({
'help' : 'Increase code font size',
'icon' : 'fa-search-plus',
'handler': function () {
$( document ).ready(code_change_fontsize(true));
}
},
{
'label' : 'Decrease code font size',
'icon' : 'fa-search-minus',
'callback': function () {
}),
Jupyter.actions.register ({
'help' : 'Decrease code font size',
'icon' : 'fa-search-minus',
'handler': function () {
$( document ).ready(code_change_fontsize(false));
}
}
})

]);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -834,10 +834,11 @@
function add_buttons_and_shortcuts () {
// (Maybe) add buttons to the toolbar
if (params.add_button) {
Jupyter.toolbar.add_buttons_group([{
label: 'toggle heading',
icon: 'fa-angle-double-up',
callback: function () {
Jupyter.toolbar.add_buttons_group([
Jupyter.actions.register ({
help : 'toggle heading',
icon : 'fa-angle-double-up',
handler: function () {
/**
* Collapse the closest uncollapsed heading above the
* currently selected cell.
Expand All @@ -850,13 +851,15 @@
Jupyter.notebook.select(Jupyter.notebook.find_cell_index(heading_cell));
}
}
}]);
})
]);
}
if (params.add_all_cells_button) {
Jupyter.toolbar.add_buttons_group([{
label: 'toggle all headings',
icon: 'fa-angle-double-up',
callback: function () {
Jupyter.toolbar.add_buttons_group([
Jupyter.actions.register ({
help : 'toggle all headings',
icon : 'fa-angle-double-up',
handler: function () {
/**
* Collapse/uncollapse all heading cells based on status of first
*/
Expand All @@ -869,7 +872,8 @@
}
}
}
}]);
})
]);
}
if (params.add_insert_header_buttons) {
Jupyter.toolbar.add_buttons_group([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@ define([

var load_ipython_extension = function () {
IPython.toolbar.add_buttons_group([
{
id : 'datestamp',
label : 'insert datestamp',
icon : 'fa-calendar',
callback : datestamp
}
Jupyter.actions.register ({
help : 'insert datestamp',
icon : 'fa-calendar',
handler: datestamp
}, 'datestamp')
]);
};

var extension = {
load_ipython_extension : load_ipython_extension,
};
return extension;
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@ define([

var load_ipython_extension = function() {
IPython.toolbar.add_buttons_group([
{
id: 'reset_numbering',
label: 'Reset equation numbering',
icon: 'fa-sort-numeric-asc',
callback: function () {
Jupyter.actions.register ({
help : 'Reset equation numbering',
icon : 'fa-sort-numeric-asc',
handler: function () {
MathJax.Hub.Queue(
["resetEquationNumbers", MathJax.InputJax.TeX],
["PreProcess", MathJax.Hub],
["Reprocess", MathJax.Hub]
);
$('#reset_numbering').blur();
}
}
}, 'reset_numbering')
]);
MathJax.Hub.Config({
TeX: { equationNumbers: { autoNumber: "AMS" } }
Expand Down
11 changes: 5 additions & 6 deletions src/jupyter_contrib_nbextensions/nbextensions/exercise/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,14 @@ define([

function load_ipython_extension(){
IPython.toolbar.add_buttons_group([
{
id : 'hide_solutions',
label : 'Exercise: Create/Remove solutions',
icon : 'fa-mortar-board',
callback : function () {
Jupyter.actions.register ({
help : 'Exercise: Create/Remove solutions',
icon : 'fa-mortar-board',
handler : function () {
//console.log(IPython.notebook.get_selected_cells())
hide_solutions();
}
}
}, 'hide_solutions')
]);

/**
Expand Down
11 changes: 5 additions & 6 deletions src/jupyter_contrib_nbextensions/nbextensions/exercise2/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,13 @@ id=\"myCheck' + cbx + '\" >\

function load_ipython_extension(){
IPython.toolbar.add_buttons_group([
{
id : 'process_solution',
label : 'Exercise2: Create/Remove solution',
icon : 'fa-toggle-on',
callback : function () {
Jupyter.actions.register ({
help : 'Exercise2: Create/Remove solution',
icon : 'fa-toggle-on',
handler : function () {
process_solution();
}
}
}, 'process_solution')
]);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ define([

/* Add also a Button, currently disabled */
/*
Jupyter.toolbar.add_buttons_group([{
id : 'export_embeddedhtml',
label : 'Embedded HTML Export',
icon : 'fa-save',
callback : function() {
Jupyter.menubar._nbconvert('html_embed', true);
}
}]);
Jupyter.toolbar.add_buttons_group([
Jupyter.actions.register ({
help : 'Embedded HTML Export',
icon : 'fa-save',
handler: function() {
Jupyter.menubar._nbconvert('html_embed', true);
}
}, 'export_embeddedhtml')
]);
*/
if (Jupyter.notebook !== undefined && Jupyter.notebook._fully_loaded) {
// notebook_loaded.Notebook event has already happened
Expand Down
12 changes: 7 additions & 5 deletions src/jupyter_contrib_nbextensions/nbextensions/gist_it/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ define([

var initialize = function () {
update_params();
Jupyter.toolbar.add_buttons_group([{
label : 'Create/Edit Gist of Notebook',
icon : 'fa-github',
callback: show_gist_editor_modal
}]);
Jupyter.toolbar.add_buttons_group([
Jupyter.actions.register ({
help : 'Create/Edit Gist of Notebook',
icon : 'fa-github',
handler: show_gist_editor_modal
})
]);
};

// update params with any specified in the server's config file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,17 @@ define([
var initialize = function () {
update_params();
if (params.help_panel_add_toolbar_button) {
IPython.toolbar.add_buttons_group([{
id : 'btn_help_panel',
label : 'Show help panel',
icon : 'fa-book',
callback : function() {
var visible = toggleHelpPanel();
var btn = $(this);
setTimeout(function() { btn.blur(); }, 500);
}
}]);
IPython.toolbar.add_buttons_group([
Jupyter.actions.register ({
help : 'Show help panel',
icon : 'fa-book',
handler: function() {
var visible = toggleHelpPanel();
var btn = $(this);
setTimeout(function() { btn.blur(); }, 500);
}
}, 'btn_help_panel')
]);
$('#btn_help_panel').attr({
'data-toggle': 'button',
'aria-pressed': 'false'
Expand Down
19 changes: 10 additions & 9 deletions src/jupyter_contrib_nbextensions/nbextensions/hide_input/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ define([
var load_ipython_extension = function() {

// Add a button to the toolbar
Jupyter.toolbar.add_buttons_group([{
id: 'btn-hide-input',
label: 'Toggle selected cell input display',
icon: 'fa-chevron-up',
callback: function() {
toggle_selected_input();
setTimeout(function() { $('#btn-hide-input').blur(); }, 500);
}
}]);
Jupyter.toolbar.add_buttons_group([
Jupyter.actions.register ({
help : 'Toggle selected cell input display',
icon : 'fa-chevron-up',
handler: function() {
toggle_selected_input();
setTimeout(function() { $('#btn-hide-input').blur(); }, 500);
}
}, 'btn-hide-input')
]);
// Collapse all cells that are marked as hidden
if (Jupyter.notebook !== undefined && Jupyter.notebook._fully_loaded) {
// notebook already loaded. Update directly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@ define([
}

var load_ipython_extension = function() {
Jupyter.toolbar.add_buttons_group([{
id : 'toggle_codecells',
label : 'Hide codecell inputs',
icon : 'fa-eye',
callback : function() {
toggle();
setTimeout(function() { $('#toggle_codecells').blur(); }, 500);
}
}]);
Jupyter.toolbar.add_buttons_group([
Jupyter.actions.register ({
help : 'Hide codecell inputs',
icon : 'fa-eye',
handler: function() {
toggle();
setTimeout(function() { $('#toggle_codecells').blur(); }, 500);
}
}, 'toggle_codecells')
]);
if (Jupyter.notebook !== undefined && Jupyter.notebook._fully_loaded) {
// notebook_loaded.Notebook event has already happened
initialize();
Expand Down
23 changes: 12 additions & 11 deletions src/jupyter_contrib_nbextensions/nbextensions/nbTranslate/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,18 @@ define(function(require, exports, module) {

function showToolbar() {
if ($('#showToolbar').length == 0) {
Jupyter.toolbar.add_buttons_group([{
'label': 'Translate current cell',
'icon': 'fa-language',
'callback': translateCurrentCell,
'id': 'showToolbar'
},
{
'label': 'nbTranslate: Configuration (toggle toolbar)',
'icon': 'fa-wrench',
'callback': translateToolbarToggle //translateToolbar
}]);
Jupyter.toolbar.add_buttons_group([
Jupyter.actions.register ({
'help' : 'Translate current cell',
'icon' : 'fa-language',
'handler': translateCurrentCell,
}, 'showToolbar'),
Jupyter.actions.register ({
'help' : 'nbTranslate: Configuration (toggle toolbar)',
'icon' : 'fa-wrench',
'handler': translateToolbarToggle //translateToolbar
})
]);
}
}

Expand Down
11 changes: 5 additions & 6 deletions src/jupyter_contrib_nbextensions/nbextensions/notify/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@ define([
var add_permissions_button = function () {
if ($("#permissions-button").length === 0) {
Jupyter.toolbar.add_buttons_group([
{
'label' : 'Grant Notification Permissions',
'icon' : 'fa-check',
'callback': ask_permission,
'id' : 'permissions-button'
},
Jupyter.actions.register ({
'help' : 'Grant Notification Permissions',
'icon' : 'fa-check',
'handler': ask_permission,
},'permissions-button')
]);
}
};
Expand Down
11 changes: 5 additions & 6 deletions src/jupyter_contrib_nbextensions/nbextensions/printview/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ define([

var load_ipython_extension = function() {
IPython.toolbar.add_buttons_group([
{
id: 'doPrintView',
label: 'Create static print view',
icon: 'fa-print',
callback: nbconvertPrintView
}
Jupyter.actions.register ({
help : 'Create static print view',
icon : 'fa-print',
handler: nbconvertPrintView
}, 'doPrintView')
]);
return IPython.notebook.config.loaded.then(initialize);
};
Expand Down
Loading

0 comments on commit 4b06a54

Please sign in to comment.