##// END OF EJS Templates
Fixing execution related things....
Brian E. Granger -
Show More
@@ -25,7 +25,8 b' var IPython = (function (IPython) {'
25 this.code_mirror = CodeMirror(input_area.get(0), {
25 this.code_mirror = CodeMirror(input_area.get(0), {
26 indentUnit : 4,
26 indentUnit : 4,
27 enterMode : 'flat',
27 enterMode : 'flat',
28 tabMode: 'shift'
28 tabMode: 'shift',
29 onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this)
29 });
30 });
30 input.append(input_area);
31 input.append(input_area);
31 var output = $('<div></div>').addClass('output vbox');
32 var output = $('<div></div>').addClass('output vbox');
@@ -35,6 +36,18 b' 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 CodeCell.prototype.select = function () {
51 CodeCell.prototype.select = function () {
39 IPython.Cell.prototype.select.apply(this);
52 IPython.Cell.prototype.select.apply(this);
40 this.code_mirror.focus();
53 this.code_mirror.focus();
@@ -57,42 +57,9 b' var IPython = (function (IPython) {'
57 that.select_next();
57 that.select_next();
58 };
58 };
59 } else if (event.which === 13 && event.shiftKey) {
59 } else if (event.which === 13 && event.shiftKey) {
60 // The focus is not quite working here.
60 console.log('Entering execute');
61 var cell = that.selected_cell();
61 that.execute_selected_cell(true);
62 var cell_index = that.find_cell_index(cell);
62 console.log('Leaving execute');
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 };
96 };
63 };
97 });
64 });
98
65
@@ -489,6 +456,54 b' 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 // Persistance and loading
507 // Persistance and loading
493
508
494
509
@@ -149,10 +149,10 b' var IPython = (function (IPython) {'
149 IPython.notebook.code_to_text();
149 IPython.notebook.code_to_text();
150 });
150 });
151 this.content.find('#run_selected_cell').click(function () {
151 this.content.find('#run_selected_cell').click(function () {
152 alert("Not Implemented");
152 IPython.notebook.execute_selected_cell();
153 });
153 });
154 this.content.find('#run_all_cells').click(function () {
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