2018-04-02 19:01:53 +00:00
|
|
|
import inherits from 'inherits';
|
2016-06-21 13:18:29 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import EditorActions from 'diagram-js/lib/features/editor-actions/EditorActions';
|
2016-06-21 13:18:29 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import { filter } from 'min-dash';
|
2016-06-21 13:18:29 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import { is } from '../../util/ModelUtil';
|
2016-06-21 13:18:29 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
getBBox
|
|
|
|
} from 'diagram-js/lib/util/Elements';
|
2016-06-21 13:18:29 +00:00
|
|
|
|
2018-01-05 13:32:52 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
/**
|
|
|
|
* Registers and executes BPMN specific editor actions.
|
2018-10-26 22:54:31 +00:00
|
|
|
*
|
|
|
|
* @param {Injector} injector
|
2018-04-02 19:01:53 +00:00
|
|
|
*/
|
2018-10-26 22:54:31 +00:00
|
|
|
export default function BpmnEditorActions(injector) {
|
2016-06-21 13:18:29 +00:00
|
|
|
injector.invoke(EditorActions, this);
|
2018-10-26 22:54:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inherits(BpmnEditorActions, EditorActions);
|
|
|
|
|
|
|
|
BpmnEditorActions.$inject = [
|
|
|
|
'injector'
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register default actions.
|
|
|
|
*
|
|
|
|
* @param {Injector} injector
|
|
|
|
*/
|
|
|
|
BpmnEditorActions.prototype._registerDefaultActions = function(injector) {
|
|
|
|
|
|
|
|
// (0) invoke super method
|
|
|
|
|
|
|
|
EditorActions.prototype._registerDefaultActions.call(this, injector);
|
|
|
|
|
|
|
|
// (1) retrieve optional components to integrate with
|
|
|
|
|
|
|
|
var canvas = injector.get('canvas', false);
|
|
|
|
var elementRegistry = injector.get('elementRegistry', false);
|
|
|
|
var selection = injector.get('selection', false);
|
|
|
|
var spaceTool = injector.get('spaceTool', false);
|
|
|
|
var lassoTool = injector.get('lassoTool', false);
|
|
|
|
var handTool = injector.get('handTool', false);
|
|
|
|
var globalConnect = injector.get('globalConnect', false);
|
|
|
|
var distributeElements = injector.get('distributeElements', false);
|
|
|
|
var alignElements = injector.get('alignElements', false);
|
|
|
|
var directEditing = injector.get('directEditing', false);
|
|
|
|
var searchPad = injector.get('searchPad', false);
|
|
|
|
var modeling = injector.get('modeling', false);
|
|
|
|
|
|
|
|
// (2) check components and register actions
|
2016-06-21 13:18:29 +00:00
|
|
|
|
2018-10-26 22:54:31 +00:00
|
|
|
if (canvas && elementRegistry && selection) {
|
|
|
|
this._registerAction('selectElements', function() {
|
2016-06-21 13:18:29 +00:00
|
|
|
// 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;
|
2018-10-26 22:54:31 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spaceTool) {
|
|
|
|
this._registerAction('spaceTool', function() {
|
2016-06-21 13:18:29 +00:00
|
|
|
spaceTool.toggle();
|
2018-10-26 22:54:31 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lassoTool) {
|
|
|
|
this._registerAction('lassoTool', function() {
|
2016-06-21 13:18:29 +00:00
|
|
|
lassoTool.toggle();
|
2018-10-26 22:54:31 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handTool) {
|
|
|
|
this._registerAction('handTool', function() {
|
2016-06-21 13:18:29 +00:00
|
|
|
handTool.toggle();
|
2018-10-26 22:54:31 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (globalConnect) {
|
|
|
|
this._registerAction('globalConnectTool', function() {
|
2016-06-21 13:18:29 +00:00
|
|
|
globalConnect.toggle();
|
2018-10-26 22:54:31 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selection && distributeElements) {
|
|
|
|
this._registerAction('distributeElements', function(opts) {
|
2016-06-21 13:18:29 +00:00
|
|
|
var currentSelection = selection.get(),
|
|
|
|
type = opts.type;
|
|
|
|
|
|
|
|
if (currentSelection.length) {
|
|
|
|
distributeElements.trigger(currentSelection, type);
|
|
|
|
}
|
2018-10-26 22:54:31 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selection && alignElements) {
|
|
|
|
this._registerAction('alignElements', function(opts) {
|
2016-06-21 13:18:29 +00:00
|
|
|
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);
|
|
|
|
}
|
2018-10-26 22:54:31 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selection && modeling) {
|
|
|
|
this._registerAction('setColor', function(opts) {
|
2016-12-13 10:21:57 +00:00
|
|
|
var currentSelection = selection.get();
|
|
|
|
|
|
|
|
if (currentSelection.length) {
|
|
|
|
modeling.setColor(currentSelection, opts);
|
|
|
|
}
|
2018-10-26 22:54:31 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selection && directEditing) {
|
|
|
|
this._registerAction('directEditing', function() {
|
2016-06-21 13:18:29 +00:00
|
|
|
var currentSelection = selection.get();
|
|
|
|
|
|
|
|
if (currentSelection.length) {
|
|
|
|
directEditing.activate(currentSelection[0]);
|
|
|
|
}
|
2018-10-26 22:54:31 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (searchPad) {
|
|
|
|
this._registerAction('find', function() {
|
2016-06-21 13:18:29 +00:00
|
|
|
searchPad.toggle();
|
2018-10-26 22:54:31 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (canvas && modeling) {
|
|
|
|
this._registerAction('moveToOrigin', function() {
|
2016-08-18 07:08:00 +00:00
|
|
|
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);
|
|
|
|
|
2018-10-26 22:54:31 +00:00
|
|
|
modeling.moveElements(
|
|
|
|
elements,
|
|
|
|
{ x: -boundingBox.x, y: -boundingBox.y },
|
|
|
|
rootElement
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2016-06-21 13:18:29 +00:00
|
|
|
|
2018-10-26 22:54:31 +00:00
|
|
|
};
|