##// END OF EJS Templates
implemented whiteboard logic
Jonathan Frederic -
Show More
@@ -167,7 +167,7 b' var IPython = (function (IPython) {'
167 167 event.preventDefault();
168 168 IPython.notebook.command_mode();
169 169 IPython.notebook.select_prev();
170 IPython.notebook.edit_mode();
170 IPython.notebook.trigger_edit_mode();
171 171 return false;
172 172 }
173 173 }
@@ -181,7 +181,7 b' var IPython = (function (IPython) {'
181 181 event.preventDefault();
182 182 IPython.notebook.command_mode();
183 183 IPython.notebook.select_next();
184 IPython.notebook.edit_mode();
184 IPython.notebook.trigger_edit_mode();
185 185 return false;
186 186 }
187 187 }
@@ -253,7 +253,7 b' var IPython = (function (IPython) {'
253 253 help : 'edit mode',
254 254 help_index : 'aa',
255 255 handler : function (event) {
256 IPython.notebook.edit_mode();
256 IPython.notebook.trigger_edit_mode();
257 257 return false;
258 258 }
259 259 },
@@ -116,7 +116,7 b' var IPython = (function (IPython) {'
116 116 });
117 117
118 118 $([IPython.events]).on('edit_mode.Cell', function (event, data) {
119 that.edit_mode(that.find_cell_index(data.cell), false);
119 that.handle_edit_mode(that.find_cell_index(data.cell));
120 120 });
121 121
122 122 $([IPython.events]).on('command_mode.Cell', function (event, data) {
@@ -540,31 +540,21 b' var IPython = (function (IPython) {'
540 540 };
541 541
542 542 /**
543 * Make the notebook enter edit mode.
543 * Handle when a cell fires it's edit_mode event.
544 544 *
545 * @method edit_mode
545 * @method handle_edit_mode
546 546 * @param [index] {int} Cell index to select. If no index is provided,
547 547 * the current selected cell is used.
548 * @param [focust_editor] {bool} Should this method focus the cell's editor? Defaults to true.
549 548 **/
550 Notebook.prototype.edit_mode = function (index, focus_editor) {
551 if (focus_editor===undefined) {
552 focus_editor = true;
553 }
554 // Must explictly check for undefined CBool(0) = false.
555 if (index===undefined) {
556 index = this.get_selected_index();
557 } else {
558 this.select(index);
559 }
549 Notebook.prototype.handle_edit_mode = function (index) {
560 550 // Make sure the cell exists.
561 551 var cell = this.get_cell(index);
562 552 if (cell === null) { return; }
563 553
564 554 // Set the cell to edit mode and notify the keyboard manager if this
565 555 // is a change of mode for the notebook as a whole.
566 cell.edit_mode(focus_editor);
567 556 if (this.mode !== 'edit') {
557 cell.edit_mode(focus_editor);
568 558 this.mode = 'edit';
569 559 $([IPython.events]).trigger('edit_mode.Notebook');
570 560 IPython.keyboard_manager.edit_mode();
@@ -572,6 +562,26 b' var IPython = (function (IPython) {'
572 562 };
573 563
574 564 /**
565 * Make a cell enter edit mode.
566 *
567 * @method trigger_edit_mode
568 * @param [index] {int} Cell index to select. If no index is provided,
569 * the current selected cell is used.
570 **/
571 Notebook.prototype.trigger_edit_mode = function (index) {
572 if (index===undefined) {
573 index = this.get_selected_index();
574 }
575 // Make sure the cell exists.
576 var cell = this.get_cell(index);
577 if (cell === null) { return; }
578 if (cell.mode != 'edit') {
579 cell.unrender();
580 cell.focus_editor();
581 }
582 };
583
584 /**
575 585 * Focus the currently selected cell.
576 586 *
577 587 * @method focus_cell
@@ -1458,14 +1468,14 b' var IPython = (function (IPython) {'
1458 1468 // If we are at the end always insert a new cell and return
1459 1469 if (cell_index === (this.ncells()-1)) {
1460 1470 this.insert_cell_below('code');
1461 this.edit_mode(cell_index+1, true);
1471 this.trigger_edit_mode(cell_index+1);
1462 1472 this.scroll_to_bottom();
1463 1473 this.set_dirty(true);
1464 1474 return;
1465 1475 }
1466 1476
1467 1477 this.insert_cell_below('code');
1468 this.edit_mode(cell_index+1, true);
1478 this.trigger_edit_mode(cell_index+1);
1469 1479 this.set_dirty(true);
1470 1480 };
1471 1481
@@ -1484,7 +1494,7 b' var IPython = (function (IPython) {'
1484 1494 // If we are at the end always insert a new cell and return
1485 1495 if (cell_index === (this.ncells()-1)) {
1486 1496 this.insert_cell_below('code');
1487 this.edit_mode(cell_index+1, true);
1497 this.trigger_edit_mode(cell_index+1);
1488 1498 this.scroll_to_bottom();
1489 1499 this.set_dirty(true);
1490 1500 return;
@@ -1960,7 +1970,7 b' var IPython = (function (IPython) {'
1960 1970 console.log('load notebook success');
1961 1971 if (this.ncells() === 0) {
1962 1972 this.insert_cell_below('code');
1963 this.edit_mode(0, true);
1973 this.trigger_edit_mode(0);
1964 1974 } else {
1965 1975 this.select(0);
1966 1976 this.command_mode();
@@ -105,7 +105,10 b' var IPython = (function (IPython) {'
105 105 if (that.selected === false) {
106 106 $([IPython.events]).trigger('select.Cell', {'cell':that});
107 107 }
108 $([IPython.events]).trigger('edit_mode.Cell', {cell: that});
108 var cont = that.unrender();
109 if (cont) {
110 that.focus_editor();
111 }
109 112 });
110 113 };
111 114
General Comments 0
You need to be logged in to leave comments. Login now