##// END OF EJS Templates
Merge pull request #7316 from yarikoptic/enh/emb_sphinx_shell_cleanup...
Merge pull request #7316 from yarikoptic/enh/emb_sphinx_shell_cleanup BF(BK): cleanup tempdir in EmbeddedSphinxShell atexit

File last commit:

r19572:58654e86
r19734:911aaedd merge
Show More
codecell.js
679 lines | 22.7 KiB | application/javascript | JavascriptLexer
Jonathan Frederic
Almost done!...
r17198 // Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
Matthias BUSSONNIER
Update to codemirror 4...
r18280 /**
*
*
* @module codecell
* @namespace codecell
* @class CodeCell
*/
Jonathan Frederic
Almost done!...
r17198
define([
'base/js/namespace',
Jonathan Frederic
MWE,...
r17200 'jquery',
Jonathan Frederic
Almost done!...
r17198 'base/js/utils',
'base/js/keyboard',
Thomas Kluyver
Remove user_config js module
r19529 'services/config',
Jonathan Frederic
Almost done!...
r17198 'notebook/js/cell',
'notebook/js/outputarea',
'notebook/js/completer',
Jonathan Frederic
MWE,...
r17200 'notebook/js/celltoolbar',
Matthias BUSSONNIER
Update to codemirror 4...
r18280 'codemirror/lib/codemirror',
'codemirror/mode/python/python',
'notebook/js/codemirror-ipython'
Thomas Kluyver
Remove user_config js module
r19529 ], function(IPython,
$,
utils,
keyboard,
configmod,
cell,
outputarea,
completer,
celltoolbar,
CodeMirror,
cmpython,
cmip
) {
Matthias BUSSONNIER
use strict and clean a little....
r7132 "use strict";
Jonathan Frederic
Output Widget
r18953
Jonathan Frederic
Fix all the bugs!
r17203 var Cell = cell.Cell;
Matthias BUSSONNIER
use strict and clean a little....
r7132
Jonathan Frederic
Almost done!...
r17198 /* local util for codemirror */
var posEq = function(a, b) {return a.line == b.line && a.ch == b.ch;};
/**
*
* function to delete until previous non blanking space character
* or first multiple of 4 tabstop.
* @private
*/
CodeMirror.commands.delSpaceToPrevTabStop = function(cm){
var from = cm.getCursor(true), to = cm.getCursor(false), sel = !posEq(from, to);
if (!posEq(from, to)) { cm.replaceRange("", from, to); return; }
var cur = cm.getCursor(), line = cm.getLine(cur.line);
var tabsize = cm.getOption('tabSize');
var chToPrevTabStop = cur.ch-(Math.ceil(cur.ch/tabsize)-1)*tabsize;
from = {ch:cur.ch-chToPrevTabStop,line:cur.line};
var select = cm.getRange(from,cur);
if( select.match(/^\ +$/) !== null){
cm.replaceRange("",from,cur);
} else {
cm.deleteH(-1,"char");
}
};
var keycodes = keyboard.keycodes;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
jon
In person review with @ellisonbg
r17210 var CodeCell = function (kernel, options) {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Constructor
*
* A Cell conceived to write code.
*
* Parameters:
* kernel: Kernel instance
* The kernel doesn't have to be set at creation time, in that case
* it will be null and set_kernel has to be called later.
* options: dictionary
* Dictionary of keyword arguments.
* events: $(Events) instance
* config: dictionary
* keyboard_manager: KeyboardManager instance
* notebook: Notebook instance
* tooltip: Tooltip instance
*/
MinRK
Cells shouldn't know about Sessions
r13133 this.kernel = kernel || null;
jon
In person review with @ellisonbg
r17210 this.notebook = options.notebook;
MinRK
restore collapsed state for cells...
r7524 this.collapsed = false;
jon
In person review with @ellisonbg
r17210 this.events = options.events;
Jonathan Frederic
More requirejs fixes
r17215 this.tooltip = options.tooltip;
jon
In person review with @ellisonbg
r17210 this.config = options.config;
Thomas Kluyver
Remove user_config js module
r19529 this.class_config = new configmod.ConfigWithDefaults(this.config,
CodeCell.config_defaults, 'CodeCell');
Matthias BUSSONNIER
Make CodeMirror configurable...
r9537
Matthias BUSSONNIER
some optimisation and code cleaning...
r13574 // create all attributed in constructor function
// even if null for V8 VM optimisation
this.input_prompt_number = null;
this.celltoolbar = null;
this.output_area = null;
Jonathan Frederic
Added comment describing output area stack.
r18955 // Keep a stack of the 'active' output areas (where active means the
// output area that recieves output). When a user activates an output
// area, it gets pushed to the stack. Then, when the output area is
// deactivated, it's popped from the stack. When the stack is empty,
// the cell's output area is used.
Jonathan Frederic
active_output_areas (plural)
r18957 this.active_output_areas = [];
Jonathan Frederic
Address @carreau 's comments
r18958 var that = this;
Object.defineProperty(this, 'active_output_area', {
get: function() {
if (that.active_output_areas && that.active_output_areas.length > 0) {
return that.active_output_areas[that.active_output_areas.length-1];
} else {
return that.output_area;
}
},
});
Matthias BUSSONNIER
some optimisation and code cleaning...
r13574 this.last_msg_id = null;
this.completer = null;
Jonathan Frederic
Persistence API,...
r19350 this.widget_views = [];
Jonathan Frederic
Bubble event and implement logic in CodeCell
r19572 this._widgets_live = true;
Matthias BUSSONNIER
Make CodeMirror configurable...
r9537
jon
In person review with @ellisonbg
r17210 Cell.apply(this,[{
Thomas Kluyver
Remove user_config js module
r19529 config: $.extend({}, CodeCell.options_default),
jon
In person review with @ellisonbg
r17210 keyboard_manager: options.keyboard_manager,
events: this.events}]);
Matthias BUSSONNIER
autochange highlight with cell magics...
r8202
Brian E. Granger
Fixing cell_type in CodeCell constructor....
r13661 // Attributes we want to override in this subclass.
this.cell_type = "code";
Matthias BUSSONNIER
autochange highlight with cell magics...
r8202 this.element.focusout(
Matthias BUSSONNIER
fix some whitespace
r8281 function() { that.auto_highlight(); }
);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Matthias BUSSONNIER
JS Configurablity Take 2...
r10165 CodeCell.options_default = {
cm_config : {
MinRK
enable comment/uncomment selection...
r11488 extraKeys: {
"Tab" : "indentMore",
"Shift-Tab" : "indentLess",
"Backspace" : "delSpaceToPrevTabStop",
"Cmd-/" : "toggleComment",
"Ctrl-/" : "toggleComment"
},
Brian E. Granger
Changing mode name from python -> ipython.
r10418 mode: 'ipython',
Matthias BUSSONNIER
Make CodeMirror configurable...
r9537 theme: 'ipython',
Matthias BUSSONNIER
Update to codemirror 4...
r18280 matchBrackets: true
Matthias BUSSONNIER
JS Configurablity Take 2...
r10165 }
Matthias BUSSONNIER
Make CodeMirror configurable...
r9537 };
Thomas Kluyver
Remove user_config js module
r19529 CodeCell.config_defaults = {
cell_magic_highlight : {
'magic_javascript' :{'reg':[/^%%javascript/]},
'magic_perl' :{'reg':[/^%%perl/]},
'magic_ruby' :{'reg':[/^%%ruby/]},
'magic_python' :{'reg':[/^%%python3?/]},
'magic_shell' :{'reg':[/^%%bash/]},
'magic_r' :{'reg':[/^%%R/]},
'magic_text/x-cython' :{'reg':[/^%%cython/]},
},
};
Jonathan Frederic
Remove O(N) cell by msg-id lookup
r14604 CodeCell.msg_cells = {};
Matthias BUSSONNIER
Make CodeMirror configurable...
r9537
Matthias Bussonnier
Use low overhead object heritence in Js (Object.create vs new)...
r18377 CodeCell.prototype = Object.create(Cell.prototype);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Matthias BUSSONNIER
start docummenting kernel
r8768 /**
Jonathan Frederic
Output Widget
r18953 * @method push_output_area
*/
CodeCell.prototype.push_output_area = function (output_area) {
Jonathan Frederic
active_output_areas (plural)
r18957 this.active_output_areas.push(output_area);
Jonathan Frederic
Output Widget
r18953 };
/**
* @method pop_output_area
*/
Jonathan Frederic
Pop output now removes a specific output
r18956 CodeCell.prototype.pop_output_area = function (output_area) {
Jonathan Frederic
active_output_areas (plural)
r18957 var index = this.active_output_areas.lastIndexOf(output_area);
Jonathan Frederic
Pop output now removes a specific output
r18956 if (index > -1) {
Jonathan Frederic
active_output_areas (plural)
r18957 this.active_output_areas.splice(index, 1);
Jonathan Frederic
Pop output now removes a specific output
r18956 }
Jonathan Frederic
Output Widget
r18953 };
/**
Matthias BUSSONNIER
start docummenting kernel
r8768 * @method auto_highlight
*/
Matthias BUSSONNIER
autochange highlight with cell magics...
r8202 CodeCell.prototype.auto_highlight = function () {
Thomas Kluyver
Remove user_config js module
r19529 this._auto_highlight(this.class_config.get_sync('cell_magic_highlight'));
Matthias BUSSONNIER
autochange highlight with cell magics...
r8202 };
Matthias BUSSONNIER
start docummenting kernel
r8768 /** @method create_element */
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 CodeCell.prototype.create_element = function () {
Jonathan Frederic
Fix all the bugs!
r17203 Cell.prototype.create_element.apply(this, arguments);
Matthias BUSSONNIER
Add a per cell toolbar....
r9055
Matthias BUSSONNIER
Transfer of border-box-sizing from js to css...
r17422 var cell = $('<div></div>').addClass('cell code_cell');
Brian E. Granger
Better tabindex support.
r4629 cell.attr('tabindex','2');
Brian E. Granger
Fixing styling issues with CellToolbar....
r9142
Matthias BUSSONNIER
use hbox mixin instead of class...
r10215 var input = $('<div></div>').addClass('input');
Brian E. Granger
Adding prompt area to non-CodeCells to indent content....
r13776 var prompt = $('<div/>').addClass('prompt input_prompt');
var inner_cell = $('<div/>').addClass('inner_cell');
Jonathan Frederic
More review changes
r17214 this.celltoolbar = new celltoolbar.CellToolbar({
cell: this,
notebook: this.notebook});
Brian E. Granger
Adding prompt area to non-CodeCells to indent content....
r13776 inner_cell.append(this.celltoolbar.element);
Matthias BUSSONNIER
fix celltoolbar layout on FF
r9422 var input_area = $('<div/>').addClass('input_area');
Jonathan Frederic
Fixed cell toolbars
r17217 this.code_mirror = new CodeMirror(input_area.get(0), this.cm_config);
Matthias Bussonnier
rework keyboard management to avoit completer and up/down bugs
r18282 this.code_mirror.on('keydown', $.proxy(this.handle_keyevent,this))
MinRK
set `spellcheck=false` in CodeCell inputarea...
r10065 $(this.code_mirror.getInputField()).attr("spellcheck", "false");
Brian E. Granger
Adding prompt area to non-CodeCells to indent content....
r13776 inner_cell.append(input_area);
input.append(prompt).append(inner_cell);
Jonathan Frederic
Added widget output area
r14219
Jonathan Frederic
Added clear widget area button
r14234 var widget_area = $('<div/>')
Jonathan Frederic
Changed underscores in CSS names to dashes
r14293 .addClass('widget-area')
Jonathan Frederic
Added clear widget area button
r14234 .hide();
this.widget_area = widget_area;
var widget_prompt = $('<div/>')
.addClass('prompt')
.appendTo(widget_area);
var widget_subarea = $('<div/>')
Jonathan Frederic
Changed underscores in CSS names to dashes
r14293 .addClass('widget-subarea')
Jonathan Frederic
Added clear widget area button
r14234 .appendTo(widget_area);
this.widget_subarea = widget_subarea;
Jonathan Frederic
Persistence API,...
r19350 var that = this;
Jonathan Frederic
Added clear widget area button
r14234 var widget_clear_buton = $('<button />')
.addClass('close')
.html('&times;')
.click(function() {
Jonathan Frederic
Persistence API,...
r19350 widget_area.slideUp('', function(){
for (var i = 0; i < that.widget_views.length; i++) {
Jonathan Frederic
Bubble event and implement logic in CodeCell
r19572 var view = that.widget_views[i];
view.remove();
// Remove widget live events.
view.off('comm:live', that._widget_live);
view.off('comm:dead', that._widget_dead);
Jonathan Frederic
Persistence API,...
r19350 }
that.widget_views = [];
widget_subarea.html('');
});
})
Jonathan Frederic
Added clear widget area button
r14234 .appendTo(widget_prompt);
Jonathan Frederic
Added widget output area
r14219
Brian Granger
Refactored CodeCell to use new OutputArea object for output....
r7177 var output = $('<div></div>');
Jonathan Frederic
Added widget output area
r14219 cell.append(input).append(widget_area).append(output);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 this.element = cell;
Jonathan Frederic
More review changes
r17214 this.output_area = new outputarea.OutputArea({
selector: output,
prompt_area: true,
events: this.events,
keyboard_manager: this.keyboard_manager});
Jonathan Frederic
Fix imports of "modules",...
r17202 this.completer = new completer.Completer(this, this.events);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Jonathan Frederic
Persistence API,...
r19350 /**
* Display a widget view in the cell.
*/
CodeCell.prototype.display_widget_view = function(view_promise) {
Jonathan Frederic
Promises...
r19351
Jonathan Frederic
Persistence API,...
r19350 // Display a dummy element
var dummy = $('<div/>');
this.widget_subarea.append(dummy);
// Display the view.
var that = this;
return view_promise.then(function(view) {
Jonathan Frederic
Promises...
r19351 that.widget_area.show();
Jonathan Frederic
Persistence API,...
r19350 dummy.replaceWith(view.$el);
Jonathan Frederic
Promises...
r19351 that.widget_views.push(view);
Jonathan Frederic
Bubble event and implement logic in CodeCell
r19572
// Check the live state of the view's model.
if (view.model.comm_live) {
that._widget_live(view);
} else {
that._widget_dead(view);
}
// Listen to comm live events for the view.
view.on('comm:live', that._widget_live, that);
view.on('comm:dead', that._widget_dead, that);
Jonathan Frederic
Persistence API,...
r19350 return view;
});
};
Jonathan Frederic
Bubble event and implement logic in CodeCell
r19572 /**
* Handles when a widget loses it's comm connection.
* @param {WidgetView} view
*/
CodeCell.prototype._widget_dead = function(view) {
if (this._widgets_live) {
this._widgets_live = false;
this.widget_area.addClass('connection-problems');
}
};
/**
* Handles when a widget is connected to a live comm.
* @param {WidgetView} view
*/
CodeCell.prototype._widget_live = function(view) {
if (!this._widgets_live) {
// Check that the other widgets are live too. O(N) operation.
// Abort the function at the first dead widget found.
for (var i = 0; i < this.widget_views.length; i++) {
if (!this.widget_views[i].model.comm_live) return;
}
this._widgets_live = true;
this.widget_area.removeClass('connection-problems');
}
};
Brian E. Granger
More work on the dual mode UX.
r14015 /** @method bind_events */
CodeCell.prototype.bind_events = function () {
Jonathan Frederic
Fix all the bugs!
r17203 Cell.prototype.bind_events.apply(this);
Brian E. Granger
More work on the dual mode UX.
r14015 var that = this;
this.element.focusout(
function() { that.auto_highlight(); }
);
};
Brian E. Granger
Lots of updates and changes....
r14021
Matthias BUSSONNIER
start docummenting kernel
r8768 /**
* This method gets called in CodeMirror's onKeyDown/onKeyPress
* handlers and is used to provide custom key handling. Its return
* value is used to determine if CodeMirror should ignore the event:
* true = ignore, false = don't ignore.
* @method handle_codemirror_keyevent
*/
foogunlana
Fixed code mirror skipping Markdown cell bug
r19098
Brian E. Granger
Fixing execution related things....
r4378 CodeCell.prototype.handle_codemirror_keyevent = function (editor, event) {
Brian E. Granger
Lots of updates and changes....
r14021
Matthias BUSSONNIER
tooltip on <tab>
r5398 var that = this;
Brian E. Granger
Lots of updates and changes....
r14021 // whatever key is pressed, first, cancel the tooltip request before
// they are sent, and remove tooltip if any, except for tab again
Brian E. Granger
Special handling for CM's vim keyboard mapping.
r14062 var tooltip_closed = null;
Brian E. Granger
Removing old keyboard handling from IPython.utils.
r15619 if (event.type === 'keydown' && event.which != keycodes.tab ) {
Jonathan Frederic
Almost done!...
r17198 tooltip_closed = this.tooltip.remove_and_cancel_tooltip();
Brian E. Granger
Lots of updates and changes....
r14021 }
Brian Granger
Making keyboard shortcut for showing line numbers consistent.
r6059
Brian E. Granger
Lots of updates and changes....
r14021 var cur = editor.getCursor();
Brian E. Granger
Removing old keyboard handling from IPython.utils.
r15619 if (event.keyCode === keycodes.enter){
Brian E. Granger
Lots of updates and changes....
r14021 this.auto_highlight();
}
Brian Granger
Making keyboard shortcut for showing line numbers consistent.
r6059
Jonathan Frederic
Almost done!...
r17198 if (event.which === keycodes.down && event.type === 'keypress' && this.tooltip.time_before_tooltip >= 0) {
Brian E. Granger
Lots of updates and changes....
r14021 // triger on keypress (!) otherwise inconsistent event.which depending on plateform
// browser and keyboard layout !
// Pressing '(' , request tooltip, don't forget to reappend it
// The second argument says to hide the tooltip if the docstring
// is actually empty
Jonathan Frederic
Almost done!...
r17198 this.tooltip.pending(that, true);
Paul Ivanov
DRY: refactor common keyboard handling to Cell...
r15757 } else if ( tooltip_closed && event.which === keycodes.esc && event.type === 'keydown') {
Paul Ivanov
minor fixes to docs to address PR feedback
r15820 // If tooltip is active, cancel it. The call to
// remove_and_cancel_tooltip above doesn't pass, force=true.
// Because of this it won't actually close the tooltip
Paul Ivanov
DRY: refactor common keyboard handling to Cell...
r15757 // if it is in sticky mode. Thus, we have to check again if it is open
// and close it with force=true.
Jonathan Frederic
Almost done!...
r17198 if (!this.tooltip._hidden) {
this.tooltip.remove_and_cancel_tooltip(true);
Brian E. Granger
Lots of updates and changes....
r14021 }
Paul Ivanov
DRY: refactor common keyboard handling to Cell...
r15757 // If we closed the tooltip, don't let CM or the global handlers
// handle this event.
Matthias BUSSONNIER
Update to codemirror 4...
r18280 event.codemirrorIgnore = true;
event.preventDefault();
Paul Ivanov
DRY: refactor common keyboard handling to Cell...
r15757 return true;
Brian E. Granger
Removing old keyboard handling from IPython.utils.
r15619 } else if (event.keyCode === keycodes.tab && event.type === 'keydown' && event.shiftKey) {
Matthias Bussonnier
handle somehting selected and multiple cursors and 4 tabs show content in pager
r18284 if (editor.somethingSelected() || editor.getSelections().length !== 1){
Brian E. Granger
Lots of updates and changes....
r14021 var anchor = editor.getCursor("anchor");
var head = editor.getCursor("head");
if( anchor.line != head.line){
return false;
Bussonnier Matthias
shift tqb for tooltip
r8949 }
}
Jonathan Frederic
Almost done!...
r17198 this.tooltip.request(that);
Matthias BUSSONNIER
Update to codemirror 4...
r18280 event.codemirrorIgnore = true;
event.preventDefault();
Bussonnier Matthias
shift tqb for tooltip
r8949 return true;
Brian E. Granger
Removing old keyboard handling from IPython.utils.
r15619 } else if (event.keyCode === keycodes.tab && event.type == 'keydown') {
Brian E. Granger
Fixing tab completion edge cases.
r4555 // Tab completion.
Jonathan Frederic
Almost done!...
r17198 this.tooltip.remove_and_cancel_tooltip();
Matthias Bussonnier
handle somehting selected and multiple cursors and 4 tabs show content in pager
r18284
// completion does not work on multicursor, it might be possible though in some cases
if (editor.somethingSelected() || editor.getSelections().length > 1) {
Matthias BUSSONNIER
prompt '*' strore fix + tab remove tooltip...
r13572 return false;
}
Matthias BUSSONNIER
tooltip on <tab>
r5398 var pre_cursor = editor.getRange({line:cur.line,ch:0},cur);
if (pre_cursor.trim() === "") {
Fernando Perez
Add Ctrl-L as a way to toggle line-numbers for any individual code cell
r5016 // Don't autocomplete if the part of the line before the cursor
// is empty. In this case, let CodeMirror handle indentation.
Brian E. Granger
Notebook now uses tab for autocompletion.
r4393 return false;
} else {
Matthias BUSSONNIER
Update to codemirror 4...
r18280 event.codemirrorIgnore = true;
event.preventDefault();
Brian E. Granger
Lots of updates and changes....
r14021 this.completer.startCompletion();
return true;
}
Paul Ivanov
DRY: refactor common keyboard handling to Cell...
r15757 }
// keyboard event wasn't one of those unique to code cells, let's see
// if it's one of the generic ones (i.e. check edit mode shortcuts)
Jonathan Frederic
Fix all the bugs!
r17203 return Cell.prototype.handle_codemirror_keyevent.apply(this, [editor, event]);
Brian E. Granger
Fixing execution related things....
r4378 };
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 // Kernel related calls.
MinRK
Cells shouldn't know about Sessions
r13133 CodeCell.prototype.set_kernel = function (kernel) {
this.kernel = kernel;
MinRK
jshint on codecell
r13210 };
Brian Granger
Fixed order of notebook loading and kernel starting....
r7197
Matthias BUSSONNIER
start docummenting kernel
r8768 /**
* Execute current code cell to the kernel
* @method execute
*/
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 CodeCell.prototype.execute = function () {
Min RK
don't execute if kernel is not connected
r18931 if (!this.kernel || !this.kernel.is_connected()) {
console.log("Can't execute, kernel is not connected.");
return;
}
Jonathan Frederic
Output Widget
r18953
Jonathan Frederic
Address @carreau 's comments
r18958 this.active_output_area.clear_output();
Jonathan Frederic
Fixed glitch when widgetarea wouldn't get completely hidden upon re-execution
r14248
// Clear widget area
Jonathan Frederic
Persistence API,...
r19350 for (var i = 0; i < this.widget_views.length; i++) {
Jonathan Frederic
Bubble event and implement logic in CodeCell
r19572 var view = this.widget_views[i];
view.remove();
// Remove widget live events.
view.off('comm:live', this._widget_live);
view.off('comm:dead', this._widget_dead);
Jonathan Frederic
Persistence API,...
r19350 }
this.widget_views = [];
Jonathan Frederic
Clear widgets upon cell execute
r14235 this.widget_subarea.html('');
this.widget_subarea.height('');
this.widget_area.height('');
Jonathan Frederic
Fixed glitch when widgetarea wouldn't get completely hidden upon re-execution
r14248 this.widget_area.hide();
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 this.set_input_prompt('*');
this.element.addClass("running");
MinRK
add CodeCell.get_callbacks...
r13225 if (this.last_msg_id) {
this.kernel.clear_callbacks_for_msg(this.last_msg_id);
}
var callbacks = this.get_callbacks();
Jonathan Frederic
Remove O(N) cell by msg-id lookup
r14604 var old_msg_id = this.last_msg_id;
MinRK
add CodeCell.get_callbacks...
r13225 this.last_msg_id = this.kernel.execute(this.get_text(), callbacks, {silent: false, store_history: true});
Jonathan Frederic
Remove O(N) cell by msg-id lookup
r14604 if (old_msg_id) {
delete CodeCell.msg_cells[old_msg_id];
}
CodeCell.msg_cells[this.last_msg_id] = this;
Matthias BUSSONNIER
Generalise render/unrender to all cells type...
r18270 this.render();
Scott Sanderson
DEV: Pass current cell to the execute cell event.
r19041 this.events.trigger('execute.CodeCell', {cell: this});
MinRK
add CodeCell.get_callbacks...
r13225 };
/**
* Construct the default callbacks for
* @method get_callbacks
*/
CodeCell.prototype.get_callbacks = function () {
Jonathan Frederic
Output Widget
r18953 var that = this;
MinRK
add CodeCell.get_callbacks...
r13225 return {
MinRK
refactor js callbacks...
r13207 shell : {
reply : $.proxy(this._handle_execute_reply, this),
payload : {
set_next_input : $.proxy(this._handle_set_next_input, this),
MinRK
add CodeCell.get_callbacks...
r13225 page : $.proxy(this._open_with_pager, this)
MinRK
refactor js callbacks...
r13207 }
},
iopub : {
Jonathan Frederic
Output Widget
r18953 output : function() {
Jonathan Frederic
Bug fix, typo
r18959 that.active_output_area.handle_output.apply(that.active_output_area, arguments);
Jonathan Frederic
Output Widget
r18953 },
clear_output : function() {
Jonathan Frederic
Bug fix, typo
r18959 that.active_output_area.handle_clear_output.apply(that.active_output_area, arguments);
Jonathan Frederic
Output Widget
r18953 },
MinRK
refactor js callbacks...
r13207 },
input : $.proxy(this._handle_input_request, this)
MinRK
jshint on codecell
r13210 };
MinRK
add CodeCell.get_callbacks...
r13225 };
CodeCell.prototype._open_with_pager = function (payload) {
Jonathan Frederic
Almost done!...
r17198 this.events.trigger('open_with_text.Pager', payload);
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 };
Matthias BUSSONNIER
start docummenting kernel
r8768 /**
* @method _handle_execute_reply
* @private
*/
MinRK
refactor js callbacks...
r13207 CodeCell.prototype._handle_execute_reply = function (msg) {
this.set_input_prompt(msg.content.execution_count);
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 this.element.removeClass("running");
Jonathan Frederic
Almost done!...
r17198 this.events.trigger('set_dirty.Notebook', {value: true});
MinRK
jshint on codecell
r13210 };
Brian E. Granger
Autocompletion working with CTRL-SPACE.
r4389
MinRK
use inline raw_input instead of a dialog
r10368 /**
* @method _handle_set_next_input
* @private
*/
MinRK
refactor js callbacks...
r13207 CodeCell.prototype._handle_set_next_input = function (payload) {
Thomas Kluyver
Machinery to replace the current cell instead of adding a new one
r19250 var data = {'cell': this, 'text': payload.text, replace: payload.replace};
Jonathan Frederic
Almost done!...
r17198 this.events.trigger('set_next_input.Notebook', data);
MinRK
jshint on codecell
r13210 };
Takeshi Kanmae
ESC should be handled by CM if tooltip is not on
r12458
MinRK
use inline raw_input instead of a dialog
r10368 /**
* @method _handle_input_request
* @private
*/
MinRK
refactor js callbacks...
r13207 CodeCell.prototype._handle_input_request = function (msg) {
Jonathan Frederic
Address @carreau 's comments
r18958 this.active_output_area.append_raw_input(msg);
MinRK
jshint on codecell
r13210 };
MinRK
use inline raw_input instead of a dialog
r10368
Brian Granger
Removing cell from execute callbacks in kernel.js.
r7223
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 // Basic cell manipulation.
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 CodeCell.prototype.select = function () {
Jonathan Frederic
Fix all the bugs!
r17203 var cont = Cell.prototype.select.apply(this);
Brian E. Granger
More work on the dual mode UX.
r14015 if (cont) {
Brian E. Granger
Adding new logic to cells.
r14014 this.code_mirror.refresh();
this.auto_highlight();
Brian E. Granger
Semicolon cleanup.
r14092 }
Brian E. Granger
More work on the dual mode UX.
r14015 return cont;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian E. Granger
Adding new logic to cells.
r14014 CodeCell.prototype.render = function () {
Jonathan Frederic
Fix all the bugs!
r17203 var cont = Cell.prototype.render.apply(this);
Brian E. Granger
More work on the dual mode UX.
r14015 // Always execute, even if we are already in the rendered state
return cont;
Brian E. Granger
Starting work on select/focus logic.
r14013 };
Brian E. Granger
More work on the dual mode UX.
r14015
Brian E. Granger
Ctrl-Enter now does not delete input, but selects it.
r4675 CodeCell.prototype.select_all = function () {
var start = {line: 0, ch: 0};
var nlines = this.code_mirror.lineCount();
var last_line = this.code_mirror.getLine(nlines-1);
var end = {line: nlines-1, ch: last_line.length};
this.code_mirror.setSelection(start, end);
};
Brian E. Granger
Cleaning up output management in code and menus.
r14867 CodeCell.prototype.collapse_output = function () {
MinRK
restore collapsed state for cells...
r7524 this.output_area.collapse();
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 };
Brian E. Granger
Cleaning up output management in code and menus.
r14867 CodeCell.prototype.expand_output = function () {
MinRK
restore collapsed state for cells...
r7524 this.output_area.expand();
Brian E. Granger
Cleaning up output management in code and menus.
r14867 this.output_area.unscroll_area();
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 };
Brian E. Granger
Cleaning up output management in code and menus.
r14867 CodeCell.prototype.scroll_output = function () {
this.output_area.expand();
this.output_area.scroll_if_long();
};
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168
CodeCell.prototype.toggle_output = function () {
MinRK
restore collapsed state for cells...
r7524 this.output_area.toggle_output();
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 };
MinRK
add ^M-O for toggling output scroll
r7429 CodeCell.prototype.toggle_output_scroll = function () {
Brian E. Granger
Cleaning up output management in code and menus.
r14867 this.output_area.toggle_scroll();
MinRK
add ^M-O for toggling output scroll
r7429 };
Bussonnier Matthias
add ability to create continuation prompt
r8467 CodeCell.input_prompt_classical = function (prompt_value, lines_number) {
Matthias BUSSONNIER
avoid injection in input prompt
r14714 var ns;
Jessica B. Hamrick
Display prompt in the notebook correctly
r18326 if (prompt_value === undefined || prompt_value === null) {
Matthias BUSSONNIER
avoid injection in input prompt
r14714 ns = "&nbsp;";
} else {
ns = encodeURIComponent(prompt_value);
}
MinRK
jshint on codecell
r13210 return 'In&nbsp;[' + ns + ']:';
Bussonnier Matthias
add ability to create continuation prompt
r8467 };
Matthias BUSSONNIER
start docummenting kernel
r8768
Bussonnier Matthias
add ability to create continuation prompt
r8467 CodeCell.input_prompt_continuation = function (prompt_value, lines_number) {
var html = [CodeCell.input_prompt_classical(prompt_value, lines_number)];
MinRK
jshint on codecell
r13210 for(var i=1; i < lines_number; i++) {
html.push(['...:']);
}
return html.join('<br/>');
Bussonnier Matthias
add ability to create continuation prompt
r8467 };
Matthias BUSSONNIER
start docummenting kernel
r8768
Bussonnier Matthias
add ability to create continuation prompt
r8467 CodeCell.input_prompt_function = CodeCell.input_prompt_classical;
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 CodeCell.prototype.set_input_prompt = function (number) {
MinRK
jshint on codecell
r13210 var nline = 1;
if (this.code_mirror !== undefined) {
Bussonnier Matthias
add ability to create continuation prompt
r8467 nline = this.code_mirror.lineCount();
}
Paul Ivanov
clear In[ ] prompt numbers again
r8603 this.input_prompt_number = number;
Bussonnier Matthias
add ability to create continuation prompt
r8467 var prompt_html = CodeCell.input_prompt_function(this.input_prompt_number, nline);
Jonathan Frederic
Audit .html() calls take #2
r15376 // This HTML call is okay because the user contents are escaped.
Bussonnier Matthias
add ability to create continuation prompt
r8467 this.element.find('div.input_prompt').html(prompt_html);
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168 };
CodeCell.prototype.clear_input = function () {
this.code_mirror.setValue('');
};
CodeCell.prototype.get_text = function () {
return this.code_mirror.getValue();
};
CodeCell.prototype.set_text = function (code) {
return this.code_mirror.setValue(code);
};
MinRK
fixup bad rebase
r13102 CodeCell.prototype.clear_output = function (wait) {
Jonathan Frederic
Address @carreau 's comments
r18958 this.active_output_area.clear_output(wait);
Brian E. Granger
Cleaning up output management in code and menus.
r14867 this.set_input_prompt();
MinRK
[notebook] clear_output is handled after a delay...
r6423 };
Brian Granger
Major refactoring of the Notebook, Kernel and CodeCell JavaScript....
r7168
// JSON serialization
Brian E. Granger
Splitting notebook.js into muliple files for development ease.
r4349
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 CodeCell.prototype.fromJSON = function (data) {
Jonathan Frederic
Fix all the bugs!
r17203 Cell.prototype.fromJSON.apply(this, arguments);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 if (data.cell_type === 'code') {
MinRK
update html/js to nbformat 4
r18584 if (data.source !== undefined) {
this.set_text(data.source);
Paul Ivanov
fix for #1678, undo no longer clears cells...
r7587 // make this value the starting point, so that we can only undo
// to this state, instead of a blank cell
this.code_mirror.clearHistory();
Matthias BUSSONNIER
autochange highlight with cell magics...
r8202 this.auto_highlight();
Brian E. Granger
Massive work on the notebook document format....
r4484 }
MinRK
s/prompt_number/execution_count in nbformat 4
r18587 this.set_input_prompt(data.execution_count);
MinRK
trust is stored in code_cell.metadata...
r18255 this.output_area.trusted = data.metadata.trusted || false;
Brian Granger
Refactored CodeCell to use new OutputArea object for output....
r7177 this.output_area.fromJSON(data.outputs);
MinRK
update html/js to nbformat 4
r18584 if (data.metadata.collapsed !== undefined) {
if (data.metadata.collapsed) {
Brian E. Granger
Cleaning up output management in code and menus.
r14867 this.collapse_output();
Brian Granger
Fixing minor bugs in nbformat and saving....
r6032 } else {
Brian E. Granger
Cleaning up output management in code and menus.
r14867 this.expand_output();
MinRK
jshint on codecell
r13210 }
}
}
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
CodeCell.prototype.toJSON = function () {
Jonathan Frederic
Fix all the bugs!
r17203 var data = Cell.prototype.toJSON.apply(this);
MinRK
update html/js to nbformat 4
r18584 data.source = this.get_text();
Matthias BUSSONNIER
prompt '*' strore fix + tab remove tooltip...
r13572 // is finite protect against undefined and '*' value
if (isFinite(this.input_prompt_number)) {
MinRK
s/prompt_number/execution_count in nbformat 4
r18587 data.execution_count = this.input_prompt_number;
MinRK
update html/js to nbformat 4
r18584 } else {
MinRK
s/prompt_number/execution_count in nbformat 4
r18587 data.execution_count = null;
MinRK
jshint on codecell
r13210 }
Brian Granger
Refactored CodeCell to use new OutputArea object for output....
r7177 var outputs = this.output_area.toJSON();
Brian E. Granger
Added saving and loading of output of all types.
r4497 data.outputs = outputs;
MinRK
trust is stored in code_cell.metadata...
r18255 data.metadata.trusted = this.output_area.trusted;
MinRK
update html/js to nbformat 4
r18584 data.metadata.collapsed = this.output_area.collapsed;
Brian E. Granger
Massive work on the notebook document format....
r4484 return data;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Jonathan Frederic
Add logic to close tt when cell is unselected
r15793 /**
* handle cell level logic when a cell is unselected
* @method unselect
* @return is the action being taken
*/
CodeCell.prototype.unselect = function () {
Jonathan Frederic
Fix all the bugs!
r17203 var cont = Cell.prototype.unselect.apply(this);
Jonathan Frederic
Add logic to close tt when cell is unselected
r15793 if (cont) {
Jonathan Frederic
Added some comments
r15818 // When a code cell is usnelected, make sure that the corresponding
Jonathan Frederic
Getting a lot closer...
r15952 // tooltip and completer to that cell is closed.
Jonathan Frederic
Almost done!...
r17198 this.tooltip.remove_and_cancel_tooltip(true);
Jonathan Frederic
Getting a lot closer...
r15952 if (this.completer !== null) {
this.completer.close();
}
Jonathan Frederic
Add logic to close tt when cell is unselected
r15793 }
return cont;
};
Brian E. Granger
Added saving and loading of output of all types.
r4497
Jonathan Frederic
Almost done!...
r17198 // Backwards compatability.
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 IPython.CodeCell = CodeCell;
Jonathan Frederic
Return dicts instead of classes,...
r17201 return {'CodeCell': CodeCell};
Jonathan Frederic
Almost done!...
r17198 });