##// END OF EJS Templates
Merge pull request #5061 from minrk/execute-button...
Brian E. Granger -
r15210:aa3723f7 merge
parent child Browse files
Show More
@@ -1,213 +1,214 b''
1 //----------------------------------------------------------------------------
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2011 The IPython Development Team
2 // Copyright (C) 2011 The IPython Development Team
3 //
3 //
4 // Distributed under the terms of the BSD License. The full license is in
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
6 //----------------------------------------------------------------------------
7
7
8 //============================================================================
8 //============================================================================
9 // ToolBar
9 // ToolBar
10 //============================================================================
10 //============================================================================
11
11
12 var IPython = (function (IPython) {
12 var IPython = (function (IPython) {
13 "use strict";
13 "use strict";
14
14
15 var MainToolBar = function (selector) {
15 var MainToolBar = function (selector) {
16 IPython.ToolBar.apply(this, arguments);
16 IPython.ToolBar.apply(this, arguments);
17 this.construct();
17 this.construct();
18 this.add_celltype_list();
18 this.add_celltype_list();
19 this.add_celltoolbar_list();
19 this.add_celltoolbar_list();
20 this.bind_events();
20 this.bind_events();
21 };
21 };
22
22
23 MainToolBar.prototype = new IPython.ToolBar();
23 MainToolBar.prototype = new IPython.ToolBar();
24
24
25 MainToolBar.prototype.construct = function () {
25 MainToolBar.prototype.construct = function () {
26 this.add_buttons_group([
26 this.add_buttons_group([
27 {
27 {
28 id : 'save_b',
28 id : 'save_b',
29 label : 'Save and Checkpoint',
29 label : 'Save and Checkpoint',
30 icon : 'icon-save',
30 icon : 'icon-save',
31 callback : function () {
31 callback : function () {
32 IPython.notebook.save_checkpoint();
32 IPython.notebook.save_checkpoint();
33 }
33 }
34 }
34 }
35 ]);
35 ]);
36
36
37 this.add_buttons_group([
37 this.add_buttons_group([
38 {
38 {
39 id : 'insert_below_b',
39 id : 'insert_below_b',
40 label : 'Insert Cell Below',
40 label : 'Insert Cell Below',
41 icon : 'icon-plus-sign',
41 icon : 'icon-plus-sign',
42 callback : function () {
42 callback : function () {
43 IPython.notebook.insert_cell_below('code');
43 IPython.notebook.insert_cell_below('code');
44 IPython.notebook.select_next();
44 IPython.notebook.select_next();
45 IPython.notebook.focus_cell();
45 IPython.notebook.focus_cell();
46 }
46 }
47 }
47 }
48 ],'insert_above_below');
48 ],'insert_above_below');
49
49
50 this.add_buttons_group([
50 this.add_buttons_group([
51 {
51 {
52 id : 'cut_b',
52 id : 'cut_b',
53 label : 'Cut Cell',
53 label : 'Cut Cell',
54 icon : 'icon-cut',
54 icon : 'icon-cut',
55 callback : function () {
55 callback : function () {
56 IPython.notebook.cut_cell();
56 IPython.notebook.cut_cell();
57 }
57 }
58 },
58 },
59 {
59 {
60 id : 'copy_b',
60 id : 'copy_b',
61 label : 'Copy Cell',
61 label : 'Copy Cell',
62 icon : 'icon-copy',
62 icon : 'icon-copy',
63 callback : function () {
63 callback : function () {
64 IPython.notebook.copy_cell();
64 IPython.notebook.copy_cell();
65 }
65 }
66 },
66 },
67 {
67 {
68 id : 'paste_b',
68 id : 'paste_b',
69 label : 'Paste Cell Below',
69 label : 'Paste Cell Below',
70 icon : 'icon-paste',
70 icon : 'icon-paste',
71 callback : function () {
71 callback : function () {
72 IPython.notebook.paste_cell_below();
72 IPython.notebook.paste_cell_below();
73 }
73 }
74 }
74 }
75 ],'cut_copy_paste');
75 ],'cut_copy_paste');
76
76
77 this.add_buttons_group([
77 this.add_buttons_group([
78 {
78 {
79 id : 'move_up_b',
79 id : 'move_up_b',
80 label : 'Move Cell Up',
80 label : 'Move Cell Up',
81 icon : 'icon-arrow-up',
81 icon : 'icon-arrow-up',
82 callback : function () {
82 callback : function () {
83 IPython.notebook.move_cell_up();
83 IPython.notebook.move_cell_up();
84 }
84 }
85 },
85 },
86 {
86 {
87 id : 'move_down_b',
87 id : 'move_down_b',
88 label : 'Move Cell Down',
88 label : 'Move Cell Down',
89 icon : 'icon-arrow-down',
89 icon : 'icon-arrow-down',
90 callback : function () {
90 callback : function () {
91 IPython.notebook.move_cell_down();
91 IPython.notebook.move_cell_down();
92 }
92 }
93 }
93 }
94 ],'move_up_down');
94 ],'move_up_down');
95
95
96
96
97 this.add_buttons_group([
97 this.add_buttons_group([
98 {
98 {
99 id : 'run_b',
99 id : 'run_b',
100 label : 'Run Cell',
100 label : 'Run Cell',
101 icon : 'icon-play',
101 icon : 'icon-play',
102 callback : function () {
102 callback : function () {
103 IPython.notebook.execute_cell();
103 // emulate default shift-enter behavior
104 }
104 IPython.notebook.execute_cell_and_select_below();
105 }
105 },
106 },
106 {
107 {
107 id : 'interrupt_b',
108 id : 'interrupt_b',
108 label : 'Interrupt',
109 label : 'Interrupt',
109 icon : 'icon-stop',
110 icon : 'icon-stop',
110 callback : function () {
111 callback : function () {
111 IPython.notebook.session.interrupt_kernel();
112 IPython.notebook.session.interrupt_kernel();
112 }
113 }
113 },
114 },
114 {
115 {
115 id : 'repeat_b',
116 id : 'repeat_b',
116 label : 'Restart Kernel',
117 label : 'Restart Kernel',
117 icon : 'icon-repeat',
118 icon : 'icon-repeat',
118 callback : function () {
119 callback : function () {
119 IPython.notebook.restart_kernel();
120 IPython.notebook.restart_kernel();
120 }
121 }
121 }
122 }
122 ],'run_int');
123 ],'run_int');
123 };
124 };
124
125
125 MainToolBar.prototype.add_celltype_list = function () {
126 MainToolBar.prototype.add_celltype_list = function () {
126 this.element
127 this.element
127 .append($('<select/>')
128 .append($('<select/>')
128 .attr('id','cell_type')
129 .attr('id','cell_type')
129 // .addClass('ui-widget-content')
130 // .addClass('ui-widget-content')
130 .append($('<option/>').attr('value','code').text('Code'))
131 .append($('<option/>').attr('value','code').text('Code'))
131 .append($('<option/>').attr('value','markdown').text('Markdown'))
132 .append($('<option/>').attr('value','markdown').text('Markdown'))
132 .append($('<option/>').attr('value','raw').text('Raw NBConvert'))
133 .append($('<option/>').attr('value','raw').text('Raw NBConvert'))
133 .append($('<option/>').attr('value','heading1').text('Heading 1'))
134 .append($('<option/>').attr('value','heading1').text('Heading 1'))
134 .append($('<option/>').attr('value','heading2').text('Heading 2'))
135 .append($('<option/>').attr('value','heading2').text('Heading 2'))
135 .append($('<option/>').attr('value','heading3').text('Heading 3'))
136 .append($('<option/>').attr('value','heading3').text('Heading 3'))
136 .append($('<option/>').attr('value','heading4').text('Heading 4'))
137 .append($('<option/>').attr('value','heading4').text('Heading 4'))
137 .append($('<option/>').attr('value','heading5').text('Heading 5'))
138 .append($('<option/>').attr('value','heading5').text('Heading 5'))
138 .append($('<option/>').attr('value','heading6').text('Heading 6'))
139 .append($('<option/>').attr('value','heading6').text('Heading 6'))
139 );
140 );
140 };
141 };
141
142
142
143
143 MainToolBar.prototype.add_celltoolbar_list = function () {
144 MainToolBar.prototype.add_celltoolbar_list = function () {
144 var label = $('<span/>').addClass("navbar-text").text('Cell Toolbar:');
145 var label = $('<span/>').addClass("navbar-text").text('Cell Toolbar:');
145 var select = $('<select/>')
146 var select = $('<select/>')
146 // .addClass('ui-widget-content')
147 // .addClass('ui-widget-content')
147 .attr('id', 'ctb_select')
148 .attr('id', 'ctb_select')
148 .append($('<option/>').attr('value', '').text('None'));
149 .append($('<option/>').attr('value', '').text('None'));
149 this.element.append(label).append(select);
150 this.element.append(label).append(select);
150 select.change(function() {
151 select.change(function() {
151 var val = $(this).val()
152 var val = $(this).val()
152 if (val =='') {
153 if (val =='') {
153 IPython.CellToolbar.global_hide();
154 IPython.CellToolbar.global_hide();
154 delete IPython.notebook.metadata.celltoolbar;
155 delete IPython.notebook.metadata.celltoolbar;
155 } else {
156 } else {
156 IPython.CellToolbar.global_show();
157 IPython.CellToolbar.global_show();
157 IPython.CellToolbar.activate_preset(val);
158 IPython.CellToolbar.activate_preset(val);
158 IPython.notebook.metadata.celltoolbar = val;
159 IPython.notebook.metadata.celltoolbar = val;
159 }
160 }
160 });
161 });
161 // Setup the currently registered presets.
162 // Setup the currently registered presets.
162 var presets = IPython.CellToolbar.list_presets();
163 var presets = IPython.CellToolbar.list_presets();
163 for (var i=0; i<presets.length; i++) {
164 for (var i=0; i<presets.length; i++) {
164 var name = presets[i];
165 var name = presets[i];
165 select.append($('<option/>').attr('value', name).text(name));
166 select.append($('<option/>').attr('value', name).text(name));
166 }
167 }
167 // Setup future preset registrations.
168 // Setup future preset registrations.
168 $([IPython.events]).on('preset_added.CellToolbar', function (event, data) {
169 $([IPython.events]).on('preset_added.CellToolbar', function (event, data) {
169 var name = data.name;
170 var name = data.name;
170 select.append($('<option/>').attr('value', name).text(name));
171 select.append($('<option/>').attr('value', name).text(name));
171 });
172 });
172 };
173 };
173
174
174
175
175 MainToolBar.prototype.bind_events = function () {
176 MainToolBar.prototype.bind_events = function () {
176 var that = this;
177 var that = this;
177
178
178 this.element.find('#cell_type').change(function () {
179 this.element.find('#cell_type').change(function () {
179 var cell_type = $(this).val();
180 var cell_type = $(this).val();
180 if (cell_type === 'code') {
181 if (cell_type === 'code') {
181 IPython.notebook.to_code();
182 IPython.notebook.to_code();
182 } else if (cell_type === 'markdown') {
183 } else if (cell_type === 'markdown') {
183 IPython.notebook.to_markdown();
184 IPython.notebook.to_markdown();
184 } else if (cell_type === 'raw') {
185 } else if (cell_type === 'raw') {
185 IPython.notebook.to_raw();
186 IPython.notebook.to_raw();
186 } else if (cell_type === 'heading1') {
187 } else if (cell_type === 'heading1') {
187 IPython.notebook.to_heading(undefined, 1);
188 IPython.notebook.to_heading(undefined, 1);
188 } else if (cell_type === 'heading2') {
189 } else if (cell_type === 'heading2') {
189 IPython.notebook.to_heading(undefined, 2);
190 IPython.notebook.to_heading(undefined, 2);
190 } else if (cell_type === 'heading3') {
191 } else if (cell_type === 'heading3') {
191 IPython.notebook.to_heading(undefined, 3);
192 IPython.notebook.to_heading(undefined, 3);
192 } else if (cell_type === 'heading4') {
193 } else if (cell_type === 'heading4') {
193 IPython.notebook.to_heading(undefined, 4);
194 IPython.notebook.to_heading(undefined, 4);
194 } else if (cell_type === 'heading5') {
195 } else if (cell_type === 'heading5') {
195 IPython.notebook.to_heading(undefined, 5);
196 IPython.notebook.to_heading(undefined, 5);
196 } else if (cell_type === 'heading6') {
197 } else if (cell_type === 'heading6') {
197 IPython.notebook.to_heading(undefined, 6);
198 IPython.notebook.to_heading(undefined, 6);
198 }
199 }
199 });
200 });
200 $([IPython.events]).on('selected_cell_type_changed.Notebook', function (event, data) {
201 $([IPython.events]).on('selected_cell_type_changed.Notebook', function (event, data) {
201 if (data.cell_type === 'heading') {
202 if (data.cell_type === 'heading') {
202 that.element.find('#cell_type').val(data.cell_type+data.level);
203 that.element.find('#cell_type').val(data.cell_type+data.level);
203 } else {
204 } else {
204 that.element.find('#cell_type').val(data.cell_type);
205 that.element.find('#cell_type').val(data.cell_type);
205 }
206 }
206 });
207 });
207 };
208 };
208
209
209 IPython.MainToolBar = MainToolBar;
210 IPython.MainToolBar = MainToolBar;
210
211
211 return IPython;
212 return IPython;
212
213
213 }(IPython));
214 }(IPython));
General Comments 0
You need to be logged in to leave comments. Login now