From 201217d847560e37bb05e5d516644eea6b5b02dc Mon Sep 17 00:00:00 2001 From: "Brian E. Granger" Date: Thu, 9 Jan 2014 12:30:06 -0800 Subject: [PATCH] Renaming execute methods. --- .../static/notebook/js/keyboardmanager.js | 6 +- .../html/static/notebook/js/maintoolbar.js | 2 +- IPython/html/static/notebook/js/menubar.js | 9 ++- IPython/html/static/notebook/js/notebook.js | 77 +++++++++++++------ IPython/html/templates/notebook.html | 6 +- 5 files changed, 67 insertions(+), 33 deletions(-) diff --git a/IPython/html/static/notebook/js/keyboardmanager.js b/IPython/html/static/notebook/js/keyboardmanager.js index 7fdb797b2..62a3b34d1 100644 --- a/IPython/html/static/notebook/js/keyboardmanager.js +++ b/IPython/html/static/notebook/js/keyboardmanager.js @@ -104,21 +104,21 @@ var IPython = (function (IPython) { 'shift+enter' : { help : 'run cell', handler : function (event) { - IPython.notebook.execute_selected_cell('shift'); + IPython.notebook.execute_cell(); return false; } }, 'alt+enter' : { help : 'run cell, insert below', handler : function (event) { - IPython.notebook.execute_selected_cell('alt'); + IPython.notebook.execute_cell_and_insert_below(); return false; } }, 'ctrl+enter' : { help : 'run cell, select below', handler : function (event) { - IPython.notebook.execute_selected_cell('ctrl'); + IPython.notebook.execute_cell_and_select_below(); return false; } } diff --git a/IPython/html/static/notebook/js/maintoolbar.js b/IPython/html/static/notebook/js/maintoolbar.js index 3bed0b01e..9c09e3732 100644 --- a/IPython/html/static/notebook/js/maintoolbar.js +++ b/IPython/html/static/notebook/js/maintoolbar.js @@ -100,7 +100,7 @@ var IPython = (function (IPython) { label : 'Run Cell', icon : 'icon-play', callback : function () { - IPython.notebook.execute_selected_cell(); + IPython.notebook.execute_cell(); } }, { diff --git a/IPython/html/static/notebook/js/menubar.js b/IPython/html/static/notebook/js/menubar.js index 42694179a..e531eef91 100644 --- a/IPython/html/static/notebook/js/menubar.js +++ b/IPython/html/static/notebook/js/menubar.js @@ -208,10 +208,13 @@ var IPython = (function (IPython) { }); // Cell this.element.find('#run_cell').click(function () { - IPython.notebook.execute_selected_cell(); + IPython.notebook.execute_cell(); }); - this.element.find('#run_cell_in_place').click(function () { - IPython.notebook.execute_selected_cell({terminal:true}); + this.element.find('#run_cell_select_below').click(function () { + IPython.notebook.execute_cell_and_select_below(); + }); + this.element.find('#run_cell_insert_below').click(function () { + IPython.notebook.execute_cell_and_insert_below(); }); this.element.find('#run_all_cells').click(function () { IPython.notebook.execute_all_cells(); diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index c301950cf..3249fb308 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -1336,48 +1336,77 @@ var IPython = (function (IPython) { }; /** - * Run the selected cell. + * Execute or render cell outputs and go into command mode. * - * Execute or render cell outputs. - * - * @method execute_selected_cell - * @param {Object} options Customize post-execution behavior + * @method execute_cell */ - Notebook.prototype.execute_selected_cell = function (mode) { + Notebook.prototype.execute_cell = function () { // mode = shift, ctrl, alt - mode = mode || 'shift' + var cell = this.get_selected_cell(); + var cell_index = this.find_cell_index(cell); + + cell.execute(); + this.command_mode(); + this.set_dirty(true); + } + + /** + * Execute or render cell outputs and insert a new cell below. + * + * @method execute_cell_and_insert_below + */ + Notebook.prototype.execute_cell_and_insert_below = function () { var cell = this.get_selected_cell(); var cell_index = this.find_cell_index(cell); cell.execute(); // If we are at the end always insert a new cell and return - if (cell_index === (this.ncells()-1) && mode !== 'shift') { + if (cell_index === (this.ncells()-1)) { this.insert_cell_below('code'); this.select(cell_index+1); this.edit_mode(); this.scroll_to_bottom(); this.set_dirty(true); return; - } - - if (mode === 'shift') { - this.command_mode(); - } else if (mode === 'ctrl') { - this.select(cell_index+1); - this.get_cell(cell_index+1).focus_cell(); - } else if (mode === 'alt') { - // Only insert a new cell, if we ended up in an already populated cell - var next_text = this.get_cell(cell_index+1).get_text(); - if (/\S/.test(next_text) === true) { - this.insert_cell_below('code'); - } - this.select(cell_index+1); - this.edit_mode(); } + + // Only insert a new cell, if we ended up in an already populated cell + var next_text = this.get_cell(cell_index+1).get_text(); + if (/\S/.test(next_text) === true) { + this.insert_cell_below('code'); + } + this.select(cell_index+1); + this.edit_mode(); this.set_dirty(true); }; + /** + * Execute or render cell outputs and select the next cell. + * + * @method execute_cell_and_select_below + */ + Notebook.prototype.execute_cell_and_select_below = function () { + + var cell = this.get_selected_cell(); + var cell_index = this.find_cell_index(cell); + + cell.execute(); + + // If we are at the end always insert a new cell and return + if (cell_index === (this.ncells()-1)) { + this.insert_cell_below('code'); + this.select(cell_index+1); + this.edit_mode(); + this.scroll_to_bottom(); + this.set_dirty(true); + return; + } + + this.select(cell_index+1); + this.get_cell(cell_index+1).focus_cell(); + this.set_dirty(true); + }; /** * Execute all cells below the selected cell. @@ -1418,7 +1447,7 @@ var IPython = (function (IPython) { Notebook.prototype.execute_cell_range = function (start, end) { for (var i=start; i
  • Run
  • -
  • - Run in Place
  • +
  • + Run and Select Below
  • +
  • + Run and Insert Below
  • Run All