2016-06-21 13:18:29 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var inherits = require('inherits');
|
|
|
|
|
|
|
|
var EditorActions = require('diagram-js/lib/features/editor-actions/EditorActions');
|
|
|
|
|
|
|
|
var filter = require('lodash/collection/filter');
|
|
|
|
|
|
|
|
var is = require('../../util/ModelUtil').is;
|
|
|
|
|
2016-08-18 07:08:00 +00:00
|
|
|
var getBBox = require('diagram-js/lib/util/Elements').getBBox;
|
2016-06-21 13:18:29 +00:00
|
|
|
|
|
|
|
function BpmnEditorActions(
|
|
|
|
injector,
|
|
|
|
canvas, elementRegistry, selection,
|
|
|
|
spaceTool,
|
|
|
|
lassoTool,
|
|
|
|
handTool,
|
|
|
|
globalConnect,
|
|
|
|
distributeElements,
|
|
|
|
alignElements,
|
|
|
|
directEditing,
|
2016-08-18 07:08:00 +00:00
|
|
|
searchPad,
|
|
|
|
modeling) {
|
2016-06-21 13:18:29 +00:00
|
|
|
|
|
|
|
injector.invoke(EditorActions, this);
|
|
|
|
|
|
|
|
this.register({
|
|
|
|
selectElements: function() {
|
|
|
|
// select all elements except for the invisible
|
|
|
|
// root element
|
|
|
|
var rootElement = canvas.getRootElement();
|
|
|
|
|
|
|
|
var elements = elementRegistry.filter(function(element) {
|
2016-08-18 07:08:00 +00:00
|
|
|
return element !== rootElement;
|
2016-06-21 13:18:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
selection.select(elements);
|
2016-08-18 07:08:00 +00:00
|
|
|
|
|
|
|
return elements;
|
2016-06-21 13:18:29 +00:00
|
|
|
},
|
|
|
|
spaceTool: function() {
|
|
|
|
spaceTool.toggle();
|
|
|
|
},
|
|
|
|
lassoTool: function() {
|
|
|
|
lassoTool.toggle();
|
|
|
|
},
|
|
|
|
handTool: function() {
|
|
|
|
handTool.toggle();
|
|
|
|
},
|
|
|
|
globalConnectTool: function() {
|
|
|
|
globalConnect.toggle();
|
|
|
|
},
|
|
|
|
distributeElements: function(opts) {
|
|
|
|
var currentSelection = selection.get(),
|
|
|
|
type = opts.type;
|
|
|
|
|
|
|
|
if (currentSelection.length) {
|
|
|
|
distributeElements.trigger(currentSelection, type);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
alignElements: function(opts) {
|
|
|
|
var currentSelection = selection.get(),
|
|
|
|
aligneableElements = [],
|
|
|
|
type = opts.type;
|
|
|
|
|
|
|
|
if (currentSelection.length) {
|
|
|
|
aligneableElements = filter(currentSelection, function(element) {
|
|
|
|
return !is(element, 'bpmn:Lane');
|
|
|
|
});
|
|
|
|
|
|
|
|
alignElements.trigger(aligneableElements, type);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
directEditing: function() {
|
|
|
|
var currentSelection = selection.get();
|
|
|
|
|
|
|
|
if (currentSelection.length) {
|
|
|
|
directEditing.activate(currentSelection[0]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
find: function() {
|
|
|
|
searchPad.toggle();
|
2016-08-18 07:08:00 +00:00
|
|
|
},
|
|
|
|
moveToOrigin: function() {
|
|
|
|
var rootElement = canvas.getRootElement(),
|
|
|
|
boundingBox,
|
|
|
|
elements;
|
|
|
|
|
|
|
|
if (is(rootElement, 'bpmn:Collaboration')) {
|
|
|
|
elements = elementRegistry.filter(function(element) {
|
|
|
|
return is(element.parent, 'bpmn:Collaboration');
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
elements = elementRegistry.filter(function(element) {
|
|
|
|
return element !== rootElement;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
boundingBox = getBBox(elements);
|
|
|
|
|
|
|
|
modeling.moveElements(elements, { x: -boundingBox.x, y: -boundingBox.y }, rootElement);
|
2016-06-21 13:18:29 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
inherits(BpmnEditorActions, EditorActions);
|
|
|
|
|
|
|
|
BpmnEditorActions.$inject = [
|
|
|
|
'injector',
|
|
|
|
'canvas', 'elementRegistry', 'selection',
|
|
|
|
'spaceTool',
|
|
|
|
'lassoTool',
|
|
|
|
'handTool',
|
|
|
|
'globalConnect',
|
|
|
|
'distributeElements',
|
|
|
|
'alignElements',
|
|
|
|
'directEditing',
|
2016-08-18 07:08:00 +00:00
|
|
|
'searchPad',
|
|
|
|
'modeling'
|
2016-06-21 13:18:29 +00:00
|
|
|
];
|
|
|
|
|
2016-08-18 07:08:00 +00:00
|
|
|
module.exports = BpmnEditorActions;
|