-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Persist header and toolbar toggle status in nbconfig #1769
Changes from 3 commits
11d56a2
61eec92
c656fc0
6c1fe1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,29 +164,79 @@ import {ShortcutEditor} from 'notebook/js/shortcuteditor'; | |
var that = this; | ||
|
||
Object.defineProperty(this, 'line_numbers', { | ||
get: function(){ | ||
var d = that.config.data||{} | ||
var cmc = (d['Cell']||{})['cm_config']||{} | ||
return cmc['lineNumbers'] || false; | ||
}, | ||
set: function(value){ | ||
this.get_cells().map(function(c) { | ||
c.code_mirror.setOption('lineNumbers', value); | ||
}) | ||
that.config.update({'Cell':{'cm_config':{'lineNumbers':value}}}) | ||
} | ||
|
||
}) | ||
get: function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to update the line numbers toggle logic to use {
"Notebook": {
"Toolbar": false,
"Cell": {
"cm_config": {
"lineNumbers": false
}
},
"Header": false
},
"Cell": {
"cm_config": {
"lineNumbers": true
}
}
} The top-level |
||
var d = that.config.data || {}; | ||
var cmc = (d['Cell'] || {}) ['cm_config'] || {}; | ||
return cmc['lineNumbers'] || false; | ||
}, | ||
set: function(value) { | ||
this.get_cells().map(function(c) { | ||
c.code_mirror.setOption('lineNumbers', value); | ||
}); | ||
that.config.update({ | ||
'Cell': { | ||
'cm_config': { | ||
'lineNumbers':value | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
Object.defineProperty(this, 'header', { | ||
get: function() { | ||
return that.class_config.get_sync('Header'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I switched from ConfigSection to ConfigWithDefaults to take advantage of defaults. |
||
}, | ||
set: function(value) { | ||
if (value === true) { | ||
$('#header-container').show(); | ||
$('.header-bar').show(); | ||
} else if (value === false) { | ||
$('#header-container').hide(); | ||
$('.header-bar').hide(); | ||
} | ||
that.events.trigger('resize-header.Page'); | ||
that.class_config.set('Header', value); | ||
} | ||
}); | ||
|
||
Object.defineProperty(this, 'toolbar', { | ||
get: function() { | ||
return that.class_config.get_sync('Toolbar'); | ||
}, | ||
set: function(value) { | ||
if (value === true) { | ||
$('div#maintoolbar').show(); | ||
} else if (value === false) { | ||
$('div#maintoolbar').hide(); | ||
} | ||
that.events.trigger('resize-header.Page'); | ||
that.class_config.set('Toolbar', value); | ||
} | ||
}); | ||
|
||
this.class_config.get('Header').then(function(header) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To revisit my other question: Is there a better place to put this (like |
||
if (header === false) { | ||
that.header = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels a bit icky - it waits for the config to load, and then does something which sets the value from the config back into the config. I think there should be a separate piece of API which actually hides/shows the toolbar on the page, and a higher level wrapper around that which also pushes the state into config. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good point, thanks for the feedback. I just pushed a new commit that moves the toggle logic to the actions and then calls the actions to toggle the header/toolbar on notebook load. |
||
} | ||
}); | ||
|
||
this.class_config.get('Toolbar').then(function(toolbar) { | ||
if (toolbar === false) { | ||
that.toolbar = false; | ||
} | ||
}); | ||
|
||
// prevent assign to miss-typed properties. | ||
Object.seal(this); | ||
}; | ||
|
||
|
||
|
||
Notebook.options_default = { | ||
// can be any cell type, or the special values of | ||
// 'above', 'below', or 'selected' to get the value from another cell. | ||
default_cell_type: 'code' | ||
default_cell_type: 'code', | ||
Header: true, | ||
Toolbar: true | ||
}; | ||
|
||
/** | ||
|
@@ -578,7 +628,7 @@ import {ShortcutEditor} from 'notebook/js/shortcuteditor'; | |
*/ | ||
Notebook.prototype.toggle_all_line_numbers = function () { | ||
this.line_numbers = !this.line_numbers; | ||
} | ||
}; | ||
|
||
/** | ||
* Get the cell above a given cell. | ||
|
@@ -3185,4 +3235,3 @@ import {ShortcutEditor} from 'notebook/js/shortcuteditor'; | |
this.events.trigger('checkpoint_deleted.Notebook'); | ||
this.load_notebook(this.notebook_path); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actions are quite public API - they're used to define keyboard shortcuts - so I'd rather not remove them without a good reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I added back the show/hide line numbers as well as adding show/hide actions for header and toolbar.