##// END OF EJS Templates
Merge pull request #7207 from takluyver/rm-nb-user-config...
Matthias Bussonnier -
r19551:a1acff00 merge
parent child Browse files
Show More
@@ -14,6 +14,7 b' define(['
14 14 'jquery',
15 15 'base/js/utils',
16 16 'base/js/keyboard',
17 'services/config',
17 18 'notebook/js/cell',
18 19 'notebook/js/outputarea',
19 20 'notebook/js/completer',
@@ -21,7 +22,19 b' define(['
21 22 'codemirror/lib/codemirror',
22 23 'codemirror/mode/python/python',
23 24 'notebook/js/codemirror-ipython'
24 ], function(IPython, $, utils, keyboard, cell, outputarea, completer, celltoolbar, CodeMirror, cmpython, cmip) {
25 ], function(IPython,
26 $,
27 utils,
28 keyboard,
29 configmod,
30 cell,
31 outputarea,
32 completer,
33 celltoolbar,
34 CodeMirror,
35 cmpython,
36 cmip
37 ) {
25 38 "use strict";
26 39
27 40 var Cell = cell.Cell;
@@ -76,6 +89,8 b' define(['
76 89 this.events = options.events;
77 90 this.tooltip = options.tooltip;
78 91 this.config = options.config;
92 this.class_config = new configmod.ConfigWithDefaults(this.config,
93 CodeCell.config_defaults, 'CodeCell');
79 94
80 95 // create all attributed in constructor function
81 96 // even if null for V8 VM optimisation
@@ -103,9 +118,8 b' define(['
103 118 this.completer = null;
104 119 this.widget_views = [];
105 120
106 var config = utils.mergeopt(CodeCell, this.config);
107 121 Cell.apply(this,[{
108 config: config,
122 config: $.extend({}, CodeCell.options_default),
109 123 keyboard_manager: options.keyboard_manager,
110 124 events: this.events}]);
111 125
@@ -131,6 +145,18 b' define(['
131 145 }
132 146 };
133 147
148 CodeCell.config_defaults = {
149 cell_magic_highlight : {
150 'magic_javascript' :{'reg':[/^%%javascript/]},
151 'magic_perl' :{'reg':[/^%%perl/]},
152 'magic_ruby' :{'reg':[/^%%ruby/]},
153 'magic_python' :{'reg':[/^%%python3?/]},
154 'magic_shell' :{'reg':[/^%%bash/]},
155 'magic_r' :{'reg':[/^%%R/]},
156 'magic_text/x-cython' :{'reg':[/^%%cython/]},
157 },
158 };
159
134 160 CodeCell.msg_cells = {};
135 161
136 162 CodeCell.prototype = Object.create(Cell.prototype);
@@ -156,7 +182,7 b' define(['
156 182 * @method auto_highlight
157 183 */
158 184 CodeCell.prototype.auto_highlight = function () {
159 this._auto_highlight(this.config.cell_magic_highlight);
185 this._auto_highlight(this.class_config.get_sync('cell_magic_highlight'));
160 186 };
161 187
162 188 /** @method create_element */
@@ -19,7 +19,6 b' require(['
19 19 'notebook/js/savewidget',
20 20 'notebook/js/actions',
21 21 'notebook/js/keyboardmanager',
22 'notebook/js/config',
23 22 'notebook/js/kernelselector',
24 23 'codemirror/lib/codemirror',
25 24 'notebook/js/about',
@@ -43,7 +42,6 b' require(['
43 42 savewidget,
44 43 actions,
45 44 keyboardmanager,
46 config,
47 45 kernelselector,
48 46 CodeMirror,
49 47 about,
@@ -62,7 +60,6 b' require(['
62 60 notebook_name : utils.get_body_data('notebookName')
63 61 };
64 62
65 var user_config = $.extend({}, config.default_config);
66 63 var page = new page.Page();
67 64 var pager = new pager.Pager('div#pager', {
68 65 events: events});
@@ -84,7 +81,7 b' require(['
84 81 keyboard_manager: keyboard_manager,
85 82 save_widget: save_widget,
86 83 contents: contents,
87 config: user_config},
84 config: config_section},
88 85 common_options));
89 86 var login_widget = new loginwidget.LoginWidget('span#login_widget', common_options);
90 87 var toolbar = new maintoolbar.MainToolBar('#maintoolbar-container', {
@@ -150,7 +147,6 b' require(['
150 147 IPython.notification_area = notification_area;
151 148 IPython.keyboard_manager = keyboard_manager;
152 149 IPython.save_widget = save_widget;
153 IPython.config = user_config;
154 150 IPython.tooltip = notebook.tooltip;
155 151
156 152 events.trigger('app_initialized.NotebookApp');
@@ -12,6 +12,7 b' define(['
12 12 'notebook/js/cell',
13 13 'notebook/js/textcell',
14 14 'notebook/js/codecell',
15 'services/config',
15 16 'services/sessions/session',
16 17 'notebook/js/celltoolbar',
17 18 'components/marked/lib/marked',
@@ -32,6 +33,7 b' define(['
32 33 cellmod,
33 34 textcell,
34 35 codecell,
36 configmod,
35 37 session,
36 38 celltoolbar,
37 39 marked,
@@ -63,7 +65,9 b' define(['
63 65 * @param {string} options.notebook_name
64 66 */
65 67 var Notebook = function (selector, options) {
66 this.config = utils.mergeopt(Notebook, options.config);
68 this.config = options.config;
69 this.class_config = new configmod.ConfigWithDefaults(this.config,
70 Notebook.options_default, 'Notebook');
67 71 this.base_url = options.base_url;
68 72 this.notebook_path = options.notebook_path;
69 73 this.notebook_name = options.notebook_name;
@@ -74,7 +78,6 b' define(['
74 78 this.tooltip = new tooltip.Tooltip(this.events);
75 79 this.ws_url = options.ws_url;
76 80 this._session_starting = false;
77 this.default_cell_type = this.config.default_cell_type || 'code';
78 81
79 82 // Create default scroll manager.
80 83 this.scroll_manager = new scrollmanager.ScrollManager(this);
@@ -172,9 +175,7 b' define(['
172 175 Notebook.options_default = {
173 176 // can be any cell type, or the special values of
174 177 // 'above', 'below', or 'selected' to get the value from another cell.
175 Notebook: {
176 default_cell_type: 'code'
177 }
178 default_cell_type: 'code'
178 179 };
179 180
180 181 /**
@@ -861,7 +862,7 b' define(['
861 862 index = Math.min(index, ncells);
862 863 index = Math.max(index, 0);
863 864 var cell = null;
864 type = type || this.default_cell_type;
865 type = type || this.class_config.get_sync('default_cell_type');
865 866 if (type === 'above') {
866 867 if (index > 0) {
867 868 type = this.get_cell(index-1).cell_type;
@@ -7,13 +7,26 b' define(['
7 7 'jquery',
8 8 'notebook/js/cell',
9 9 'base/js/security',
10 'services/config',
10 11 'notebook/js/mathjaxutils',
11 12 'notebook/js/celltoolbar',
12 13 'components/marked/lib/marked',
13 14 'codemirror/lib/codemirror',
14 15 'codemirror/mode/gfm/gfm',
15 16 'notebook/js/codemirror-ipythongfm'
16 ], function(IPython,utils , $, cell, security, mathjaxutils, celltoolbar, marked, CodeMirror, gfm, ipgfm) {
17 ], function(IPython,
18 utils,
19 $,
20 cell,
21 security,
22 configmod,
23 mathjaxutils,
24 celltoolbar,
25 marked,
26 CodeMirror,
27 gfm,
28 ipgfm
29 ) {
17 30 "use strict";
18 31 var Cell = cell.Cell;
19 32
@@ -204,14 +217,16 b' define(['
204 217 * options: dictionary
205 218 * Dictionary of keyword arguments.
206 219 * events: $(Events) instance
207 * config: dictionary
220 * config: ConfigSection instance
208 221 * keyboard_manager: KeyboardManager instance
209 222 * notebook: Notebook instance
210 223 */
211 224 options = options || {};
212 var config = utils.mergeopt(MarkdownCell, options.config);
225 var config = utils.mergeopt(MarkdownCell, {});
213 226 TextCell.apply(this, [$.extend({}, options, {config: config})]);
214 227
228 this.class_config = new configmod.ConfigWithDefaults(options.config,
229 {}, 'MarkdownCell');
215 230 this.cell_type = 'markdown';
216 231 };
217 232
@@ -287,14 +302,16 b' define(['
287 302 * options: dictionary
288 303 * Dictionary of keyword arguments.
289 304 * events: $(Events) instance
290 * config: dictionary
305 * config: ConfigSection instance
291 306 * keyboard_manager: KeyboardManager instance
292 307 * notebook: Notebook instance
293 308 */
294 309 options = options || {};
295 var config = utils.mergeopt(RawCell, options.config);
310 var config = utils.mergeopt(RawCell, {});
296 311 TextCell.apply(this, [$.extend({}, options, {config: config})]);
297 312
313 this.class_config = new configmod.ConfigWithDefaults(options.config,
314 RawCell.config_defaults, 'RawCell');
298 315 this.cell_type = 'raw';
299 316 };
300 317
@@ -303,6 +320,12 b' define(['
303 320 "It will not be rendered in the notebook. " +
304 321 "When passing through nbconvert, a Raw Cell's content is added to the output unmodified."
305 322 };
323
324 RawCell.config_defaults = {
325 highlight_modes : {
326 'diff' :{'reg':[/^diff/]}
327 },
328 };
306 329
307 330 RawCell.prototype = Object.create(TextCell.prototype);
308 331
@@ -323,7 +346,7 b' define(['
323 346 * @method auto_highlight
324 347 */
325 348 RawCell.prototype.auto_highlight = function () {
326 this._auto_highlight(this.config.raw_cell_highlight);
349 this._auto_highlight(this.class_config.get_sync('highlight_modes'));
327 350 };
328 351
329 352 /** @method render **/
@@ -48,7 +48,14 b' function($, utils) {'
48 48 });
49 49 };
50 50
51 /**
52 * Modify the config values stored. Update the local data immediately,
53 * send the change to the server, and use the updated data from the server
54 * when the reply comes.
55 */
51 56 ConfigSection.prototype.update = function(newdata) {
57 $.extend(true, this.data, newdata); // true -> recursive update
58
52 59 var that = this;
53 60 return utils.promising_ajax(this.api_url(), {
54 61 processData: false,
@@ -63,6 +70,60 b' function($, utils) {'
63 70 });
64 71 };
65 72
66 return {ConfigSection: ConfigSection};
73
74 var ConfigWithDefaults = function(section, defaults, classname) {
75 this.section = section;
76 this.defaults = defaults;
77 this.classname = classname;
78 };
79
80 ConfigWithDefaults.prototype._class_data = function() {
81 if (this.classname) {
82 return this.section.data[this.classname] || {};
83 } else {
84 return this.section.data
85 }
86 };
87
88 /**
89 * Wait for config to have loaded, then get a value or the default.
90 * Returns a promise.
91 */
92 ConfigWithDefaults.prototype.get = function(key) {
93 var that = this;
94 return this.section.loaded.then(function() {
95 return this._class_data()[key] || this.defaults[key]
96 });
97 };
98
99 /**
100 * Return a config value. If config is not yet loaded, return the default
101 * instead of waiting for it to load.
102 */
103 ConfigWithDefaults.prototype.get_sync = function(key) {
104 return this._class_data()[key] || this.defaults[key];
105 };
106
107 /**
108 * Set a config value. Send the update to the server, and change our
109 * local copy of the data immediately.
110 * Returns a promise which is fulfilled when the server replies to the
111 * change.
112 */
113 ConfigWithDefaults.prototype.set = function(key, value) {
114 var d = {};
115 d[key] = value;
116 if (this.classname) {
117 var d2 = {};
118 d2[this.classname] = d;
119 return this.section.update(d2);
120 } else {
121 return this.section.update(d);
122 }
123 };
124
125 return {ConfigSection: ConfigSection,
126 ConfigWithDefaults: ConfigWithDefaults,
127 };
67 128
68 129 });
@@ -33,7 +33,7 b' casper.notebook_test(function () {'
33 33 });
34 34
35 35 this.thenEvaluate(function() {
36 IPython.notebook.default_cell_type = 'selected';
36 IPython.notebook.class_config.set('default_cell_type', 'selected');
37 37 });
38 38
39 39 this.then(function () {
@@ -47,7 +47,7 b' casper.notebook_test(function () {'
47 47 });
48 48
49 49 this.thenEvaluate(function() {
50 IPython.notebook.default_cell_type = 'above';
50 IPython.notebook.class_config.set('default_cell_type', 'above');
51 51 });
52 52
53 53 this.then(function () {
@@ -61,7 +61,7 b' casper.notebook_test(function () {'
61 61 });
62 62
63 63 this.thenEvaluate(function() {
64 IPython.notebook.default_cell_type = 'below';
64 IPython.notebook.class_config.set('default_cell_type', 'below');
65 65 });
66 66
67 67 this.then(function () {
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now