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