mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-12 11:45:38 +08:00
Renaming execute methods.
This commit is contained in:
parent
8d73a3ac05
commit
201217d847
@ -104,21 +104,21 @@ var IPython = (function (IPython) {
|
|||||||
'shift+enter' : {
|
'shift+enter' : {
|
||||||
help : 'run cell',
|
help : 'run cell',
|
||||||
handler : function (event) {
|
handler : function (event) {
|
||||||
IPython.notebook.execute_selected_cell('shift');
|
IPython.notebook.execute_cell();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'alt+enter' : {
|
'alt+enter' : {
|
||||||
help : 'run cell, insert below',
|
help : 'run cell, insert below',
|
||||||
handler : function (event) {
|
handler : function (event) {
|
||||||
IPython.notebook.execute_selected_cell('alt');
|
IPython.notebook.execute_cell_and_insert_below();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'ctrl+enter' : {
|
'ctrl+enter' : {
|
||||||
help : 'run cell, select below',
|
help : 'run cell, select below',
|
||||||
handler : function (event) {
|
handler : function (event) {
|
||||||
IPython.notebook.execute_selected_cell('ctrl');
|
IPython.notebook.execute_cell_and_select_below();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ var IPython = (function (IPython) {
|
|||||||
label : 'Run Cell',
|
label : 'Run Cell',
|
||||||
icon : 'icon-play',
|
icon : 'icon-play',
|
||||||
callback : function () {
|
callback : function () {
|
||||||
IPython.notebook.execute_selected_cell();
|
IPython.notebook.execute_cell();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -208,10 +208,13 @@ var IPython = (function (IPython) {
|
|||||||
});
|
});
|
||||||
// Cell
|
// Cell
|
||||||
this.element.find('#run_cell').click(function () {
|
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 () {
|
this.element.find('#run_cell_select_below').click(function () {
|
||||||
IPython.notebook.execute_selected_cell({terminal:true});
|
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 () {
|
this.element.find('#run_all_cells').click(function () {
|
||||||
IPython.notebook.execute_all_cells();
|
IPython.notebook.execute_all_cells();
|
||||||
|
@ -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_cell
|
||||||
*
|
|
||||||
* @method execute_selected_cell
|
|
||||||
* @param {Object} options Customize post-execution behavior
|
|
||||||
*/
|
*/
|
||||||
Notebook.prototype.execute_selected_cell = function (mode) {
|
Notebook.prototype.execute_cell = function () {
|
||||||
// mode = shift, ctrl, alt
|
// 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 = this.get_selected_cell();
|
||||||
var cell_index = this.find_cell_index(cell);
|
var cell_index = this.find_cell_index(cell);
|
||||||
|
|
||||||
cell.execute();
|
cell.execute();
|
||||||
|
|
||||||
// If we are at the end always insert a new cell and return
|
// 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.insert_cell_below('code');
|
||||||
this.select(cell_index+1);
|
this.select(cell_index+1);
|
||||||
this.edit_mode();
|
this.edit_mode();
|
||||||
this.scroll_to_bottom();
|
this.scroll_to_bottom();
|
||||||
this.set_dirty(true);
|
this.set_dirty(true);
|
||||||
return;
|
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);
|
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.
|
* Execute all cells below the selected cell.
|
||||||
@ -1418,7 +1447,7 @@ var IPython = (function (IPython) {
|
|||||||
Notebook.prototype.execute_cell_range = function (start, end) {
|
Notebook.prototype.execute_cell_range = function (start, end) {
|
||||||
for (var i=start; i<end; i++) {
|
for (var i=start; i<end; i++) {
|
||||||
this.select(i);
|
this.select(i);
|
||||||
this.execute_selected_cell({add_new:false});
|
this.execute_cell();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -140,8 +140,10 @@ class="notebook_app"
|
|||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
<li id="run_cell" title="Run this cell, and move cursor to the next one">
|
<li id="run_cell" title="Run this cell, and move cursor to the next one">
|
||||||
<a href="#">Run</a></li>
|
<a href="#">Run</a></li>
|
||||||
<li id="run_cell_in_place" title="Run this cell, without moving to the next one">
|
<li id="run_cell_select_below" title="Run this cell, select below">
|
||||||
<a href="#">Run in Place</a></li>
|
<a href="#">Run and Select Below</a></li>
|
||||||
|
<li id="run_cell_insert_below" title="Run this cell, insert below">
|
||||||
|
<a href="#">Run and Insert Below</a></li>
|
||||||
<li id="run_all_cells" title="Run all cells in the notebook">
|
<li id="run_all_cells" title="Run all cells in the notebook">
|
||||||
<a href="#">Run All</a></li>
|
<a href="#">Run All</a></li>
|
||||||
<li id="run_all_cells_above" title="Run all cells above (but not including) this cell">
|
<li id="run_all_cells_above" title="Run all cells above (but not including) this cell">
|
||||||
|
Loading…
Reference in New Issue
Block a user