##// END OF EJS Templates
Work on the base Cell API....
Brian Granger -
Show More
@@ -30,18 +30,8 b' var IPython = (function (IPython) {'
30 this.cell_id = utils.uuid();
30 this.cell_id = utils.uuid();
31 };
31 };
32
32
33
33 // Subclasses must implement create_element.
34 Cell.prototype.select = function () {
34 Cell.prototype.create_element = function () {};
35 this.element.addClass('ui-widget-content ui-corner-all');
36 this.selected = true;
37 };
38
39
40 Cell.prototype.unselect = function () {
41 this.element.removeClass('ui-widget-content ui-corner-all');
42 this.selected = false;
43 };
44
45
35
46 Cell.prototype.bind_events = function () {
36 Cell.prototype.bind_events = function () {
47 var that = this;
37 var that = this;
@@ -58,6 +48,55 b' var IPython = (function (IPython) {'
58 });
48 });
59 };
49 };
60
50
51 // typeset with MathJax if MathJax is available
52 Cell.prototype.typeset = function () {
53 if (window.MathJax){
54 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
55 }
56 };
57
58
59 Cell.prototype.select = function () {
60 this.element.addClass('ui-widget-content ui-corner-all');
61 this.selected = true;
62 };
63
64
65 Cell.prototype.unselect = function () {
66 this.element.removeClass('ui-widget-content ui-corner-all');
67 this.selected = false;
68 };
69
70
71 Cell.prototype.get_text = function () {
72 };
73
74
75 Cell.prototype.set_text = function (text) {
76 };
77
78
79 Cell.prototype.refresh = function () {
80 this.code_mirror.refresh();
81 };
82
83
84 Cell.prototype.edit = function () {
85 };
86
87
88 Cell.prototype.render = function () {
89 };
90
91
92 Cell.prototype.toJSON = function () {
93 };
94
95
96 Cell.prototype.fromJSON = function (data) {
97 };
98
99
61 Cell.prototype.grow = function(element) {
100 Cell.prototype.grow = function(element) {
62 // Grow the cell by hand. This is used upon reloading from JSON, when the
101 // Grow the cell by hand. This is used upon reloading from JSON, when the
63 // autogrow handler is not called.
102 // autogrow handler is not called.
@@ -85,16 +124,6 b' var IPython = (function (IPython) {'
85 }
124 }
86 };
125 };
87
126
88 // Subclasses must implement create_element.
89 Cell.prototype.create_element = function () {};
90
91 // typeset with MathJax if MathJax is available
92 Cell.prototype.typeset = function () {
93 if (window.MathJax){
94 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
95 }
96 };
97
98 IPython.Cell = Cell;
127 IPython.Cell = Cell;
99
128
100 return IPython;
129 return IPython;
@@ -754,12 +754,12 b' var IPython = (function (IPython) {'
754 };
754 };
755
755
756
756
757 CodeCell.prototype.get_code = function () {
757 CodeCell.prototype.get_text = function () {
758 return this.code_mirror.getValue();
758 return this.code_mirror.getValue();
759 };
759 };
760
760
761
761
762 CodeCell.prototype.set_code = function (code) {
762 CodeCell.prototype.set_text = function (code) {
763 return this.code_mirror.setValue(code);
763 return this.code_mirror.setValue(code);
764 };
764 };
765
765
@@ -787,7 +787,7 b' var IPython = (function (IPython) {'
787 CodeCell.prototype.fromJSON = function (data) {
787 CodeCell.prototype.fromJSON = function (data) {
788 if (data.cell_type === 'code') {
788 if (data.cell_type === 'code') {
789 if (data.input !== undefined) {
789 if (data.input !== undefined) {
790 this.set_code(data.input);
790 this.set_text(data.input);
791 }
791 }
792 if (data.prompt_number !== undefined) {
792 if (data.prompt_number !== undefined) {
793 this.set_input_prompt(data.prompt_number);
793 this.set_input_prompt(data.prompt_number);
@@ -809,7 +809,7 b' var IPython = (function (IPython) {'
809
809
810 CodeCell.prototype.toJSON = function () {
810 CodeCell.prototype.toJSON = function () {
811 var data = {};
811 var data = {};
812 data.input = this.get_code();
812 data.input = this.get_text();
813 data.cell_type = 'code';
813 data.cell_type = 'code';
814 if (this.input_prompt_number !== ' ') {
814 if (this.input_prompt_number !== ' ') {
815 data.prompt_number = this.input_prompt_number;
815 data.prompt_number = this.input_prompt_number;
@@ -55,7 +55,7 b' var IPython = (function (IPython) {'
55 $('#main_app').hide();
55 $('#main_app').hide();
56 $('#menubar').hide();
56 $('#menubar').hide();
57 $('body').css({overflow : 'auto'});
57 $('body').css({overflow : 'auto'});
58 var code = cell.get_code();
58 var code = cell.get_text();
59 this.ace_editor.getSession().setValue(code);
59 this.ace_editor.getSession().setValue(code);
60 this.ace_editor.focus();
60 this.ace_editor.focus();
61 // On Safari (and Chrome/FF on Linux) the editor doesn't get
61 // On Safari (and Chrome/FF on Linux) the editor doesn't get
@@ -76,7 +76,7 b' var IPython = (function (IPython) {'
76 $('body').css({overflow : 'hidden'});
76 $('body').css({overflow : 'hidden'});
77 var code = this.ace_editor.getSession().getValue();
77 var code = this.ace_editor.getSession().getValue();
78 var cell = IPython.notebook.selected_cell();
78 var cell = IPython.notebook.selected_cell();
79 cell.set_code(code);
79 cell.set_text(code);
80 cell.select();
80 cell.select();
81 this.opened = false;
81 this.opened = false;
82 };
82 };
@@ -516,11 +516,11 b' var IPython = (function (IPython) {'
516 source_cell instanceof IPython.MarkdownCell) {
516 source_cell instanceof IPython.MarkdownCell) {
517 this.insert_code_cell_below(i);
517 this.insert_code_cell_below(i);
518 var target_cell = this.cells()[i+1];
518 var target_cell = this.cells()[i+1];
519 var text = source_cell.get_source();
519 var text = source_cell.get_text();
520 if (text === source_cell.placeholder) {
520 if (text === source_cell.placeholder) {
521 text = '';
521 text = '';
522 }
522 }
523 target_cell.set_code(text);
523 target_cell.set_text(text);
524 source_element.remove();
524 source_element.remove();
525 target_cell.select();
525 target_cell.select();
526 };
526 };
@@ -537,20 +537,20 b' var IPython = (function (IPython) {'
537 if (source_cell instanceof IPython.CodeCell) {
537 if (source_cell instanceof IPython.CodeCell) {
538 this.insert_markdown_cell_below(i);
538 this.insert_markdown_cell_below(i);
539 target_cell = this.cells()[i+1];
539 target_cell = this.cells()[i+1];
540 var text = source_cell.get_code();
540 var text = source_cell.get_text();
541 } else if (source_cell instanceof IPython.HTMLCell) {
541 } else if (source_cell instanceof IPython.HTMLCell) {
542 this.insert_markdown_cell_below(i);
542 this.insert_markdown_cell_below(i);
543 target_cell = this.cells()[i+1];
543 target_cell = this.cells()[i+1];
544 var text = source_cell.get_source();
544 var text = source_cell.get_text();
545 if (text === source_cell.placeholder) {
545 if (text === source_cell.placeholder) {
546 text = target_cell.placeholder;
546 text = target_cell.placeholder;
547 }
547 }
548 }
548 }
549 if (target_cell !== null) {
549 if (target_cell !== null) {
550 if (text === "") {text = target_cell.placeholder;};
550 if (text === "") {text = target_cell.placeholder;};
551 // The edit must come before the set_source.
551 // The edit must come before the set_text.
552 target_cell.edit();
552 target_cell.edit();
553 target_cell.set_source(text);
553 target_cell.set_text(text);
554 source_element.remove();
554 source_element.remove();
555 target_cell.select();
555 target_cell.select();
556 }
556 }
@@ -567,18 +567,18 b' var IPython = (function (IPython) {'
567 if (source_cell instanceof IPython.CodeCell) {
567 if (source_cell instanceof IPython.CodeCell) {
568 this.insert_html_cell_below(i);
568 this.insert_html_cell_below(i);
569 target_cell = this.cells()[i+1];
569 target_cell = this.cells()[i+1];
570 var text = source_cell.get_code();
570 var text = source_cell.get_text();
571 } else if (source_cell instanceof IPython.MarkdownCell) {
571 } else if (source_cell instanceof IPython.MarkdownCell) {
572 this.insert_html_cell_below(i);
572 this.insert_html_cell_below(i);
573 target_cell = this.cells()[i+1];
573 target_cell = this.cells()[i+1];
574 var text = source_cell.get_source();
574 var text = source_cell.get_text();
575 if (text === source_cell.placeholder) {
575 if (text === source_cell.placeholder) {
576 text = target_cell.placeholder;
576 text = target_cell.placeholder;
577 }
577 }
578 }
578 }
579 if (target_cell !== null) {
579 if (target_cell !== null) {
580 if (text === "") {text = target_cell.placeholder;};
580 if (text === "") {text = target_cell.placeholder;};
581 target_cell.set_source(text);
581 target_cell.set_text(text);
582 source_element.remove();
582 source_element.remove();
583 target_cell.edit();
583 target_cell.edit();
584 }
584 }
@@ -689,9 +689,9 b' var IPython = (function (IPython) {'
689 var textb = cell.code_mirror.getRange(cursor, end);
689 var textb = cell.code_mirror.getRange(cursor, end);
690 texta = texta.replace(/^\n+/, '').replace(/\n+$/, '');
690 texta = texta.replace(/^\n+/, '').replace(/\n+$/, '');
691 textb = textb.replace(/^\n+/, '').replace(/\n+$/, '');
691 textb = textb.replace(/^\n+/, '').replace(/\n+$/, '');
692 cell.set_code(texta);
692 cell.set_text(texta);
693 var new_cell = this.insert_code_cell_below();
693 var new_cell = this.insert_code_cell_below();
694 new_cell.set_code(textb);
694 new_cell.set_text(textb);
695 };
695 };
696 };
696 };
697
697
@@ -704,9 +704,9 b' var IPython = (function (IPython) {'
704 upper_cell = this.cells()[index-1];
704 upper_cell = this.cells()[index-1];
705 lower_cell = this.cells()[index];
705 lower_cell = this.cells()[index];
706 if (upper_cell instanceof IPython.CodeCell && lower_cell instanceof IPython.CodeCell) {
706 if (upper_cell instanceof IPython.CodeCell && lower_cell instanceof IPython.CodeCell) {
707 upper_text = upper_cell.get_code();
707 upper_text = upper_cell.get_text();
708 lower_text = lower_cell.get_code();
708 lower_text = lower_cell.get_text();
709 lower_cell.set_code(upper_text+'\n'+lower_text);
709 lower_cell.set_text(upper_text+'\n'+lower_text);
710 this.delete_cell(index-1);
710 this.delete_cell(index-1);
711 };
711 };
712 };
712 };
@@ -721,9 +721,9 b' var IPython = (function (IPython) {'
721 upper_cell = this.cells()[index];
721 upper_cell = this.cells()[index];
722 lower_cell = this.cells()[index+1];
722 lower_cell = this.cells()[index+1];
723 if (upper_cell instanceof IPython.CodeCell && lower_cell instanceof IPython.CodeCell) {
723 if (upper_cell instanceof IPython.CodeCell && lower_cell instanceof IPython.CodeCell) {
724 upper_text = upper_cell.get_code();
724 upper_text = upper_cell.get_text();
725 lower_text = lower_cell.get_code();
725 lower_text = lower_cell.get_text();
726 upper_cell.set_code(upper_text+'\n'+lower_text);
726 upper_cell.set_text(upper_text+'\n'+lower_text);
727 this.delete_cell(index+1);
727 this.delete_cell(index+1);
728 };
728 };
729 };
729 };
@@ -875,7 +875,7 b' var IPython = (function (IPython) {'
875 } else if (payload[i].source === 'IPython.zmq.zmqshell.ZMQInteractiveShell.set_next_input') {
875 } else if (payload[i].source === 'IPython.zmq.zmqshell.ZMQInteractiveShell.set_next_input') {
876 var index = this.find_cell_index(cell);
876 var index = this.find_cell_index(cell);
877 var new_cell = this.insert_code_cell_below(index);
877 var new_cell = this.insert_code_cell_below(index);
878 new_cell.set_code(payload[i].text);
878 new_cell.set_text(payload[i].text);
879 this.dirty = true;
879 this.dirty = true;
880 }
880 }
881 };
881 };
@@ -1000,8 +1000,8 b' var IPython = (function (IPython) {'
1000 cell.clear_output(true, true, true);
1000 cell.clear_output(true, true, true);
1001 cell.set_input_prompt('*');
1001 cell.set_input_prompt('*');
1002 cell.element.addClass("running");
1002 cell.element.addClass("running");
1003 var code = cell.get_code();
1003 var code = cell.get_text();
1004 var msg_id = that.kernel.execute(cell.get_code());
1004 var msg_id = that.kernel.execute(cell.get_text());
1005 that.msg_cell_map[msg_id] = cell.cell_id;
1005 that.msg_cell_map[msg_id] = cell.cell_id;
1006 } else if (cell instanceof IPython.HTMLCell) {
1006 } else if (cell instanceof IPython.HTMLCell) {
1007 cell.render();
1007 cell.render();
@@ -99,8 +99,8 b' var IPython = (function (IPython) {'
99 this.code_mirror.focus();
99 this.code_mirror.focus();
100 that.code_mirror.refresh();
100 that.code_mirror.refresh();
101 this.rendered = false;
101 this.rendered = false;
102 if (this.get_source() === this.placeholder) {
102 if (this.get_text() === this.placeholder) {
103 this.set_source('');
103 this.set_text('');
104 }
104 }
105 }
105 }
106 };
106 };
@@ -120,12 +120,12 b' var IPython = (function (IPython) {'
120 };
120 };
121
121
122
122
123 TextCell.prototype.get_source = function() {
123 TextCell.prototype.get_text = function() {
124 return this.code_mirror.getValue();
124 return this.code_mirror.getValue();
125 };
125 };
126
126
127
127
128 TextCell.prototype.set_source = function(text) {
128 TextCell.prototype.set_text = function(text) {
129 this.code_mirror.setValue(text);
129 this.code_mirror.setValue(text);
130 this.code_mirror.refresh();
130 this.code_mirror.refresh();
131 };
131 };
@@ -162,7 +162,7 b' var IPython = (function (IPython) {'
162 TextCell.prototype.fromJSON = function (data) {
162 TextCell.prototype.fromJSON = function (data) {
163 if (data.cell_type === this.cell_type) {
163 if (data.cell_type === this.cell_type) {
164 if (data.source !== undefined) {
164 if (data.source !== undefined) {
165 this.set_source(data.source);
165 this.set_text(data.source);
166 this.set_rendered(data.rendered || '');
166 this.set_rendered(data.rendered || '');
167 this.rendered = false;
167 this.rendered = false;
168 this.render();
168 this.render();
@@ -174,7 +174,7 b' var IPython = (function (IPython) {'
174 TextCell.prototype.toJSON = function () {
174 TextCell.prototype.toJSON = function () {
175 var data = {};
175 var data = {};
176 data.cell_type = this.cell_type;
176 data.cell_type = this.cell_type;
177 data.source = this.get_source();
177 data.source = this.get_text();
178 return data;
178 return data;
179 };
179 };
180
180
@@ -193,7 +193,7 b' var IPython = (function (IPython) {'
193
193
194 HTMLCell.prototype.render = function () {
194 HTMLCell.prototype.render = function () {
195 if (this.rendered === false) {
195 if (this.rendered === false) {
196 var text = this.get_source();
196 var text = this.get_text();
197 if (text === "") { text = this.placeholder; }
197 if (text === "") { text = this.placeholder; }
198 this.set_rendered(text);
198 this.set_rendered(text);
199 this.typeset();
199 this.typeset();
@@ -218,7 +218,7 b' var IPython = (function (IPython) {'
218
218
219 MarkdownCell.prototype.render = function () {
219 MarkdownCell.prototype.render = function () {
220 if (this.rendered === false) {
220 if (this.rendered === false) {
221 var text = this.get_source();
221 var text = this.get_text();
222 if (text === "") { text = this.placeholder; }
222 if (text === "") { text = this.placeholder; }
223 var html = IPython.markdown_converter.makeHtml(text);
223 var html = IPython.markdown_converter.makeHtml(text);
224 this.set_rendered(html);
224 this.set_rendered(html);
@@ -256,7 +256,7 b' var IPython = (function (IPython) {'
256
256
257 RSTCell.prototype.render = function () {
257 RSTCell.prototype.render = function () {
258 if (this.rendered === false) {
258 if (this.rendered === false) {
259 var text = this.get_source();
259 var text = this.get_text();
260 if (text === "") { text = this.placeholder; }
260 if (text === "") { text = this.placeholder; }
261 var settings = {
261 var settings = {
262 processData : false,
262 processData : false,
General Comments 0
You need to be logged in to leave comments. Login now