Skip to content

Commit fc40b4e

Browse files
committed
Merge pull request ipython#5605 from AlbertHilb/CellToolbar
Two cell toolbar fixes.
2 parents 5a27f3a + 9102970 commit fc40b4e

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

IPython/html/static/notebook/js/celltoolbar.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ var IPython = (function (IPython) {
185185
CellToolbar.register_preset = function(name, preset_list) {
186186
CellToolbar._presets[name] = preset_list;
187187
$([IPython.events]).trigger('preset_added.CellToolbar', {name: name});
188+
// When "register_callback" is called by a custom extension, it may be executed after notebook is loaded.
189+
// In that case, activate the preset if needed.
190+
if (IPython.notebook && IPython.notebook.metadata && IPython.notebook.metadata.celltoolbar === name)
191+
this.activate_preset(name);
188192
};
189193

190194

@@ -224,6 +228,8 @@ var IPython = (function (IPython) {
224228
CellToolbar._ui_controls_list = preset;
225229
CellToolbar.rebuild_all();
226230
}
231+
232+
$([IPython.events]).trigger('preset_activated.CellToolbar', {name: preset_name});
227233
};
228234

229235

IPython/html/static/notebook/js/maintoolbar.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var IPython = (function (IPython) {
2020
this.bind_events();
2121
};
2222

23-
MainToolBar.prototype = new IPython.ToolBar();
23+
MainToolBar.prototype = new IPython.ToolBar();
2424

2525
MainToolBar.prototype.construct = function () {
2626
this.add_buttons_group([
@@ -92,7 +92,7 @@ var IPython = (function (IPython) {
9292
}
9393
}
9494
],'move_up_down');
95-
95+
9696

9797
this.add_buttons_group([
9898
{
@@ -170,12 +170,17 @@ var IPython = (function (IPython) {
170170
var name = data.name;
171171
select.append($('<option/>').attr('value', name).text(name));
172172
});
173+
// Update select value when a preset is activated.
174+
$([IPython.events]).on('preset_activated.CellToolbar', function (event, data) {
175+
if (select.val() !== data.name)
176+
select.val(data.name);
177+
});
173178
};
174179

175180

176181
MainToolBar.prototype.bind_events = function () {
177182
var that = this;
178-
183+
179184
this.element.find('#cell_type').change(function () {
180185
var cell_type = $(this).val();
181186
if (cell_type === 'code') {

IPython/html/static/notebook/js/notebook.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,6 +2106,8 @@ var IPython = (function (IPython) {
21062106
if (this.metadata.celltoolbar) {
21072107
IPython.CellToolbar.global_show();
21082108
IPython.CellToolbar.activate_preset(this.metadata.celltoolbar);
2109+
} else {
2110+
IPython.CellToolbar.global_hide();
21092111
}
21102112

21112113
// now that we're fully loaded, it is safe to restore save functionality

0 commit comments

Comments
 (0)