protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e) { if (e != null && !this.Disabled) { this.offset = e.GetPosition(this); this.CaptureMouse(); if (this.scope != null) { this.ParentStateContainerEditor.StoreShapeSizeWithUndoRecursively(this.ParentStateContainerEditor.ModelItem); } // Select the designer when it is being resized WorkflowViewElement designer = this.ParentStateContainerEditor.ModelItem.View as WorkflowViewElement; if (!designer.IsKeyboardFocusWithin) { // Fix 185562 - if the designer has the keyboard focus (i.e. DisplayName being edited) // then there is no need to refocus on the designer again. That prevents the // DisplayName editing to be group into the same EditingScope as resizing, and // also the defaultDisplayNameReadOnlyControl from being Visible but not modified. Keyboard.Focus(designer); } StateMachineDesigner stateMachineDesigner = VisualTreeUtils.FindVisualAncestor <StateMachineDesigner>(this.ParentStateContainerEditor); stateMachineDesigner.IsResizing = true; e.Handled = true; } base.OnPreviewMouseLeftButtonDown(e); }
protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e) { if (e != null && !this.Disabled && this.scope != null) { ModelItem stateContainerModelItem = this.ParentStateContainerEditor.ModelItem; ViewStateService viewStateService = this.ParentStateContainerEditor.Context.Services.GetService <ViewStateService>(); viewStateService.StoreViewStateWithUndo(stateContainerModelItem, StateContainerEditor.StateContainerWidthViewStateKey, this.ParentStateContainerEditor.StateContainerWidth); viewStateService.StoreViewStateWithUndo(stateContainerModelItem, StateContainerEditor.StateContainerHeightViewStateKey, this.ParentStateContainerEditor.StateContainerHeight); Mouse.OverrideCursor = null; Mouse.Capture(null); StateMachineDesigner stateMachineDesigner = VisualTreeUtils.FindVisualAncestor <StateMachineDesigner>(this.ParentStateContainerEditor); stateMachineDesigner.IsResizing = false; e.Handled = true; } base.OnPreviewMouseLeftButtonUp(e); }
// Called by the designer to register any design-time metadata. // // Be aware of the accidential performance impact when adding things into this method. // In particular, pay attention to calls that will lead to loading extra assemblies. // public void Register() { AttributeTableBuilder builder = new AttributeTableBuilder(); //shared component builder.AddCustomAttributes(typeof(Collection <Constraint>), new BrowsableAttribute(false)); builder.AddCustomAttributes(typeof(string), new EditorReuseAttribute(false)); builder.AddCustomAttributes(typeof(ActivityAction), new EditorReuseAttribute(false)); builder.AddCustomAttributes(typeof(XName), new EditorReuseAttribute(false)); //Flowchart activities FlowchartDesigner.RegisterMetadata(builder); FlowSwitchDesigner.RegisterMetadata(builder); FlowDecisionDesigner.RegisterMetadata(builder); // Messaging activities ServiceDesigner.RegisterMetadata(builder); // Registering inline for designers for InitializeCorrelation, Send, Receive, SendReply, ReceiveReply activities to avoid calling // their static constructors. This will avoid instantiating the ResourceDictionary for their PropertyValueEditors during designer load. builder.AddCustomAttributes(typeof(Send), new DesignerAttribute(typeof(SendDesigner))); builder.AddCustomAttributes(typeof(Send), new ActivityDesignerOptionsAttribute { AllowDrillIn = false }); builder.AddCustomAttributes(typeof(Receive), new DesignerAttribute(typeof(ReceiveDesigner))); builder.AddCustomAttributes(typeof(Receive), new ActivityDesignerOptionsAttribute { AllowDrillIn = false }); builder.AddCustomAttributes(typeof(SendReply), new FeatureAttribute(typeof(SendReplyValidationFeature))); builder.AddCustomAttributes(typeof(SendReply), new DesignerAttribute(typeof(SendReplyDesigner))); builder.AddCustomAttributes(typeof(SendReply), new ActivityDesignerOptionsAttribute { AllowDrillIn = false }); CutCopyPasteHelper.AddDisallowedTypeForCopy(typeof(SendReply)); builder.AddCustomAttributes(typeof(ReceiveReply), new FeatureAttribute(typeof(ReceiveReplyValidationFeature))); builder.AddCustomAttributes(typeof(ReceiveReply), new DesignerAttribute(typeof(ReceiveReplyDesigner))); builder.AddCustomAttributes(typeof(ReceiveReply), new ActivityDesignerOptionsAttribute { AllowDrillIn = false }); CutCopyPasteHelper.AddDisallowedTypeForCopy(typeof(ReceiveReply)); builder.AddCustomAttributes(typeof(InitializeCorrelation), new DesignerAttribute(typeof(InitializeCorrelationDesigner))); builder.AddCustomAttributes(typeof(InitializeCorrelation), new ActivityDesignerOptionsAttribute { AllowDrillIn = false }); TransactedReceiveScopeDesigner.RegisterMetadata(builder); CorrelationScopeDesigner.RegisterMetadata(builder); //Procedural activities AssignDesigner.RegisterMetadata(builder); IfElseDesigner.RegisterMetadata(builder); InvokeMethodDesigner.RegisterMetadata(builder); DoWhileDesigner.RegisterMetadata(builder); WhileDesigner.RegisterMetadata(builder); ForEachDesigner.RegisterMetadata(builder); TryCatchDesigner.RegisterMetadata(builder); CatchDesigner.RegisterMetadata(builder); ParallelDesigner.RegisterMetadata(builder); SequenceDesigner.RegisterMetadata(builder); SwitchDesigner.RegisterMetadata(builder); CaseDesigner.RegisterMetadata(builder); //Compensation/Transaction CancellationScopeDesigner.RegisterMetadata(builder); CompensableActivityDesigner.RegisterMetadata(builder); TransactionScopeDesigner.RegisterMetadata(builder); //Misc activities PickDesigner.RegisterMetadata(builder); PickBranchDesigner.RegisterMetadata(builder); WriteLineDesigner.RegisterMetadata(builder); NoPersistScopeDesigner.RegisterMetadata(builder); InvokeDelegateDesigner.RegisterMetadata(builder); // StateMachine StateMachineDesigner.RegisterMetadata(builder); StateDesigner.RegisterMetadata(builder); TransitionDesigner.RegisterMetadata(builder); builder.AddCustomAttributes(typeof(AddToCollection <>), new FeatureAttribute(typeof(UpdatableGenericArgumentsFeature))); builder.AddCustomAttributes(typeof(RemoveFromCollection <>), new FeatureAttribute(typeof(UpdatableGenericArgumentsFeature))); builder.AddCustomAttributes(typeof(ClearCollection <>), new FeatureAttribute(typeof(UpdatableGenericArgumentsFeature))); builder.AddCustomAttributes(typeof(ExistsInCollection <>), new FeatureAttribute(typeof(UpdatableGenericArgumentsFeature))); builder.AddCustomAttributes(typeof(AddToCollection <>), new DefaultTypeArgumentAttribute(typeof(int))); builder.AddCustomAttributes(typeof(RemoveFromCollection <>), new DefaultTypeArgumentAttribute(typeof(int))); builder.AddCustomAttributes(typeof(ClearCollection <>), new DefaultTypeArgumentAttribute(typeof(int))); builder.AddCustomAttributes(typeof(ExistsInCollection <>), new DefaultTypeArgumentAttribute(typeof(int))); MetadataStore.AddAttributeTable(builder.CreateTable()); MorphHelper.AddPropertyValueMorphHelper(typeof(InArgument <>), MorphHelpers.ArgumentMorphHelper); MorphHelper.AddPropertyValueMorphHelper(typeof(OutArgument <>), MorphHelpers.ArgumentMorphHelper); MorphHelper.AddPropertyValueMorphHelper(typeof(InOutArgument <>), MorphHelpers.ArgumentMorphHelper); MorphHelper.AddPropertyValueMorphHelper(typeof(ActivityAction <>), MorphHelpers.ActivityActionMorphHelper); MorphHelper.AddPropertyValueMorphHelper(typeof(ActivityFunc <,>), MorphHelpers.ActivityFuncMorphHelper); // There is no need to keep an reference to this delayed worker since the AppDomain event handler will do it. RegisterMetadataDelayedWorker delayedWorker = new RegisterMetadataDelayedWorker(); delayedWorker.RegisterMetadataDelayed("System.Workflow.Runtime", InteropDesigner.RegisterMetadata); delayedWorker.RegisterMetadataDelayed("System.ServiceModel", RegisterMetadataForMessagingActivitiesSearchMetadata); delayedWorker.RegisterMetadataDelayed("System.ServiceModel", RegisterMetadataForMessagingActivitiesPropertyEditors); delayedWorker.WorkNowIfApplicable(); }
void UpdateLocationViewStatesToAvoidOverlap(List <ModelItem> itemsPasted) { int offset = 0; if (itemsPasted.Count > 0) { //Check to see if the first element in the input list needs offset. Generalize that information for all ModelItems in the input list. object location = this.ViewStateService.RetrieveViewState(itemsPasted[0], ShapeLocationViewStateKey); HashSet <Point> targetOccupiedLocations = null; if (this.ModelItem.ItemType == typeof(StateMachine)) { targetOccupiedLocations = this.shapeLocations; } else { ModelItem stateMachineModelItem = StateContainerEditor.GetStateMachineModelItem(this.ModelItem); StateMachineDesigner designer = stateMachineModelItem.View as StateMachineDesigner; if (designer != null) { targetOccupiedLocations = designer.StateContainerEditor.shapeLocations; } } if (location != null && targetOccupiedLocations != null) { Point locationOfShape = (Point)location; bool isOverlapped; do { isOverlapped = false; // need to check for each point on the canvas foreach (var point in targetOccupiedLocations) { // When the pasting occurs, the pasted point may not be exactly the same // as the copied point (with a slight margin of offset). Therefore, // we need to detect if the pasted point is within the boundary of the copied // object. If so, offset the pasted position such that the overlap is not observable. if ((locationOfShape.X < point.X + FreeFormPanel.GridSize && locationOfShape.X > point.X - FreeFormPanel.GridSize) && (locationOfShape.Y < point.Y + FreeFormPanel.GridSize && locationOfShape.Y > point.Y - FreeFormPanel.GridSize)) { offset++; locationOfShape.Offset(FreeFormPanel.GridSize, FreeFormPanel.GridSize); isOverlapped = true; break; } } } while (isOverlapped); } } //Update ViewState according to calculated offset. if (offset > 0) { double offsetValue = FreeFormPanel.GridSize * offset; OffsetLocationViewStates(new Vector(offsetValue, offsetValue), itemsPasted, GetTransitionModelItems(itemsPasted), false); } }