##// END OF EJS Templates
set 'In [*]' to indicate pending code cell
set 'In [*]' to indicate pending code cell

File last commit:

r5220:3381794c
r5220:3381794c
Show More
notebook.js
1007 lines | 35.0 KiB | application/javascript | JavascriptLexer
Brian E. Granger
More review changes....
r4609 //----------------------------------------------------------------------------
// Copyright (C) 2008-2011 The IPython Development Team
//
// Distributed under the terms of the BSD License. The full license is in
// the file COPYING, distributed as part of this software.
//----------------------------------------------------------------------------
Brian Granger
Basic notebook saving and loading....
r4315
Brian Granger
Initial reply handling implemented along with css fixes.
r4299 //============================================================================
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292 // Notebook
//============================================================================
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var IPython = (function (IPython) {
Brian E. Granger
Initial payload handling....
r4356 var utils = IPython.utils;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var Notebook = function (selector) {
MinRK
move read_only flag to page-level...
r5213 this.read_only = IPython.read_only;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 this.element = $(selector);
this.element.scroll();
this.element.data("notebook", this);
this.next_prompt_number = 1;
this.kernel = null;
Brian E. Granger
Added a notebook dirty flag that is used when exiting page.
r4550 this.dirty = false;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 this.msg_cell_map = {};
Brian E. Granger
Implemented metadata for notebook format.
r4637 this.metadata = {};
Brian E. Granger
Adding keyboard shortcuts.
r4645 this.control_key_active = false;
Brian E. Granger
Refactoring pager into its own class.
r4357 this.style();
Brian E. Granger
Improving the scrolling model.
r4364 this.create_elements();
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 this.bind_events();
};
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Brian E. Granger
Refactoring pager into its own class.
r4357 Notebook.prototype.style = function () {
Brian E. Granger
Left panel is now working.
r4363 $('div#notebook').addClass('border-box-sizing');
Brian E. Granger
Refactoring pager into its own class.
r4357 };
Brian E. Granger
Improving the scrolling model.
r4364 Notebook.prototype.create_elements = function () {
// We add this end_space div to the end of the notebook div to:
// i) provide a margin between the last cell and the end of the notebook
// ii) to prevent the div from scrolling up when the last cell is being
// edited, but is too low on the page, which browsers will do automatically.
Brian E. Granger
Double clicking on the end space will insert a new cell.
r4628 var that = this;
Brian E. Granger
Don't scroll to bottom when last cell is selected.
r4604 var end_space = $('<div class="end_space"></div>').height(150);
Brian E. Granger
Double clicking on the end space will insert a new cell.
r4628 end_space.dblclick(function (e) {
MinRK
add read-only view for notebooks...
r5200 if (that.read_only) return;
Brian E. Granger
Double clicking on the end space will insert a new cell.
r4628 var ncells = that.ncells();
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 that.insert_code_cell_below(ncells-1);
Brian E. Granger
Double clicking on the end space will insert a new cell.
r4628 });
Brian E. Granger
Don't scroll to bottom when last cell is selected.
r4604 this.element.append(end_space);
Brian E. Granger
Improving the scrolling model.
r4364 $('div#notebook').addClass('border-box-sizing');
};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Notebook.prototype.bind_events = function () {
var that = this;
$(document).keydown(function (event) {
Brian E. Granger
Fixing console.log messages related to keyboard shortcuts.
r4647 // console.log(event);
MinRK
add read-only view for notebooks...
r5200 if (that.read_only) return;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 if (event.which === 38) {
var cell = that.selected_cell();
if (cell.at_top()) {
event.preventDefault();
that.select_prev();
};
} else if (event.which === 40) {
var cell = that.selected_cell();
if (cell.at_bottom()) {
event.preventDefault();
that.select_next();
};
} else if (event.which === 13 && event.shiftKey) {
Brian E. Granger
Fixes to terminal mode execution (ctrl-enter).
r4394 that.execute_selected_cell();
Brian E. Granger
Prevent shift-enter from propagating and performing default.
r4380 return false;
Brian E. Granger
CTRL-ENTER now runs a cell in "terminal mode"...
r4390 } else if (event.which === 13 && event.ctrlKey) {
Brian E. Granger
Fixes to terminal mode execution (ctrl-enter).
r4394 that.execute_selected_cell({terminal:true});
Brian E. Granger
CTRL-ENTER now runs a cell in "terminal mode"...
r4390 return false;
Brian E. Granger
Adding keyboard shortcuts.
r4645 } else if (event.which === 77 && event.ctrlKey) {
that.control_key_active = true;
return false;
} else if (event.which === 68 && that.control_key_active) {
// Delete selected cell = d
that.delete_cell();
that.control_key_active = false;
return false;
} else if (event.which === 65 && that.control_key_active) {
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 // Insert code cell above selected = a
that.insert_code_cell_above();
Brian E. Granger
Adding keyboard shortcuts.
r4645 that.control_key_active = false;
return false;
} else if (event.which === 66 && that.control_key_active) {
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 // Insert code cell below selected = b
that.insert_code_cell_below();
Brian E. Granger
Adding keyboard shortcuts.
r4645 that.control_key_active = false;
return false;
} else if (event.which === 67 && that.control_key_active) {
// To code = c
that.to_code();
that.control_key_active = false;
return false;
} else if (event.which === 77 && that.control_key_active) {
// To markdown = m
that.to_markdown();
that.control_key_active = false;
return false;
} else if (event.which === 84 && that.control_key_active) {
// Toggle output = t
that.toggle_output();
that.control_key_active = false;
return false;
} else if (event.which === 83 && that.control_key_active) {
// Save notebook = s
IPython.save_widget.save_notebook();
that.control_key_active = false;
return false;
} else if (event.which === 74 && that.control_key_active) {
// Move cell down = j
that.move_cell_down();
that.control_key_active = false;
return false;
} else if (event.which === 75 && that.control_key_active) {
// Move cell up = k
that.move_cell_up();
that.control_key_active = false;
return false;
Brian E. Granger
Changing prev/next keyboard shortcut to use p/n.
r4648 } else if (event.which === 80 && that.control_key_active) {
// Select previous = p
Brian E. Granger
Adding keyboard shortcuts.
r4645 that.select_prev();
that.control_key_active = false;
return false;
Brian E. Granger
Changing prev/next keyboard shortcut to use p/n.
r4648 } else if (event.which === 78 && that.control_key_active) {
// Select next = n
Brian E. Granger
Adding keyboard shortcuts.
r4645 that.select_next();
that.control_key_active = false;
return false;
Fernando Perez
Keep kernel-related bindings together in code.
r5026 } else if (event.which === 76 && that.control_key_active) {
// Toggle line numbers = l
that.cell_toggle_line_numbers();
Brian E. Granger
Adding keyboard shortcut help dialog.
r4646 that.control_key_active = false;
return false;
Fernando Perez
Add C-m-{'i', '.'} as keybindings for kernel interrupt/restart.
r5018 } else if (event.which === 73 && that.control_key_active) {
// Interrupt kernel = i
IPython.notebook.kernel.interrupt();
that.control_key_active = false;
return false;
} else if (event.which === 190 && that.control_key_active) {
// Restart kernel = . # matches qt console
Fernando Perez
Clean up accidentally introduced hard tabs in JS code.
r5025 IPython.notebook.restart_kernel();
Fernando Perez
Add C-m-{'i', '.'} as keybindings for kernel interrupt/restart.
r5018 that.control_key_active = false;
return false;
Brian E. Granger
Adding keyboard shortcut help dialog.
r4646 } else if (event.which === 72 && that.control_key_active) {
// Show keyboard shortcuts = h
MinRK
show_keyboard_shortcuts -> toggle_keyboard_shortcuts...
r5067 that.toggle_keyboard_shortcuts();
Brian E. Granger
Adding keyboard shortcut help dialog.
r4646 that.control_key_active = false;
return false;
Brian E. Granger
Adding keyboard shortcuts.
r4645 } else if (that.control_key_active) {
that.control_key_active = false;
return true;
Brian Granger
Much improved nagivation for the notebook cells....
r4334 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 });
Brian E. Granger
Pager is working again.
r4361
this.element.bind('collapse_pager', function () {
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 var app_height = $('div#main_app').height(); // content height
Brian E. Granger
More accuract height calculations for the pager collapse/expand.
r4362 var splitter_height = $('div#pager_splitter').outerHeight(true);
var new_height = app_height - splitter_height;
Brian E. Granger
Pager is working again.
r4361 that.element.animate({height : new_height + 'px'}, 'fast');
});
this.element.bind('expand_pager', function () {
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 var app_height = $('div#main_app').height(); // content height
Brian E. Granger
More accuract height calculations for the pager collapse/expand.
r4362 var splitter_height = $('div#pager_splitter').outerHeight(true);
Brian E. Granger
Pager is working again.
r4361 var pager_height = $('div#pager').outerHeight(true);
Brian E. Granger
More accuract height calculations for the pager collapse/expand.
r4362 var new_height = app_height - pager_height - splitter_height;
Brian E. Granger
Pager is working again.
r4361 that.element.animate({height : new_height + 'px'}, 'fast');
});
Brian E. Granger
Left panel is now working.
r4363
this.element.bind('collapse_left_panel', function () {
var splitter_width = $('div#left_panel_splitter').outerWidth(true);
var new_margin = splitter_width;
$('div#notebook_panel').animate({marginLeft : new_margin + 'px'}, 'fast');
});
this.element.bind('expand_left_panel', function () {
var splitter_width = $('div#left_panel_splitter').outerWidth(true);
var left_panel_width = IPython.left_panel.width;
var new_margin = splitter_width + left_panel_width;
$('div#notebook_panel').animate({marginLeft : new_margin + 'px'}, 'fast');
});
Brian E. Granger
Disabling auto-save at exit.
r4542
$(window).bind('beforeunload', function () {
MinRK
add read-only view for notebooks...
r5200 var kill_kernel = $('#kill_kernel').prop('checked');
Brian E. Granger
Disabling auto-save at exit.
r4542 if (kill_kernel) {
that.kernel.kill();
Brian E. Granger
Added a notebook dirty flag that is used when exiting page.
r4550 }
MinRK
add read-only view for notebooks...
r5200 if (that.dirty && ! that.read_only) {
Brian E. Granger
Added a notebook dirty flag that is used when exiting page.
r4550 return "You have unsaved changes that will be lost if you leave this page.";
Brian E. Granger
Disabling auto-save at exit.
r4542 };
});
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
MinRK
show_keyboard_shortcuts -> toggle_keyboard_shortcuts...
r5067 Notebook.prototype.toggle_keyboard_shortcuts = function () {
// toggles display of keyboard shortcut dialog
var that = this;
if ( this.shortcut_dialog ){
// if dialog is already shown, close it
this.shortcut_dialog.dialog("close");
this.shortcut_dialog = null;
return;
}
Brian E. Granger
Adding keyboard shortcut help dialog.
r4646 var dialog = $('<div/>');
MinRK
show_keyboard_shortcuts -> toggle_keyboard_shortcuts...
r5067 this.shortcut_dialog = dialog;
Brian E. Granger
Adding keyboard shortcut help dialog.
r4646 var shortcuts = [
{key: 'Shift-Enter', help: 'run cell'},
Fernando Perez
Refactor line num. toggle into proper function, access via C-m-l....
r5020 {key: 'Ctrl-Enter', help: 'run cell in-place'},
Brian E. Granger
Adding keyboard shortcut help dialog.
r4646 {key: 'Ctrl-m d', help: 'delete cell'},
{key: 'Ctrl-m a', help: 'insert cell above'},
{key: 'Ctrl-m b', help: 'insert cell below'},
{key: 'Ctrl-m t', help: 'toggle output'},
Fernando Perez
Refactor line num. toggle into proper function, access via C-m-l....
r5020 {key: 'Ctrl-m l', help: 'toggle line numbers'},
Brian E. Granger
Adding keyboard shortcut help dialog.
r4646 {key: 'Ctrl-m s', help: 'save notebook'},
{key: 'Ctrl-m j', help: 'move cell down'},
{key: 'Ctrl-m k', help: 'move cell up'},
{key: 'Ctrl-m c', help: 'code cell'},
{key: 'Ctrl-m m', help: 'markdown cell'},
Brian E. Granger
Changing prev/next keyboard shortcut to use p/n.
r4648 {key: 'Ctrl-m p', help: 'select previous'},
{key: 'Ctrl-m n', help: 'select next'},
Fernando Perez
Clean up accidentally introduced hard tabs in JS code.
r5025 {key: 'Ctrl-m i', help: 'interrupt kernel'},
{key: 'Ctrl-m .', help: 'restart kernel'},
Fernando Perez
Refactor line num. toggle into proper function, access via C-m-l....
r5020 {key: 'Ctrl-m h', help: 'show keyboard shortcuts'}
Brian E. Granger
Adding keyboard shortcut help dialog.
r4646 ];
for (var i=0; i<shortcuts.length; i++) {
dialog.append($('<div>').
Stefan van der Walt
Align colons in help dialog.
r4650 append($('<span/>').addClass('shortcut_key').html(shortcuts[i].key)).
append($('<span/>').addClass('shortcut_descr').html(' : ' + shortcuts[i].help))
Brian E. Granger
Adding keyboard shortcut help dialog.
r4646 );
};
MinRK
show_keyboard_shortcuts -> toggle_keyboard_shortcuts...
r5067 dialog.bind('dialogclose', function(event) {
// dialog has been closed, allow it to be drawn again.
that.shortcut_dialog = null;
});
Brian E. Granger
Adding keyboard shortcut help dialog.
r4646 dialog.dialog({title: 'Keyboard shortcuts'});
};
Brian E. Granger
Improving the scrolling model.
r4364 Notebook.prototype.scroll_to_bottom = function () {
Brian Granger
Minor fixes to fonts and spacing.
r4366 this.element.animate({scrollTop:this.element.get(0).scrollHeight}, 0);
Brian E. Granger
Improving the scrolling model.
r4364 };
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488
Notebook.prototype.scroll_to_top = function () {
this.element.animate({scrollTop:0}, 0);
};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 // Cell indexing, retrieval, etc.
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Notebook.prototype.cell_elements = function () {
return this.element.children("div.cell");
}
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Notebook.prototype.ncells = function (cell) {
return this.cell_elements().length;
}
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 // TODO: we are often calling cells as cells()[i], which we should optimize
// to cells(i) or a new method.
Notebook.prototype.cells = function () {
return this.cell_elements().toArray().map(function (e) {
return $(e).data("cell");
});
}
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Notebook.prototype.find_cell_index = function (cell) {
var result = null;
this.cell_elements().filter(function (index) {
if ($(this).data("cell") === cell) {
result = index;
};
});
return result;
};
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Notebook.prototype.index_or_selected = function (index) {
return index || this.selected_index() || 0;
}
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Notebook.prototype.select = function (index) {
if (index !== undefined && index >= 0 && index < this.ncells()) {
if (this.selected_index() !== null) {
this.selected_cell().unselect();
};
this.cells()[index].select();
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 return this;
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Notebook.prototype.select_next = function () {
var index = this.selected_index();
if (index !== null && index >= 0 && (index+1) < this.ncells()) {
this.select(index+1);
};
return this;
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Notebook.prototype.select_prev = function () {
var index = this.selected_index();
if (index !== null && index >= 0 && (index-1) < this.ncells()) {
this.select(index-1);
Brian Granger
Initial reply handling implemented along with css fixes.
r4299 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 return this;
};
Brian Granger
Initial reply handling implemented along with css fixes.
r4299
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Notebook.prototype.selected_index = function () {
var result = null;
this.cell_elements().filter(function (index) {
if ($(this).data("cell").selected === true) {
result = index;
};
});
return result;
};
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Notebook.prototype.cell_for_msg = function (msg_id) {
var cell_id = this.msg_cell_map[msg_id];
var result = null;
this.cell_elements().filter(function (index) {
cell = $(this).data("cell");
if (cell.cell_id === cell_id) {
result = cell;
};
});
return result;
};
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Notebook.prototype.selected_cell = function () {
return this.cell_elements().eq(this.selected_index()).data("cell");
}
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 // Cell insertion, deletion and moving.
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Notebook.prototype.delete_cell = function (index) {
var i = index || this.selected_index();
if (i !== null && i >= 0 && i < this.ncells()) {
this.cell_elements().eq(i).remove();
if (i === (this.ncells())) {
this.select(i-1);
} else {
this.select(i);
};
};
Brian E. Granger
Added a notebook dirty flag that is used when exiting page.
r4550 this.dirty = true;
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292 return this;
};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Notebook.prototype.append_cell = function (cell) {
Brian E. Granger
Improving the scrolling model.
r4364 this.element.find('div.end_space').before(cell.element);
Brian E. Granger
Added a notebook dirty flag that is used when exiting page.
r4550 this.dirty = true;
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292 return this;
};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 Notebook.prototype.insert_cell_below = function (cell, index) {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var ncells = this.ncells();
if (ncells === 0) {
this.append_cell(cell);
return this;
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 if (index >= 0 && index < ncells) {
this.cell_elements().eq(index).after(cell.element);
};
Brian E. Granger
Added a notebook dirty flag that is used when exiting page.
r4550 this.dirty = true;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 return this
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 Notebook.prototype.insert_cell_above = function (cell, index) {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var ncells = this.ncells();
if (ncells === 0) {
this.append_cell(cell);
return this;
};
if (index >= 0 && index < ncells) {
this.cell_elements().eq(index).before(cell.element);
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292 };
Brian E. Granger
Added a notebook dirty flag that is used when exiting page.
r4550 this.dirty = true;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 return this;
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Notebook.prototype.move_cell_up = function (index) {
var i = index || this.selected_index();
if (i !== null && i < this.ncells() && i > 0) {
var pivot = this.cell_elements().eq(i-1);
var tomove = this.cell_elements().eq(i);
if (pivot !== null && tomove !== null) {
tomove.detach();
pivot.before(tomove);
this.select(i-1);
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292 };
};
Brian E. Granger
Added a notebook dirty flag that is used when exiting page.
r4550 this.dirty = true;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 return this;
}
Notebook.prototype.move_cell_down = function (index) {
var i = index || this.selected_index();
if (i !== null && i < (this.ncells()-1) && i >= 0) {
var pivot = this.cell_elements().eq(i+1)
var tomove = this.cell_elements().eq(i)
if (pivot !== null && tomove !== null) {
tomove.detach();
pivot.after(tomove);
this.select(i+1);
};
};
Brian E. Granger
Added a notebook dirty flag that is used when exiting page.
r4550 this.dirty = true;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 return this;
}
Notebook.prototype.sort_cells = function () {
var ncells = this.ncells();
var sindex = this.selected_index();
var swapped;
do {
swapped = false
for (var i=1; i<ncells; i++) {
current = this.cell_elements().eq(i).data("cell");
previous = this.cell_elements().eq(i-1).data("cell");
if (previous.input_prompt_number > current.input_prompt_number) {
this.move_cell_up(i);
swapped = true;
};
};
} while (swapped);
this.select(sindex);
return this;
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292 };
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 Notebook.prototype.insert_code_cell_above = function (index) {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 // TODO: Bounds check for i
var i = this.index_or_selected(index);
var cell = new IPython.CodeCell(this);
Brian E. Granger
Removing default input prompt number....
r4391 cell.set_input_prompt();
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 this.insert_cell_above(cell, i);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 this.select(this.find_cell_index(cell));
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 return cell;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 }
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 Notebook.prototype.insert_code_cell_below = function (index) {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 // TODO: Bounds check for i
var i = this.index_or_selected(index);
var cell = new IPython.CodeCell(this);
Brian E. Granger
Removing default input prompt number....
r4391 cell.set_input_prompt();
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 this.insert_cell_below(cell, i);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 this.select(this.find_cell_index(cell));
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 return cell;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 }
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
Brian Granger
Initial reply handling implemented along with css fixes.
r4299
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 Notebook.prototype.insert_html_cell_above = function (index) {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 // TODO: Bounds check for i
var i = this.index_or_selected(index);
Brian E. Granger
New HTMl cell working with CodeMirror editing.
r4499 var cell = new IPython.HTMLCell(this);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 cell.config_mathjax();
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 this.insert_cell_above(cell, i);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 this.select(this.find_cell_index(cell));
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 return cell;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 }
Brian Granger
Initial reply handling implemented along with css fixes.
r4299
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 Notebook.prototype.insert_html_cell_below = function (index) {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 // TODO: Bounds check for i
var i = this.index_or_selected(index);
Brian E. Granger
New HTMl cell working with CodeMirror editing.
r4499 var cell = new IPython.HTMLCell(this);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 cell.config_mathjax();
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 this.insert_cell_below(cell, i);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 this.select(this.find_cell_index(cell));
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 return cell;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 }
Brian Granger
Initial reply handling implemented along with css fixes.
r4299
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 Notebook.prototype.insert_markdown_cell_above = function (index) {
Brian E. Granger
Starting work on a Markdown cell.
r4507 // TODO: Bounds check for i
var i = this.index_or_selected(index);
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 var cell = new IPython.MarkdownCell(this);
Brian E. Granger
Starting work on a Markdown cell.
r4507 cell.config_mathjax();
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 this.insert_cell_above(cell, i);
Brian E. Granger
Starting work on a Markdown cell.
r4507 this.select(this.find_cell_index(cell));
return cell;
}
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 Notebook.prototype.insert_markdown_cell_below = function (index) {
Brian E. Granger
Starting work on a Markdown cell.
r4507 // TODO: Bounds check for i
var i = this.index_or_selected(index);
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 var cell = new IPython.MarkdownCell(this);
Brian E. Granger
Starting work on a Markdown cell.
r4507 cell.config_mathjax();
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 this.insert_cell_below(cell, i);
Brian E. Granger
Starting work on a Markdown cell.
r4507 this.select(this.find_cell_index(cell));
return cell;
}
Notebook.prototype.to_code = function (index) {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 // TODO: Bounds check for i
var i = this.index_or_selected(index);
var source_element = this.cell_elements().eq(i);
var source_cell = source_element.data("cell");
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 if (source_cell instanceof IPython.HTMLCell ||
source_cell instanceof IPython.MarkdownCell) {
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 this.insert_code_cell_below(i);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var target_cell = this.cells()[i+1];
Brian E. Granger
New HTMl cell working with CodeMirror editing.
r4499 target_cell.set_code(source_cell.get_source());
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 source_element.remove();
Brian E. Granger
Code cell gets focused after "To Code" is triggered.
r4557 target_cell.select();
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian E. Granger
Added a notebook dirty flag that is used when exiting page.
r4550 this.dirty = true;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian Granger
Initial reply handling implemented along with css fixes.
r4299
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 Notebook.prototype.to_markdown = function (index) {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 // TODO: Bounds check for i
var i = this.index_or_selected(index);
var source_element = this.cell_elements().eq(i);
var source_cell = source_element.data("cell");
Brian E. Granger
Starting work on a Markdown cell.
r4507 var target_cell = null;
if (source_cell instanceof IPython.CodeCell) {
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 this.insert_markdown_cell_below(i);
Brian E. Granger
Starting work on a Markdown cell.
r4507 var target_cell = this.cells()[i+1];
var text = source_cell.get_code();
} else if (source_cell instanceof IPython.HTMLCell) {
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 this.insert_markdown_cell_below(i);
Brian E. Granger
Starting work on a Markdown cell.
r4507 var target_cell = this.cells()[i+1];
var text = source_cell.get_source();
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 if (text === source_cell.placeholder) {
text = target_cell.placeholder;
}
Brian E. Granger
Starting work on a Markdown cell.
r4507 }
if (target_cell !== null) {
if (text === "") {text = target_cell.placeholder;};
target_cell.set_source(text);
source_element.remove();
target_cell.edit();
}
Brian E. Granger
Added a notebook dirty flag that is used when exiting page.
r4550 this.dirty = true;
Brian E. Granger
Starting work on a Markdown cell.
r4507 };
Notebook.prototype.to_html = function (index) {
// TODO: Bounds check for i
var i = this.index_or_selected(index);
var source_element = this.cell_elements().eq(i);
var source_cell = source_element.data("cell");
var target_cell = null;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 if (source_cell instanceof IPython.CodeCell) {
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 this.insert_html_cell_below(i);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 var target_cell = this.cells()[i+1];
var text = source_cell.get_code();
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 } else if (source_cell instanceof IPython.MarkdownCell) {
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 this.insert_html_cell_below(i);
Brian E. Granger
Starting work on a Markdown cell.
r4507 var target_cell = this.cells()[i+1];
var text = source_cell.get_source();
Brian Granger
Refactoring of text/markdown/rst/html cells.
r4508 if (text === source_cell.placeholder) {
text = target_cell.placeholder;
}
Brian E. Granger
Starting work on a Markdown cell.
r4507 }
if (target_cell !== null) {
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 if (text === "") {text = target_cell.placeholder;};
Brian E. Granger
New HTMl cell working with CodeMirror editing.
r4499 target_cell.set_source(text);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 source_element.remove();
target_cell.edit();
Brian E. Granger
Starting work on a Markdown cell.
r4507 }
Brian E. Granger
Added a notebook dirty flag that is used when exiting page.
r4550 this.dirty = true;
Brian Granger
Initial reply handling implemented along with css fixes.
r4299 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Brian E. Granger
Clear all output is implemented.
r4543 // Cell collapsing and output clearing
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Notebook.prototype.collapse = function (index) {
var i = this.index_or_selected(index);
this.cells()[i].collapse();
Brian E. Granger
Added a notebook dirty flag that is used when exiting page.
r4550 this.dirty = true;
Brian Granger
Initial reply handling implemented along with css fixes.
r4299 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Notebook.prototype.expand = function (index) {
var i = this.index_or_selected(index);
this.cells()[i].expand();
Brian E. Granger
Added a notebook dirty flag that is used when exiting page.
r4550 this.dirty = true;
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian Granger
Basic notebook saving and loading....
r4315
Brian E. Granger
Cell collapse/expand is not called "Toggle".
r4639 Notebook.prototype.toggle_output = function (index) {
var i = this.index_or_selected(index);
this.cells()[i].toggle_output();
this.dirty = true;
};
Brian E. Granger
Implemented smart autoindenting.
r4512 Notebook.prototype.set_autoindent = function (state) {
var cells = this.cells();
len = cells.length;
for (var i=0; i<len; i++) {
cells[i].set_autoindent(state)
};
};
Brian E. Granger
Clear all output is implemented.
r4543
Notebook.prototype.clear_all_output = function () {
var ncells = this.ncells();
var cells = this.cells();
for (var i=0; i<ncells; i++) {
if (cells[i] instanceof IPython.CodeCell) {
MinRK
add channel-selection to clear_output...
r5085 cells[i].clear_output(true,true,true);
Brian E. Granger
Clear all output is implemented.
r4543 }
};
Brian E. Granger
Added a notebook dirty flag that is used when exiting page.
r4550 this.dirty = true;
Brian E. Granger
Clear all output is implemented.
r4543 };
Fernando Perez
Refactor line num. toggle into proper function, access via C-m-l....
r5020 // Other cell functions: line numbers, ...
Notebook.prototype.cell_toggle_line_numbers = function() {
Fernando Perez
Clean up accidentally introduced hard tabs in JS code.
r5025 this.selected_cell().toggle_line_numbers()
Fernando Perez
Refactor line num. toggle into proper function, access via C-m-l....
r5020 };
Brian E. Granger
Clear all output is implemented.
r4543
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 // Kernel related things
Brian Granger
Basic notebook saving and loading....
r4315
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 Notebook.prototype.start_kernel = function () {
this.kernel = new IPython.Kernel();
Brian E. Granger
Adding kernel/notebook associations.
r4494 var notebook_id = IPython.save_widget.get_notebook_id();
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 this.kernel.start(notebook_id, $.proxy(this.kernel_started, this));
};
Notebook.prototype.restart_kernel = function () {
Fernando Perez
Clean up accidentally introduced hard tabs in JS code.
r5025 var that = this;
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 var notebook_id = IPython.save_widget.get_notebook_id();
Fernando Perez
Add confirmation dialog to kernel restart action.
r5021
var dialog = $('<div/>');
dialog.html('Do you want to restart the current kernel? You will lose all variables defined in it.');
$(document).append(dialog);
dialog.dialog({
resizable: false,
modal: true,
title: "Restart kernel or continue running?",
buttons : {
"Restart": function () {
Fernando Perez
Clean up accidentally introduced hard tabs in JS code.
r5025 that.kernel.restart($.proxy(that.kernel_started, that));
Fernando Perez
Add confirmation dialog to kernel restart action.
r5021 $(this).dialog('close');
},
"Continue running": function () {
$(this).dialog('close');
}
}
});
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 };
Notebook.prototype.kernel_started = function () {
console.log("Kernel started: ", this.kernel.kernel_id);
this.kernel.shell_channel.onmessage = $.proxy(this.handle_shell_reply,this);
this.kernel.iopub_channel.onmessage = $.proxy(this.handle_iopub_reply,this);
Brian Granger
Basic notebook saving and loading....
r4315 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Brian E. Granger
Using $.proxy to clean up callbacks.
r4353 Notebook.prototype.handle_shell_reply = function (e) {
reply = $.parseJSON(e.data);
Brian E. Granger
Initial payload handling....
r4356 var header = reply.header;
var content = reply.content;
var msg_type = header.msg_type;
Brian E. Granger
Initial draft of panel section and the cell section working.
r4365 // console.log(reply);
Brian E. Granger
Using $.proxy to clean up callbacks.
r4353 var cell = this.cell_for_msg(reply.parent_header.msg_id);
if (msg_type === "execute_reply") {
Brian E. Granger
Initial payload handling....
r4356 cell.set_input_prompt(content.execution_count);
Brian E. Granger
Added a notebook dirty flag that is used when exiting page.
r4550 this.dirty = true;
Brian Granger
Added complete method of JS kernel object.
r4388 } else if (msg_type === "complete_reply") {
Brian E. Granger
Autocompletion working with CTRL-SPACE.
r4389 cell.finish_completing(content.matched_text, content.matches);
Brian E. Granger
Using $.proxy to clean up callbacks.
r4353 };
Brian E. Granger
Initial payload handling....
r4356 var payload = content.payload || [];
Brian E. Granger
%loadpy works in the notebook and bug with inline plotting fixed.
r4530 this.handle_payload(cell, payload);
Brian E. Granger
Using $.proxy to clean up callbacks.
r4353 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Brian E. Granger
%loadpy works in the notebook and bug with inline plotting fixed.
r4530 Notebook.prototype.handle_payload = function (cell, payload) {
Brian E. Granger
Initial payload handling....
r4356 var l = payload.length;
for (var i=0; i<l; i++) {
Brian E. Granger
%loadpy works in the notebook and bug with inline plotting fixed.
r4530 if (payload[i].source === 'IPython.zmq.page.page') {
Brian E. Granger
Pager is not activated if the pager text is empty....
r4560 if (payload[i].text.trim() !== '') {
IPython.pager.clear();
IPython.pager.expand();
IPython.pager.append_text(payload[i].text);
}
Brian E. Granger
%loadpy works in the notebook and bug with inline plotting fixed.
r4530 } else if (payload[i].source === 'IPython.zmq.zmqshell.ZMQInteractiveShell.set_next_input') {
var index = this.find_cell_index(cell);
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 var new_cell = this.insert_code_cell_below(index);
Brian E. Granger
%loadpy works in the notebook and bug with inline plotting fixed.
r4530 new_cell.set_code(payload[i].text);
Brian E. Granger
Added a notebook dirty flag that is used when exiting page.
r4550 this.dirty = true;
Brian E. Granger
%loadpy works in the notebook and bug with inline plotting fixed.
r4530 }
Brian E. Granger
Initial payload handling....
r4356 };
};
Brian E. Granger
Refactoring pager into its own class.
r4357
Brian E. Granger
Using $.proxy to clean up callbacks.
r4353 Notebook.prototype.handle_iopub_reply = function (e) {
reply = $.parseJSON(e.data);
var content = reply.content;
// console.log(reply);
var msg_type = reply.header.msg_type;
var cell = this.cell_for_msg(reply.parent_header.msg_id);
Brian E. Granger
Added saving and loading of output of all types.
r4497 var output_types = ['stream','display_data','pyout','pyerr'];
if (output_types.indexOf(msg_type) >= 0) {
this.handle_output(cell, msg_type, content);
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 } else if (msg_type === 'status') {
if (content.execution_state === 'busy') {
Brian E. Granger
Work on save widget, kernel status widget and notebook section.
r4372 IPython.kernel_status_widget.status_busy();
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 } else if (content.execution_state === 'idle') {
Brian E. Granger
Work on save widget, kernel status widget and notebook section.
r4372 IPython.kernel_status_widget.status_idle();
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 } else if (content.execution_state === 'dead') {
this.handle_status_dead();
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian Granger
Adding clear_output to kernel and HTML notebook.
r5080 } else if (msg_type === 'clear_output') {
MinRK
add channel-selection to clear_output...
r5085 cell.clear_output(content.stdout, content.stderr, content.other);
Brian Granger
Adding clear_output to kernel and HTML notebook.
r5080 };
Brian E. Granger
Using $.proxy to clean up callbacks.
r4353 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Brian E. Granger
Using $.proxy to clean up callbacks.
r4353
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 Notebook.prototype.handle_status_dead = function () {
var that = this;
this.kernel.stop_channels();
var dialog = $('<div/>');
dialog.html('The kernel has died, would you like to restart it? If you do not restart the kernel, you will be able to save the notebook, but running code will not work until the notebook is reopened.');
$(document).append(dialog);
dialog.dialog({
resizable: false,
modal: true,
title: "Dead kernel",
buttons : {
Fernando Perez
Change button labels in restart dialog to action words.
r5022 "Restart": function () {
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 that.start_kernel();
$(this).dialog('close');
},
Fernando Perez
Change button labels in restart dialog to action words.
r5022 "Continue running": function () {
Brian E. Granger
Major refactor of kernel connection management in the notebook....
r4545 $(this).dialog('close');
}
}
});
};
Brian E. Granger
Added saving and loading of output of all types.
r4497 Notebook.prototype.handle_output = function (cell, msg_type, content) {
var json = {};
json.output_type = msg_type;
if (msg_type === "stream") {
MinRK
support contiguous stream output in notebook...
r4864 json.text = utils.fixConsole(content.data);
json.stream = content.name;
Brian E. Granger
Added saving and loading of output of all types.
r4497 } else if (msg_type === "display_data") {
json = this.convert_mime_types(json, content.data);
} else if (msg_type === "pyout") {
json.prompt_number = content.execution_count;
json = this.convert_mime_types(json, content.data);
} else if (msg_type === "pyerr") {
json.ename = content.ename;
json.evalue = content.evalue;
Brian E. Granger
Adding tracebacks, evalue and etype to the nbformat and notebook.
r4540 var traceback = [];
for (var i=0; i<content.traceback.length; i++) {
traceback.push(utils.fixConsole(content.traceback[i]));
}
json.traceback = traceback;
Brian E. Granger
Added saving and loading of output of all types.
r4497 };
cell.append_output(json);
Brian E. Granger
Added a notebook dirty flag that is used when exiting page.
r4550 this.dirty = true;
Brian E. Granger
Added saving and loading of output of all types.
r4497 };
Notebook.prototype.convert_mime_types = function (json, data) {
if (data['text/plain'] !== undefined) {
Brian E. Granger
Adding tracebacks, evalue and etype to the nbformat and notebook.
r4540 json.text = utils.fixConsole(data['text/plain']);
Brian E. Granger
Added saving and loading of output of all types.
r4497 };
if (data['text/html'] !== undefined) {
json.html = data['text/html'];
};
if (data['image/svg+xml'] !== undefined) {
json.svg = data['image/svg+xml'];
};
if (data['image/png'] !== undefined) {
json.png = data['image/png'];
};
Brian E. Granger
Finishing display system work....
r4528 if (data['image/jpeg'] !== undefined) {
json.jpeg = data['image/jpeg'];
};
Brian E. Granger
Added saving and loading of output of all types.
r4497 if (data['text/latex'] !== undefined) {
json.latex = data['text/latex'];
};
if (data['application/json'] !== undefined) {
json.json = data['application/json'];
};
if (data['application/javascript'] !== undefined) {
json.javascript = data['application/javascript'];
}
return json;
};
Brian Granger
Basic notebook saving and loading....
r4315
Brian E. Granger
Fixes to terminal mode execution (ctrl-enter).
r4394 Notebook.prototype.execute_selected_cell = function (options) {
// add_new: should a new cell be added if we are at the end of the nb
// terminal: execute in terminal mode, which stays in the current cell
default_options = {terminal: false, add_new: true}
$.extend(default_options, options)
Brian E. Granger
Fixing execution related things....
r4378 var that = this;
var cell = that.selected_cell();
var cell_index = that.find_cell_index(cell);
if (cell instanceof IPython.CodeCell) {
MinRK
add channel-selection to clear_output...
r5085 cell.clear_output(true, true, true);
MinRK
set 'In [*]' to indicate pending code cell
r5220 cell.set_input_prompt('*');
Brian E. Granger
Fixing execution related things....
r4378 var code = cell.get_code();
Brian E. Granger
Massive work on the notebook document format....
r4484 var msg_id = that.kernel.execute(cell.get_code());
that.msg_cell_map[msg_id] = cell.cell_id;
Brian E. Granger
New HTMl cell working with CodeMirror editing.
r4499 } else if (cell instanceof IPython.HTMLCell) {
Brian E. Granger
Fixing execution related things....
r4378 cell.render();
}
Brian E. Granger
Fixes to terminal mode execution (ctrl-enter).
r4394 if (default_options.terminal) {
Brian E. Granger
Ctrl-Enter now does not delete input, but selects it.
r4675 cell.select_all();
Brian E. Granger
Fixing execution related things....
r4378 } else {
Brian E. Granger
Fixes to terminal mode execution (ctrl-enter).
r4394 if ((cell_index === (that.ncells()-1)) && default_options.add_new) {
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 that.insert_code_cell_below();
Brian E. Granger
Fixes to terminal mode execution (ctrl-enter).
r4394 // If we are adding a new cell at the end, scroll down to show it.
that.scroll_to_bottom();
} else {
that.select(cell_index+1);
};
Brian E. Granger
Fixing execution related things....
r4378 };
Brian E. Granger
Added a notebook dirty flag that is used when exiting page.
r4550 this.dirty = true;
Brian E. Granger
Fixing execution related things....
r4378 };
Notebook.prototype.execute_all_cells = function () {
var ncells = this.ncells();
for (var i=0; i<ncells; i++) {
this.select(i);
Brian E. Granger
Fixes to terminal mode execution (ctrl-enter).
r4394 this.execute_selected_cell({add_new:false});
Brian E. Granger
Fixing execution related things....
r4378 };
this.scroll_to_bottom();
};
Brian E. Granger
Autocompletion working with CTRL-SPACE.
r4389
Notebook.prototype.complete_cell = function (cell, line, cursor_pos) {
var msg_id = this.kernel.complete(line, cursor_pos);
this.msg_cell_map[msg_id] = cell.cell_id;
};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 // Persistance and loading
Notebook.prototype.fromJSON = function (data) {
var ncells = this.ncells();
for (var i=0; i<ncells; i++) {
// Always delete cell 0 as they get renumbered as they are deleted.
this.delete_cell(0);
};
Brian E. Granger
Implemented metadata for notebook format.
r4637 // Save the metadata
this.metadata = data.metadata;
Brian E. Granger
Massive work on the notebook document format....
r4484 // Only handle 1 worksheet for now.
var worksheet = data.worksheets[0];
if (worksheet !== undefined) {
var new_cells = worksheet.cells;
ncells = new_cells.length;
var cell_data = null;
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 var new_cell = null;
Brian E. Granger
Massive work on the notebook document format....
r4484 for (var i=0; i<ncells; i++) {
cell_data = new_cells[i];
if (cell_data.cell_type == 'code') {
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 new_cell = this.insert_code_cell_below();
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 new_cell.fromJSON(cell_data);
Brian E. Granger
New HTMl cell working with CodeMirror editing.
r4499 } else if (cell_data.cell_type === 'html') {
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 new_cell = this.insert_html_cell_below();
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 new_cell.fromJSON(cell_data);
Brian E. Granger
Markdown cells are now saved and restored in notebooks.
r4511 } else if (cell_data.cell_type === 'markdown') {
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 new_cell = this.insert_markdown_cell_below();
Brian E. Granger
Markdown cells are now saved and restored in notebooks.
r4511 new_cell.fromJSON(cell_data);
Brian E. Granger
Massive work on the notebook document format....
r4484 };
};
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian Granger
Basic notebook saving and loading....
r4315 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Notebook.prototype.toJSON = function () {
var cells = this.cells();
var ncells = cells.length;
cell_array = new Array(ncells);
for (var i=0; i<ncells; i++) {
cell_array[i] = cells[i].toJSON();
};
Brian E. Granger
Massive work on the notebook document format....
r4484 data = {
// Only handle 1 worksheet for now.
Brian E. Granger
Implemented metadata for notebook format.
r4637 worksheets : [{cells:cell_array}],
metadata : this.metadata
Brian E. Granger
Massive work on the notebook document format....
r4484 }
return data
};
Notebook.prototype.save_notebook = function () {
if (IPython.save_widget.test_notebook_name()) {
var notebook_id = IPython.save_widget.get_notebook_id();
var nbname = IPython.save_widget.get_notebook_name();
// We may want to move the name/id/nbformat logic inside toJSON?
var data = this.toJSON();
Brian E. Granger
Implemented metadata for notebook format.
r4637 data.metadata.name = nbname;
Brian E. Granger
Massive work on the notebook document format....
r4484 data.nbformat = 2;
// We do the call with settings so we can set cache to false.
var settings = {
Brian E. Granger
Improvements to file uploaded, mime types and .py reader....
r4493 processData : false,
cache : false,
type : "PUT",
data : JSON.stringify(data),
headers : {'Content-Type': 'application/json'},
Felix Werner
Notify the user of errors when saving a notebook.
r5007 success : $.proxy(this.notebook_saved,this),
error : $.proxy(this.notebook_save_failed,this)
Brian E. Granger
Massive work on the notebook document format....
r4484 };
IPython.save_widget.status_saving();
Brian E. Granger
Updating JS URL scheme to use embedded data....
r5106 var url = $('body').data('baseProjectUrl') + 'notebooks/' + notebook_id
$.ajax(url, settings);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian Granger
Basic notebook saving and loading....
r4315 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Brian E. Granger
Massive work on the notebook document format....
r4484 Notebook.prototype.notebook_saved = function (data, status, xhr) {
Brian E. Granger
Added a notebook dirty flag that is used when exiting page.
r4550 this.dirty = false;
Felix Werner
Update document title and last_saved_name only after a successful save.
r5006 IPython.save_widget.notebook_saved();
Brian E. Granger
Removed save widget delay.
r5113 IPython.save_widget.status_save();
Brian E. Granger
Massive work on the notebook document format....
r4484 }
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352
Felix Werner
Notify the user of errors when saving a notebook.
r5007 Notebook.prototype.notebook_save_failed = function (xhr, status, error_msg) {
// Notify the user and reset the save button
// TODO: Handle different types of errors (timeout etc.)
alert('An unexpected error occured while saving the notebook.');
Brian E. Granger
Removed save widget delay.
r5113 IPython.save_widget.reset_status();
Felix Werner
Notify the user of errors when saving a notebook.
r5007 }
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 Notebook.prototype.load_notebook = function (callback) {
var that = this;
Brian E. Granger
Massive work on the notebook document format....
r4484 var notebook_id = IPython.save_widget.get_notebook_id();
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 // We do the call with settings so we can set cache to false.
var settings = {
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 processData : false,
cache : false,
type : "GET",
dataType : "json",
success : function (data, status, xhr) {
that.notebook_loaded(data, status, xhr);
if (callback !== undefined) {
callback();
};
}
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 };
Brian E. Granger
Massive work on the notebook document format....
r4484 IPython.save_widget.status_loading();
Brian E. Granger
Updating JS URL scheme to use embedded data....
r5106 var url = $('body').data('baseProjectUrl') + 'notebooks/' + notebook_id
$.ajax(url, settings);
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 }
Brian E. Granger
Massive work on the notebook document format....
r4484
Notebook.prototype.notebook_loaded = function (data, status, xhr) {
MinRK
add read-only view for notebooks...
r5200 var allowed = xhr.getResponseHeader('Allow');
Brian E. Granger
Massive work on the notebook document format....
r4484 this.fromJSON(data);
if (this.ncells() === 0) {
Fernando Perez
Fix above/below keybinding mismatch and rename api to use above/below
r4659 this.insert_code_cell_below();
Brian E. Granger
Massive work on the notebook document format....
r4484 };
IPython.save_widget.status_save();
Brian E. Granger
Implemented metadata for notebook format.
r4637 IPython.save_widget.set_notebook_name(data.metadata.name);
Brian E. Granger
Added a notebook dirty flag that is used when exiting page.
r4550 this.dirty = false;
MinRK
move read_only flag to page-level...
r5213 if (! this.read_only) {
MinRK
add read-only view for notebooks...
r5200 this.start_kernel();
}
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 // fromJSON always selects the last cell inserted. We need to wait
// until that is done before scrolling to the top.
setTimeout(function () {
IPython.notebook.select(0);
IPython.notebook.scroll_to_top();
}, 50);
Brian E. Granger
Massive work on the notebook document format....
r4484 };
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 IPython.Notebook = Notebook;
Brian E. Granger
Further work updating JS URL scheme to use data-base-project-url.
r5108
Brian E. Granger
Implemented module and namespace pattern in js notebook.
r4352 return IPython;
}(IPython));
Brian Granger
Basic notebook saving and loading....
r4315