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