mirror of
https://github.com/sartography/bpmn-js.git
synced 2025-01-28 17:54:57 +00:00
62 lines
1.6 KiB
JavaScript
62 lines
1.6 KiB
JavaScript
|
'use strict';
|
||
|
|
||
|
var inherits = require('inherits');
|
||
|
|
||
|
var forEach = require('lodash/collection/forEach');
|
||
|
|
||
|
var is = require('../../../util/ModelUtil').is;
|
||
|
|
||
|
var CommandInterceptor = require('diagram-js/lib/command/CommandInterceptor');
|
||
|
|
||
|
|
||
|
function CopyPasteBehavior(eventBus, modeling, canvas) {
|
||
|
|
||
|
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();
|
||
|
}
|
||
|
}, 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);
|
||
|
}
|
||
|
|
||
|
|
||
|
CopyPasteBehavior.$inject = [ 'eventBus', 'modeling', 'canvas' ];
|
||
|
|
||
|
inherits(CopyPasteBehavior, CommandInterceptor);
|
||
|
|
||
|
module.exports = CopyPasteBehavior;
|