Skip to content

Commit 558ed9a

Browse files
authored
Merge pull request #1769 from gnestor/persist-header-toggle
Persist header and toolbar toggle status in nbconfig
2 parents 884eb8c + 6c1fe1f commit 558ed9a

File tree

2 files changed

+118
-29
lines changed

2 files changed

+118
-29
lines changed

notebook/static/notebook/js/actions.js

Lines changed: 69 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -462,38 +462,95 @@ define(function(require){
462462
env.notebook.show_command_palette();
463463
}
464464
},
465+
'toggle-all-line-numbers': {
466+
help : 'toggles line numbers in all cells, and persist the setting',
467+
icon: 'fa-list-ol',
468+
handler: function(env) {
469+
var value = !env.notebook.line_numbers;
470+
env.notebook.get_cells().map(function(c) {
471+
c.code_mirror.setOption('lineNumbers', value);
472+
});
473+
env.notebook.line_numbers = value;
474+
}
475+
},
465476
'show-all-line-numbers': {
466477
help : 'show line numbers in all cells, and persist the setting',
467478
handler: function(env) {
479+
env.notebook.get_cells().map(function(c) {
480+
c.code_mirror.setOption('lineNumbers', true);
481+
});
468482
env.notebook.line_numbers = true;
469483
}
470484
},
471485
'hide-all-line-numbers': {
472486
help : 'hide line numbers in all cells, and persist the setting',
473487
handler: function(env) {
488+
env.notebook.get_cells().map(function(c) {
489+
c.code_mirror.setOption('lineNumbers', false);
490+
});
474491
env.notebook.line_numbers = false;
475492
}
476493
},
477-
'toggle-all-line-numbers': {
478-
help : 'toggles line numbers in all cells, and persist the setting',
479-
icon: 'fa-list-ol',
480-
handler: function(env) {
481-
env.notebook.line_numbers = !env.notebook.line_numbers;
494+
'toggle-header':{
495+
help: 'hide/show the header',
496+
handler : function(env) {
497+
var value = !env.notebook.header;
498+
if (value === true) {
499+
$('#header-container').show();
500+
$('.header-bar').show();
501+
} else if (value === false) {
502+
$('#header-container').hide();
503+
$('.header-bar').hide();
504+
}
505+
events.trigger('resize-header.Page');
506+
env.notebook.header = value;
507+
}
508+
},
509+
'show-header':{
510+
help: 'show the header',
511+
handler : function(env) {
512+
$('#header-container').show();
513+
$('.header-bar').show();
514+
events.trigger('resize-header.Page');
515+
env.notebook.header = true;
516+
}
517+
},
518+
'hide-header':{
519+
help: 'hide the header',
520+
handler : function(env) {
521+
$('#header-container').hide();
522+
$('.header-bar').hide();
523+
events.trigger('resize-header.Page');
524+
env.notebook.header = false;
482525
}
483526
},
484527
'toggle-toolbar':{
485528
help: 'hide/show the toolbar',
486-
handler : function(env){
487-
$('div#maintoolbar').toggle();
529+
handler : function(env) {
530+
var value = !env.notebook.toolbar;
531+
if (value === true) {
532+
$('div#maintoolbar').show();
533+
} else if (value === false) {
534+
$('div#maintoolbar').hide();
535+
}
488536
events.trigger('resize-header.Page');
537+
env.notebook.toolbar = value;
489538
}
490539
},
491-
'toggle-header':{
492-
help: 'hide/show the header',
493-
handler : function(env){
494-
$('#header-container').toggle();
495-
$('.header-bar').toggle();
540+
'show-toolbar':{
541+
help: 'show the toolbar',
542+
handler : function(env) {
543+
$('div#maintoolbar').show();
544+
events.trigger('resize-header.Page');
545+
env.notebook.toolbar = true;
546+
}
547+
},
548+
'hide-toolbar':{
549+
help: 'hide the toolbar',
550+
handler : function(env) {
551+
$('div#maintoolbar').hide();
496552
events.trigger('resize-header.Page');
553+
env.notebook.toolbar = false;
497554
}
498555
},
499556
'close-pager': {

notebook/static/notebook/js/notebook.js

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -164,29 +164,62 @@ import {ShortcutEditor} from 'notebook/js/shortcuteditor';
164164
var that = this;
165165

166166
Object.defineProperty(this, 'line_numbers', {
167-
get: function(){
168-
var d = that.config.data||{}
169-
var cmc = (d['Cell']||{})['cm_config']||{}
170-
return cmc['lineNumbers'] || false;
171-
},
172-
set: function(value){
173-
this.get_cells().map(function(c) {
174-
c.code_mirror.setOption('lineNumbers', value);
175-
})
176-
that.config.update({'Cell':{'cm_config':{'lineNumbers':value}}})
167+
get: function() {
168+
var d = that.config.data || {};
169+
var cmc = (d['Cell'] || {}) ['cm_config'] || {};
170+
return cmc['lineNumbers'] || false;
171+
},
172+
set: function(value) {
173+
that.config.update({
174+
'Cell': {
175+
'cm_config': {
176+
'lineNumbers':value
177+
}
178+
}
179+
});
180+
}
181+
});
182+
183+
Object.defineProperty(this, 'header', {
184+
get: function() {
185+
return that.class_config.get_sync('Header');
186+
},
187+
set: function(value) {
188+
that.class_config.set('Header', value);
189+
}
190+
});
191+
192+
Object.defineProperty(this, 'toolbar', {
193+
get: function() {
194+
return that.class_config.get_sync('Toolbar');
195+
},
196+
set: function(value) {
197+
that.class_config.set('Toolbar', value);
198+
}
199+
});
200+
201+
this.class_config.get('Header').then(function(header) {
202+
if (header === false) {
203+
that.keyboard_manager.actions.call('jupyter-notebook:hide-header');
204+
}
205+
});
206+
207+
this.class_config.get('Toolbar').then(function(toolbar) {
208+
if (toolbar === false) {
209+
that.keyboard_manager.actions.call('jupyter-notebook:hide-toolbar');
177210
}
178-
179-
})
211+
});
212+
180213
// prevent assign to miss-typed properties.
181214
Object.seal(this);
182215
};
183216

184-
185-
186217
Notebook.options_default = {
187218
// can be any cell type, or the special values of
188219
// 'above', 'below', or 'selected' to get the value from another cell.
189-
default_cell_type: 'code'
220+
default_cell_type: 'code',
221+
Header: true,
222+
Toolbar: true
190223
};
191224

192225
/**
@@ -578,7 +611,7 @@ import {ShortcutEditor} from 'notebook/js/shortcuteditor';
578611
*/
579612
Notebook.prototype.toggle_all_line_numbers = function () {
580613
this.line_numbers = !this.line_numbers;
581-
}
614+
};
582615

583616
/**
584617
* Get the cell above a given cell.
@@ -3185,4 +3218,3 @@ import {ShortcutEditor} from 'notebook/js/shortcuteditor';
31853218
this.events.trigger('checkpoint_deleted.Notebook');
31863219
this.load_notebook(this.notebook_path);
31873220
};
3188-

0 commit comments

Comments
 (0)