setting the notebook dirty flag is now an event

set_dirty.Notebook
MinRK 13 years ago
parent 91c82dcfae
commit 04726d2563

@ -258,7 +258,7 @@ var IPython = (function (IPython) {
CodeCell.prototype._handle_execute_reply = function (content) { CodeCell.prototype._handle_execute_reply = function (content) {
this.set_input_prompt(content.execution_count); this.set_input_prompt(content.execution_count);
this.element.removeClass("running"); this.element.removeClass("running");
$([IPython.events]).trigger('set_dirty.Notebook', {'value': true}); $([IPython.events]).trigger('set_dirty.Notebook', {value: true});
} }
/** /**

@ -37,7 +37,7 @@ var IPython = (function (IPython) {
this.undelete_index = null; this.undelete_index = null;
this.undelete_below = false; this.undelete_below = false;
this.paste_enabled = false; this.paste_enabled = false;
this.dirty = false; this.set_dirty(false);
this.metadata = {}; this.metadata = {};
this._checkpoint_after_save = false; this._checkpoint_after_save = false;
this.last_checkpoint = null; this.last_checkpoint = null;
@ -308,10 +308,13 @@ var IPython = (function (IPython) {
} else if (that.control_key_active) { } else if (that.control_key_active) {
that.control_key_active = false; that.control_key_active = false;
return true; return true;
}; } else if ( utils.is_typing(event) ) {
that.set_dirty(true);
return true;
}
return true; return true;
}); });
var collapse_time = function(time){ var collapse_time = function(time){
var app_height = $('#ipython-main-app').height(); // content height var app_height = $('#ipython-main-app').height(); // content height
var splitter_height = $('div#pager_splitter').outerHeight(true); var splitter_height = $('div#pager_splitter').outerHeight(true);
@ -353,6 +356,21 @@ var IPython = (function (IPython) {
}); });
}; };
/**
* Set the dirty flag, and trigger the set_dirty.Notebook event
*
* @method set_dirty
*/
Notebook.prototype.set_dirty = function (value) {
if (value === undefined) {
value = true;
}
if (this.dirty == value) {
return;
}
$([IPython.events]).trigger('set_dirty.Notebook', {value: value});
};
/** /**
* Scroll the top of the page to a given cell. * Scroll the top of the page to a given cell.
* *
@ -645,7 +663,7 @@ var IPython = (function (IPython) {
pivot.before(tomove); pivot.before(tomove);
this.select(i-1); this.select(i-1);
}; };
this.dirty = true; this.set_dirty(true);
}; };
return this; return this;
}; };
@ -669,7 +687,7 @@ var IPython = (function (IPython) {
this.select(i+1); this.select(i+1);
}; };
}; };
this.dirty = true; this.set_dirty();
return this; return this;
}; };
@ -700,7 +718,7 @@ var IPython = (function (IPython) {
this.undelete_index = i; this.undelete_index = i;
this.undelete_below = false; this.undelete_below = false;
}; };
this.dirty = true; this.set_dirty(true);
}; };
return this; return this;
}; };
@ -740,7 +758,7 @@ var IPython = (function (IPython) {
if(this._insert_element_at_index(cell.element,index)){ if(this._insert_element_at_index(cell.element,index)){
cell.render(); cell.render();
this.select(this.find_cell_index(cell)); this.select(this.find_cell_index(cell));
this.dirty = true; this.set_dirty(true);
} }
} }
return cell; return cell;
@ -779,7 +797,7 @@ var IPython = (function (IPython) {
if (this.undelete_index !== null && index <= this.undelete_index) { if (this.undelete_index !== null && index <= this.undelete_index) {
this.undelete_index = this.undelete_index + 1; this.undelete_index = this.undelete_index + 1;
this.dirty = true; this.set_dirty(true);
} }
return true; return true;
}; };
@ -855,7 +873,7 @@ var IPython = (function (IPython) {
// to this state, instead of a blank cell // to this state, instead of a blank cell
target_cell.code_mirror.clearHistory(); target_cell.code_mirror.clearHistory();
source_element.remove(); source_element.remove();
this.dirty = true; this.set_dirty(true);
}; };
}; };
}; };
@ -884,7 +902,7 @@ var IPython = (function (IPython) {
// to this state, instead of a blank cell // to this state, instead of a blank cell
target_cell.code_mirror.clearHistory(); target_cell.code_mirror.clearHistory();
source_element.remove(); source_element.remove();
this.dirty = true; this.set_dirty(true);
}; };
}; };
}; };
@ -914,7 +932,7 @@ var IPython = (function (IPython) {
// to this state, instead of a blank cell // to this state, instead of a blank cell
target_cell.code_mirror.clearHistory(); target_cell.code_mirror.clearHistory();
source_element.remove(); source_element.remove();
this.dirty = true; this.set_dirty(true);
}; };
}; };
}; };
@ -949,7 +967,7 @@ var IPython = (function (IPython) {
// to this state, instead of a blank cell // to this state, instead of a blank cell
target_cell.code_mirror.clearHistory(); target_cell.code_mirror.clearHistory();
source_element.remove(); source_element.remove();
this.dirty = true; this.set_dirty(true);
}; };
$([IPython.events]).trigger('selected_cell_type_changed.Notebook', $([IPython.events]).trigger('selected_cell_type_changed.Notebook',
{'cell_type':'heading',level:level} {'cell_type':'heading',level:level}
@ -1177,7 +1195,7 @@ var IPython = (function (IPython) {
Notebook.prototype.collapse = function (index) { Notebook.prototype.collapse = function (index) {
var i = this.index_or_selected(index); var i = this.index_or_selected(index);
this.get_cell(i).collapse(); this.get_cell(i).collapse();
this.dirty = true; this.set_dirty(true);
}; };
/** /**
@ -1189,7 +1207,7 @@ var IPython = (function (IPython) {
Notebook.prototype.expand = function (index) { Notebook.prototype.expand = function (index) {
var i = this.index_or_selected(index); var i = this.index_or_selected(index);
this.get_cell(i).expand(); this.get_cell(i).expand();
this.dirty = true; this.set_dirty(true);
}; };
/** Toggle whether a cell's output is collapsed or expanded. /** Toggle whether a cell's output is collapsed or expanded.
@ -1200,7 +1218,7 @@ var IPython = (function (IPython) {
Notebook.prototype.toggle_output = function (index) { Notebook.prototype.toggle_output = function (index) {
var i = this.index_or_selected(index); var i = this.index_or_selected(index);
this.get_cell(i).toggle_output(); this.get_cell(i).toggle_output();
this.dirty = true; this.set_dirty(true);
}; };
/** /**
@ -1228,7 +1246,7 @@ var IPython = (function (IPython) {
} }
}; };
// this should not be set if the `collapse` key is removed from nbformat // this should not be set if the `collapse` key is removed from nbformat
this.dirty = true; this.set_dirty(true);
}; };
/** /**
@ -1246,7 +1264,7 @@ var IPython = (function (IPython) {
} }
}; };
// this should not be set if the `collapse` key is removed from nbformat // this should not be set if the `collapse` key is removed from nbformat
this.dirty = true; this.set_dirty(true);
}; };
/** /**
@ -1264,7 +1282,7 @@ var IPython = (function (IPython) {
} }
}; };
// this should not be set if the `collapse` key is removed from nbformat // this should not be set if the `collapse` key is removed from nbformat
this.dirty = true; this.set_dirty(true);
}; };
/** /**
@ -1283,7 +1301,7 @@ var IPython = (function (IPython) {
cells[i].set_input_prompt(); cells[i].set_input_prompt();
} }
}; };
this.dirty = true; this.set_dirty(true);
}; };
@ -1376,7 +1394,7 @@ var IPython = (function (IPython) {
that.select(cell_index+1); that.select(cell_index+1);
}; };
}; };
this.dirty = true; this.set_dirty(true);
}; };
/** /**
@ -1624,7 +1642,7 @@ var IPython = (function (IPython) {
* @param {jqXHR} xhr jQuery Ajax object * @param {jqXHR} xhr jQuery Ajax object
*/ */
Notebook.prototype.save_notebook_success = function (start, data, status, xhr) { Notebook.prototype.save_notebook_success = function (start, data, status, xhr) {
this.dirty = false; this.set_dirty(false);
$([IPython.events]).trigger('notebook_saved.Notebook'); $([IPython.events]).trigger('notebook_saved.Notebook');
this._update_autosave_interval(start); this._update_autosave_interval(start);
if (this._checkpoint_after_save) { if (this._checkpoint_after_save) {
@ -1703,7 +1721,7 @@ var IPython = (function (IPython) {
if (this.ncells() === 0) { if (this.ncells() === 0) {
this.insert_cell_below('code'); this.insert_cell_below('code');
}; };
this.dirty = false; this.set_dirty(false);
this.select(0); this.select(0);
this.scroll_to_top(); this.scroll_to_top();
if (data.orig_nbformat !== undefined && data.nbformat !== data.orig_nbformat) { if (data.orig_nbformat !== undefined && data.nbformat !== data.orig_nbformat) {

Loading…
Cancel
Save