Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50654 views
1
//----------------------------------------------------------------------------
2
// Copyright (C) 2011 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
"use strict";
14
15
var MainToolBar = function (selector) {
16
IPython.ToolBar.apply(this, arguments);
17
this.construct();
18
this.add_celltype_list();
19
this.add_celltoolbar_list();
20
this.bind_events();
21
};
22
23
MainToolBar.prototype = new IPython.ToolBar();
24
25
MainToolBar.prototype.construct = function () {
26
this.add_buttons_group([
27
{
28
id : 'save_b',
29
label : 'Save and Checkpoint',
30
icon : 'icon-save',
31
callback : function () {
32
IPython.notebook.save_checkpoint();
33
}
34
}
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
IPython.notebook.select_next();
45
IPython.notebook.focus_cell();
46
}
47
}
48
],'insert_above_below');
49
50
this.add_buttons_group([
51
{
52
id : 'cut_b',
53
label : 'Cut Cell',
54
icon : 'icon-cut',
55
callback : function () {
56
IPython.notebook.cut_cell();
57
}
58
},
59
{
60
id : 'copy_b',
61
label : 'Copy Cell',
62
icon : 'icon-copy',
63
callback : function () {
64
IPython.notebook.copy_cell();
65
}
66
},
67
{
68
id : 'paste_b',
69
label : 'Paste Cell Below',
70
icon : 'icon-paste',
71
callback : function () {
72
IPython.notebook.paste_cell_below();
73
}
74
}
75
],'cut_copy_paste');
76
77
this.add_buttons_group([
78
{
79
id : 'move_up_b',
80
label : 'Move Cell Up',
81
icon : 'icon-arrow-up',
82
callback : function () {
83
IPython.notebook.move_cell_up();
84
}
85
},
86
{
87
id : 'move_down_b',
88
label : 'Move Cell Down',
89
icon : 'icon-arrow-down',
90
callback : function () {
91
IPython.notebook.move_cell_down();
92
}
93
}
94
],'move_up_down');
95
96
97
this.add_buttons_group([
98
{
99
id : 'run_b',
100
label : 'Run Cell',
101
icon : 'icon-play',
102
callback : function () {
103
// emulate default shift-enter behavior
104
IPython.notebook.execute_cell_and_select_below();
105
}
106
},
107
{
108
id : 'interrupt_b',
109
label : 'Interrupt',
110
icon : 'icon-stop',
111
callback : function () {
112
IPython.notebook.session.interrupt_kernel();
113
}
114
},
115
{
116
id : 'repeat_b',
117
label : 'Restart Kernel',
118
icon : 'icon-repeat',
119
callback : function () {
120
IPython.notebook.restart_kernel();
121
}
122
}
123
],'run_int');
124
};
125
126
MainToolBar.prototype.add_celltype_list = function () {
127
this.element
128
.append($('<select/>')
129
.attr('id','cell_type')
130
// .addClass('ui-widget-content')
131
.append($('<option/>').attr('value','code').text('Code'))
132
.append($('<option/>').attr('value','markdown').text('Markdown'))
133
.append($('<option/>').attr('value','raw').text('Raw NBConvert'))
134
.append($('<option/>').attr('value','heading1').text('Heading 1'))
135
.append($('<option/>').attr('value','heading2').text('Heading 2'))
136
.append($('<option/>').attr('value','heading3').text('Heading 3'))
137
.append($('<option/>').attr('value','heading4').text('Heading 4'))
138
.append($('<option/>').attr('value','heading5').text('Heading 5'))
139
.append($('<option/>').attr('value','heading6').text('Heading 6'))
140
);
141
};
142
143
144
MainToolBar.prototype.add_celltoolbar_list = function () {
145
var label = $('<span/>').addClass("navbar-text").text('Cell Toolbar:');
146
var select = $('<select/>')
147
// .addClass('ui-widget-content')
148
.attr('id', 'ctb_select')
149
.append($('<option/>').attr('value', '').text('None'));
150
this.element.append(label).append(select);
151
select.change(function() {
152
var val = $(this).val()
153
if (val =='') {
154
IPython.CellToolbar.global_hide();
155
delete IPython.notebook.metadata.celltoolbar;
156
} else {
157
IPython.CellToolbar.global_show();
158
IPython.CellToolbar.activate_preset(val);
159
IPython.notebook.metadata.celltoolbar = val;
160
}
161
});
162
// Setup the currently registered presets.
163
var presets = IPython.CellToolbar.list_presets();
164
for (var i=0; i<presets.length; i++) {
165
var name = presets[i];
166
select.append($('<option/>').attr('value', name).text(name));
167
}
168
// Setup future preset registrations.
169
$([IPython.events]).on('preset_added.CellToolbar', function (event, data) {
170
var name = data.name;
171
select.append($('<option/>').attr('value', name).text(name));
172
});
173
// Update select value when a preset is activated.
174
$([IPython.events]).on('preset_activated.CellToolbar', function (event, data) {
175
if (select.val() !== data.name)
176
select.val(data.name);
177
});
178
};
179
180
181
MainToolBar.prototype.bind_events = function () {
182
var that = this;
183
184
this.element.find('#cell_type').change(function () {
185
var cell_type = $(this).val();
186
if (cell_type === 'code') {
187
IPython.notebook.to_code();
188
} else if (cell_type === 'markdown') {
189
IPython.notebook.to_markdown();
190
} else if (cell_type === 'raw') {
191
IPython.notebook.to_raw();
192
} else if (cell_type === 'heading1') {
193
IPython.notebook.to_heading(undefined, 1);
194
} else if (cell_type === 'heading2') {
195
IPython.notebook.to_heading(undefined, 2);
196
} else if (cell_type === 'heading3') {
197
IPython.notebook.to_heading(undefined, 3);
198
} else if (cell_type === 'heading4') {
199
IPython.notebook.to_heading(undefined, 4);
200
} else if (cell_type === 'heading5') {
201
IPython.notebook.to_heading(undefined, 5);
202
} else if (cell_type === 'heading6') {
203
IPython.notebook.to_heading(undefined, 6);
204
}
205
});
206
$([IPython.events]).on('selected_cell_type_changed.Notebook', function (event, data) {
207
if (data.cell_type === 'heading') {
208
that.element.find('#cell_type').val(data.cell_type+data.level);
209
} else {
210
that.element.find('#cell_type').val(data.cell_type);
211
}
212
});
213
};
214
215
IPython.MainToolBar = MainToolBar;
216
217
return IPython;
218
219
}(IPython));
220
221