2018-04-02 19:01:53 +00:00
|
|
|
import inherits from 'inherits';
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
forEach
|
|
|
|
} from 'min-dash';
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import { is } from '../../../util/ModelUtil';
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
|
2016-04-20 15:31:42 +00:00
|
|
|
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
export default function CopyPasteBehavior(eventBus, modeling, canvas) {
|
2016-04-20 15:31:42 +00:00
|
|
|
|
|
|
|
CommandInterceptor.call(this, eventBus);
|
|
|
|
|
|
|
|
this.preExecute('elements.paste', 1500, function(context) {
|
|
|
|
var topParent = context.topParent;
|
|
|
|
|
|
|
|
// always grab the latest root
|
|
|
|
if (!topParent.parent) {
|
|
|
|
context.topParent = canvas.getRootElement();
|
|
|
|
}
|
2016-04-26 12:02:41 +00:00
|
|
|
|
|
|
|
if (is(topParent, 'bpmn:Lane')) {
|
|
|
|
do {
|
|
|
|
// unwrap Lane -> LaneSet -> (Lane | FlowElementsContainer)
|
2016-05-03 14:49:10 +00:00
|
|
|
topParent = context.topParent = topParent.parent;
|
2016-04-26 12:02:41 +00:00
|
|
|
|
2016-05-03 14:49:10 +00:00
|
|
|
} while (is(topParent, 'bpmn:Lane') || !is(topParent, 'bpmn:Participant'));
|
2016-04-26 12:02:41 +00:00
|
|
|
}
|
2016-04-20 15:31:42 +00:00
|
|
|
}, true);
|
|
|
|
|
|
|
|
this.postExecute('elements.paste', function(context) {
|
|
|
|
|
|
|
|
var tree = context.tree,
|
|
|
|
createdElements = tree.createdElements;
|
|
|
|
|
|
|
|
forEach(createdElements, function(data) {
|
|
|
|
var element = data.element,
|
|
|
|
businessObject = element.businessObject,
|
|
|
|
descriptor = data.descriptor,
|
|
|
|
defaultFlow;
|
|
|
|
|
|
|
|
if ((is(businessObject, 'bpmn:ExclusiveGateway') || is(businessObject, 'bpmn:InclusiveGateway') ||
|
|
|
|
is(businessObject, 'bpmn:Activity')) && descriptor.default) {
|
|
|
|
|
|
|
|
defaultFlow = createdElements[descriptor.default];
|
|
|
|
|
|
|
|
// if the default flow wasn't created, means that it wasn't copied
|
|
|
|
if (defaultFlow) {
|
|
|
|
defaultFlow = defaultFlow.element;
|
|
|
|
} else {
|
|
|
|
defaultFlow = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete element.default;
|
|
|
|
|
|
|
|
modeling.updateProperties(element, { default: defaultFlow });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
CopyPasteBehavior.$inject = [
|
|
|
|
'eventBus',
|
|
|
|
'modeling',
|
|
|
|
'canvas'
|
|
|
|
];
|
2016-04-20 15:31:42 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
inherits(CopyPasteBehavior, CommandInterceptor);
|