From 42cf79abe9d48a0cbc54fce7d9bfcf446fb5983b 2013-10-18 23:13:53 From: MinRK Date: 2013-10-18 23:13:53 Subject: [PATCH] Cells shouldn't know about Sessions --- diff --git a/IPython/html/static/notebook/js/codecell.js b/IPython/html/static/notebook/js/codecell.js index 53b010c..b823fa2 100644 --- a/IPython/html/static/notebook/js/codecell.js +++ b/IPython/html/static/notebook/js/codecell.js @@ -60,8 +60,8 @@ var IPython = (function (IPython) { * @param {object|undefined} [options] * @param [options.cm_config] {object} config to pass to CodeMirror */ - var CodeCell = function (session, options) { - this.session = session || null; + var CodeCell = function (kernel, options) { + this.kernel = kernel || null; this.code_mirror = null; this.input_prompt_number = null; this.collapsed = false; @@ -231,8 +231,8 @@ var IPython = (function (IPython) { // Kernel related calls. - CodeCell.prototype.set_session = function (session) { - this.session = session; + CodeCell.prototype.set_kernel = function (kernel) { + this.kernel = kernel; } /** @@ -250,7 +250,7 @@ var IPython = (function (IPython) { 'set_next_input': $.proxy(this._handle_set_next_input, this), 'input_request': $.proxy(this._handle_input_request, this) }; - this.last_msg_id = this.session.kernel.execute(this.get_text(), callbacks, {silent: false, store_history: true}); + this.last_msg_id = this.kernel.execute(this.get_text(), callbacks, {silent: false, store_history: true}); }; /** diff --git a/IPython/html/static/notebook/js/completer.js b/IPython/html/static/notebook/js/completer.js index 0b5cb01..992c87f 100644 --- a/IPython/html/static/notebook/js/completer.js +++ b/IPython/html/static/notebook/js/completer.js @@ -153,7 +153,7 @@ var IPython = (function (IPython) { var callbacks = { 'complete_reply': $.proxy(this.finish_completing, this) }; - this.cell.session.kernel.complete(line, cur.ch, callbacks); + this.cell.kernel.complete(line, cur.ch, callbacks); } }; diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 16d9297..f073419 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -33,6 +33,7 @@ var IPython = (function (IPython) { this.element.data("notebook", this); this.next_prompt_number = 1; this.session = null; + this.kernel = null; this.clipboard = null; this.undelete_backup = null; this.undelete_index = null; @@ -797,7 +798,7 @@ var IPython = (function (IPython) { if (ncells === 0 || this.is_valid_cell_index(index) || index === ncells) { if (type === 'code') { - cell = new IPython.CodeCell(this.session); + cell = new IPython.CodeCell(this.kernel); cell.set_input_prompt(); } else if (type === 'markdown') { cell = new IPython.MarkdownCell(); @@ -1390,21 +1391,21 @@ var IPython = (function (IPython) { */ Notebook.prototype.start_session = function () { this.session = new IPython.Session(this.notebook_name, this.notebook_path, this); - this.session.start(); - this.link_cells_to_session(); + this.session.start($.proxy(this._session_started, this)); }; /** - * Once a session is started, link the code cells to the session + * Once a session is started, link the code cells to the kernel * */ - Notebook.prototype.link_cells_to_session= function(){ + Notebook.prototype._session_started = function(){ + this.kernel = this.session.kernel; var ncells = this.ncells(); for (var i=0; i