static bool ShouldSuppressAddingConnectorsWhenAddingStateVisuals(EditingScope scope) { return(scope.Changes.Any <Change>((p) => { return p != null && p.GetType() == typeof(SuppressAddingConnectorWhenAddingStateVisual); })); }
internal bool CreateLinkGesture(ConnectionPoint sourceConnectionPoint, ConnectionPoint destConnectionPoint, out string errorMessage, bool isLinkValidDueToLinkMove, IFlowSwitchLink caseKey) { Fx.Assert(this.panel != null, "This code should not be hit if panel is null"); Fx.Assert(sourceConnectionPoint != null, "sourceConnectionPoint is null."); Fx.Assert(destConnectionPoint != null, "destConnectionPoint is null."); bool linkCreated = false; errorMessage = string.Empty; if (destConnectionPoint.PointType != ConnectionPointKind.Outgoing && sourceConnectionPoint.PointType != ConnectionPointKind.Incoming) { using (EditingScope es = (EditingScope)this.ModelItem.BeginEdit(SR.FCCreateLink)) { linkCreated = UpdateFlowChartObject(sourceConnectionPoint, destConnectionPoint, out errorMessage, isLinkValidDueToLinkMove, caseKey); try { es.Complete(); } catch (ArgumentException) { errorMessage = SR.InvalidFlowSwitchCaseMessage; linkCreated = false; } } } else { errorMessage = SR.FCInvalidLink; } return(linkCreated); }
static bool IsTransitionReordering(EditingScope scope) { return(scope.Changes.Any <Change>((p) => { return p != null && p.GetType() == typeof(TransitionReorderChange); })); }
public override void ShowDialog(PropertyValue propertyValue, IInputElement commandSource) { ModelPropertyEntryToOwnerActivityConverter propertyEntryConverter = new ModelPropertyEntryToOwnerActivityConverter(); ModelItem activityModelItem = (ModelItem)propertyEntryConverter.Convert(propertyValue.ParentProperty, typeof(ModelItem), false, null); ModelItem parentModelItem = (ModelItem)propertyEntryConverter.Convert(propertyValue.ParentProperty, typeof(ModelItem), true, null); EditingContext context = ((IModelTreeItem)activityModelItem).ModelTreeManager.Context; var inputData = parentModelItem.Properties[propertyValue.ParentProperty.PropertyName].Collection; DynamicArgumentDesignerOptions options = new DynamicArgumentDesignerOptions { Title = propertyValue.ParentProperty.DisplayName, }; using (EditingScope scope = context.Services.GetRequiredService <ModelTreeManager>().CreateEditingScope(StringResourceDictionary.Instance.GetString("InvokeMethodParameterEditing"), true)) { if (DynamicArgumentDialog.ShowDialog(activityModelItem, inputData, context, activityModelItem.View, options)) { scope.Complete(); } } }
private void AddNewTransition(string stateName) { ModelItem stateMachineModelItem = StateContainerEditor.GetStateMachineModelItem(this.parentStateModelItem); ModelItem toStateModelItem = null; foreach (ModelItem stateModelItem in stateMachineModelItem.Properties[StateMachineDesigner.StatesPropertyName].Collection) { if (string.Equals(stateName, stateModelItem.Properties[StateDesigner.DisplayNamePropertyName].ComputedValue as string, StringComparison.Ordinal)) { toStateModelItem = stateModelItem; } } if (null == toStateModelItem) { return; } Fx.Assert(toStateModelItem != null, "To state cannot be null."); using (EditingScope editingScope = (EditingScope)this.ModelItem.BeginEdit(SR.CreateTransition)) { ModelItem triggerModelItem = this.ModelItem.Properties[TriggerPropertyName].Value; State toState = toStateModelItem.GetCurrentValue() as State; ModelItem newTransitionItem = this.parentStateModelItem.Properties[StateDesigner.TransitionsPropertyName].Collection.Add(new Transition() { Trigger = null == triggerModelItem ? null : triggerModelItem.GetCurrentValue() as Activity, DisplayName = StateContainerEditor.GenerateTransitionName(stateMachineModelItem), To = toState }); this.ViewStateService.StoreViewState(newTransitionItem, ExpandViewStateKey, true); if (null == triggerModelItem) { PointCollection thisPointCollection = this.ViewStateService.RetrieveViewState(this.ModelItem, StateContainerEditor.ConnectorLocationViewStateKey) as PointCollection; if (null != thisPointCollection && thisPointCollection.Any()) { PointCollection newTransitionViewState = new PointCollection { thisPointCollection[0] // start point }; if (toState == this.parentStateModelItem.GetCurrentValue()) { // add an invalid destination point for self-transition, to force a reroute of the connection point newTransitionViewState.Add(new Point(0, 0)); } this.ViewStateService.StoreViewState(newTransitionItem, StateContainerEditor.ConnectorLocationViewStateKey, newTransitionViewState); } } editingScope.Complete(); } this.UpdateTransitionsSharingTrigger(); }
public static void Delete(EditingContext context) { if (context == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("context")); } Selection selection = context.Items.GetValue <Selection>(); if (null != selection) { bool selectRoot = false; DesignerView designerView = context.Services.GetService <DesignerView>(); var toDelete = selection.SelectedObjects.Where(p => null != p.View && p.View is WorkflowViewElement && !p.View.Equals(designerView.RootDesigner)); if (toDelete.Count() > 0) { using (EditingScope es = (EditingScope)toDelete.FirstOrDefault().BeginEdit(SR.DeleteOperationEditingScopeDescription)) { Dictionary <ICompositeView, List <ModelItem> > containerToModelItemsDict = new Dictionary <ICompositeView, List <ModelItem> >(); List <ModelItem> modelItemsPerContainer; foreach (var item in toDelete) { ICompositeView container = (ICompositeView)DragDropHelper.GetCompositeView((WorkflowViewElement)item.View); if (null != container) { if (!containerToModelItemsDict.TryGetValue(container, out modelItemsPerContainer)) { modelItemsPerContainer = new List <ModelItem>(); containerToModelItemsDict.Add(container, modelItemsPerContainer); } modelItemsPerContainer.Add(item); } } foreach (ICompositeView container in containerToModelItemsDict.Keys) { container.OnItemsDelete(containerToModelItemsDict[container]); selectRoot = true; } if (selectRoot) { DesignerView view = context.Services.GetService <DesignerView>(); if (null != view) { WorkflowViewElement rootView = view.RootDesigner as WorkflowViewElement; if (rootView != null) { Selection.SelectOnly(context, rootView.ModelItem); } } } es.Complete(); } } } }
protected override void OnLostMouseCapture(MouseEventArgs e) { if (this.scope != null) { this.scope.Complete(); this.scope.Dispose(); this.scope = null; } base.OnLostMouseCapture(e); }
void OnSetAsInitialExecute(object sender, ExecutedRoutedEventArgs e) { using (EditingScope es = (EditingScope)this.ModelItem.BeginEdit(SR.SetInitialState)) { this.ViewStateService.RemoveViewState(this.stateMachineModelItem, StateContainerEditor.ConnectorLocationViewStateKey); this.stateMachineModelItem.Properties[StateMachineDesigner.InitialStatePropertyName].SetValue(this.ModelItem.GetCurrentValue()); es.Complete(); } e.Handled = true; }
void OnDefineButtonClicked(object sender, RoutedEventArgs args) { using (EditingScope scope = this.Context.Services.GetRequiredService <ModelTreeManager>().CreateEditingScope(StringResourceDictionary.Instance.GetString("editReceiveContent"), true)) { if (ReceiveContentDialog.ShowDialog(this.ModelItem, this.Context, this)) { scope.Complete(); } } }
// referenceConnector is used when we are re-linking the connector. internal ConnectorCreationResult CreateConnectorGesture(ConnectionPoint sourceConnectionPoint, ConnectionPoint destConnectionPoint, Connector referenceConnector, bool isConnectorStartMoved) { Fx.Assert(sourceConnectionPoint != null, "sourceConnectionPoint is null."); Fx.Assert(destConnectionPoint != null, "destConnectionPoint is null."); ConnectorCreationResult result = ConnectorCreationResult.OtherFailure; if (destConnectionPoint.PointType != ConnectionPointKind.Outgoing && sourceConnectionPoint.PointType != ConnectionPointKind.Incoming) { if (sourceConnectionPoint.ParentDesigner is VirtualizedContainerService.VirtualizingContainer) { //bool sameDestination = false; ModelItem refTransitionModelItem = null; if (referenceConnector != null) { refTransitionModelItem = StateContainerEditor.GetConnectorModelItem(referenceConnector); } using (EditingScope es = (EditingScope)this.ModelItem.BeginEdit(SR.CreateTransition)) { if (refTransitionModelItem != null) { this.CreateTransition(sourceConnectionPoint, destConnectionPoint, refTransitionModelItem, isConnectorStartMoved); } else { this.CreateTransition(sourceConnectionPoint, destConnectionPoint, null, false); } result = ConnectorCreationResult.Success; es.Complete(); } } else if (sourceConnectionPoint.ParentDesigner is StartSymbol) { ModelItem stateModelItem = ((VirtualizedContainerService.VirtualizingContainer)destConnectionPoint.ParentDesigner).ModelItem; if (IsFinalState(stateModelItem)) { result = ConnectorCreationResult.CannotSetFinalStateAsInitialState; } else { using (EditingScope es = (EditingScope)this.ModelItem.BeginEdit(SR.SetInitialState)) { this.StateMachineModelItem.Properties[StateMachineDesigner.InitialStatePropertyName].SetValue(stateModelItem); PointCollection connectorViewState = new PointCollection(ConnectorRouter.Route(this.panel, sourceConnectionPoint, destConnectionPoint)); this.StoreConnectorLocationViewState(this.StateMachineModelItem, connectorViewState, true); result = ConnectorCreationResult.Success; es.Complete(); } } } } return(result); }
// While adding an new StateContainer inside an outer StateContainer, the outter StateContainer size might change. // InsertState would recursively stores the outer containers before the insertion happens, and capture the size within a single EditingScope to facilitate Undo. ModelItem InsertState(Object droppedObject) { ModelItem droppedModelItem = null; Fx.Assert(this.ModelItem.ItemType == typeof(StateMachine), "Should only drop state with StateMachine."); using (EditingScope es = (EditingScope)this.ModelItem.BeginEdit(System.Activities.Presentation.SR.CollectionAddEditingScopeDescription)) { StoreShapeSizeWithUndoRecursively(this.ModelItem); droppedModelItem = this.ModelItem.Properties[StateMachineDesigner.StatesPropertyName].Collection.Add(droppedObject); es.Complete(); } return(droppedModelItem); }
// The method will return the CaseKey if any. // referenceUpdatedModelItems: say A linked to B by linker C, there is a relationship: // A.Properties["Relation"] = B. // When delete the linker C, A will be updated like, A.Properties["Relation"] = null; // In multiple drag/drop, the A.Properties["Relation"] is set correctly before coming // here, which means we should not set the value again, otherwise the correct, // value which is set previously, will be removed. internal IFlowSwitchLink DeleteLink(Connector link, bool isMoveOrAutoSplit = false, HashSet <ModelItem> referenceUpdatedModelItems = null) { IFlowSwitchLink caseKey = null; using (EditingScope deleteLinkEditingScope = ((IModelTreeItem)this.ModelItem).ModelTreeManager.CreateEditingScope(SR.FCDeleteLink)) { caseKey = DeleteLinkImpl(link, isMoveOrAutoSplit, referenceUpdatedModelItems); deleteLinkEditingScope.Complete(); } return(caseKey); }
public EditingScopeUndoUnit(EditingContext context, ModelTreeManager modelTreeManager, EditingScope editingScope) : base(context) { Fx.Assert(context != null, "context cannot be null"); Fx.Assert(modelTreeManager != null, "modelTreeManager cannot be null"); Fx.Assert(editingScope != null, "editingScope cannot be null"); this.context = context; this.modelTreeManager = modelTreeManager; this.editingScope = editingScope; this.Description = this.editingScope.Description; SaveGlobalState(); }
public override void Redo() { this.modelTreeManager.StopTracking(); try { EditingScope redoEditingScope = this.modelTreeManager.CreateEditingScope(this.editingScope.Description); redoEditingScope.Changes.AddRange(editingScope.Changes); redoEditingScope.Complete(); } finally { this.modelTreeManager.StartTracking(); } ApplyGlobalState(); }
internal int DeleteConnectorModelItem(Connector connector, bool rerouting = false) { ModelItem connectorModelItem = StateContainerEditor.GetConnectorModelItem(connector); if (!rerouting) { if (connector is ConnectorWithStartDot) { connector.StartDot.MouseDown -= new MouseButtonEventHandler(OnConnectorStartDotMouseDown); connector.StartDot.MouseUp -= new MouseButtonEventHandler(OnConnectorStartDotMouseUp); } connector.GotKeyboardFocus -= new KeyboardFocusChangedEventHandler(OnConnectorGotKeyboardFocus); connector.RequestBringIntoView -= new RequestBringIntoViewEventHandler(OnConnectorRequestBringIntoView); connector.GotFocus -= new RoutedEventHandler(OnConnectorGotFocus); connector.MouseDoubleClick -= new MouseButtonEventHandler(OnConnectorMouseDoubleClick); connector.MouseDown -= new MouseButtonEventHandler(OnConnectorMouseDown); connector.KeyDown -= new KeyEventHandler(OnConnectorKeyDown); connector.ContextMenuOpening -= new ContextMenuEventHandler(OnConnectorContextMenuOpening); connector.Unloaded -= new RoutedEventHandler(OnConnectorUnloaded); } int removedIndex = InvalidIndex; if (connectorModelItem.ItemType == typeof(Transition)) { ModelItemCollection transitions = StateContainerEditor.GetParentStateModelItemForTransition(connectorModelItem).Properties[StateDesigner.TransitionsPropertyName].Collection; removedIndex = transitions.IndexOf(connectorModelItem); Fx.Assert(removedIndex >= 0, "can't find the connector ModelItem in collection"); transitions.Remove(connectorModelItem); } // Connector from initial node else if (connectorModelItem.ItemType == typeof(StateMachine)) { using (EditingScope es = (EditingScope)this.ModelItem.BeginEdit(SR.ClearInitialState)) { connectorModelItem.Properties[StateMachineDesigner.InitialStatePropertyName].SetValue(null); if (!rerouting) { this.ViewStateService.StoreViewStateWithUndo(connectorModelItem, ConnectorLocationViewStateKey, null); } es.Complete(); } } return(removedIndex); }
internal void DeleteConnectorModelItem(Connector connector) { ModelItem connectorModelItem = StateContainerEditor.GetConnectorModelItem(connector); if (connectorModelItem.ItemType == typeof(Transition)) { StateContainerEditor.GetParentStateModelItemForTransition(connectorModelItem).Properties[StateDesigner.TransitionsPropertyName].Collection.Remove(connectorModelItem); } // Connector from initial node else if (connectorModelItem.ItemType == typeof(StateMachine)) { using (EditingScope es = (EditingScope)this.ModelItem.BeginEdit(SR.ClearInitialState)) { connectorModelItem.Properties[StateMachineDesigner.InitialStatePropertyName].SetValue(null); es.Complete(); } } }
public override void Undo() { this.modelTreeManager.StopTracking(); try { this.RedoList = this.DoList.Reverse <UndoUnit>().ToList(); using (EditingScope undoEditingScope = this.modelTreeManager.CreateEditingScope(this.Description, true)) { this.RedoList.ForEach(unit => unit.Undo()); undoEditingScope.Complete(); } this.DoList.Clear(); } finally { this.modelTreeManager.StartTracking(); } }
void OnCasePropertyChanged(DependencyPropertyChangedEventArgs e) { bool isUndoRedoInProgress = this.IsUndoRedoInProgress(); if (!this.internalChange && !isUndoRedoInProgress) { T oldValue = (T)e.OldValue; T newValue = (T)e.NewValue; if (newValue is string && newValue != null) { newValue = (T)((object)((string)((object)newValue)).Trim()); } string oldViewStateKey = string.Empty; if (!this.ContainsKey(newValue)) { using (EditingScope es = (EditingScope)this.flowSwitchModelItem.BeginEdit(SR.FlowSwitchCaseRenameEditingScopeDesc)) { ModelItem flowElementMI = null; flowElementMI = GenericFlowSwitchHelper.GetCaseModelItem(this.flowSwitchModelItem.Properties["Cases"], oldValue); GenericFlowSwitchHelper.RemoveCase(this.flowSwitchModelItem.Properties["Cases"], oldValue); oldViewStateKey = GenericFlowSwitchHelper.GetString(oldValue, typeof(T)) + CaseViewStateKeyAppendString; //Add the new value GenericFlowSwitchHelper.AddCase(this.flowSwitchModelItem.Properties["Cases"], newValue, flowElementMI.GetCurrentValue()); //Update the viewstate for the flowswitch. this.UpdateViewState(oldViewStateKey, GenericFlowSwitchHelper.GetString(newValue, typeof(T)) + CaseViewStateKeyAppendString); //Making sure the value for Case is always trimmed. this.internalChange = true; this.ModelItem.Properties["Case"].SetValue(newValue); es.Complete(); } } else { this.internalChange = true; this.CaseObject = oldValue; throw FxTrace.Exception.AsError(new InvalidOperationException(SR.InvalidFlowSwitchCaseMessage)); } } this.internalChange = false; }
protected override void OnGotMouseCapture(MouseEventArgs e) { ModelItem stateContainerModelItem = this.ParentStateContainerEditor.ModelItem; string undoItemName = string.Empty; if (stateContainerModelItem.ItemType == typeof(StateMachine)) { undoItemName = SR.StateMachineResize; } else if (stateContainerModelItem.ItemType == typeof(State)) { undoItemName = SR.StateResize; } else { Fx.Assert(false, "The model item type is invalid"); } this.scope = (EditingScope)this.ParentStateContainerEditor.ModelItem.BeginEdit(undoItemName); base.OnGotMouseCapture(e); }
public void ShowDialog(ModelItem activity, EditingContext context) { Fx.Assert(activity != null, "Activity model item shouldn't be null!"); Fx.Assert(context != null, "EditingContext shouldn't be null!"); string bookmarkTitle = (string)this.InlineEditorTemplate.Resources["bookmarkTitle"]; UndoEngine undoEngine = context.Services.GetService <UndoEngine>(); Fx.Assert(null != undoEngine, "UndoEngine should be available"); using (EditingScope scope = context.Services.GetRequiredService <ModelTreeManager>().CreateEditingScope(bookmarkTitle, true)) { if ((new EditorWindow(activity, context)).ShowOkCancel()) { scope.Complete(); } } }
protected override void OnDrop(DragEventArgs e) { ModelTreeManager manager = this.Context.Services.GetService <ModelTreeManager>(); // When dragging from toolbox: // editingScope should not be null // there should only be one item // When dragging from canvas: // editingScope should be null // Call editingScope.Complete() to commit changes, otherwise the editing scope will be aborted using (EditingScope editingScope = ModelItemHelper.TryCreateImmediateEditingScope(manager, SR.PropertyChangeEditingScopeDescription)) { List <object> droppedObjects = this.GetSortedObjectList(e); #pragma warning disable 618 DragDropHelper.SetDragDropCompletedEffects(e, DragDropEffects.None); #pragma warning restore 618 if (droppedObjects == null || droppedObjects.Count == 0) { return; } if (droppedObjects.Count == 1) { if (this.DoSingleDrop(droppedObjects[0], e)) { if (editingScope != null) { editingScope.Complete(); } } return; } else { // multi drop Fx.Assert(editingScope == null, "editingScope should be null for dragging from canvas."); this.DoAutoWrapDrop(InsertionPosition.None, e, droppedObjects); } base.OnDrop(e); } }
internal static void DoPaste(EditingContext context, Point pastePoint, WorkflowViewElement pastePointReference) { if (context == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("context")); } ModelItem modelItem = context.Items.GetValue <Selection>().PrimarySelection; if (modelItem == null) { return; } //Get data from clipboard. List <object> metaData = null; List <object> clipboardObjects = GetFromClipboard(out metaData, context); if (clipboardObjects != null) { using (EditingScope es = (EditingScope)modelItem.BeginEdit(SR.PasteUndoDescription)) { if (clipboardObjects.Count == 3 && clipboardObjects[1] is Func <ModelItem, object, object> ) { var factoryMethod = (Func <ModelItem, object, object>)clipboardObjects[1]; object result = factoryMethod(modelItem, clipboardObjects[2]); clipboardObjects = new List <object>(); clipboardObjects.Add(result); } ICompositeView container = GetContainerForPaste(modelItem, pastePoint); if (container != null) { container.OnItemsPasted(clipboardObjects, metaData, pastePoint, pastePointReference); } es.Complete(); } } }
public override void Undo() { this.modelTreeManager.StopTracking(); try { EditingScope undoEditingScope = this.modelTreeManager.CreateEditingScope(this.editingScope.Description); foreach (Change change in editingScope.Changes) { Change inverseChange = change.GetInverse(); if (inverseChange != null) { undoEditingScope.Changes.Add(inverseChange); } } undoEditingScope.Changes.Reverse(); undoEditingScope.Complete(); } finally { this.modelTreeManager.StartTracking(); } ApplyGlobalState(); }
internal static void DoCut(List <ModelItem> modelItemsToCut, EditingContext context) { if (modelItemsToCut == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("modelItemsToCut")); } if (context == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("context")); } modelItemsToCut.RemoveAll((modelItem) => { return(modelItem == null); }); if (modelItemsToCut.Count > 0) { using (EditingScope es = (EditingScope)modelItemsToCut[0].BeginEdit(SR.CutOperationEditingScopeDescription)) { try { CutCopyOperation(modelItemsToCut, context, true); } catch (ExternalException e) { es.Revert(); ErrorReporting.ShowErrorMessage(e.Message); return; } DesignerView view = context.Services.GetService <DesignerView>(); //Setting the selection to Breadcrumb root. Fx.Assert(view != null, "DesignerView Cannot be null during cut"); WorkflowViewElement rootView = view.RootDesigner as WorkflowViewElement; if (rootView != null) { Selection.SelectOnly(context, rootView.ModelItem); } es.Complete(); } } }
private void OnTransitionsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Move) { try { // We are updating the Transitions collection in the parent State in response to // the changes in this.TransitionsSharingTrigger. We don't want to update it again // to introduce a dead loop this.suppressUpdatingTransitionsSharingTrigger = true; using (EditingScope scope = (EditingScope)this.ModelItem.BeginEdit(SR.ReorderItems)) { ModelItem movedModelItem = this.TransitionsSharingTrigger[e.NewStartingIndex].Item; ModelItemCollection transitionsCollection = this.parentStateModelItem.Properties[StateDesigner.TransitionsPropertyName].Collection; // moving down if (e.OldStartingIndex < e.NewStartingIndex) { ModelItem nextModelItem = this.TransitionsSharingTrigger[e.OldStartingIndex].Item; SwapItems(transitionsCollection, movedModelItem, nextModelItem); } // moving up else if (e.OldStartingIndex > e.NewStartingIndex) { ModelItem previousModelItem = this.TransitionsSharingTrigger[e.OldStartingIndex].Item; SwapItems(transitionsCollection, previousModelItem, movedModelItem); } this.Context.Services.GetService <ModelTreeManager>().AddToCurrentEditingScope(new TransitionReorderChange()); scope.Complete(); } } finally { this.suppressUpdatingTransitionsSharingTrigger = false; } } }
public void OnItemsPasted(List <object> itemsToPaste, List <object> metaData, Point pastePoint, WorkflowViewElement pastePointReference) { Fx.Assert(this.panel != null, "This code shouldn't be hit if panel is null"); HashSet <Activity> workflowElementsPasted = new HashSet <Activity>(); List <ModelItem> modelItemsToSelect = new List <ModelItem>(); bool shouldStoreCurrentSizeViewState = true; Fx.Assert(this.ModelItem is IModelTreeItem, "this.ModelItem must implement IModelTreeItem"); using (EditingScope editingScope = ((IModelTreeItem)this.ModelItem).ModelTreeManager.CreateEditingScope(System.Activities.Presentation.SR.CollectionAddEditingScopeDescription)) { if (metaData != null) { List <ModelItem> modelItemsPerMetaData = new List <ModelItem>(); foreach (object designerMetaData in metaData) { if (designerMetaData is List <FlowNode> ) { //This is flowchart metadata. foreach (FlowNode element in designerMetaData as List <FlowNode> ) { FlowStep step = element as FlowStep; if (step != null) { workflowElementsPasted.Add(step.Action); } if (shouldStoreCurrentSizeViewState) { // Pasting may change the size of flowchart; need this to undo the size change. this.StoreCurrentSizeViewStateWithUndo(); shouldStoreCurrentSizeViewState = false; } ModelItem item = this.ModelItem.Properties["Nodes"].Collection.Add(element); // if the pasted item is a flowswitch but the default target is not in the pasted selection, // reset the DefaultCaseDisplayName to "Default". if (GenericFlowSwitchHelper.IsGenericFlowSwitch(item.ItemType) && item.Properties["Default"].Value == null) { item.Properties[FlowSwitchLabelFeature.DefaultCaseDisplayNamePropertyName].SetValue(FlowSwitchLabelFeature.DefaultCaseDisplayNameDefaultValue); } modelItemsPerMetaData.Add(item); if (item != null) { if (item.ItemType.Equals(typeof(FlowStep))) { modelItemsToSelect.Add(item.Properties["Action"].Value); } else { modelItemsToSelect.Add(item); } } } if (pastePoint.X > 0 && pastePoint.Y > 0) { Point panelPoint = this.TranslatePoint(pastePoint, this.panel); if (pastePointReference != null && !pastePointReference.Equals(this)) { if (pastePointReference.ModelItem != null && this.modelElement.ContainsKey(pastePointReference.ModelItem)) { panelPoint = pastePointReference.TranslatePoint(pastePoint, this.panel); } } panelPoint.X = panelPoint.X < 0 ? 0 : panelPoint.X; panelPoint.Y = panelPoint.Y < 0 ? 0 : panelPoint.Y; UpdateViewStateOnPastePoint(modelItemsPerMetaData, panelPoint); } else { UpdateViewStateToAvoidOverlapOnPaste(modelItemsPerMetaData); } modelItemsPerMetaData.Clear(); } } } foreach (object itemToPaste in itemsToPaste) { Activity workflowElementToPaste = itemToPaste as Activity; if (workflowElementToPaste != null && !workflowElementsPasted.Contains(workflowElementToPaste)) { FlowStep flowStep = new FlowStep { Action = workflowElementToPaste, Next = null }; if (shouldStoreCurrentSizeViewState) { // Pasting may change the size of flowchart; need this to undo the size change. this.StoreCurrentSizeViewStateWithUndo(); shouldStoreCurrentSizeViewState = false; } // When paste a non-flowstep object to flowchart, the existing hintsize of the object // should be removed, and let flowchart panel to compute the right size. VirtualizedContainerService.SetHintSize(workflowElementToPaste, null); ModelItem flowStepItem = this.ModelItem.Properties["Nodes"].Collection.Add(flowStep); if (flowStepItem != null) { modelItemsToSelect.Add(flowStepItem.Properties["Action"].Value); } } } editingScope.Complete(); } this.Dispatcher.BeginInvoke(() => { if (modelItemsToSelect.Count > 0 && modelItemsToSelect[0] != null) { Keyboard.Focus(modelItemsToSelect[0].View as IInputElement); } this.Context.Items.SetValue(new Selection(modelItemsToSelect)); }, DispatcherPriority.ApplicationIdle ); }
void OnIsDefaultPropertyChanged(DependencyPropertyChangedEventArgs e) { bool isUndoRedoInProgress = this.IsUndoRedoInProgress(); if (!this.internalDefaultCaseChange && !isUndoRedoInProgress) { bool value = (bool)e.NewValue; bool oldValue = (bool)e.OldValue; if (value) { if (object.Equals(this.flowSwitchModelItem.Properties["Default"].Value, null)) { using (EditingScope es = (EditingScope)this.flowSwitchModelItem.BeginEdit(SR.FlowSwitchCaseRenameEditingScopeDesc)) { ModelItem flowNodeMI = GenericFlowSwitchHelper.GetCaseModelItem(this.flowSwitchModelItem.Properties["Cases"], this.CaseObject); GenericFlowSwitchHelper.RemoveCase(this.flowSwitchModelItem.Properties["Cases"], this.CaseObject); this.flowSwitchModelItem.Properties["Default"].SetValue(flowNodeMI); this.UpdateViewState(this.CaseName + CaseViewStateKeyAppendString, DefaultConnectorViewStateKey); this.internalChange = true; es.Complete(); } } else { this.internalDefaultCaseChange = true; this.IsDefaultCase = oldValue; throw FxTrace.Exception.AsError(new InvalidOperationException(SR.DefaultCaseExists)); } } else { if (oldValue) { using (EditingScope es = (EditingScope)this.flowSwitchModelItem.BeginEdit(SR.FlowSwitchCaseRenameEditingScopeDesc)) { ModelItem defaultCase = this.flowSwitchModelItem.Properties["Default"].Value; object uniqueCase = null; string errorMessage = string.Empty; Type typeArgument = typeof(T); if (GenericFlowSwitchHelper.CanBeGeneratedUniquely(typeArgument)) { string caseName = GenericFlowSwitchHelper.GetCaseName(this.flowSwitchModelItem.Properties["Cases"], typeArgument, out errorMessage); if (!string.IsNullOrEmpty(errorMessage)) { this.internalDefaultCaseChange = true; this.IsDefaultCase = oldValue; throw FxTrace.Exception.AsError(new InvalidOperationException(errorMessage)); } uniqueCase = GenericFlowSwitchHelper.GetObject(caseName, typeArgument); } else { FlowSwitchCaseEditorDialog editor = new FlowSwitchCaseEditorDialog(this.flowSwitchModelItem, ((WorkflowViewElement)this.flowSwitchModelItem.View).Context, this.flowSwitchModelItem.View, SR.ChangeCaseValue, this.flowSwitchModelItem.ItemType.GetGenericArguments()[0]); editor.WindowSizeToContent = SizeToContent.WidthAndHeight; if (!editor.ShowOkCancel()) { this.internalDefaultCaseChange = true; this.IsDefaultCase = oldValue; return; } uniqueCase = editor.Case; if (GenericFlowSwitchHelper.ContainsCaseKey(this.flowSwitchModelItem.Properties["Cases"], uniqueCase)) { this.internalDefaultCaseChange = true; this.IsDefaultCase = oldValue; throw FxTrace.Exception.AsError(new InvalidOperationException(SR.InvalidFlowSwitchCaseMessage)); } } this.flowSwitchModelItem.Properties["Default"].SetValue(null); this.flowSwitchModelItem.Properties[FlowSwitchLabelFeature.DefaultCaseDisplayNamePropertyName].SetValue(FlowSwitchLabelFeature.DefaultCaseDisplayNameDefaultValue); this.internalChange = true; if (typeof(string) != typeof(T)) { this.ModelItem.Properties["Case"].SetValue(uniqueCase); GenericFlowSwitchHelper.AddCase(this.flowSwitchModelItem.Properties["Cases"], uniqueCase, defaultCase.GetCurrentValue()); } else { this.ModelItem.Properties["Case"].SetValue(uniqueCase); GenericFlowSwitchHelper.AddCase(this.flowSwitchModelItem.Properties["Cases"], uniqueCase, defaultCase.GetCurrentValue()); } this.UpdateViewState(DefaultConnectorViewStateKey, GenericFlowSwitchHelper.GetString(uniqueCase, typeof(T)) + CaseViewStateKeyAppendString); es.Complete(); this.internalChange = false; } this.internalDefaultCaseChange = false; } } } this.internalDefaultCaseChange = false; }
public void OnItemsPasted(List <object> itemsToPaste, List <object> metaData, Point pastePoint, WorkflowViewElement pastePointReference) { if (this.ModelItem.ItemType == typeof(State)) { WorkflowViewElement view = VisualTreeUtils.FindVisualAncestor <WorkflowViewElement>(this); if (view != null) { StateContainerEditor container = (StateContainerEditor)DragDropHelper.GetCompositeView(view); container.OnItemsPasted(itemsToPaste, metaData, pastePoint, pastePointReference); } return; } if (itemsToPaste.Count == 1 && itemsToPaste.First() is Transition) { if (metaData == null || metaData.Count != 1 || !(metaData.First() is string)) { ShowMessageBox(SR.PasteTransitionWithoutDestinationState); return; } ModelItem destinationState = FindState(metaData.First() as string); if (destinationState == null) { ShowMessageBox(SR.PasteTransitionWithoutDestinationState); return; } this.PopulateVirtualizingContainer(destinationState); ModelItem[] selectedItems = this.Context.Items.GetValue <Selection>().SelectedObjects.ToArray(); string errorMessage; if (!CanPasteTransition(destinationState, out errorMessage, selectedItems)) { ShowMessageBox(errorMessage); return; } Transition pastedTransition = itemsToPaste.First() as Transition; Fx.Assert(pastedTransition != null, "Copied Transition should not be null."); using (EditingScope es = (EditingScope)this.ModelItem.BeginEdit(System.Activities.Presentation.SR.PropertyChangeEditingScopeDescription)) { string displayName = pastedTransition.DisplayName; bool isFirst = true; foreach (ModelItem selectedItem in selectedItems) { if (!isFirst) { StringReader reader = new StringReader(XamlServices.Save(pastedTransition)); pastedTransition = (Transition)XamlServices.Load(reader); } ModelItem transitionModelItem = this.Context.Services.GetRequiredService <ModelTreeManager>().WrapAsModelItem(pastedTransition); ModelItem sourceState = selectedItem; sourceState.Properties[StateDesigner.TransitionsPropertyName].Collection.Add(transitionModelItem); transitionModelItem.Properties[TransitionDesigner.ToPropertyName].SetValue(destinationState); if (isFirst) { this.ViewStateService.RemoveViewState(transitionModelItem, ConnectorLocationViewStateKey); this.ViewStateService.RemoveViewState(transitionModelItem, SrcConnectionPointIndexStateKey); this.ViewStateService.RemoveViewState(transitionModelItem, DestConnectionPointIndexStateKey); isFirst = false; } } es.Complete(); } } else { List <ModelItem> modelItemsPasted = new List <ModelItem>(); List <State> states = new List <State>(); foreach (object obj in itemsToPaste) { State state; if (obj is FinalState) { state = new State() { DisplayName = DefaultFinalStateDisplayName, IsFinal = true }; } else { state = (State)obj; if (state.DisplayName == null) { state.DisplayName = DefaultStateDisplayName; } } states.Add(state); } RemoveDanglingTransitions(states); using (EditingScope es = (EditingScope)this.ModelItem.BeginEdit( System.Activities.Presentation.SR.CollectionAddEditingScopeDescription)) { // Fix 157591 by storing the height and width of the container "before" the new states are added to the // panel, and group the insertion inside one editing scope - such that Undo will also restore the // size of the StateMachineContainer to pre-insert size. StoreShapeSizeWithUndoRecursively(this.ModelItem); foreach (State state in states) { ModelItem stateModelItem = (this.ModelItem.ItemType == typeof(StateMachine)) ? this.ModelItem.Properties[StateMachineDesigner.StatesPropertyName].Collection.Add(state) : GetStateMachineModelItem(this.ModelItem).Properties[StateMachineDesigner.StatesPropertyName].Collection.Add(state); modelItemsPasted.Add(stateModelItem); } es.Complete(); } if (modelItemsPasted.Count > 0) { // translate location view states to be in the coordinate system of the pasting target Fx.Assert(this.ModelItem.ItemType == typeof(StateMachine), "Only StateMachine contain the StateContainerEditor."); this.UpdateLocationViewStatesByMetaData(modelItemsPasted, metaData, this); if (pastePoint.X > 0 && pastePoint.Y > 0) { if (pastePointReference != null) { pastePoint = pastePointReference.TranslatePoint(pastePoint, this.panel); pastePoint.X = pastePoint.X < 0 ? 0 : pastePoint.X; pastePoint.Y = pastePoint.Y < 0 ? 0 : pastePoint.Y; } this.UpdateLocationViewStatesByPoint(modelItemsPasted, pastePoint); } // If paste point is not available, paste the items to the top left corner. else { this.UpdateLocationViewStatesToAvoidOverlap(modelItemsPasted); } } this.Dispatcher.BeginInvoke(() => { if (modelItemsPasted.Count > 0 && modelItemsPasted[0] != null) { Keyboard.Focus(modelItemsPasted[0].View as IInputElement); } this.Context.Items.SetValue(new Selection(modelItemsPasted)); }, DispatcherPriority.ApplicationIdle ); } }
bool DoAutoWrapDrop(InsertionPosition insertionPos, DragEventArgs e, IList <object> droppedObjects = null) { if (droppedObjects == null) { ModelTreeManager manager = this.Context.Services.GetRequiredService <ModelTreeManager>(); EditingScope editingScope = null; try { editingScope = ModelItemHelper.TryCreateImmediateEditingScope(manager, SR.WrapInSequenceDescription); droppedObjects = this.GetSortedObjectList(e); if (!this.DoAutoWrapDrop(insertionPos, droppedObjects)) { return(false); } if (editingScope != null) { editingScope.Complete(); } } finally { if (editingScope != null) { editingScope.Dispose(); editingScope = null; } } } else { if (!this.DoAutoWrapDrop(insertionPos, droppedObjects)) { return(false); } } if (!DragDropHelper.IsDraggingFromToolbox(e)) { List <WorkflowViewElement> movedViewElements = ObjectList2WorkflowViewElementList(droppedObjects); DragDropHelper.SetDragDropMovedViewElements(e, movedViewElements); //Backward compatibility for 4.0 if (droppedObjects.Count == 1 && movedViewElements.Count == 1) { #pragma warning disable 618 DragDropHelper.SetDragDropCompletedEffects(e, DragDropEffects.Move); #pragma warning restore 618 } } else { Fx.Assert(droppedObjects.Count == 1, "Dropping from Toolbox with count != 1"); // Set focus if it is dropping from ToolBox. // In common drag/drop, the selection setting is done at the end of // StartDragging(). if (this.Item == null) { return(true); } Fx.Assert(typeof(Sequence).IsAssignableFrom(this.Item.ItemType), "Auto Wrap didn't add a sequence. Is Item.Properties[\"Activities\"] still correct?"); foreach (ModelItem item in this.Item.Properties["Activities"].Collection) { // Find the ModelItem whose value is an activity from Toolbox. if (item.GetCurrentValue() == droppedObjects[0]) { this.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, (Action)(() => { item.Focus(); })); break; } } } return(true); }
// referenceConnector is used when we are re-linking the connector. internal ConnectorCreationResult CreateConnectorGesture(ConnectionPoint sourceConnectionPoint, ConnectionPoint destConnectionPoint, Connector referenceConnector, bool isConnectorStartMoved) { Debug.Assert(this.IsOutmostStateContainerEditor(), "Should only be called by the outmost editor."); Debug.Assert(sourceConnectionPoint != null, "sourceConnectionPoint is null."); Debug.Assert(destConnectionPoint != null, "destConnectionPoint is null."); ConnectorCreationResult result = ConnectorCreationResult.OtherFailure; if (destConnectionPoint.PointType != ConnectionPointType.Outgoing && sourceConnectionPoint.PointType != ConnectionPointType.Incoming) { if (sourceConnectionPoint.ParentDesigner is StateDesigner) { bool sameDestination = false; ModelItem refTransitionModelItem = null; if (referenceConnector != null) { refTransitionModelItem = StateContainerEditor.GetConnectorModelItem(referenceConnector); ModelItem destStateModelItem = ((StateDesigner)destConnectionPoint.ParentDesigner).ModelItem; if (refTransitionModelItem != null && refTransitionModelItem.Properties[TransitionDesigner.ToPropertyName].Value == destStateModelItem) { sameDestination = true; } } // We do not allow transitions to composite states unless we don't change the transition destination // (e.g., we are moving the start of a connector). if (!sameDestination && !((StateDesigner)destConnectionPoint.ParentDesigner).IsSimpleState()) { result = ConnectorCreationResult.CannotCreateTransitionToCompositeState; } // We do not allow transitions from an ancestor to its descendant else if (StateContainerEditor.IsDescendantStateOf(((StateDesigner)destConnectionPoint.ParentDesigner).ModelItem, ((StateDesigner)sourceConnectionPoint.ParentDesigner).ModelItem)) { result = ConnectorCreationResult.CannotCreateTransitionFromAncestorToDescendant; } else { using (EditingScope es = (EditingScope)this.ModelItem.BeginEdit(SR.CreateTransition)) { if (refTransitionModelItem != null) { this.CreateTransition(sourceConnectionPoint, destConnectionPoint, refTransitionModelItem, isConnectorStartMoved); } else { this.CreateTransition(sourceConnectionPoint, destConnectionPoint, null, false); } result = ConnectorCreationResult.Success; es.Complete(); } } } else if (sourceConnectionPoint.ParentDesigner is InitialNode) { StateDesigner destDesigner = (StateDesigner)destConnectionPoint.ParentDesigner; // We only allow simple states to be set as the initial state if (!destDesigner.IsSimpleState()) { result = ConnectorCreationResult.CannotSetCompositeStateAsInitialState; } else if (destDesigner.IsFinalState()) { result = ConnectorCreationResult.CannotSetFinalStateAsInitialState; } else { ModelItem destModelItem = destDesigner.ModelItem; using (EditingScope es = (EditingScope)this.ModelItem.BeginEdit(SR.SetInitialState)) { this.StateMachineModelItem.Properties[StateMachineDesigner.InitialStatePropertyName].SetValue(destModelItem); PointCollection connectorViewState = new PointCollection(ConnectorRouter.Route(this.panel, sourceConnectionPoint, destConnectionPoint)); this.StoreConnectorLocationViewState(this.StateMachineModelItem, connectorViewState, true); result = ConnectorCreationResult.Success; es.Complete(); } } } } return(result); }