maintoolbar.js
209 lines
| 7.9 KiB
| application/javascript
|
JavascriptLexer
|
r7833 | //---------------------------------------------------------------------------- | ||
|
r8207 | // Copyright (C) 2011 The IPython Development Team | ||
|
r7833 | // | ||
// Distributed under the terms of the BSD License. The full license is in | ||||
// the file COPYING, distributed as part of this software. | ||||
//---------------------------------------------------------------------------- | ||||
//============================================================================ | ||||
// ToolBar | ||||
//============================================================================ | ||||
var IPython = (function (IPython) { | ||||
|
r12103 | "use strict"; | ||
|
r7833 | |||
var MainToolBar = function (selector) { | ||||
|
r8213 | IPython.ToolBar.apply(this, arguments); | ||
this.construct(); | ||||
|
r9146 | this.add_celltype_list(); | ||
this.add_celltoolbar_list(); | ||||
|
r8213 | this.bind_events(); | ||
|
r7833 | }; | ||
MainToolBar.prototype = new IPython.ToolBar(); | ||||
|
r8210 | MainToolBar.prototype.construct = function () { | ||
|
r8051 | this.add_buttons_group([ | ||
|
r7833 | { | ||
|
r8210 | id : 'save_b', | ||
|
r10513 | label : 'Save and Checkpoint', | ||
|
r11192 | icon : 'icon-save', | ||
|
r8210 | callback : function () { | ||
|
r10501 | IPython.notebook.save_checkpoint(); | ||
|
r8209 | } | ||
} | ||||
|
r7833 | ]); | ||
|
r8051 | this.add_buttons_group([ | ||
|
r7833 | { | ||
|
r8210 | id : 'cut_b', | ||
label : 'Cut Cell', | ||||
|
r10889 | icon : 'icon-cut', | ||
|
r8210 | callback : function () { | ||
|
r7833 | IPython.notebook.cut_cell(); | ||
|
r8209 | } | ||
|
r7833 | }, | ||
{ | ||||
|
r8210 | id : 'copy_b', | ||
label : 'Copy Cell', | ||||
|
r10889 | icon : 'icon-copy', | ||
|
r8210 | callback : function () { | ||
|
r7833 | IPython.notebook.copy_cell(); | ||
|
r8209 | } | ||
|
r7833 | }, | ||
{ | ||||
|
r8210 | id : 'paste_b', | ||
|
r8770 | label : 'Paste Cell Below', | ||
|
r10889 | icon : 'icon-paste', | ||
|
r8210 | callback : function () { | ||
|
r8770 | IPython.notebook.paste_cell_below(); | ||
|
r8209 | } | ||
} | ||||
|
r7833 | ],'cut_copy_paste'); | ||
|
r8051 | this.add_buttons_group([ | ||
|
r7833 | { | ||
|
r8210 | id : 'move_up_b', | ||
label : 'Move Cell Up', | ||||
|
r10889 | icon : 'icon-arrow-up', | ||
|
r8210 | callback : function () { | ||
|
r7833 | IPython.notebook.move_cell_up(); | ||
|
r8209 | } | ||
|
r7833 | }, | ||
{ | ||||
|
r8210 | id : 'move_down_b', | ||
label : 'Move Cell Down', | ||||
|
r10904 | icon : 'icon-arrow-down', | ||
|
r8210 | callback : function () { | ||
|
r7833 | IPython.notebook.move_cell_down(); | ||
|
r8209 | } | ||
} | ||||
|
r7833 | ],'move_up_down'); | ||
|
r8051 | this.add_buttons_group([ | ||
|
r7833 | { | ||
|
r8210 | id : 'insert_above_b', | ||
label : 'Insert Cell Above', | ||||
|
r10889 | icon : 'icon-circle-arrow-up', | ||
|
r8210 | callback : function () { | ||
|
r7833 | IPython.notebook.insert_cell_above('code'); | ||
|
r8209 | } | ||
|
r7833 | }, | ||
{ | ||||
|
r8210 | id : 'insert_below_b', | ||
label : 'Insert Cell Below', | ||||
|
r10889 | icon : 'icon-circle-arrow-down', | ||
|
r8210 | callback : function () { | ||
|
r7833 | IPython.notebook.insert_cell_below('code'); | ||
|
r8209 | } | ||
} | ||||
|
r7833 | ],'insert_above_below'); | ||
|
r8051 | this.add_buttons_group([ | ||
|
r7833 | { | ||
|
r8210 | id : 'run_b', | ||
label : 'Run Cell', | ||||
|
r10889 | icon : 'icon-play', | ||
|
r8210 | callback : function () { | ||
|
r7833 | IPython.notebook.execute_selected_cell(); | ||
|
r8209 | } | ||
|
r7833 | }, | ||
{ | ||||
|
r8210 | id : 'interrupt_b', | ||
label : 'Interrupt', | ||||
|
r10889 | icon : 'icon-stop', | ||
|
r8210 | callback : function () { | ||
|
r12994 | IPython.notebook.session.interrupt_kernel(); | ||
|
r8209 | } | ||
} | ||||
|
r7833 | ],'run_int'); | ||
|
r8209 | }; | ||
|
r7833 | |||
|
r9146 | MainToolBar.prototype.add_celltype_list = function () { | ||
this.element | ||||
|
r8212 | .append($('<select/>') | ||
.attr('id','cell_type') | ||||
|
r10889 | // .addClass('ui-widget-content') | ||
|
r9146 | .append($('<option/>').attr('value','code').text('Code')) | ||
.append($('<option/>').attr('value','markdown').text('Markdown')) | ||||
.append($('<option/>').attr('value','raw').text('Raw Text')) | ||||
.append($('<option/>').attr('value','heading1').text('Heading 1')) | ||||
.append($('<option/>').attr('value','heading2').text('Heading 2')) | ||||
.append($('<option/>').attr('value','heading3').text('Heading 3')) | ||||
.append($('<option/>').attr('value','heading4').text('Heading 4')) | ||||
.append($('<option/>').attr('value','heading5').text('Heading 5')) | ||||
.append($('<option/>').attr('value','heading6').text('Heading 6')) | ||||
); | ||||
|
r8212 | }; | ||
|
r9146 | |||
MainToolBar.prototype.add_celltoolbar_list = function () { | ||||
|
r10889 | var label = $('<span/>').addClass("navbar-text").text('Cell Toolbar:'); | ||
|
r9146 | var select = $('<select/>') | ||
|
r10889 | // .addClass('ui-widget-content') | ||
|
r9146 | .attr('id', 'ctb_select') | ||
.append($('<option/>').attr('value', '').text('None')); | ||||
this.element.append(label).append(select); | ||||
select.change(function() { | ||||
var val = $(this).val() | ||||
if (val =='') { | ||||
IPython.CellToolbar.global_hide(); | ||||
|
r13679 | delete IPython.notebook.metadata.celltoolbar; | ||
|
r9146 | } else { | ||
IPython.CellToolbar.global_show(); | ||||
IPython.CellToolbar.activate_preset(val); | ||||
|
r13679 | IPython.notebook.metadata.celltoolbar = val; | ||
|
r9146 | } | ||
}); | ||||
// Setup the currently registered presets. | ||||
var presets = IPython.CellToolbar.list_presets(); | ||||
for (var i=0; i<presets.length; i++) { | ||||
var name = presets[i]; | ||||
select.append($('<option/>').attr('value', name).text(name)); | ||||
} | ||||
// Setup future preset registrations. | ||||
$([IPython.events]).on('preset_added.CellToolbar', function (event, data) { | ||||
var name = data.name; | ||||
select.append($('<option/>').attr('value', name).text(name)); | ||||
}); | ||||
}; | ||||
|
r7833 | MainToolBar.prototype.bind_events = function () { | ||
var that = this; | ||||
this.element.find('#cell_type').change(function () { | ||||
var cell_type = $(this).val(); | ||||
if (cell_type === 'code') { | ||||
IPython.notebook.to_code(); | ||||
} else if (cell_type === 'markdown') { | ||||
IPython.notebook.to_markdown(); | ||||
} else if (cell_type === 'raw') { | ||||
IPython.notebook.to_raw(); | ||||
} else if (cell_type === 'heading1') { | ||||
IPython.notebook.to_heading(undefined, 1); | ||||
} else if (cell_type === 'heading2') { | ||||
IPython.notebook.to_heading(undefined, 2); | ||||
} else if (cell_type === 'heading3') { | ||||
IPython.notebook.to_heading(undefined, 3); | ||||
} else if (cell_type === 'heading4') { | ||||
IPython.notebook.to_heading(undefined, 4); | ||||
} else if (cell_type === 'heading5') { | ||||
IPython.notebook.to_heading(undefined, 5); | ||||
} else if (cell_type === 'heading6') { | ||||
IPython.notebook.to_heading(undefined, 6); | ||||
|
r8209 | } | ||
|
r7833 | }); | ||
$([IPython.events]).on('selected_cell_type_changed.Notebook', function (event, data) { | ||||
if (data.cell_type === 'heading') { | ||||
that.element.find('#cell_type').val(data.cell_type+data.level); | ||||
} else { | ||||
that.element.find('#cell_type').val(data.cell_type); | ||||
} | ||||
}); | ||||
}; | ||||
IPython.MainToolBar = MainToolBar; | ||||
return IPython; | ||||
}(IPython)); | ||||