maintoolbar.js
179 lines
| 6.8 KiB
| application/javascript
|
JavascriptLexer
Matthias BUSSONNIER
|
r7833 | //---------------------------------------------------------------------------- | ||
Matthias BUSSONNIER
|
r8207 | // Copyright (C) 2011 The IPython Development Team | ||
Matthias BUSSONNIER
|
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) { | ||||
var MainToolBar = function (selector) { | ||||
this.selector = selector; | ||||
Matthias BUSSONNIER
|
r8213 | IPython.ToolBar.apply(this, arguments); | ||
this.construct(); | ||||
this.add_drop_down_list(); | ||||
this.bind_events(); | ||||
Matthias BUSSONNIER
|
r7833 | }; | ||
MainToolBar.prototype = new IPython.ToolBar(); | ||||
Matthias BUSSONNIER
|
r8210 | MainToolBar.prototype.construct = function () { | ||
Matthias BUSSONNIER
|
r8051 | this.add_buttons_group([ | ||
Matthias BUSSONNIER
|
r7833 | { | ||
Matthias BUSSONNIER
|
r8210 | id : 'save_b', | ||
label : 'Save', | ||||
icon : 'ui-icon-disk', | ||||
callback : function () { | ||||
Matthias BUSSONNIER
|
r7833 | IPython.notebook.save_notebook(); | ||
Matthias BUSSONNIER
|
r8209 | } | ||
} | ||||
Matthias BUSSONNIER
|
r7833 | ]); | ||
Matthias BUSSONNIER
|
r8051 | this.add_buttons_group([ | ||
Matthias BUSSONNIER
|
r7833 | { | ||
Matthias BUSSONNIER
|
r8210 | id : 'cut_b', | ||
label : 'Cut Cell', | ||||
icon : 'ui-icon-scissors', | ||||
callback : function () { | ||||
Matthias BUSSONNIER
|
r7833 | IPython.notebook.cut_cell(); | ||
Matthias BUSSONNIER
|
r8209 | } | ||
Matthias BUSSONNIER
|
r7833 | }, | ||
{ | ||||
Matthias BUSSONNIER
|
r8210 | id : 'copy_b', | ||
label : 'Copy Cell', | ||||
icon : 'ui-icon-copy', | ||||
callback : function () { | ||||
Matthias BUSSONNIER
|
r7833 | IPython.notebook.copy_cell(); | ||
Matthias BUSSONNIER
|
r8209 | } | ||
Matthias BUSSONNIER
|
r7833 | }, | ||
{ | ||||
Matthias BUSSONNIER
|
r8210 | id : 'paste_b', | ||
label : 'Paste Cell', | ||||
icon : 'ui-icon-clipboard', | ||||
callback : function () { | ||||
Matthias BUSSONNIER
|
r7833 | IPython.notebook.paste_cell(); | ||
Matthias BUSSONNIER
|
r8209 | } | ||
} | ||||
Matthias BUSSONNIER
|
r7833 | ],'cut_copy_paste'); | ||
Matthias BUSSONNIER
|
r8051 | this.add_buttons_group([ | ||
Matthias BUSSONNIER
|
r7833 | { | ||
Matthias BUSSONNIER
|
r8210 | id : 'move_up_b', | ||
label : 'Move Cell Up', | ||||
icon : 'ui-icon-arrowthick-1-n', | ||||
callback : function () { | ||||
Matthias BUSSONNIER
|
r7833 | IPython.notebook.move_cell_up(); | ||
Matthias BUSSONNIER
|
r8209 | } | ||
Matthias BUSSONNIER
|
r7833 | }, | ||
{ | ||||
Matthias BUSSONNIER
|
r8210 | id : 'move_down_b', | ||
label : 'Move Cell Down', | ||||
icon : 'ui-icon-arrowthick-1-s', | ||||
callback : function () { | ||||
Matthias BUSSONNIER
|
r7833 | IPython.notebook.move_cell_down(); | ||
Matthias BUSSONNIER
|
r8209 | } | ||
} | ||||
Matthias BUSSONNIER
|
r7833 | ],'move_up_down'); | ||
Matthias BUSSONNIER
|
r8051 | this.add_buttons_group([ | ||
Matthias BUSSONNIER
|
r7833 | { | ||
Matthias BUSSONNIER
|
r8210 | id : 'insert_above_b', | ||
label : 'Insert Cell Above', | ||||
icon : 'ui-icon-arrowthickstop-1-n', | ||||
callback : function () { | ||||
Matthias BUSSONNIER
|
r7833 | IPython.notebook.insert_cell_above('code'); | ||
Matthias BUSSONNIER
|
r8209 | } | ||
Matthias BUSSONNIER
|
r7833 | }, | ||
{ | ||||
Matthias BUSSONNIER
|
r8210 | id : 'insert_below_b', | ||
label : 'Insert Cell Below', | ||||
icon : 'ui-icon-arrowthickstop-1-s', | ||||
callback : function () { | ||||
Matthias BUSSONNIER
|
r7833 | IPython.notebook.insert_cell_below('code'); | ||
Matthias BUSSONNIER
|
r8209 | } | ||
} | ||||
Matthias BUSSONNIER
|
r7833 | ],'insert_above_below'); | ||
Matthias BUSSONNIER
|
r8051 | this.add_buttons_group([ | ||
Matthias BUSSONNIER
|
r7833 | { | ||
Matthias BUSSONNIER
|
r8210 | id : 'run_b', | ||
label : 'Run Cell', | ||||
icon : 'ui-icon-play', | ||||
callback : function () { | ||||
Matthias BUSSONNIER
|
r7833 | IPython.notebook.execute_selected_cell(); | ||
Matthias BUSSONNIER
|
r8209 | } | ||
Matthias BUSSONNIER
|
r7833 | }, | ||
{ | ||||
Matthias BUSSONNIER
|
r8210 | id : 'interrupt_b', | ||
label : 'Interrupt', | ||||
icon : 'ui-icon-stop', | ||||
callback : function () { | ||||
Matthias BUSSONNIER
|
r7833 | IPython.notebook.kernel.interrupt(); | ||
Matthias BUSSONNIER
|
r8209 | } | ||
} | ||||
Matthias BUSSONNIER
|
r7833 | ],'run_int'); | ||
Matthias BUSSONNIER
|
r8209 | }; | ||
Matthias BUSSONNIER
|
r7833 | |||
Matthias BUSSONNIER
|
r8212 | MainToolBar.prototype.add_drop_down_list = function () { | ||
var select = $(this.selector) | ||||
.append($('<select/>') | ||||
.attr('id','cell_type') | ||||
.addClass('ui-widget ui-widget-content') | ||||
.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')) | ||||
.append($('<option/>').attr('value','heading7').text('Heading 7')) | ||||
.append($('<option/>').attr('value','heading8').text('Heading 8')) | ||||
); | ||||
}; | ||||
Matthias BUSSONNIER
|
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); | ||||
Matthias BUSSONNIER
|
r8209 | } | ||
Matthias BUSSONNIER
|
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)); | ||||