##// END OF EJS Templates
Add notion of action that differs from shortcuts....
Add notion of action that differs from shortcuts. This decouple the notion of shortcut from the notion of executed "action" This allow the shortcuts manager to be purely describe as data, and the same action to be later refered to either from the shortcut, from a toolbar button or a menu. This also implement a more complete keyboard shortcut handler which is able ton interpete sequences like `Cmd-X,Meta-v` By storing the shortcuts in a tree.

File last commit:

r18390:39ea1bc4
r18390:39ea1bc4
Show More
toolbar.js
100 lines | 3.0 KiB | application/javascript | JavascriptLexer
Jonathan Frederic
Progress...
r17196 // Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
Brian Granger
First draft of toolbar....
r5993
Jonathan Frederic
Progress...
r17196 define([
'base/js/namespace',
Jonathan Frederic
MWE,...
r17200 'jquery',
Jonathan Frederic
Progress...
r17196 ], function(IPython, $) {
Matthias BUSSONNIER
"use strict" in most (if not all) our javascript...
r12103 "use strict";
Brian Granger
First draft of toolbar....
r5993
Matthias BUSSONNIER
document base of toolbar
r8769 /**
* A generic toolbar on which one can add button
* @class ToolBar
* @constructor
Matthias Bussonnier
Add notion of action that differs from shortcuts....
r18390 * @param {Dom object} selector
Matthias BUSSONNIER
document base of toolbar
r8769 */
Jonathan Frederic
Progress...
r17196 var ToolBar = function (selector, layout_manager) {
Brian Granger
First draft of toolbar....
r5993 this.selector = selector;
Jonathan Frederic
Progress...
r17196 this.layout_manager = layout_manager;
Brian Granger
First draft of toolbar....
r5993 if (this.selector !== undefined) {
this.element = $(selector);
this.style();
}
};
Matthias BUSSONNIER
document base of toolbar
r8769 /**
* add a group of button into the current toolbar.
*
*
* @example
*
Matthias BUSSONNIER
Add a per cell toolbar....
r9055 * IPython.toolbar.add_buttons_group([
Matthias BUSSONNIER
document base of toolbar
r8769 * {
* label:'my button',
MinRK
bootstrap toolbar
r10889 * icon:'icon-hdd',
Matthias BUSSONNIER
Method to show hide linenumber of cell...
r9542 * callback:function(){alert('hoho')},
Matthias BUSSONNIER
document base of toolbar
r8769 * id : 'my_button_id', // this is optional
* },
* {
* label:'my second button',
MinRK
bootstrap toolbar
r10889 * icon:'icon-play',
Matthias BUSSONNIER
document base of toolbar
r8769 * callback:function(){alert('be carefull I cut')}
* }
* ],
* "my_button_group_id"
* )
*
* @method add_buttons_group
* @param list {List}
* List of button of the group, with the following paramter for each :
* @param list.label {string} text to show on button hover
MinRK
bootstrap toolbar
r10889 * @param list.icon {string} icon to choose from [Font Awesome](http://fortawesome.github.io/Font-Awesome)
Matthias BUSSONNIER
document base of toolbar
r8769 * @param list.callback {function} function to be called on button click
* @param [list.id] {String} id to give to the button
* @param [group_id] {String} optionnal id to give to the group
*
*/
Matthias BUSSONNIER
reorder methods and fix typo
r8212 ToolBar.prototype.add_buttons_group = function (list, group_id) {
MinRK
bootstrap toolbar
r10889 var btn_group = $('<div/>').addClass("btn-group");
MinRK
never use `for (var i in array)`...
r16226 if( group_id !== undefined ) {
MinRK
bootstrap toolbar
r10889 btn_group.attr('id',group_id);
Matthias BUSSONNIER
jslint 1
r8209 }
MinRK
never use `for (var i in array)`...
r16226 var el;
for(var i=0; i < list.length; i++) {
el = list[i];
MinRK
bootstrap toolbar
r10889 var button = $('<button/>')
Jonathan Frederic
Ran jdfreder/bootstrap2to3
r16913 .addClass('btn btn-default')
MinRK
never use `for (var i in array)`...
r16226 .attr("title", el.label)
MinRK
bootstrap toolbar
r10889 .append(
Matthias BUSSONNIER
fix some font-awesoem 4 icons
r17414 $("<i/>").addClass(el.icon).addClass('fa')
MinRK
bootstrap toolbar
r10889 );
MinRK
never use `for (var i in array)`...
r16226 var id = el.id;
if( id !== undefined )
Matthias BUSSONNIER
Allow toolbar construction in js...
r7832 button.attr('id',id);
MinRK
never use `for (var i in array)`...
r16226 var fun = el.callback;
Matthias BUSSONNIER
Allow toolbar construction in js...
r7832 button.click(fun);
MinRK
bootstrap toolbar
r10889 btn_group.append(button);
Matthias BUSSONNIER
Allow toolbar construction in js...
r7832 }
MinRK
bootstrap toolbar
r10889 $(this.selector).append(btn_group);
Matthias BUSSONNIER
jslint 1
r8209 };
Brian Granger
First draft of toolbar....
r5993
ToolBar.prototype.style = function () {
Matthias BUSSONNIER
move tolbar styling to css
r17434 this.element.addClass('toolbar');
Brian Granger
First draft of toolbar....
r5993 };
Matthias BUSSONNIER
document base of toolbar
r8769 /**
* Show and hide toolbar
* @method toggle
*/
Brian Granger
Further work on the toolbar UI....
r5994 ToolBar.prototype.toggle = function () {
this.element.toggle();
Jonathan Frederic
Progress...
r17196 if (this.layout_manager !== undefined) {
this.layout_manager.do_resize();
Matthias BUSSONNIER
reorder methods and fix typo
r8212 }
Brian Granger
First draft of toolbar....
r5993 };
Matthias BUSSONNIER
comment typo
r17435 // Backwards compatibility.
Brian Granger
First draft of toolbar....
r5993 IPython.ToolBar = ToolBar;
Jonathan Frederic
Return dicts instead of classes,...
r17201 return {'ToolBar': ToolBar};
Jonathan Frederic
Progress...
r17196 });