Show More
@@ -1,148 +1,148 | |||||
1 | //---------------------------------------------------------------------------- |
|
1 | //---------------------------------------------------------------------------- | |
2 | // Copyright (C) 2008-2011 The IPython Development Team |
|
2 | // Copyright (C) 2008-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 ToolBar = function (selector) { |
|
14 | var ToolBar = function (selector) { | |
15 | this.selector = selector; |
|
15 | this.selector = selector; | |
16 | if (this.selector !== undefined) { |
|
16 | if (this.selector !== undefined) { | |
17 | this.element = $(selector); |
|
17 | this.element = $(selector); | |
18 | this.style(); |
|
18 | this.style(); | |
19 | this.bind_events(); |
|
19 | this.bind_events(); | |
20 | } |
|
20 | } | |
21 | }; |
|
21 | }; | |
22 |
|
22 | |||
23 |
|
23 | |||
24 | ToolBar.prototype.style = function () { |
|
24 | ToolBar.prototype.style = function () { | |
25 | this.element.addClass('border-box-sizing'); |
|
25 | this.element.addClass('border-box-sizing'); | |
26 | this.element.find('#cell_type').addClass('ui-widget ui-widget-content'); |
|
26 | this.element.find('#cell_type').addClass('ui-widget ui-widget-content'); | |
27 | this.element.find('#save_b').button({ |
|
27 | this.element.find('#save_b').button({ | |
28 | icons : {primary: 'ui-icon-disk'}, |
|
28 | icons : {primary: 'ui-icon-disk'}, | |
29 | text : false |
|
29 | text : false | |
30 | }); |
|
30 | }); | |
31 | this.element.find('#cut_b').button({ |
|
31 | this.element.find('#cut_b').button({ | |
32 | icons: {primary: 'ui-icon-scissors'}, |
|
32 | icons: {primary: 'ui-icon-scissors'}, | |
33 | text : false |
|
33 | text : false | |
34 | }); |
|
34 | }); | |
35 | this.element.find('#copy_b').button({ |
|
35 | this.element.find('#copy_b').button({ | |
36 | icons: {primary: 'ui-icon-copy'}, |
|
36 | icons: {primary: 'ui-icon-copy'}, | |
37 | text : false |
|
37 | text : false | |
38 | }); |
|
38 | }); | |
39 | this.element.find('#paste_b').button({ |
|
39 | this.element.find('#paste_b').button({ | |
40 | icons: {primary: 'ui-icon-clipboard'}, |
|
40 | icons: {primary: 'ui-icon-clipboard'}, | |
41 | text : false |
|
41 | text : false | |
42 | }); |
|
42 | }); | |
43 | this.element.find('#cut_copy_paste').buttonset(); |
|
43 | this.element.find('#cut_copy_paste').buttonset(); | |
44 | this.element.find('#move_up_b').button({ |
|
44 | this.element.find('#move_up_b').button({ | |
45 | icons: {primary: 'ui-icon-arrowthick-1-n'}, |
|
45 | icons: {primary: 'ui-icon-arrowthick-1-n'}, | |
46 | text : false |
|
46 | text : false | |
47 | }); |
|
47 | }); | |
48 | this.element.find('#move_down_b').button({ |
|
48 | this.element.find('#move_down_b').button({ | |
49 | icons: {primary: 'ui-icon-arrowthick-1-s'}, |
|
49 | icons: {primary: 'ui-icon-arrowthick-1-s'}, | |
50 | text : false |
|
50 | text : false | |
51 | }); |
|
51 | }); | |
52 | this.element.find('#move_up_down').buttonset(); |
|
52 | this.element.find('#move_up_down').buttonset(); | |
53 | this.element.find('#insert_above_b').button({ |
|
53 | this.element.find('#insert_above_b').button({ | |
54 | icons: {primary: 'ui-icon-arrowthickstop-1-n'}, |
|
54 | icons: {primary: 'ui-icon-arrowthickstop-1-n'}, | |
55 | text : false |
|
55 | text : false | |
56 | }); |
|
56 | }); | |
57 | this.element.find('#insert_below_b').button({ |
|
57 | this.element.find('#insert_below_b').button({ | |
58 | icons: {primary: 'ui-icon-arrowthickstop-1-s'}, |
|
58 | icons: {primary: 'ui-icon-arrowthickstop-1-s'}, | |
59 | text : false |
|
59 | text : false | |
60 | }); |
|
60 | }); | |
61 | this.element.find('#insert_above_below').buttonset(); |
|
61 | this.element.find('#insert_above_below').buttonset(); | |
62 | this.element.find('#run_b').button({ |
|
62 | this.element.find('#run_b').button({ | |
63 | icons: {primary: 'ui-icon-play'}, |
|
63 | icons: {primary: 'ui-icon-play'}, | |
64 | text : false |
|
64 | text : false | |
65 | }); |
|
65 | }); | |
66 | this.element.find('#interrupt_b').button({ |
|
66 | this.element.find('#interrupt_b').button({ | |
67 | icons: {primary: 'ui-icon-stop'}, |
|
67 | icons: {primary: 'ui-icon-stop'}, | |
68 | text : false |
|
68 | text : false | |
69 | }); |
|
69 | }); | |
70 | this.element.find('#run_int').buttonset(); |
|
70 | this.element.find('#run_int').buttonset(); | |
71 | }; |
|
71 | }; | |
72 |
|
72 | |||
73 |
|
73 | |||
74 | ToolBar.prototype.bind_events = function () { |
|
74 | ToolBar.prototype.bind_events = function () { | |
75 | var that = this; |
|
75 | var that = this; | |
76 | this.element.find('#save_b').click(function () { |
|
76 | this.element.find('#save_b').click(function () { | |
77 | IPython.notebook.save_notebook(); |
|
77 | IPython.notebook.save_notebook(); | |
78 | }); |
|
78 | }); | |
79 | this.element.find('#cut_b').click(function () { |
|
79 | this.element.find('#cut_b').click(function () { | |
80 | IPython.notebook.cut_cell(); |
|
80 | IPython.notebook.cut_cell(); | |
81 | }); |
|
81 | }); | |
82 | this.element.find('#copy_b').click(function () { |
|
82 | this.element.find('#copy_b').click(function () { | |
83 | IPython.notebook.copy_cell(); |
|
83 | IPython.notebook.copy_cell(); | |
84 | }); |
|
84 | }); | |
85 | this.element.find('#paste_b').click(function () { |
|
85 | this.element.find('#paste_b').click(function () { | |
86 | IPython.notebook.paste_cell(); |
|
86 | IPython.notebook.paste_cell(); | |
87 | }); |
|
87 | }); | |
88 | this.element.find('#move_up_b').click(function () { |
|
88 | this.element.find('#move_up_b').click(function () { | |
89 | IPython.notebook.move_cell_up(); |
|
89 | IPython.notebook.move_cell_up(); | |
90 | }); |
|
90 | }); | |
91 | this.element.find('#move_down_b').click(function () { |
|
91 | this.element.find('#move_down_b').click(function () { | |
92 | IPython.notebook.move_cell_down(); |
|
92 | IPython.notebook.move_cell_down(); | |
93 | }); |
|
93 | }); | |
94 | this.element.find('#insert_above_b').click(function () { |
|
94 | this.element.find('#insert_above_b').click(function () { | |
95 | IPython.notebook.insert_cell_above('code'); |
|
95 | IPython.notebook.insert_cell_above('code'); | |
96 | }); |
|
96 | }); | |
97 | this.element.find('#insert_below_b').click(function () { |
|
97 | this.element.find('#insert_below_b').click(function () { | |
98 | IPython.notebook.insert_cell_below('code'); |
|
98 | IPython.notebook.insert_cell_below('code'); | |
99 | }); |
|
99 | }); | |
100 | this.element.find('#run_b').click(function () { |
|
100 | this.element.find('#run_b').click(function () { | |
101 | IPython.notebook.execute_selected_cell(); |
|
101 | IPython.notebook.execute_selected_cell(); | |
102 | }); |
|
102 | }); | |
103 | this.element.find('#interrupt_b').click(function () { |
|
103 | this.element.find('#interrupt_b').click(function () { | |
104 | IPython.notebook.kernel.interrupt(); |
|
104 | IPython.notebook.kernel.interrupt(); | |
105 | }); |
|
105 | }); | |
106 | this.element.find('#cell_type').change(function () { |
|
106 | this.element.find('#cell_type').change(function () { | |
107 | var cell_type = $(this).val(); |
|
107 | var cell_type = $(this).val(); | |
108 | if (cell_type === 'code') { |
|
108 | if (cell_type === 'code') { | |
109 | IPython.notebook.to_code(); |
|
109 | IPython.notebook.to_code(); | |
110 | } else if (cell_type === 'markdown') { |
|
110 | } else if (cell_type === 'markdown') { | |
111 | IPython.notebook.to_markdown(); |
|
111 | IPython.notebook.to_markdown(); | |
112 | } else if (cell_type === 'plaintext') { |
|
112 | } else if (cell_type === 'plaintext') { | |
113 | IPython.notebook.to_plaintext(); |
|
113 | IPython.notebook.to_plaintext(); | |
114 | } else if (cell_type === 'heading1') { |
|
114 | } else if (cell_type === 'heading1') { | |
115 | IPython.notebook.to_heading(undefined, 1); |
|
115 | IPython.notebook.to_heading(undefined, 1); | |
116 | } else if (cell_type === 'heading2') { |
|
116 | } else if (cell_type === 'heading2') { | |
117 | IPython.notebook.to_heading(undefined, 2); |
|
117 | IPython.notebook.to_heading(undefined, 2); | |
118 | } else if (cell_type === 'heading3') { |
|
118 | } else if (cell_type === 'heading3') { | |
119 | IPython.notebook.to_heading(undefined, 3); |
|
119 | IPython.notebook.to_heading(undefined, 3); | |
120 | } else if (cell_type === 'heading4') { |
|
120 | } else if (cell_type === 'heading4') { | |
121 | IPython.notebook.to_heading(undefined, 4); |
|
121 | IPython.notebook.to_heading(undefined, 4); | |
122 | } else if (cell_type === 'heading5') { |
|
122 | } else if (cell_type === 'heading5') { | |
123 | IPython.notebook.to_heading(undefined, 5); |
|
123 | IPython.notebook.to_heading(undefined, 5); | |
124 | } else if (cell_type === 'heading6') { |
|
124 | } else if (cell_type === 'heading6') { | |
125 | IPython.notebook.to_heading(undefined, 6); |
|
125 | IPython.notebook.to_heading(undefined, 6); | |
126 | }; |
|
126 | }; | |
127 | }); |
|
127 | }); | |
128 | $([IPython.events]).on('selected_cell_type_changed', function (event, data) { |
|
128 | $([IPython.events]).on('selected_cell_type_changed.Notebook', function (event, data) { | |
129 | if (data.cell_type === 'heading') { |
|
129 | if (data.cell_type === 'heading') { | |
130 | that.element.find('#cell_type').val(data.cell_type+data.level); |
|
130 | that.element.find('#cell_type').val(data.cell_type+data.level); | |
131 | } else { |
|
131 | } else { | |
132 | that.element.find('#cell_type').val(data.cell_type); |
|
132 | that.element.find('#cell_type').val(data.cell_type); | |
133 | } |
|
133 | } | |
134 | }); |
|
134 | }); | |
135 | }; |
|
135 | }; | |
136 |
|
136 | |||
137 |
|
137 | |||
138 | ToolBar.prototype.toggle = function () { |
|
138 | ToolBar.prototype.toggle = function () { | |
139 | this.element.toggle(); |
|
139 | this.element.toggle(); | |
140 | IPython.layout_manager.do_resize(); |
|
140 | IPython.layout_manager.do_resize(); | |
141 | }; |
|
141 | }; | |
142 |
|
142 | |||
143 |
|
143 | |||
144 | IPython.ToolBar = ToolBar; |
|
144 | IPython.ToolBar = ToolBar; | |
145 |
|
145 | |||
146 | return IPython; |
|
146 | return IPython; | |
147 |
|
147 | |||
148 | }(IPython)); |
|
148 | }(IPython)); |
General Comments 0
You need to be logged in to leave comments.
Login now