##// END OF EJS Templates
Finishing first draft of RST and heading cells.
Brian Granger -
Show More
@@ -132,6 +132,24 b' var IPython = (function (IPython) {'
132 this.element.find('#to_rst').click(function () {
132 this.element.find('#to_rst').click(function () {
133 IPython.notebook.to_rst();
133 IPython.notebook.to_rst();
134 });
134 });
135 this.element.find('#to_heading1').click(function () {
136 IPython.notebook.to_heading(undefined, 1);
137 });
138 this.element.find('#to_heading2').click(function () {
139 IPython.notebook.to_heading(undefined, 2);
140 });
141 this.element.find('#to_heading3').click(function () {
142 IPython.notebook.to_heading(undefined, 3);
143 });
144 this.element.find('#to_heading4').click(function () {
145 IPython.notebook.to_heading(undefined, 4);
146 });
147 this.element.find('#to_heading5').click(function () {
148 IPython.notebook.to_heading(undefined, 5);
149 });
150 this.element.find('#to_heading6').click(function () {
151 IPython.notebook.to_heading(undefined, 6);
152 });
135 this.element.find('#toggle_output').click(function () {
153 this.element.find('#toggle_output').click(function () {
136 IPython.notebook.toggle_output();
154 IPython.notebook.toggle_output();
137 });
155 });
@@ -140,6 +140,36 b' var IPython = (function (IPython) {'
140 that.to_rst();
140 that.to_rst();
141 that.control_key_active = false;
141 that.control_key_active = false;
142 return false;
142 return false;
143 } else if (event.which === 49 && that.control_key_active) {
144 // To Heading 1 = 1
145 that.to_heading(undefined, 1);
146 that.control_key_active = false;
147 return false;
148 } else if (event.which === 50 && that.control_key_active) {
149 // To Heading 2 = 2
150 that.to_heading(undefined, 2);
151 that.control_key_active = false;
152 return false;
153 } else if (event.which === 51 && that.control_key_active) {
154 // To Heading 3 = 3
155 that.to_heading(undefined, 3);
156 that.control_key_active = false;
157 return false;
158 } else if (event.which === 52 && that.control_key_active) {
159 // To Heading 4 = 4
160 that.to_heading(undefined, 4);
161 that.control_key_active = false;
162 return false;
163 } else if (event.which === 53 && that.control_key_active) {
164 // To Heading 5 = 5
165 that.to_heading(undefined, 5);
166 that.control_key_active = false;
167 return false;
168 } else if (event.which === 54 && that.control_key_active) {
169 // To Heading 6 = 6
170 that.to_heading(undefined, 6);
171 that.control_key_active = false;
172 return false;
143 } else if (event.which === 84 && that.control_key_active) {
173 } else if (event.which === 84 && that.control_key_active) {
144 // Toggle output = t
174 // Toggle output = t
145 that.toggle_output();
175 that.toggle_output();
@@ -483,6 +513,8 b' var IPython = (function (IPython) {'
483 cell = new IPython.HTMLCell(this);
513 cell = new IPython.HTMLCell(this);
484 } else if (type === 'rst') {
514 } else if (type === 'rst') {
485 cell = new IPython.RSTCell(this);
515 cell = new IPython.RSTCell(this);
516 } else if (type === 'heading') {
517 cell = new IPython.HeadingCell(this);
486 };
518 };
487 if (cell !== null) {
519 if (cell !== null) {
488 if (this.ncells() === 0) {
520 if (this.ncells() === 0) {
@@ -515,6 +547,8 b' var IPython = (function (IPython) {'
515 cell = new IPython.HTMLCell(this);
547 cell = new IPython.HTMLCell(this);
516 } else if (type === 'rst') {
548 } else if (type === 'rst') {
517 cell = new IPython.RSTCell(this);
549 cell = new IPython.RSTCell(this);
550 } else if (type === 'heading') {
551 cell = new IPython.HeadingCell(this);
518 };
552 };
519 if (cell !== null) {
553 if (cell !== null) {
520 if (this.ncells() === 0) {
554 if (this.ncells() === 0) {
@@ -615,6 +649,33 b' var IPython = (function (IPython) {'
615 };
649 };
616 };
650 };
617
651
652
653 Notebook.prototype.to_heading = function (index, level) {
654 level = level || 1;
655 var i = this.index_or_selected(index);
656 if (this.is_valid_cell_index(i)) {
657 var source_element = this.get_cell_element(i);
658 var source_cell = source_element.data("cell");
659 var target_cell = null;
660 if (source_cell instanceof IPython.HeadingCell) {
661 source_cell.set_level(level);
662 } else {
663 target_cell = this.insert_cell_below('heading',i);
664 var text = source_cell.get_text();
665 if (text === source_cell.placeholder) {
666 text = '';
667 };
668 // The edit must come before the set_text.
669 target_cell.set_level(level);
670 target_cell.edit();
671 target_cell.set_text(text);
672 source_element.remove();
673 this.dirty = true;
674 };
675 };
676 };
677
678
618 // Cut/Copy/Paste
679 // Cut/Copy/Paste
619
680
620 Notebook.prototype.enable_paste = function () {
681 Notebook.prototype.enable_paste = function () {
@@ -299,17 +299,31 b' var IPython = (function (IPython) {'
299 HeadingCell.prototype = new TextCell();
299 HeadingCell.prototype = new TextCell();
300
300
301
301
302 HeadingCell.prototype.set_level = function (level) {
303 this.level = level;
304 if (this.rendered) {
305 this.rendered = false;
306 this.render();
307 };
308 };
309
310
311 HeadingCell.prototype.get_level = function () {
312 return this.level;
313 };
314
315
302 HeadingCell.prototype.set_rendered = function (text) {
316 HeadingCell.prototype.set_rendered = function (text) {
303 var r = this.element.find("div.text_cell_render");
317 var r = this.element.find("div.text_cell_render");
304 r.empty();
318 r.empty();
305 r.append($('<h1/>').html(text));
319 r.append($('<h'+this.level+'/>').html(text));
306 }
320 };
307
321
308
322
309 HeadingCell.prototype.get_rendered = function () {
323 HeadingCell.prototype.get_rendered = function () {
310 var r = this.element.find("div.text_cell_render");
324 var r = this.element.find("div.text_cell_render");
311 return r.children().first().html();
325 return r.children().first().html();
312 }
326 };
313
327
314
328
315 HeadingCell.prototype.render = function () {
329 HeadingCell.prototype.render = function () {
@@ -321,13 +335,14 b' var IPython = (function (IPython) {'
321 this.element.find('div.text_cell_input').hide();
335 this.element.find('div.text_cell_input').hide();
322 this.element.find("div.text_cell_render").show();
336 this.element.find("div.text_cell_render").show();
323 this.rendered = true;
337 this.rendered = true;
324 }
338 };
325 };
339 };
326
340
327 IPython.TextCell = TextCell;
341 IPython.TextCell = TextCell;
328 IPython.HTMLCell = HTMLCell;
342 IPython.HTMLCell = HTMLCell;
329 IPython.MarkdownCell = MarkdownCell;
343 IPython.MarkdownCell = MarkdownCell;
330 IPython.RSTCell = RSTCell;
344 IPython.RSTCell = RSTCell;
345 IPython.HeadingCell = HeadingCell;
331
346
332
347
333 return IPython;
348 return IPython;
@@ -117,9 +117,15 b''
117 <li id="run_cell_in_place"><a href="#">Run in Place</a></li>
117 <li id="run_cell_in_place"><a href="#">Run in Place</a></li>
118 <li id="run_all_cells"><a href="#">Run All</a></li>
118 <li id="run_all_cells"><a href="#">Run All</a></li>
119 <hr/>
119 <hr/>
120 <li id="to_code"><a href="#">Code Cell</a></li>
120 <li id="to_code"><a href="#">Code</a></li>
121 <li id="to_markdown"><a href="#">Markdown Cell</a></li>
121 <li id="to_markdown"><a href="#">Markdown </a></li>
122 <li id="to_rst"><a href="#">RST Cell</a></li>
122 <li id="to_rst"><a href="#">RST</a></li>
123 <li id="to_heading1"><a href="#">Heading 1</a></li>
124 <li id="to_heading2"><a href="#">Heading 2</a></li>
125 <li id="to_heading3"><a href="#">Heading 3</a></li>
126 <li id="to_heading4"><a href="#">Heading 4</a></li>
127 <li id="to_heading5"><a href="#">Heading 5</a></li>
128 <li id="to_heading6"><a href="#">Heading 6</a></li>
123 <hr/>
129 <hr/>
124 <li id="toggle_output"><a href="#">Toggle Output</a></li>
130 <li id="toggle_output"><a href="#">Toggle Output</a></li>
125 <li id="clear_all_output"><a href="#">Clear All Output</a></li>
131 <li id="clear_all_output"><a href="#">Clear All Output</a></li>
General Comments 0
You need to be logged in to leave comments. Login now