feat(modelling): unify drag/drop handling from palette/context-pad

Related to bpmn-io/diagram-js#60
This commit is contained in:
Nico Rehwaldt 2014-12-23 16:48:12 +01:00
parent 1dd19fdb0d
commit 355059c30a
2 changed files with 34 additions and 32 deletions

View File

@ -47,29 +47,23 @@ ContextPadProvider.prototype.getContextPadEntries = function(element) {
var bpmnElement = element.businessObject; var bpmnElement = element.businessObject;
function startConnect(event, element) { function startConnect(event, element, autoActivate) {
connect.start(event, element, null); connect.start(event, element, autoActivate);
}
function append(element, type) {
var target = modeling.appendShape(element, { type: type });
selection.select(target);
directEditing.activate(target);
} }
function appendAction(type, className) { function appendAction(type, className) {
function appendListener(event, element) {
var shape = elementFactory.createShape({ type: type });
create.start(event, shape, element);
}
return { return {
group: 'model', group: 'model',
className: className, className: className,
action: { action: {
dragstart: function(event, element) { dragstart: appendListener,
var shape = elementFactory.createShape({ type: type }); click: appendListener
create.start(event, shape, element);
},
click: function(event, element) {
append(element, type);
}
} }
}; };
} }
@ -99,18 +93,22 @@ ContextPadProvider.prototype.getContextPadEntries = function(element) {
}); });
} }
_.extend(actions, { function removeElement(e) {
'delete': {
group: 'edit',
className: 'icon-trash',
action: function(e) {
if (element.waypoints) { if (element.waypoints) {
modeling.removeConnection(element); modeling.removeConnection(element);
} else { } else {
modeling.removeShape(element); modeling.removeShape(element);
} }
} }
_.extend(actions, {
'delete': {
group: 'edit',
className: 'icon-trash',
action: {
click: removeElement,
dragstart: removeElement
}
} }
}); });

View File

@ -20,12 +20,8 @@ PaletteProvider.$inject = [ 'palette', 'create', 'elementFactory' ];
PaletteProvider.prototype.getPaletteEntries = function(element) { PaletteProvider.prototype.getPaletteEntries = function(element) {
function createAction(type, group, className, title, options) { function createAction(type, group, className, title, options) {
return {
group: group, function createListener(event) {
className: className,
title: title || 'Create ' + type,
action: {
dragstart: function(event) {
var shape = elementFactory.createShape(_.extend({ type: type }, options)); var shape = elementFactory.createShape(_.extend({ type: type }, options));
if (options) { if (options) {
@ -34,6 +30,14 @@ PaletteProvider.prototype.getPaletteEntries = function(element) {
create.start(event, shape); create.start(event, shape);
} }
return {
group: group,
className: className,
title: title || 'Create ' + type,
action: {
dragstart: createListener,
click: createListener
} }
}; };
} }