##// END OF EJS Templates
Machinery to replace the current cell instead of adding a new one
Machinery to replace the current cell instead of adding a new one

File last commit:

r19176:f48e011c
r19250:bdae5330
Show More
maintoolbar.js
224 lines | 7.7 KiB | application/javascript | JavascriptLexer
Jonathan Frederic
Start of work to make notebook.html requirejs friendly.
r17192 // Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
'base/js/namespace',
Jonathan Frederic
MWE,...
r17200 'jquery',
Jonathan Frederic
Start of work to make notebook.html requirejs friendly.
r17192 'notebook/js/toolbar',
Jonathan Frederic
Progress...
r17196 'notebook/js/celltoolbar',
Jonathan Frederic
Removed ScrollManager selector combo.
r17872 ], function(IPython, $, toolbar, celltoolbar) {
Matthias BUSSONNIER
"use strict" in most (if not all) our javascript...
r12103 "use strict";
Matthias BUSSONNIER
add maintoolbar file
r7833
jon
In person review with @ellisonbg
r17210 var MainToolBar = function (selector, options) {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Constructor
*
* Parameters:
* selector: string
* options: dictionary
* Dictionary of keyword arguments.
* events: $(Events) instance
* notebook: Notebook instance
*/
Jonathan Frederic
Fix all the bugs!
r17203 toolbar.ToolBar.apply(this, arguments);
jon
In person review with @ellisonbg
r17210 this.events = options.events;
this.notebook = options.notebook;
Matthias BUSSONNIER
check for selector only in parent classes
r8213 this.construct();
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 this.add_celltype_list();
this.add_celltoolbar_list();
Matthias BUSSONNIER
check for selector only in parent classes
r8213 this.bind_events();
Matthias BUSSONNIER
add maintoolbar file
r7833 };
Matthias Bussonnier
Use low overhead object heritence in Js (Object.create vs new)...
r18377 MainToolBar.prototype = Object.create(toolbar.ToolBar.prototype);
Matthias BUSSONNIER
add maintoolbar file
r7833
Matthias BUSSONNIER
space around :
r8210 MainToolBar.prototype.construct = function () {
Jonathan Frederic
Fix all the bugs!
r17203 var that = this;
Matthias BUSSONNIER
DeCamelCasify method names
r8051 this.add_buttons_group([
Matthias BUSSONNIER
add maintoolbar file
r7833 {
Matthias BUSSONNIER
space around :
r8210 id : 'save_b',
MinRK
Save and Checkpoint
r10513 label : 'Save and Checkpoint',
Matthias BUSSONNIER
fix some font-awesoem 4 icons
r17414 icon : 'fa-save',
Matthias BUSSONNIER
space around :
r8210 callback : function () {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.save_checkpoint();
Matthias BUSSONNIER
jslint 1
r8209 }
}
Matthias BUSSONNIER
add maintoolbar file
r7833 ]);
Susan Tan
Fixed #2923 Move Save Away from Cut in toolbar
r13731
this.add_buttons_group([
{
id : 'insert_below_b',
label : 'Insert Cell Below',
Matthias BUSSONNIER
fix some font-awesoem 4 icons
r17414 icon : 'fa-plus',
Susan Tan
Fixed #2923 Move Save Away from Cut in toolbar
r13731 callback : function () {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.insert_cell_below('code');
that.notebook.select_next();
that.notebook.focus_cell();
Susan Tan
Fixed #2923 Move Save Away from Cut in toolbar
r13731 }
}
],'insert_above_below');
Matthias BUSSONNIER
DeCamelCasify method names
r8051 this.add_buttons_group([
Matthias BUSSONNIER
add maintoolbar file
r7833 {
Matthias BUSSONNIER
space around :
r8210 id : 'cut_b',
label : 'Cut Cell',
Matthias BUSSONNIER
fix some font-awesoem 4 icons
r17414 icon : 'fa-cut',
Matthias BUSSONNIER
space around :
r8210 callback : function () {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.cut_cell();
Matthias BUSSONNIER
jslint 1
r8209 }
Matthias BUSSONNIER
add maintoolbar file
r7833 },
{
Matthias BUSSONNIER
space around :
r8210 id : 'copy_b',
label : 'Copy Cell',
Matthias BUSSONNIER
fix some font-awesoem 4 icons
r17414 icon : 'fa-copy',
Matthias BUSSONNIER
space around :
r8210 callback : function () {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.copy_cell();
Matthias BUSSONNIER
jslint 1
r8209 }
Matthias BUSSONNIER
add maintoolbar file
r7833 },
{
Matthias BUSSONNIER
space around :
r8210 id : 'paste_b',
Matthias BUSSONNIER
past below by default
r8770 label : 'Paste Cell Below',
Matthias BUSSONNIER
fix some font-awesoem 4 icons
r17414 icon : 'fa-paste',
Matthias BUSSONNIER
space around :
r8210 callback : function () {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.paste_cell_below();
Matthias BUSSONNIER
jslint 1
r8209 }
}
Matthias BUSSONNIER
add maintoolbar file
r7833 ],'cut_copy_paste');
Matthias BUSSONNIER
DeCamelCasify method names
r8051 this.add_buttons_group([
Matthias BUSSONNIER
add maintoolbar file
r7833 {
Matthias BUSSONNIER
space around :
r8210 id : 'move_up_b',
label : 'Move Cell Up',
Matthias BUSSONNIER
fix some font-awesoem 4 icons
r17414 icon : 'fa-arrow-up',
Matthias BUSSONNIER
space around :
r8210 callback : function () {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.move_cell_up();
Matthias BUSSONNIER
jslint 1
r8209 }
Matthias BUSSONNIER
add maintoolbar file
r7833 },
{
Matthias BUSSONNIER
space around :
r8210 id : 'move_down_b',
label : 'Move Cell Down',
Matthias BUSSONNIER
fix some font-awesoem 4 icons
r17414 icon : 'fa-arrow-down',
Matthias BUSSONNIER
space around :
r8210 callback : function () {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.move_cell_down();
Matthias BUSSONNIER
jslint 1
r8209 }
}
Matthias BUSSONNIER
add maintoolbar file
r7833 ],'move_up_down');
jon
Added function to create Bootstrap specific drop down.
r16931
Matthias BUSSONNIER
add maintoolbar file
r7833
Matthias BUSSONNIER
DeCamelCasify method names
r8051 this.add_buttons_group([
Matthias BUSSONNIER
add maintoolbar file
r7833 {
Matthias BUSSONNIER
space around :
r8210 id : 'run_b',
label : 'Run Cell',
Matthias BUSSONNIER
fix some font-awesoem 4 icons
r17414 icon : 'fa-play',
Matthias BUSSONNIER
space around :
r8210 callback : function () {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* emulate default shift-enter behavior
*/
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.execute_cell_and_select_below();
MinRK
make execute button in menu bar match shift-enter...
r15179 }
Matthias BUSSONNIER
add maintoolbar file
r7833 },
{
Matthias BUSSONNIER
space around :
r8210 id : 'interrupt_b',
label : 'Interrupt',
Matthias BUSSONNIER
fix some font-awesoem 4 icons
r17414 icon : 'fa-stop',
Matthias BUSSONNIER
space around :
r8210 callback : function () {
Jessica B. Hamrick
Fix session references in toolbar and menubar
r18204 that.notebook.kernel.interrupt();
Matthias BUSSONNIER
jslint 1
r8209 }
Brian E. Granger
Add kernel restart button to toolbar.
r14866 },
{
id : 'repeat_b',
label : 'Restart Kernel',
Matthias BUSSONNIER
fix some font-awesoem 4 icons
r17414 icon : 'fa-repeat',
Brian E. Granger
Add kernel restart button to toolbar.
r14866 callback : function () {
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.restart_kernel();
Brian E. Granger
Add kernel restart button to toolbar.
r14866 }
Matthias BUSSONNIER
jslint 1
r8209 }
Matthias BUSSONNIER
add maintoolbar file
r7833 ],'run_int');
Matthias BUSSONNIER
jslint 1
r8209 };
jon
Fixed cell toolbar dropdown
r16934
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 MainToolBar.prototype.add_celltype_list = function () {
this.element
Matthias BUSSONNIER
reorder methods and fix typo
r8212 .append($('<select/>')
.attr('id','cell_type')
Jonathan Frederic
Make maintoolbar select dropdowns look nice
r16948 .addClass('form-control select-xs')
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 .append($('<option/>').attr('value','code').text('Code'))
.append($('<option/>').attr('value','markdown').text('Markdown'))
MinRK
add raw cell toolbar preset
r13671 .append($('<option/>').attr('value','raw').text('Raw NBConvert'))
Min RK
deprecate heading cells in UI...
r18680 .append($('<option/>').attr('value','heading').text('Heading'))
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 );
Matthias BUSSONNIER
reorder methods and fix typo
r8212 };
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 MainToolBar.prototype.add_celltoolbar_list = function () {
MinRK
bootstrap toolbar
r10889 var label = $('<span/>').addClass("navbar-text").text('Cell Toolbar:');
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 var select = $('<select/>')
.attr('id', 'ctb_select')
Jonathan Frederic
Make maintoolbar select dropdowns look nice
r16948 .addClass('form-control select-xs')
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 .append($('<option/>').attr('value', '').text('None'));
this.element.append(label).append(select);
Jonathan Frederic
Fixed cell toolbars
r17217 var that = this;
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 select.change(function() {
Jonathan Frederic
Start of work to make notebook.html requirejs friendly.
r17192 var val = $(this).val();
if (val ==='') {
Jonathan Frederic
Fix imports of "modules",...
r17202 celltoolbar.CellToolbar.global_hide();
Jonathan Frederic
Fix all the bugs!
r17203 delete that.notebook.metadata.celltoolbar;
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 } else {
Jonathan Frederic
Fix imports of "modules",...
r17202 celltoolbar.CellToolbar.global_show();
Jonathan Frederic
Fixed cell toolbars
r17217 celltoolbar.CellToolbar.activate_preset(val, that.events);
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.metadata.celltoolbar = val;
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 }
});
// Setup the currently registered presets.
Jonathan Frederic
Fix imports of "modules",...
r17202 var presets = celltoolbar.CellToolbar.list_presets();
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 for (var i=0; i<presets.length; i++) {
var name = presets[i];
select.append($('<option/>').attr('value', name).text(name));
}
// Setup future preset registrations.
Jonathan Frederic
Progress...
r17196 this.events.on('preset_added.CellToolbar', function (event, data) {
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 var name = data.name;
select.append($('<option/>').attr('value', name).text(name));
});
Raffaele De Feo
When a preset is activated fire "preset_activated" event....
r16533 // Update select value when a preset is activated.
Jonathan Frederic
Progress...
r17196 this.events.on('preset_activated.CellToolbar', function (event, data) {
Raffaele De Feo
When a preset is activated fire "preset_activated" event....
r16533 if (select.val() !== data.name)
select.val(data.name);
});
Brian Granger
Decoupling the celltoolbar select UI from CellToolbar....
r9146 };
Matthias BUSSONNIER
add maintoolbar file
r7833 MainToolBar.prototype.bind_events = function () {
var that = this;
jon
Added function to create Bootstrap specific drop down.
r16931
Matthias BUSSONNIER
add maintoolbar file
r7833 this.element.find('#cell_type').change(function () {
var cell_type = $(this).val();
MinRK
remove heading cells in v4
r18596 switch (cell_type) {
case 'code':
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.to_code();
MinRK
remove heading cells in v4
r18596 break;
case 'markdown':
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.to_markdown();
MinRK
remove heading cells in v4
r18596 break;
case 'raw':
Jonathan Frederic
Fix all the bugs!
r17203 that.notebook.to_raw();
MinRK
remove heading cells in v4
r18596 break;
Min RK
deprecate heading cells in UI...
r18680 case 'heading':
that.notebook._warn_heading();
that.notebook.to_heading();
that.element.find('#cell_type').val("markdown");
break;
MinRK
remove heading cells in v4
r18596 default:
console.log("unrecognized cell type:", cell_type);
Matthias BUSSONNIER
jslint 1
r8209 }
Matthias BUSSONNIER
add maintoolbar file
r7833 });
Jonathan Frederic
Progress...
r17196 this.events.on('selected_cell_type_changed.Notebook', function (event, data) {
Matthias BUSSONNIER
add maintoolbar file
r7833 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);
}
});
};
Jonathan Frederic
Start of work to make notebook.html requirejs friendly.
r17192 // Backwards compatability.
Matthias BUSSONNIER
add maintoolbar file
r7833 IPython.MainToolBar = MainToolBar;
Jonathan Frederic
Return dicts instead of classes,...
r17201 return {'MainToolBar': MainToolBar};
Jonathan Frederic
Start of work to make notebook.html requirejs friendly.
r17192 });