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