public override void OnActivate() { if (this.AssociatedDesigner == null) { Type type = base.UserData[UserDataKey_ActivityType] as Type; CompositeActivity activity = this.parentDesigner.Activity as CompositeActivity; if (((type != null) && (activity != null)) && this.parentDesigner.IsEditable) { Activity activity2 = Activator.CreateInstance(type) as Activity; try { CompositeActivityDesigner.InsertActivities(this.parentDesigner, new System.Workflow.ComponentModel.Design.HitTestInfo(this.parentDesigner, HitTestLocations.Designer), new List <Activity>(new Activity[] { activity2 }).AsReadOnly(), SR.GetString("AddingImplicitActivity")); } catch (Exception exception) { if (exception != CheckoutException.Canceled) { IUIService service = this.parentDesigner.Activity.Site.GetService(typeof(IUIService)) as IUIService; if (service != null) { service.ShowError(exception.Message); } } } ActivityDesigner designer = ActivityDesigner.GetDesigner(activity2); base.UserData[UserDataKey_Designer] = designer; } } }
protected override void OnDragDrop(ActivityDragEventArgs e) { base.OnDragDrop(e); bool ctrlKeyPressed = ((e.KeyState & 8) == 8); if (ctrlKeyPressed && (e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) { e.Effect = DragDropEffects.Copy; } else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) { e.Effect = DragDropEffects.Move; } //If the component is sited then that means that we are moving it try { CompositeActivityDesigner.InsertActivities(this, new ConnectorHitTestInfo(this, HitTestLocations.Designer, CurrentDropTarget), e.Activities, SR.GetString(SR.DragDropActivities)); } finally { CurrentDropTarget = -1; } }
private void OnAddBranch(object sender, EventArgs e) { CompositeActivity activity = this.OnCreateNewBranch(); CompositeActivity activity2 = base.Activity as CompositeActivity; if ((activity2 != null) && (activity != null)) { int count = this.ContainedDesigners.Count; CompositeActivityDesigner.InsertActivities(this, new ConnectorHitTestInfo(this, HitTestLocations.Designer, activity2.Activities.Count), new List <Activity>(new Activity[] { activity }).AsReadOnly(), DR.GetString("AddingBranch", new object[] { activity.GetType().Name })); if ((this.ContainedDesigners.Count > count) && (this.ContainedDesigners.Count > 0)) { this.ContainedDesigners[this.ContainedDesigners.Count - 1].EnsureVisible(); } } }
protected override void OnDragDrop(ActivityDragEventArgs e) { if (((e.KeyState & 8) == 8) && ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy)) { e.Effect = DragDropEffects.Copy; } else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) { e.Effect = DragDropEffects.Move; } List <Activity> list = new List <Activity>(); List <Activity> list2 = new List <Activity>(); foreach (Activity activity in e.Activities) { if ((activity.Site == null) || (activity.Parent != base.Activity)) { list.Add(activity); } if (activity.Site == null) { list2.Add(activity); } } if (list.Count > 0) { CompositeActivityDesigner.InsertActivities(this, new ConnectorHitTestInfo(this, HitTestLocations.Designer, ((CompositeActivity)base.Activity).Activities.Count), list.AsReadOnly(), SR.GetString("DragDropActivities")); } Point endPoint = new Point(e.X, e.Y); Point[] pointArray = FreeFormDragDropManager.GetDesignerLocations(e.DragInitiationPoint, endPoint, e.Activities); if (pointArray.Length == e.Activities.Count) { for (int i = 0; i < e.Activities.Count; i++) { ActivityDesigner containedDesigner = ActivityDesigner.GetDesigner(e.Activities[i]); if (containedDesigner != null) { Point newLocation = list2.Contains(containedDesigner.Activity) ? endPoint : pointArray[i]; this.MoveContainedDesigner(containedDesigner, newLocation); } } } }
private void OnAddBranch(object sender, EventArgs e) { CompositeActivity branchActivity = OnCreateNewBranch(); CompositeActivity compositeActivity = Activity as CompositeActivity; if (compositeActivity != null && branchActivity != null) { // Record the current number of child activities int designerCount = ContainedDesigners.Count; CompositeActivityDesigner.InsertActivities(this, new ConnectorHitTestInfo(this, HitTestLocations.Designer, compositeActivity.Activities.Count), new List <Activity>(new Activity[] { branchActivity }).AsReadOnly(), DR.GetString(DR.AddingBranch, branchActivity.GetType().Name)); // If the number of child activities has increased, the branch add was successful, so // make sure the highest indexed branch is visible if (ContainedDesigners.Count > designerCount && ContainedDesigners.Count > 0) { ContainedDesigners[ContainedDesigners.Count - 1].EnsureVisible(); } } }
protected override void OnDragDrop(ActivityDragEventArgs e) { base.OnDragDrop(e); if (((e.KeyState & 8) == 8) && ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy)) { e.Effect = DragDropEffects.Copy; } else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) { e.Effect = DragDropEffects.Move; } try { CompositeActivityDesigner.InsertActivities(this, new ConnectorHitTestInfo(this, HitTestLocations.Designer, this.CurrentDropTarget), e.Activities, SR.GetString("DragDropActivities")); } finally { this.CurrentDropTarget = -1; } }
public override void OnActivate() { if (AssociatedDesigner != null) { return; } Type activityType = UserData[UserDataKey_ActivityType] as Type; Debug.Assert(activityType != null); CompositeActivity parentActivity = this.parentDesigner.Activity as CompositeActivity; if (activityType == null || parentActivity == null || !this.parentDesigner.IsEditable) { return; } Activity activity = Activator.CreateInstance(activityType) as Activity; try { CompositeActivityDesigner.InsertActivities(this.parentDesigner, new HitTestInfo(this.parentDesigner, HitTestLocations.Designer), new List <Activity>(new Activity[] { activity }).AsReadOnly(), SR.GetString(SR.AddingImplicitActivity)); } catch (Exception e) { if (e != CheckoutException.Canceled) { IUIService uiService = this.parentDesigner.Activity.Site.GetService(typeof(IUIService)) as IUIService; if (uiService != null) { uiService.ShowError(e.Message); } } } ActivityDesigner designer = ActivityDesigner.GetDesigner(activity); UserData[UserDataKey_Designer] = designer; }
private void OnMenuPaste(object sender, EventArgs e) { object primarySelection = this.selectionService.PrimarySelection; CompositeActivityDesigner parentDesigner = ActivityDesigner.GetDesigner(primarySelection as Activity) as CompositeActivityDesigner; if (parentDesigner == null) { parentDesigner = ActivityDesigner.GetParentDesigner(primarySelection); } if ((parentDesigner != null) && parentDesigner.IsEditable) { IDataObject dataObject = Clipboard.GetDataObject(); ICollection activities = null; try { activities = CompositeActivityDesigner.DeserializeActivitiesFromDataObject(this.serviceProvider, dataObject, true); } catch (Exception exception) { if (exception != CheckoutException.Canceled) { throw new Exception(DR.GetString("ActivityInsertError", new object[0]) + "\n" + exception.Message, exception); } } if (activities == null) { throw new InvalidOperationException(DR.GetString("InvalidOperationBadClipboardFormat", new object[0])); } System.Workflow.ComponentModel.Design.HitTestInfo insertLocation = null; if (primarySelection is System.Workflow.ComponentModel.Design.HitTestInfo) { insertLocation = (System.Workflow.ComponentModel.Design.HitTestInfo)primarySelection; } else if (primarySelection is CompositeActivity) { insertLocation = new System.Workflow.ComponentModel.Design.HitTestInfo(parentDesigner, HitTestLocations.Designer); } else if (primarySelection is Activity) { Activity item = primarySelection as Activity; CompositeActivity parent = item.Parent; CompositeActivityDesigner designer = ActivityDesigner.GetDesigner(parent) as CompositeActivityDesigner; if (designer != null) { insertLocation = new ConnectorHitTestInfo(designer, HitTestLocations.Designer, parent.Activities.IndexOf(item) + 1); } } List <Activity> list = new List <Activity>(Helpers.GetTopLevelActivities(activities)); if ((insertLocation == null) || !parentDesigner.CanInsertActivities(insertLocation, list.AsReadOnly())) { throw new Exception(SR.GetString("Error_NoPasteSupport")); } IExtendedUIService service = this.serviceProvider.GetService(typeof(IExtendedUIService)) as IExtendedUIService; if (service != null) { foreach (Activity activity3 in activities) { service.AddAssemblyReference(activity3.GetType().Assembly.GetName()); } } CompositeActivityDesigner.InsertActivities(parentDesigner, insertLocation, list.AsReadOnly(), SR.GetString("PastingActivities")); Stream data = dataObject.GetData("CF_WINOEDESIGNERCOMPONENTSSTATE") as Stream; if (data != null) { Helpers.DeserializeDesignersFromStream(activities, data); } this.selectionService.SetSelectedComponents(list.ToArray(), SelectionTypes.Replace); this.workflowView.EnsureVisible(this.selectionService.PrimarySelection); } }