/// <summary> /// Executes the paste operation on the given element. /// </summary> /// <param name="modelElement">Element.</param> /// <returns>Validation result, indicating problems during the paste operation.</returns> public static ValidationResult ExecutePaste(ModelElement modelElement) { System.Windows.IDataObject idataObject = System.Windows.Clipboard.GetDataObject(); ValidationResult result = null; using (Transaction transaction = modelElement.Store.TransactionManager.BeginTransaction("Paste", true)) { result = ModelElementOperations.Merge(modelElement, idataObject); List <Guid> shapes = DiagramsShapeStore.GetFromStore(modelElement.Id); if (shapes != null) { foreach (Guid s in shapes) { NodeShape shape = modelElement.Store.ElementDirectory.FindElement(s) as NodeShape; if (shape != null) { using (Transaction tShape = modelElement.Store.TransactionManager.BeginTransaction("Create shape", true)) { shape.FixUpMissingShapes(); tShape.Commit(); } using (Transaction tLinkShapes = modelElement.Store.TransactionManager.BeginTransaction("Fixup missing link shapes", true)) { shape.FixUpMissingLinkShapes(); tLinkShapes.Commit(); } } } } transaction.Commit(); } ModelProtoGroup group = ModelElementOperations.GetModelProtoGroup(idataObject); if (group != null) { if (group.Operation == ModelProtoGroupOperation.Move) { System.Windows.Clipboard.Clear(); ElementsInMoveMode.Clear(); } } return(result); }
/// <summary> /// Helper method of the cut opeation. /// </summary> /// <param name="eventManager">Event manager.</param> /// <param name="idataObject">Data object.</param> public static void ProcessMoveMode(ViewModelEventManager eventManager, System.Windows.IDataObject idataObject) { bool isInMoveMode = false; if (idataObject != null) { ModelProtoGroup group = ModelElementOperations.GetModelProtoGroup(idataObject); if (group != null) { if (group.Operation == ModelProtoGroupOperation.Move) { isInMoveMode = true; List <System.Guid> guids = new List <System.Guid>(); foreach (ModelProtoElement root in group.ProtoRootElements) { guids.Add(root.ElementId); } foreach (System.Guid id in guids) { if (!ElementsInMoveMode.Contains(id)) { eventManager.GetEvent <ModelElementCustomEvent <bool> >().Publish(true, ModelElementCustomEventNames.ModelElementMoveModeStatus, id); ElementsInMoveMode.Add(id); } } for (int i = ElementsInMoveMode.Count - 1; i >= 0; i--) { if (!guids.Contains(ElementsInMoveMode[i])) { eventManager.GetEvent <ModelElementCustomEvent <bool> >().Publish(false, ModelElementCustomEventNames.ModelElementMoveModeStatus, ElementsInMoveMode[i]); ElementsInMoveMode.RemoveAt(i); } } } } } if (!isInMoveMode) { // remove all elements from the current list and notify them to change status foreach (System.Guid id in ElementsInMoveMode) { eventManager.GetEvent <ModelElementCustomEvent <bool> >().Publish(false, ModelElementCustomEventNames.ModelElementMoveModeStatus, id); } } }