feat(hand-tool): add hand-tool

Closes #412
This commit is contained in:
Ricardo Matias 2016-01-25 14:26:26 +01:00 committed by Nico Rehwaldt
parent 7196624b8c
commit fd2230a8fa
6 changed files with 42 additions and 8 deletions

View File

@ -135,6 +135,7 @@ Modeler.prototype._modelingModules = [
require('diagram-js/lib/features/resize'), require('diagram-js/lib/features/resize'),
require('diagram-js/lib/features/space-tool'), require('diagram-js/lib/features/space-tool'),
require('diagram-js/lib/features/lasso-tool'), require('diagram-js/lib/features/lasso-tool'),
require('diagram-js/lib/features/hand-tool'),
require('./features/keyboard'), require('./features/keyboard'),
require('./features/snapping'), require('./features/snapping'),
require('./features/modeling'), require('./features/modeling'),

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
function BpmnKeyBindings(keyboard, spaceTool, lassoTool, directEditing, function BpmnKeyBindings(keyboard, spaceTool, lassoTool, handTool, directEditing,
selection, canvas, elementRegistry, editorActions) { selection, canvas, elementRegistry, editorActions) {
var actions = { var actions = {
@ -21,6 +21,9 @@ function BpmnKeyBindings(keyboard, spaceTool, lassoTool, directEditing,
lassoTool: function() { lassoTool: function() {
lassoTool.activateSelection(); lassoTool.activateSelection();
}, },
handTool: function() {
handTool.activateHand();
},
directEditing: function() { directEditing: function() {
var currentSelection = selection.get(); var currentSelection = selection.get();
@ -59,6 +62,13 @@ function BpmnKeyBindings(keyboard, spaceTool, lassoTool, directEditing,
return true; return true;
} }
// h -> activate hand tool
if (key === 72) {
editorActions.trigger('handTool');
return true;
}
// e -> activate direct editing // e -> activate direct editing
if (key === 69) { if (key === 69) {
editorActions.trigger('directEditing'); editorActions.trigger('directEditing');
@ -72,6 +82,7 @@ BpmnKeyBindings.$inject = [
'keyboard', 'keyboard',
'spaceTool', 'spaceTool',
'lassoTool', 'lassoTool',
'handTool',
'directEditing', 'directEditing',
'selection', 'selection',
'canvas', 'canvas',

View File

@ -5,19 +5,28 @@ var assign = require('lodash/object/assign');
/** /**
* A palette provider for BPMN 2.0 elements. * A palette provider for BPMN 2.0 elements.
*/ */
function PaletteProvider(palette, create, elementFactory, spaceTool, lassoTool) { function PaletteProvider(palette, create, elementFactory, spaceTool, lassoTool, handTool) {
this._palette = palette;
this._create = create; this._create = create;
this._elementFactory = elementFactory; this._elementFactory = elementFactory;
this._spaceTool = spaceTool; this._spaceTool = spaceTool;
this._lassoTool = lassoTool; this._lassoTool = lassoTool;
this._handTool = handTool;
palette.registerProvider(this); palette.registerProvider(this);
} }
module.exports = PaletteProvider; module.exports = PaletteProvider;
PaletteProvider.$inject = [ 'palette', 'create', 'elementFactory', 'spaceTool', 'lassoTool' ]; PaletteProvider.$inject = [
'palette',
'create',
'elementFactory',
'spaceTool',
'lassoTool',
'handTool'
];
PaletteProvider.prototype.getPaletteEntries = function(element) { PaletteProvider.prototype.getPaletteEntries = function(element) {
@ -26,8 +35,8 @@ PaletteProvider.prototype.getPaletteEntries = function(element) {
create = this._create, create = this._create,
elementFactory = this._elementFactory, elementFactory = this._elementFactory,
spaceTool = this._spaceTool, spaceTool = this._spaceTool,
lassoTool = this._lassoTool; lassoTool = this._lassoTool,
handTool = this._handTool;
function createAction(type, group, className, title, options) { function createAction(type, group, className, title, options) {
@ -79,6 +88,16 @@ PaletteProvider.prototype.getPaletteEntries = function(element) {
} }
} }
}, },
'hand-tool': {
group: 'tools',
className: 'bpmn-icon-hand-tool',
title: 'Activate the hand tool',
action: {
click: function(event) {
handTool.activateHand(event);
}
}
},
'tool-separator': { 'tool-separator': {
group: 'tools', group: 'tools',
separator: true separator: true

View File

@ -3,7 +3,8 @@ module.exports = {
require('diagram-js/lib/features/palette'), require('diagram-js/lib/features/palette'),
require('diagram-js/lib/features/create'), require('diagram-js/lib/features/create'),
require('diagram-js/lib/features/space-tool'), require('diagram-js/lib/features/space-tool'),
require('diagram-js/lib/features/lasso-tool') require('diagram-js/lib/features/lasso-tool'),
require('diagram-js/lib/features/hand-tool')
], ],
__init__: [ 'paletteProvider' ], __init__: [ 'paletteProvider' ],
paletteProvider: [ 'type', require('./PaletteProvider') ] paletteProvider: [ 'type', require('./PaletteProvider') ]

View File

@ -10,6 +10,7 @@ var coreModule = require('../../../../lib/core'),
selectionModule = require('diagram-js/lib/features/selection'), selectionModule = require('diagram-js/lib/features/selection'),
spaceToolModule = require('diagram-js/lib/features/space-tool'), spaceToolModule = require('diagram-js/lib/features/space-tool'),
lassoToolModule = require('diagram-js/lib/features/lasso-tool'), lassoToolModule = require('diagram-js/lib/features/lasso-tool'),
handToolModule = require('diagram-js/lib/features/hand-tool'),
zoomScrollModule = require('diagram-js/lib/navigation/zoomscroll'), zoomScrollModule = require('diagram-js/lib/navigation/zoomscroll'),
editorActionsModule = require('diagram-js/lib/features/editor-actions'); editorActionsModule = require('diagram-js/lib/features/editor-actions');
@ -27,6 +28,7 @@ describe('features - keyboard', function() {
selectionModule, selectionModule,
spaceToolModule, spaceToolModule,
lassoToolModule, lassoToolModule,
handToolModule,
keyboardModule, keyboardModule,
zoomScrollModule, zoomScrollModule,
editorActionsModule editorActionsModule
@ -44,7 +46,7 @@ describe('features - keyboard', function() {
it('should include triggers inside editorActions', inject(function(editorActions) { it('should include triggers inside editorActions', inject(function(editorActions) {
// then // then
expect(editorActions.length()).to.equal(10); expect(editorActions.length()).to.equal(11);
})); }));

View File

@ -27,7 +27,7 @@ describe('features/palette', function() {
var entries = domQuery.all('.entry', paletteElement); var entries = domQuery.all('.entry', paletteElement);
// then // then
expect(entries.length).to.equal(10); expect(entries.length).to.equal(11);
})); }));
}); });