Moved the logic to get a cell by message id into the notebook.js.

Also added more detail to the comments in the get output area function in widgets.js
Jonathan Frederic 12 years ago
parent 215060e8e8
commit 48eaebf683

@ -300,6 +300,24 @@ var IPython = (function (IPython) {
return result;
};
/**
* Try to get a particular cell by msg_id.
*
* @method get_msg_cell
* @param {String} msg_id A message UUID
* @return {Cell} Cell or null if no cell was found.
*/
Notebook.prototype.get_msg_cell = function (msg_id) {
var cells = this.get_cells();
for (var cell_index in cells) {
if (cells[cell_index].last_msg_id == msg_id) {
var cell = this.get_cell(cell_index)
return cell;
}
}
return null;
};
/**
* Count the cells in this notebook.
*

@ -298,25 +298,30 @@ define(["components/underscore/underscore-min",
// output_area is an instance of Ipython.OutputArea
_get_output_area: function (msg_id) {
// First, guess cell.execute triggered
var cells = IPython.notebook.get_cells();
for (var cell_index in cells) {
if (cells[cell_index].last_msg_id == msg_id) {
var cell = IPython.notebook.get_cell(cell_index)
return cell.output_area;
}
// First, check to see if the msg was triggered by cell execution.
var cell = IPython.notebook.get_msg_cell();
if (cell != null) {
return cell.output_area;
}
// Second, guess widget triggered
var callbacks = this.comm_manager.kernel.get_callbacks_for_msg(msg_id)
if (callbacks != undefined && callbacks.iopub != undefined && callbacks.iopub.get_output_area != undefined) {
// Second, check to see if a get_output_area callback was defined
// for the message. get_output_area callbacks are registered for
// widget messages, so this block is actually checking to see if the
// message was triggered by a widget.
var kernel = this.comm_manager.kernel;
var callbacks = kernel.get_callbacks_for_msg(msg_id);
if (callbacks != undefined &&
callbacks.iopub != undefined &&
callbacks.iopub.get_output_area != undefined) {
var output_area = callbacks.iopub.get_output_area();
if (output_area != null) {
return output_area;
}
}
// Not triggered by a widget or a cell
// Not triggered by a cell or widget (no get_output_area callback
// exists).
return null;
},

Loading…
Cancel
Save