From c7aaa9e5586bd128be7f233102fff931f2e653d4 2014-05-16 17:11:54 From: MinRK Date: 2014-05-16 17:11:54 Subject: [PATCH] Backport PR #5605: Two cell toolbar fixes. 1. When a new notebook is loaded we should update the state of the ``select`` element listing the cell tollbar presets in the main toolbar, so that its value reflects the ``celltollbar`` metadata entry of the notebook. 2. When a new notebook without ``celltoolbar`` metadata entry is loaded we should make sure that the cell tollbars are hidden. In particular, that is needed when you are working to a notebook with a certain cell toolbar preset and then you revert the notebook to a state with no cell toolbars. --- diff --git a/IPython/html/static/notebook/js/celltoolbar.js b/IPython/html/static/notebook/js/celltoolbar.js index fc69d38..4305664 100644 --- a/IPython/html/static/notebook/js/celltoolbar.js +++ b/IPython/html/static/notebook/js/celltoolbar.js @@ -184,6 +184,10 @@ var IPython = (function (IPython) { CellToolbar.register_preset = function(name, preset_list) { CellToolbar._presets[name] = preset_list; $([IPython.events]).trigger('preset_added.CellToolbar', {name: name}); + // When "register_callback" is called by a custom extension, it may be executed after notebook is loaded. + // In that case, activate the preset if needed. + if (IPython.notebook && IPython.notebook.metadata && IPython.notebook.metadata.celltoolbar === name) + this.activate_preset(name); }; @@ -223,6 +227,8 @@ var IPython = (function (IPython) { CellToolbar._ui_controls_list = preset; CellToolbar.rebuild_all(); } + + $([IPython.events]).trigger('preset_activated.CellToolbar', {name: preset_name}); }; diff --git a/IPython/html/static/notebook/js/maintoolbar.js b/IPython/html/static/notebook/js/maintoolbar.js index 6db1956..8a8ee75 100644 --- a/IPython/html/static/notebook/js/maintoolbar.js +++ b/IPython/html/static/notebook/js/maintoolbar.js @@ -20,7 +20,7 @@ var IPython = (function (IPython) { this.bind_events(); }; - MainToolBar.prototype = new IPython.ToolBar(); + MainToolBar.prototype = new IPython.ToolBar(); MainToolBar.prototype.construct = function () { this.add_buttons_group([ @@ -92,7 +92,7 @@ var IPython = (function (IPython) { } } ],'move_up_down'); - + this.add_buttons_group([ { @@ -170,12 +170,17 @@ var IPython = (function (IPython) { var name = data.name; select.append($('