diff --git a/notebook/static/notebook/js/actions.js b/notebook/static/notebook/js/actions.js index d61e9ee75..9cd5ea489 100644 --- a/notebook/static/notebook/js/actions.js +++ b/notebook/static/notebook/js/actions.js @@ -462,38 +462,95 @@ define(function(require){ env.notebook.show_command_palette(); } }, + 'toggle-all-line-numbers': { + help : 'toggles line numbers in all cells, and persist the setting', + icon: 'fa-list-ol', + handler: function(env) { + var value = !env.notebook.line_numbers; + env.notebook.get_cells().map(function(c) { + c.code_mirror.setOption('lineNumbers', value); + }); + env.notebook.line_numbers = value; + } + }, 'show-all-line-numbers': { help : 'show line numbers in all cells, and persist the setting', handler: function(env) { + env.notebook.get_cells().map(function(c) { + c.code_mirror.setOption('lineNumbers', true); + }); 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.get_cells().map(function(c) { + c.code_mirror.setOption('lineNumbers', false); + }); 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-header':{ + help: 'hide/show the header', + handler : function(env) { + var value = !env.notebook.header; + if (value === true) { + $('#header-container').show(); + $('.header-bar').show(); + } else if (value === false) { + $('#header-container').hide(); + $('.header-bar').hide(); + } + events.trigger('resize-header.Page'); + env.notebook.header = value; + } + }, + 'show-header':{ + help: 'show the header', + handler : function(env) { + $('#header-container').show(); + $('.header-bar').show(); + events.trigger('resize-header.Page'); + env.notebook.header = true; + } + }, + 'hide-header':{ + help: 'hide the header', + handler : function(env) { + $('#header-container').hide(); + $('.header-bar').hide(); + events.trigger('resize-header.Page'); + env.notebook.header = false; } }, 'toggle-toolbar':{ help: 'hide/show the toolbar', - handler : function(env){ - $('div#maintoolbar').toggle(); + handler : function(env) { + var value = !env.notebook.toolbar; + if (value === true) { + $('div#maintoolbar').show(); + } else if (value === false) { + $('div#maintoolbar').hide(); + } events.trigger('resize-header.Page'); + env.notebook.toolbar = value; } }, - 'toggle-header':{ - help: 'hide/show the header', - handler : function(env){ - $('#header-container').toggle(); - $('.header-bar').toggle(); + 'show-toolbar':{ + help: 'show the toolbar', + handler : function(env) { + $('div#maintoolbar').show(); + events.trigger('resize-header.Page'); + env.notebook.toolbar = true; + } + }, + 'hide-toolbar':{ + help: 'hide the toolbar', + handler : function(env) { + $('div#maintoolbar').hide(); events.trigger('resize-header.Page'); + env.notebook.toolbar = false; } }, 'close-pager': { diff --git a/notebook/static/notebook/js/notebook.js b/notebook/static/notebook/js/notebook.js index e10f33798..6f0694bf3 100644 --- a/notebook/static/notebook/js/notebook.js +++ b/notebook/static/notebook/js/notebook.js @@ -164,29 +164,62 @@ 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() { + var d = that.config.data || {}; + var cmc = (d['Cell'] || {}) ['cm_config'] || {}; + return cmc['lineNumbers'] || false; + }, + set: function(value) { + that.config.update({ + 'Cell': { + 'cm_config': { + 'lineNumbers':value + } + } + }); + } + }); + + Object.defineProperty(this, 'header', { + get: function() { + return that.class_config.get_sync('Header'); + }, + set: function(value) { + that.class_config.set('Header', value); + } + }); + + Object.defineProperty(this, 'toolbar', { + get: function() { + return that.class_config.get_sync('Toolbar'); + }, + set: function(value) { + that.class_config.set('Toolbar', value); + } + }); + + this.class_config.get('Header').then(function(header) { + if (header === false) { + that.keyboard_manager.actions.call('jupyter-notebook:hide-header'); + } + }); + + this.class_config.get('Toolbar').then(function(toolbar) { + if (toolbar === false) { + that.keyboard_manager.actions.call('jupyter-notebook:hide-toolbar'); } - - }) + }); + // 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 +611,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 +3218,3 @@ import {ShortcutEditor} from 'notebook/js/shortcuteditor'; this.events.trigger('checkpoint_deleted.Notebook'); this.load_notebook(this.notebook_path); }; -