Show More
@@ -25,7 +25,8 var IPython = (function (IPython) { | |||
|
25 | 25 | this.code_mirror = CodeMirror(input_area.get(0), { |
|
26 | 26 | indentUnit : 4, |
|
27 | 27 | enterMode : 'flat', |
|
28 | tabMode: 'shift' | |
|
28 | tabMode: 'shift', | |
|
29 | onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this) | |
|
29 | 30 | }); |
|
30 | 31 | input.append(input_area); |
|
31 | 32 | var output = $('<div></div>').addClass('output vbox'); |
@@ -35,6 +36,18 var IPython = (function (IPython) { | |||
|
35 | 36 | }; |
|
36 | 37 | |
|
37 | 38 | |
|
39 | CodeCell.prototype.handle_codemirror_keyevent = function (editor, event) { | |
|
40 | // This method gets called in CodeMirror's onKeyDown/onKeyPress handlers and | |
|
41 | // is used to provide custom key handling. Its return value is used to determine | |
|
42 | // if CodeMirror should ignore the event: true = ignore, false = don't ignore. | |
|
43 | if (event.keyCode === 13 && event.shiftKey) { | |
|
44 | // Always ignore shift-enter in CodeMirror as we handle it. | |
|
45 | return true; | |
|
46 | } else { | |
|
47 | return false; | |
|
48 | }; | |
|
49 | }; | |
|
50 | ||
|
38 | 51 | CodeCell.prototype.select = function () { |
|
39 | 52 | IPython.Cell.prototype.select.apply(this); |
|
40 | 53 | this.code_mirror.focus(); |
@@ -57,42 +57,9 var IPython = (function (IPython) { | |||
|
57 | 57 | that.select_next(); |
|
58 | 58 | }; |
|
59 | 59 | } else if (event.which === 13 && event.shiftKey) { |
|
60 | // The focus is not quite working here. | |
|
61 |
|
|
|
62 | var cell_index = that.find_cell_index(cell); | |
|
63 | // TODO: the logic here needs to be moved into appropriate | |
|
64 | // methods of Notebook. | |
|
65 | if (cell instanceof IPython.CodeCell) { | |
|
66 | event.preventDefault(); | |
|
67 | cell.clear_output(); | |
|
68 | var code = cell.get_code(); | |
|
69 | if (that.notebook_load_re.test(code)) { | |
|
70 | var code_parts = code.split(' '); | |
|
71 | if (code_parts.length === 3) { | |
|
72 | that.load_notebook(code_parts[2]); | |
|
73 | }; | |
|
74 | } else if (that.notebook_save_re.test(code)) { | |
|
75 | var code_parts = code.split(' '); | |
|
76 | if (code_parts.length === 3) { | |
|
77 | that.save_notebook(code_parts[2]); | |
|
78 | } else { | |
|
79 | that.save_notebook() | |
|
80 | }; | |
|
81 | } else { | |
|
82 | var msg_id = that.kernel.execute(cell.get_code()); | |
|
83 | that.msg_cell_map[msg_id] = cell.cell_id; | |
|
84 | }; | |
|
85 | } else if (cell instanceof IPython.TextCell) { | |
|
86 | event.preventDefault(); | |
|
87 | cell.render(); | |
|
88 | } | |
|
89 | if (cell_index === (that.ncells()-1)) { | |
|
90 | that.insert_code_cell_after(); | |
|
91 | // If we are adding a new cell at the end, scroll down to show it. | |
|
92 | that.scroll_to_bottom(); | |
|
93 | } else { | |
|
94 | that.select(cell_index+1); | |
|
95 | }; | |
|
60 | console.log('Entering execute'); | |
|
61 | that.execute_selected_cell(true); | |
|
62 | console.log('Leaving execute'); | |
|
96 | 63 | }; |
|
97 | 64 | }); |
|
98 | 65 | |
@@ -489,6 +456,54 var IPython = (function (IPython) { | |||
|
489 | 456 | }; |
|
490 | 457 | |
|
491 | 458 | |
|
459 | Notebook.prototype.execute_selected_cell = function (add_new) { | |
|
460 | if (add_new === undefined) {add_new = true;}; | |
|
461 | var that = this; | |
|
462 | var cell = that.selected_cell(); | |
|
463 | var cell_index = that.find_cell_index(cell); | |
|
464 | // TODO: the logic here needs to be moved into appropriate | |
|
465 | // methods of Notebook. | |
|
466 | if (cell instanceof IPython.CodeCell) { | |
|
467 | cell.clear_output(); | |
|
468 | var code = cell.get_code(); | |
|
469 | if (that.notebook_load_re.test(code)) { | |
|
470 | var code_parts = code.split(' '); | |
|
471 | if (code_parts.length === 3) { | |
|
472 | that.load_notebook(code_parts[2]); | |
|
473 | }; | |
|
474 | } else if (that.notebook_save_re.test(code)) { | |
|
475 | var code_parts = code.split(' '); | |
|
476 | if (code_parts.length === 3) { | |
|
477 | that.save_notebook(code_parts[2]); | |
|
478 | } else { | |
|
479 | that.save_notebook() | |
|
480 | }; | |
|
481 | } else { | |
|
482 | var msg_id = that.kernel.execute(cell.get_code()); | |
|
483 | that.msg_cell_map[msg_id] = cell.cell_id; | |
|
484 | }; | |
|
485 | } else if (cell instanceof IPython.TextCell) { | |
|
486 | cell.render(); | |
|
487 | } | |
|
488 | if ((cell_index === (that.ncells()-1)) && add_new) { | |
|
489 | that.insert_code_cell_after(); | |
|
490 | // If we are adding a new cell at the end, scroll down to show it. | |
|
491 | that.scroll_to_bottom(); | |
|
492 | } else { | |
|
493 | that.select(cell_index+1); | |
|
494 | }; | |
|
495 | }; | |
|
496 | ||
|
497 | ||
|
498 | Notebook.prototype.execute_all_cells = function () { | |
|
499 | var ncells = this.ncells(); | |
|
500 | for (var i=0; i<ncells; i++) { | |
|
501 | this.select(i); | |
|
502 | this.execute_selected_cell(false); | |
|
503 | }; | |
|
504 | this.scroll_to_bottom(); | |
|
505 | }; | |
|
506 | ||
|
492 | 507 | // Persistance and loading |
|
493 | 508 | |
|
494 | 509 |
@@ -149,10 +149,10 var IPython = (function (IPython) { | |||
|
149 | 149 | IPython.notebook.code_to_text(); |
|
150 | 150 | }); |
|
151 | 151 | this.content.find('#run_selected_cell').click(function () { |
|
152 | alert("Not Implemented"); | |
|
152 | IPython.notebook.execute_selected_cell(); | |
|
153 | 153 | }); |
|
154 | 154 | this.content.find('#run_all_cells').click(function () { |
|
155 | alert("Not Implemented"); | |
|
155 | IPython.notebook.execute_all_cells(); | |
|
156 | 156 | }); |
|
157 | 157 | }; |
|
158 | 158 |
General Comments 0
You need to be logged in to leave comments.
Login now