Handle 'deletable' cell metadata

Jessica B. Hamrick 12 years ago
parent 3cb8c5a0a1
commit 990425f034

@ -385,7 +385,8 @@ define([
**/
Cell.prototype.toJSON = function () {
var data = {};
data.metadata = this.metadata;
// deepcopy the metadata so copied cells don't share the same object
data.metadata = JSON.parse(JSON.stringify(this.metadata));
data.cell_type = this.cell_type;
return data;
};
@ -404,22 +405,32 @@ define([
/**
* can the cell be split into two cells
* can the cell be split into two cells (false if not deletable)
* @method is_splittable
**/
Cell.prototype.is_splittable = function () {
return true;
return this.is_deletable();
};
/**
* can the cell be merged with other cells
* can the cell be merged with other cells (false if not deletable)
* @method is_mergeable
**/
Cell.prototype.is_mergeable = function () {
return true;
return this.is_deletable();
};
/**
* is the cell deletable? (true by default)
* @method is_deletable
**/
Cell.prototype.is_deletable = function () {
if (this.metadata.deletable === undefined) {
return true;
}
return Boolean(this.metadata.deletable);
};
/**
* @return {String} - the text before the cursor

@ -765,7 +765,11 @@ define([
*/
Notebook.prototype.delete_cell = function (index) {
var i = this.index_or_selected(index);
var cell = this.get_selected_cell();
var cell = this.get_cell(i);
if (!cell.is_deletable()) {
return this;
}
this.undelete_backup = cell.toJSON();
$('#undelete_cell').removeClass('disabled');
if (this.is_valid_cell_index(i)) {
@ -1193,6 +1197,10 @@ define([
Notebook.prototype.copy_cell = function () {
var cell = this.get_selected_cell();
this.clipboard = cell.toJSON();
// remove undeletable status from the copied cell
if (this.clipboard.metadata.deletable !== undefined) {
delete this.clipboard.metadata.deletable;
}
this.enable_paste();
};

Loading…
Cancel
Save