Merge pull request #1676 from gnestor/toggle-line-numbers

View > Toggle line numbers
pull/1695/head
Brian E. Granger 10 years ago committed by GitHub
commit 6c8d453762

@ -462,6 +462,25 @@ 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, and persist the setting',
icon: 'fa-list-ol',
handler: function(env) {
env.notebook.line_numbers = !env.notebook.line_numbers;
}
},
'toggle-toolbar':{
help: 'hide/show the toolbar',
handler : function(env){

@ -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;
@ -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;

@ -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}]);

@ -159,6 +159,7 @@ define([
'o' : 'jupyter-notebook:toggle-cell-output-collapsed',
's' : 'jupyter-notebook:save-notebook',
'l' : 'jupyter-notebook:toggle-cell-line-numbers',
'shift-l' : 'jupyter-notebook:toggle-all-line-numbers',
'h' : 'jupyter-notebook:show-keyboard-shortcuts',
'z' : 'jupyter-notebook:undo-cell-deletion',
'q' : 'jupyter-notebook:close-pager',

@ -264,6 +264,7 @@ define([
'#move_cell_down': 'move-cell-down',
'#toggle_header': 'toggle-header',
'#toggle_toolbar': 'toggle-toolbar',
'#toggle_line_numbers': 'toggle-all-line-numbers',
'#insert_cell_above': 'insert-cell-above',
'#insert_cell_below': 'insert-cell-below',
'#run_cell': 'run-cell',

@ -161,11 +161,28 @@ import {ShortcutEditor} from 'notebook/js/shortcuteditor';
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.
@ -555,6 +572,13 @@ import {ShortcutEditor} from 'notebook/js/shortcuteditor';
}
return result;
};
/**
* Toggles the display of line numbers in all cells.
*/
Notebook.prototype.toggle_all_line_numbers = function () {
this.line_numbers = !this.line_numbers;
}
/**
* Get the cell above a given cell.

@ -58,7 +58,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}]);
@ -282,7 +282,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';
@ -528,7 +528,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');

@ -157,10 +157,16 @@ data-notebook-path="{{notebook_path | urlencode}}"
<ul id="view_menu" class="dropdown-menu">
<li id="toggle_header"
title="Show/Hide the logo and notebook title (above menu bar)">
<a href="#">Toggle Header</a></li>
<a href="#">Toggle Header</a>
</li>
<li id="toggle_toolbar"
title="Show/Hide the action icons (below menu bar)">
<a href="#">Toggle Toolbar</a></li>
<a href="#">Toggle Toolbar</a>
</li>
<li id="toggle_line_numbers"
title="Show/Hide line numbers in cells">
<a href="#">Toggle Line Numbers</a>
</li>
<li id="menu-cell-toolbar" class="dropdown-submenu">
<a href="#">Cell Toolbar</a>
<ul class="dropdown-menu" id="menu-cell-toolbar-submenu"></ul>

Loading…
Cancel
Save