From 9e2ad175df0e216c1a4bc0689c90d124fdd389f5 Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Mon, 4 Aug 2014 09:32:36 +0200 Subject: [PATCH] chore(label-editing): integrate into modeling --- lib/features/label-editing/LabelEditingProvider.js | 11 +++++------ .../{UpdateTextHandler.js => UpdateLabelHandler.js} | 5 +++-- lib/features/modeling/Modeling.js | 8 ++++++++ lib/features/modeling/index.js | 1 + 4 files changed, 17 insertions(+), 8 deletions(-) rename lib/features/label-editing/cmd/{UpdateTextHandler.js => UpdateLabelHandler.js} (78%) diff --git a/lib/features/label-editing/LabelEditingProvider.js b/lib/features/label-editing/LabelEditingProvider.js index ecbcee32..a1f44e8c 100644 --- a/lib/features/label-editing/LabelEditingProvider.js +++ b/lib/features/label-editing/LabelEditingProvider.js @@ -2,7 +2,7 @@ var _ = require('lodash'); -var UpdateTextHandler = require('./cmd/UpdateTextHandler'); +var UpdateLabelHandler = require('./cmd/UpdateLabelHandler'); var LabelUtil = require('./LabelUtil'), DiUtil = require('../../util/Di'); @@ -17,7 +17,7 @@ var minBounds = { function LabelEditingProvider(eventBus, canvas, directEditing, commandStack) { directEditing.registerProvider(this); - commandStack.registerHandler('bpmnElement.updateText', UpdateTextHandler); + commandStack.registerHandler('element.updateLabel', UpdateLabelHandler); // per default, listen to double click events eventBus.on('shape.dblclick', function(event) { @@ -101,11 +101,10 @@ LabelEditingProvider.prototype.getEditingBBox = function(element, maxBounds) { }; -LabelEditingProvider.prototype.update = function(element, newText, oldText) { - this._commandStack.execute('bpmnElement.updateText', { +LabelEditingProvider.prototype.update = function(element, newLabel) { + this._commandStack.execute('element.updateLabel', { element: element, - oldText: oldText, - newText: newText + newLabel: newLabel }); }; diff --git a/lib/features/label-editing/cmd/UpdateTextHandler.js b/lib/features/label-editing/cmd/UpdateLabelHandler.js similarity index 78% rename from lib/features/label-editing/cmd/UpdateTextHandler.js rename to lib/features/label-editing/cmd/UpdateLabelHandler.js index 277b30c0..3fbe80cd 100644 --- a/lib/features/label-editing/cmd/UpdateTextHandler.js +++ b/lib/features/label-editing/cmd/UpdateLabelHandler.js @@ -20,11 +20,12 @@ function UpdateTextHandler(eventBus) { } function execute(ctx) { - setText(ctx.element, ctx.newText); + ctx.oldLabel = LabelUtil.getLabel(ctx.element.businessObject); + setText(ctx.element, ctx.newLabel); } function revert(ctx) { - setText(ctx.element, ctx.oldText); + setText(ctx.element, ctx.oldLabel); } diff --git a/lib/features/modeling/Modeling.js b/lib/features/modeling/Modeling.js index ef6c6837..fb07bb8a 100644 --- a/lib/features/modeling/Modeling.js +++ b/lib/features/modeling/Modeling.js @@ -44,6 +44,14 @@ Modeling.prototype.registerHandlers = function(commandStack) { }; +Modeling.prototype.updateLabel = function(element, newLabel) { + this._commandStack.execute('element.updateLabel', { + element: element, + newLabel: newLabel + }); +}; + + /** * Append a flow node to the element with the given source * at the specified position. diff --git a/lib/features/modeling/index.js b/lib/features/modeling/index.js index 5e9ecd65..cebc1257 100644 --- a/lib/features/modeling/index.js +++ b/lib/features/modeling/index.js @@ -2,6 +2,7 @@ module.exports = { __init__: [ 'modeling', 'bpmnUpdater', 'labelSupport' ], __depends__: [ require('../../core'), + require('../label-editing'), require('diagram-js/lib/command'), require('diagram-js/lib/features/change-support') ],