##// END OF EJS Templates
Added cell level cut/copy/paste.
Brian Granger -
Show More
@@ -61,6 +61,12 b' var IPython = (function (IPython) {'
61 IPython.print_widget.print_notebook();
61 IPython.print_widget.print_notebook();
62 });
62 });
63 // Edit
63 // Edit
64 this.element.find('#cut_cell').click(function () {
65 IPython.notebook.cut_cell();
66 });
67 this.element.find('#copy_cell').click(function () {
68 IPython.notebook.copy_cell();
69 });
64 this.element.find('#delete_cell').click(function () {
70 this.element.find('#delete_cell').click(function () {
65 IPython.notebook.delete_cell();
71 IPython.notebook.delete_cell();
66 });
72 });
@@ -20,6 +20,7 b' var IPython = (function (IPython) {'
20 this.element.data("notebook", this);
20 this.element.data("notebook", this);
21 this.next_prompt_number = 1;
21 this.next_prompt_number = 1;
22 this.kernel = null;
22 this.kernel = null;
23 this.clipboard = null;
23 this.dirty = false;
24 this.dirty = false;
24 this.msg_cell_map = {};
25 this.msg_cell_map = {};
25 this.metadata = {};
26 this.metadata = {};
@@ -321,7 +322,6 b' var IPython = (function (IPython) {'
321
322
322 // Cell insertion, deletion and moving.
323 // Cell insertion, deletion and moving.
323
324
324
325 Notebook.prototype.delete_cell = function (index) {
325 Notebook.prototype.delete_cell = function (index) {
326 var i = index || this.selected_index();
326 var i = index || this.selected_index();
327 if (i !== null && i >= 0 && i < this.ncells()) {
327 if (i !== null && i >= 0 && i < this.ncells()) {
@@ -563,6 +563,91 b' var IPython = (function (IPython) {'
563 };
563 };
564
564
565
565
566 // Copy/Paste
567
568 Notebook.prototype.enable_paste = function () {
569 var that = this;
570 $('#paste_cell').removeClass('ui-state-disabled')
571 .on('click', function () {that.paste_cell();});
572 $('#paste_cell_above').removeClass('ui-state-disabled')
573 .on('click', function () {that.paste_cell_above();});
574 $('#paste_cell_below').removeClass('ui-state-disabled')
575 .on('click', function () {that.paste_cell_below();});
576 };
577
578
579 Notebook.prototype.disable_paste = function () {
580 $('#paste_cell').addClass('ui-state-disabled').off('click');
581 $('#paste_cell_above').addClass('ui-state-disabled').off('click');
582 $('#paste_cell_below').addClass('ui-state-disabled').off('click');
583 };
584
585
586 Notebook.prototype.cut_cell = function () {
587 this.copy_cell();
588 this.delete_cell();
589 }
590
591 Notebook.prototype.copy_cell = function () {
592 var cell = this.selected_cell();
593 this.clipboard = cell.toJSON();
594 this.enable_paste();
595 };
596
597
598 Notebook.prototype.paste_cell = function () {
599 if (this.clipboard !== null) {
600 var cell_data = this.clipboard;
601 if (cell_data.cell_type == 'code') {
602 new_cell = this.insert_code_cell_above();
603 new_cell.fromJSON(cell_data);
604 } else if (cell_data.cell_type === 'html') {
605 new_cell = this.insert_html_cell_above();
606 new_cell.fromJSON(cell_data);
607 } else if (cell_data.cell_type === 'markdown') {
608 new_cell = this.insert_markdown_cell_above();
609 new_cell.fromJSON(cell_data);
610 };
611 };
612 this.select_next();
613 this.delete_cell();
614 };
615
616
617 Notebook.prototype.paste_cell_above = function () {
618 if (this.clipboard !== null) {
619 var cell_data = this.clipboard;
620 if (cell_data.cell_type == 'code') {
621 new_cell = this.insert_code_cell_above();
622 new_cell.fromJSON(cell_data);
623 } else if (cell_data.cell_type === 'html') {
624 new_cell = this.insert_html_cell_above();
625 new_cell.fromJSON(cell_data);
626 } else if (cell_data.cell_type === 'markdown') {
627 new_cell = this.insert_markdown_cell_above();
628 new_cell.fromJSON(cell_data);
629 };
630 };
631 };
632
633
634 Notebook.prototype.paste_cell_below = function () {
635 if (this.clipboard !== null) {
636 var cell_data = this.clipboard;
637 if (cell_data.cell_type == 'code') {
638 new_cell = this.insert_code_cell_above();
639 new_cell.fromJSON(cell_data);
640 } else if (cell_data.cell_type === 'html') {
641 new_cell = this.insert_html_cell_above();
642 new_cell.fromJSON(cell_data);
643 } else if (cell_data.cell_type === 'markdown') {
644 new_cell = this.insert_markdown_cell_above();
645 new_cell.fromJSON(cell_data);
646 };
647 };
648 };
649
650
566 // Cell collapsing and output clearing
651 // Cell collapsing and output clearing
567
652
568 Notebook.prototype.collapse = function (index) {
653 Notebook.prototype.collapse = function (index) {
@@ -925,7 +1010,7 b' var IPython = (function (IPython) {'
925 new_cell = this.insert_markdown_cell_below();
1010 new_cell = this.insert_markdown_cell_below();
926 new_cell.fromJSON(cell_data);
1011 new_cell.fromJSON(cell_data);
927 };
1012 };
928 };
1013 };
929 };
1014 };
930 };
1015 };
931
1016
@@ -84,6 +84,11 b''
84 </li>
84 </li>
85 <li><a href="#">Edit</a>
85 <li><a href="#">Edit</a>
86 <ul>
86 <ul>
87 <li id="cut_cell"><a href="#">Cut</a></li>
88 <li id="copy_cell"><a href="#">Copy</a></li>
89 <li id="paste_cell" class="ui-state-disabled"><a href="#">Paste</a></li>
90 <li id="paste_cell_above" class="ui-state-disabled"><a href="#">Paste Above</a></li>
91 <li id="paste_cell_below" class="ui-state-disabled"><a href="#">Paste Below</a></li>
87 <li id="delete_cell"><a href="#">Delete</a></li>
92 <li id="delete_cell"><a href="#">Delete</a></li>
88 <hr/>
93 <hr/>
89 <li id="move_cell_up"><a href="#">Move Cell Up</a></li>
94 <li id="move_cell_up"><a href="#">Move Cell Up</a></li>
General Comments 0
You need to be logged in to leave comments. Login now