Show More
@@ -0,0 +1,182 b'' | |||
|
1 | //---------------------------------------------------------------------------- | |
|
2 | // Copyright (C) 2008 The IPython Development Team | |
|
3 | // | |
|
4 | // Distributed under the terms of the BSD License. The full license is in | |
|
5 | // the file COPYING, distributed as part of this software. | |
|
6 | //---------------------------------------------------------------------------- | |
|
7 | ||
|
8 | //============================================================================ | |
|
9 | // ToolBar | |
|
10 | //============================================================================ | |
|
11 | ||
|
12 | var IPython = (function (IPython) { | |
|
13 | ||
|
14 | var MainToolBar = function (selector) { | |
|
15 | this.selector = selector; | |
|
16 | if (this.selector !== undefined) { | |
|
17 | IPython.Cell.apply(this, arguments); | |
|
18 | // move the rest ouside | |
|
19 | this.construct(); | |
|
20 | this.addDropDownList(); | |
|
21 | this.bind_events(); | |
|
22 | } | |
|
23 | }; | |
|
24 | ||
|
25 | MainToolBar.prototype = new IPython.ToolBar(); | |
|
26 | ||
|
27 | MainToolBar.prototype.addDropDownList = function() { | |
|
28 | var select = $(this.selector) | |
|
29 | .append($('<select/>') | |
|
30 | .attr('id','cell_type') | |
|
31 | .addClass('ui-widget ui-widget-content') | |
|
32 | .append($('<option/>').attr('value','code').text('Code')) | |
|
33 | .append($('<option/>').attr('value','markdown').text('Markdown')) | |
|
34 | .append($('<option/>').attr('value','raw').text('Raw Text')) | |
|
35 | .append($('<option/>').attr('value','heading1').text('Heading 1')) | |
|
36 | .append($('<option/>').attr('value','heading2').text('Heading 2')) | |
|
37 | .append($('<option/>').attr('value','heading3').text('Heading 3')) | |
|
38 | .append($('<option/>').attr('value','heading4').text('Heading 4')) | |
|
39 | .append($('<option/>').attr('value','heading5').text('Heading 5')) | |
|
40 | .append($('<option/>').attr('value','heading6').text('Heading 6')) | |
|
41 | .append($('<option/>').attr('value','heading7').text('Heading 7')) | |
|
42 | .append($('<option/>').attr('value','heading8').text('Heading 8')) | |
|
43 | ); | |
|
44 | } | |
|
45 | ||
|
46 | MainToolBar.prototype.construct = function() { | |
|
47 | this.addButtonsGroup([ | |
|
48 | { | |
|
49 | 'id':'save_b', | |
|
50 | 'label':'Save', | |
|
51 | 'icon':'ui-icon-disk', | |
|
52 | 'callback':function(){ | |
|
53 | IPython.notebook.save_notebook(); | |
|
54 | }, | |
|
55 | }, | |
|
56 | ]); | |
|
57 | this.addButtonsGroup([ | |
|
58 | { | |
|
59 | 'id':'cut_b', | |
|
60 | 'label':'Cut Cell', | |
|
61 | 'icon':'ui-icon-scissors', | |
|
62 | 'callback':function(){ | |
|
63 | IPython.notebook.cut_cell(); | |
|
64 | }, | |
|
65 | }, | |
|
66 | { | |
|
67 | 'id':'copy_b', | |
|
68 | 'label':'Copy Cell', | |
|
69 | 'icon':'ui-icon-copy', | |
|
70 | 'callback':function(){ | |
|
71 | IPython.notebook.copy_cell(); | |
|
72 | }, | |
|
73 | }, | |
|
74 | { | |
|
75 | 'id':'paste_b', | |
|
76 | 'label':'Paste Cell', | |
|
77 | 'icon':'ui-icon-clipboard', | |
|
78 | 'callback':function(){ | |
|
79 | IPython.notebook.paste_cell(); | |
|
80 | }, | |
|
81 | }, | |
|
82 | ],'cut_copy_paste'); | |
|
83 | ||
|
84 | this.addButtonsGroup([ | |
|
85 | { | |
|
86 | 'id':'move_up_b', | |
|
87 | 'label':'Move Cell Up', | |
|
88 | 'icon':'ui-icon-arrowthick-1-n', | |
|
89 | 'callback':function(){ | |
|
90 | IPython.notebook.move_cell_up(); | |
|
91 | }, | |
|
92 | }, | |
|
93 | { | |
|
94 | 'id':'move_down_b', | |
|
95 | 'label':'Move Cell Down', | |
|
96 | 'icon':'ui-icon-arrowthick-1-s', | |
|
97 | 'callback':function(){ | |
|
98 | IPython.notebook.move_cell_down(); | |
|
99 | }, | |
|
100 | }, | |
|
101 | ],'move_up_down'); | |
|
102 | ||
|
103 | this.addButtonsGroup([ | |
|
104 | { | |
|
105 | 'id':'insert_above_b', | |
|
106 | 'label':'Insert Cell Above', | |
|
107 | 'icon':'ui-icon-arrowthickstop-1-n', | |
|
108 | 'callback':function(){ | |
|
109 | IPython.notebook.insert_cell_above('code'); | |
|
110 | }, | |
|
111 | }, | |
|
112 | { | |
|
113 | 'id':'insert_below_b', | |
|
114 | 'label':'Insert Cell Below', | |
|
115 | 'icon':'ui-icon-arrowthickstop-1-s', | |
|
116 | 'callback':function(){ | |
|
117 | IPython.notebook.insert_cell_below('code'); | |
|
118 | }, | |
|
119 | }, | |
|
120 | ],'insert_above_below'); | |
|
121 | ||
|
122 | this.addButtonsGroup([ | |
|
123 | { | |
|
124 | 'id':'run_b', | |
|
125 | 'label':'Run Cell', | |
|
126 | 'icon':'ui-icon-play', | |
|
127 | 'callback':function(){ | |
|
128 | IPython.notebook.execute_selected_cell(); | |
|
129 | }, | |
|
130 | }, | |
|
131 | { | |
|
132 | 'id':'interrupt_b', | |
|
133 | 'label':'Interrupt', | |
|
134 | 'icon':'ui-icon-stop', | |
|
135 | 'callback':function(){ | |
|
136 | IPython.notebook.kernel.interrupt(); | |
|
137 | }, | |
|
138 | }, | |
|
139 | ],'run_int'); | |
|
140 | ||
|
141 | ||
|
142 | } | |
|
143 | ||
|
144 | MainToolBar.prototype.bind_events = function () { | |
|
145 | var that = this; | |
|
146 | ||
|
147 | this.element.find('#cell_type').change(function () { | |
|
148 | var cell_type = $(this).val(); | |
|
149 | if (cell_type === 'code') { | |
|
150 | IPython.notebook.to_code(); | |
|
151 | } else if (cell_type === 'markdown') { | |
|
152 | IPython.notebook.to_markdown(); | |
|
153 | } else if (cell_type === 'raw') { | |
|
154 | IPython.notebook.to_raw(); | |
|
155 | } else if (cell_type === 'heading1') { | |
|
156 | IPython.notebook.to_heading(undefined, 1); | |
|
157 | } else if (cell_type === 'heading2') { | |
|
158 | IPython.notebook.to_heading(undefined, 2); | |
|
159 | } else if (cell_type === 'heading3') { | |
|
160 | IPython.notebook.to_heading(undefined, 3); | |
|
161 | } else if (cell_type === 'heading4') { | |
|
162 | IPython.notebook.to_heading(undefined, 4); | |
|
163 | } else if (cell_type === 'heading5') { | |
|
164 | IPython.notebook.to_heading(undefined, 5); | |
|
165 | } else if (cell_type === 'heading6') { | |
|
166 | IPython.notebook.to_heading(undefined, 6); | |
|
167 | }; | |
|
168 | }); | |
|
169 | $([IPython.events]).on('selected_cell_type_changed.Notebook', function (event, data) { | |
|
170 | if (data.cell_type === 'heading') { | |
|
171 | that.element.find('#cell_type').val(data.cell_type+data.level); | |
|
172 | } else { | |
|
173 | that.element.find('#cell_type').val(data.cell_type); | |
|
174 | } | |
|
175 | }); | |
|
176 | }; | |
|
177 | ||
|
178 | IPython.MainToolBar = MainToolBar; | |
|
179 | ||
|
180 | return IPython; | |
|
181 | ||
|
182 | }(IPython)); |
General Comments 0
You need to be logged in to leave comments.
Login now