Merge pull request #3371 from minrk/dirty-event

make setting the notebook dirty flag an event
Matthias Bussonnier 13 years ago
commit 3d57f9b0a0

@ -225,8 +225,8 @@ IPython.utils = (function (IPython) {
"$1<a target=\"_blank\" href=\"$2$3\">$2$3</a>");
}
// some keycodes that seem to be platform/browser independant
var keycodes ={
// some keycodes that seem to be platform/browser independent
var keycodes = {
BACKSPACE: 8,
TAB : 9,
ENTER : 13,
@ -253,7 +253,10 @@ IPython.utils = (function (IPython) {
DOWN_ARROW: 40,
DOWNARROW: 40,
DOWN : 40,
COMMAND : 91,
// all three of these keys may be COMMAND on OS X:
LEFT_SUPER : 91,
RIGHT_SUPER : 92,
COMMAND : 93,
};

@ -97,6 +97,11 @@ var IPython = (function (IPython) {
$([IPython.events]).trigger('select.Cell', {'cell':that});
}
});
if (this.code_mirror) {
this.code_mirror.on("change", function(cm, change) {
$([IPython.events]).trigger("set_dirty.Notebook", {value: true});
});
}
};
/**

@ -258,7 +258,7 @@ var IPython = (function (IPython) {
CodeCell.prototype._handle_execute_reply = function (content) {
this.set_input_prompt(content.execution_count);
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_below = false;
this.paste_enabled = false;
this.dirty = false;
this.set_dirty(false);
this.metadata = {};
this._checkpoint_after_save = false;
this.last_checkpoint = null;
@ -308,10 +308,10 @@ var IPython = (function (IPython) {
} else if (that.control_key_active) {
that.control_key_active = false;
return true;
};
}
return true;
});
var collapse_time = function(time){
var app_height = $('#ipython-main-app').height(); // content height
var splitter_height = $('div#pager_splitter').outerHeight(true);
@ -353,6 +353,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.
*
@ -645,7 +660,7 @@ var IPython = (function (IPython) {
pivot.before(tomove);
this.select(i-1);
};
this.dirty = true;
this.set_dirty(true);
};
return this;
};
@ -669,7 +684,7 @@ var IPython = (function (IPython) {
this.select(i+1);
};
};
this.dirty = true;
this.set_dirty();
return this;
};
@ -700,7 +715,7 @@ var IPython = (function (IPython) {
this.undelete_index = i;
this.undelete_below = false;
};
this.dirty = true;
this.set_dirty(true);
};
return this;
};
@ -740,7 +755,7 @@ var IPython = (function (IPython) {
if(this._insert_element_at_index(cell.element,index)){
cell.render();
this.select(this.find_cell_index(cell));
this.dirty = true;
this.set_dirty(true);
}
}
return cell;
@ -779,7 +794,7 @@ var IPython = (function (IPython) {
if (this.undelete_index !== null && index <= this.undelete_index) {
this.undelete_index = this.undelete_index + 1;
this.dirty = true;
this.set_dirty(true);
}
return true;
};
@ -855,7 +870,7 @@ var IPython = (function (IPython) {
// to this state, instead of a blank cell
target_cell.code_mirror.clearHistory();
source_element.remove();
this.dirty = true;
this.set_dirty(true);
};
};
};
@ -884,7 +899,7 @@ var IPython = (function (IPython) {
// to this state, instead of a blank cell
target_cell.code_mirror.clearHistory();
source_element.remove();
this.dirty = true;
this.set_dirty(true);
};
};
};
@ -914,7 +929,7 @@ var IPython = (function (IPython) {
// to this state, instead of a blank cell
target_cell.code_mirror.clearHistory();
source_element.remove();
this.dirty = true;
this.set_dirty(true);
};
};
};
@ -949,7 +964,7 @@ var IPython = (function (IPython) {
// to this state, instead of a blank cell
target_cell.code_mirror.clearHistory();
source_element.remove();
this.dirty = true;
this.set_dirty(true);
};
$([IPython.events]).trigger('selected_cell_type_changed.Notebook',
{'cell_type':'heading',level:level}
@ -1177,7 +1192,7 @@ var IPython = (function (IPython) {
Notebook.prototype.collapse = function (index) {
var i = this.index_or_selected(index);
this.get_cell(i).collapse();
this.dirty = true;
this.set_dirty(true);
};
/**
@ -1189,7 +1204,7 @@ var IPython = (function (IPython) {
Notebook.prototype.expand = function (index) {
var i = this.index_or_selected(index);
this.get_cell(i).expand();
this.dirty = true;
this.set_dirty(true);
};
/** Toggle whether a cell's output is collapsed or expanded.
@ -1200,7 +1215,7 @@ var IPython = (function (IPython) {
Notebook.prototype.toggle_output = function (index) {
var i = this.index_or_selected(index);
this.get_cell(i).toggle_output();
this.dirty = true;
this.set_dirty(true);
};
/**
@ -1228,7 +1243,7 @@ var IPython = (function (IPython) {
}
};
// this should not be set if the `collapse` key is removed from nbformat
this.dirty = true;
this.set_dirty(true);
};
/**
@ -1246,7 +1261,7 @@ var IPython = (function (IPython) {
}
};
// this should not be set if the `collapse` key is removed from nbformat
this.dirty = true;
this.set_dirty(true);
};
/**
@ -1264,7 +1279,7 @@ var IPython = (function (IPython) {
}
};
// this should not be set if the `collapse` key is removed from nbformat
this.dirty = true;
this.set_dirty(true);
};
/**
@ -1283,7 +1298,7 @@ var IPython = (function (IPython) {
cells[i].set_input_prompt();
}
};
this.dirty = true;
this.set_dirty(true);
};
@ -1376,7 +1391,7 @@ var IPython = (function (IPython) {
that.select(cell_index+1);
};
};
this.dirty = true;
this.set_dirty(true);
};
/**
@ -1624,7 +1639,7 @@ var IPython = (function (IPython) {
* @param {jqXHR} xhr jQuery Ajax object
*/
Notebook.prototype.save_notebook_success = function (start, data, status, xhr) {
this.dirty = false;
this.set_dirty(false);
$([IPython.events]).trigger('notebook_saved.Notebook');
this._update_autosave_interval(start);
if (this._checkpoint_after_save) {
@ -1703,7 +1718,7 @@ var IPython = (function (IPython) {
if (this.ncells() === 0) {
this.insert_cell_below('code');
};
this.dirty = false;
this.set_dirty(false);
this.select(0);
this.scroll_to_top();
if (data.orig_nbformat !== undefined && data.nbformat !== data.orig_nbformat) {

@ -44,17 +44,15 @@ var IPython = (function (IPython) {
$(this).removeClass("ui-state-hover");
});
$([IPython.events]).on('notebook_loaded.Notebook', function () {
that.set_last_saved();
that.update_notebook_name();
that.update_document_title();
});
$([IPython.events]).on('notebook_saved.Notebook', function () {
that.set_last_saved();
that.update_notebook_name();
that.update_document_title();
});
$([IPython.events]).on('notebook_save_failed.Notebook', function () {
that.set_save_status('Last Save Failed!');
that.set_save_status('Autosave Failed!');
});
$([IPython.events]).on('checkpoints_listed.Notebook', function (event, data) {
that.set_last_checkpoint(data[0]);
@ -63,6 +61,9 @@ var IPython = (function (IPython) {
$([IPython.events]).on('checkpoint_created.Notebook', function (event, data) {
that.set_last_checkpoint(data);
});
$([IPython.events]).on('set_dirty.Notebook', function (event, data) {
that.set_autosaved(data.value);
});
};
@ -148,9 +149,12 @@ var IPython = (function (IPython) {
);
}
SaveWidget.prototype.set_last_saved = function () {
var d = new Date();
this.set_save_status('(autosaved: '+d.format('mmm dd HH:MM') + ')');
SaveWidget.prototype.set_autosaved = function (dirty) {
if (dirty) {
this.set_save_status("(unsaved changes)");
} else {
this.set_save_status("(autosaved)");
}
};

Loading…
Cancel
Save