2016-06-21 13:18:29 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var inherits = require('inherits');
|
|
|
|
|
|
|
|
var EditorActions = require('diagram-js/lib/features/editor-actions/EditorActions');
|
|
|
|
|
2018-03-14 20:43:53 +00:00
|
|
|
var filter = require('min-dash').filter;
|
2016-06-21 13:18:29 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2018-01-05 13:32:52 +00:00
|
|
|
|
2016-06-21 13:18:29 +00:00
|
|
|
function BpmnEditorActions(
|
2018-01-05 13:32:52 +00:00
|
|
|
injector, canvas, elementRegistry,
|
|
|
|
selection, spaceTool, lassoTool, handTool,
|
|
|
|
globalConnect, distributeElements, alignElements,
|
|
|
|
directEditing, 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);
|
|
|
|
}
|
|
|
|
},
|
2016-12-13 10:21:57 +00:00
|
|
|
setColor: function(opts) {
|
|
|
|
var currentSelection = selection.get();
|
|
|
|
|
|
|
|
if (currentSelection.length) {
|
|
|
|
modeling.setColor(currentSelection, opts);
|
|
|
|
}
|
|
|
|
},
|
2016-06-21 13:18:29 +00:00
|
|
|
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) {
|
2017-01-09 13:30:39 +00:00
|
|
|
return element !== rootElement && !is(element.parent, 'bpmn:SubProcess');
|
2016-08-18 07:08:00 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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',
|
2018-01-05 13:32:52 +00:00
|
|
|
'canvas',
|
|
|
|
'elementRegistry',
|
|
|
|
'selection',
|
2016-06-21 13:18:29 +00:00
|
|
|
'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;
|