Skip to content

Commit

Permalink
Inherit configuration and propagate it from MD cell
Browse files Browse the repository at this point in the history
Persist the configuration of toggling in nbconfig.
  • Loading branch information
Carreau committed May 3, 2016
1 parent c30390e commit c040464
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 16 deletions.
17 changes: 14 additions & 3 deletions notebook/static/notebook/js/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,12 +456,23 @@ define(function(require){
env.notebook.show_command_palette();
}
},
'show-all-line-numbers': {
help : 'show line numbers in all cells, and persist the setting',
handler: function(env) {
env.notebook.line_numbers = true;
}
},
'hide-all-line-numbers': {
help : 'hide line numbers in all cells, and persist the setting',
handler: function(env) {
env.notebook.line_numbers = false;
}
},
'toggle-all-line-numbers': {
help : 'toggles line numbers in all cells',
help : 'toggles line numbers in all cells, and persist the setting',
icon: 'fa-list-ol',
handler: function(env) {
console.log('calling function');
env.notebook.toggle_all_line_numbers();
env.notebook.line_numbers = !env.notebook.line_numbers;
}
},
'toggle-toolbar':{
Expand Down
12 changes: 9 additions & 3 deletions notebook/static/notebook/js/cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ define([
'codemirror/lib/codemirror',
'codemirror/addon/edit/matchbrackets',
'codemirror/addon/edit/closebrackets',
'codemirror/addon/comment/comment'
], function(utils, CodeMirror, cm_match, cm_closeb, cm_comment) {
'codemirror/addon/comment/comment',
'services/config',
], function(utils, CodeMirror, cm_match, cm_closeb, cm_comment, configmod) {
"use strict";

var overlayHack = CodeMirror.scrollbarModel.native.prototype.overlayHack;
Expand Down Expand Up @@ -87,7 +88,12 @@ define([
if(this.class_config){
_local_cm_config = this.class_config.get_sync('cm_config');
}
config.cm_config = utils.mergeopt({}, config.cm_config, _local_cm_config);

var local = new configmod.ConfigWithDefaults(options.config,
{}, 'Cell');
var llcm = local.get_sync('cm_config');

config.cm_config = utils.mergeopt({}, config.cm_config, utils.mergeopt({}, llcm, _local_cm_config));
this.cell_id = utils.uuid();
this._options = config;

Expand Down
2 changes: 1 addition & 1 deletion notebook/static/notebook/js/codecell.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ define([
this.completer = null;

Cell.apply(this,[{
config: $.extend({}, CodeCell.options_default),
config: options.config,
keyboard_manager: options.keyboard_manager,
events: this.events}]);

Expand Down
1 change: 0 additions & 1 deletion notebook/static/notebook/js/maintoolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ define([
'run_int'],
['<add_celltype_list>'],
[['jupyter-notebook:show-command-palette']],
[['jupyter-notebook:toggle-all-line-numbers']],
['<add_celltoolbar_reminder>']
];
this.construct(grps);
Expand Down
22 changes: 17 additions & 5 deletions notebook/static/notebook/js/notebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ define(function (require) {
this.ws_url = options.ws_url;
this._session_starting = false;
this.last_modified = null;
this.line_numbers = false;
// debug 484
this._last_modified = 'init';
// Firefox workaround
Expand Down Expand Up @@ -161,11 +160,28 @@ define(function (require) {
slideshow_celltoolbar.register(this);
attachments_celltoolbar.register(this);

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}}})
}

})
// 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.
Expand Down Expand Up @@ -559,10 +575,6 @@ define(function (require) {
*/
Notebook.prototype.toggle_all_line_numbers = function () {
this.line_numbers = !this.line_numbers;
var display = this.line_numbers;
this.get_cells().map(function(c) {
c.code_mirror.setOption('lineNumbers', display);
})
}

/**
Expand Down
6 changes: 3 additions & 3 deletions notebook/static/notebook/js/textcell.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ define([
// we cannot put this as a class key as it has handle to "this".
var config = utils.mergeopt(TextCell, this.config);
Cell.apply(this, [{
config: config,
config: options.config,
keyboard_manager: options.keyboard_manager,
events: this.events}]);

Expand Down Expand Up @@ -279,7 +279,7 @@ define([
var config = utils.mergeopt(MarkdownCell, {});
this.class_config = new configmod.ConfigWithDefaults(options.config,
{}, 'MarkdownCell');
TextCell.apply(this, [$.extend({}, options, {config: config})]);
TextCell.apply(this, [$.extend({}, options, {config: options.config})]);

this.cell_type = 'markdown';
};
Expand Down Expand Up @@ -492,7 +492,7 @@ define([
*/
options = options || {};
var config = utils.mergeopt(RawCell, {});
TextCell.apply(this, [$.extend({}, options, {config: config})]);
TextCell.apply(this, [$.extend({}, options, {config: options.config})]);

this.class_config = new configmod.ConfigWithDefaults(options.config,
RawCell.config_defaults, 'RawCell');
Expand Down

0 comments on commit c040464

Please sign in to comment.