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