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