Add Cut/Copy/Paste Cell attachments menu items

This commit is contained in:
Julien Rebetez 2015-10-30 10:52:36 +01:00 committed by Julien Rebetez
parent 646619d5cd
commit 865de47233
3 changed files with 87 additions and 1 deletions

View File

@ -160,6 +160,27 @@ define(function(require){
env.notebook.insert_image();
}
},
'cut-cell-attachments': {
help : 'cut cell attachments',
help_index : 'dza',
handler: function (env) {
env.notebook.cut_cell_attachments();
}
},
'copy-cell-attachments': {
help : 'copy cell attachments',
help_index: 'dzb',
handler: function (env) {
env.notebook.copy_cell_attachments();
}
},
'paste-cell-attachments': {
help : 'paste cell attachments',
help_index: 'dzc',
handler: function (env) {
env.notebook.paste_cell_attachments();
}
},
'split-cell-at-cursor': {
help : 'split cell',
help_index : 'ea',

View File

@ -128,6 +128,7 @@ define(function (require) {
this.clipboard = null;
this.undelete_backup_stack = [];
this.paste_enabled = false;
this.paste_attachments_enabled = false;
this.writable = false;
// It is important to start out in command mode to match the intial mode
// of the KeyboardManager.
@ -1673,7 +1674,7 @@ define(function (require) {
this.merge_cells([index, index+1], false);
};
// Image insertion
// Attachments handling
/**
* Shows a dialog letting the user pick an image from her computer and
@ -1703,6 +1704,66 @@ define(function (require) {
});
};
/**
* Cut the attachments of a cell
*/
Notebook.prototype.cut_cell_attachments = function() {
var cell = this.get_selected_cell();
this.clipboard_attachments = cell.attachments;
this.enable_attachments_paste();
cell.attachments = {};
cell.unrender();
cell.render();
};
/**
* Copy the attachments of a cell
*/
Notebook.prototype.copy_cell_attachments = function() {
var cell = this.get_selected_cell();
// Do a deep copy of attachments to avoid subsequent modification
// to the cell to modify the clipboard
this.clipboard_attachments = $.extend(true, {}, cell.attachments);
this.enable_attachments_paste();
cell.unrender();
cell.render();
};
/**
* Paste the attachments in the clipboard into the currently selected
* cell
*/
Notebook.prototype.paste_cell_attachments = function() {
if (this.clipboard_attachments !== null &&
this.paste_attachments_enabled) {
var cell = this.get_selected_cell();
$.extend(cell.attachments, this.clipboard_attachments);
cell.unrender();
cell.render();
}
};
/**
* Disable the "Paste Cell Attachments" menu item
*/
Notebook.prototype.disable_attachments_paste = function () {
if (this.paste_attachments_enabled) {
$('#paste_cell_attachments').addClass('disabled');
this.paste_attachments_enabled = false;
}
};
/**
* Enable the "Paste Cell Attachments" menu item
*/
Notebook.prototype.enable_attachments_paste = function () {
var that = this;
if (!this.paste_attachments_enabled) {
$('#paste_cell_attachments').removeClass('disabled');
this.paste_attachments_enabled = true;
}
};
/**
* Enable/disable the "Insert image" menu item
*/

View File

@ -144,6 +144,10 @@ data-notebook-path="{{notebook_path | urlencode}}"
<li class="divider"></li>
<li id="find_and_replace"><a href="#"> Find and Replace </a></li>
<li class="divider"></li>
<li id="cut_cell_attachments"><a href="#">Cut Cell Attachments</a></li>
<li id="copy_cell_attachments"><a href="#">Copy Cell Attachments</a></li>
<li id="paste_cell_attachments" class="disabled"><a href="#">Paste Cell Attachments</a></li>
<li class="divider"></li>
<li id="insert_image" class="disabled"><a href="#"> Insert Image </a></li>
</ul>
</li>