internal bool IsValidDropContext(HitTestInfo dropLocation) { if (this.draggedActivities.Count == 0) { return(false); } if (dropLocation == null || dropLocation.AssociatedDesigner == null) { return(false); } CompositeActivityDesigner compositeDesigner = dropLocation.AssociatedDesigner as CompositeActivityDesigner; if (compositeDesigner == null) { return(false); } if (!compositeDesigner.IsEditable || !compositeDesigner.CanInsertActivities(dropLocation, new List <Activity>(this.draggedActivities).AsReadOnly())) { return(false); } if (!this.wasCtrlKeyPressed && this.existingDraggedActivities.Count > 0) { //We are trying to move the actvities with designer if (!DesignerHelpers.AreAssociatedDesignersMovable(this.draggedActivities)) { return(false); } if (IsRecursiveDropOperation(dropLocation.AssociatedDesigner)) { return(false); } IDictionary commonParentActivities = Helpers.PairUpCommonParentActivities(this.draggedActivities); foreach (DictionaryEntry entry in commonParentActivities) { CompositeActivityDesigner compositeActivityDesigner = ActivityDesigner.GetDesigner(entry.Key as Activity) as CompositeActivityDesigner; Activity[] activitiesToMove = (Activity[])((ArrayList)entry.Value).ToArray(typeof(Activity)); if (compositeActivityDesigner != null && !compositeActivityDesigner.CanMoveActivities(dropLocation, new List <Activity>(activitiesToMove).AsReadOnly())) { return(false); } } } return(true); }
internal bool IsValidDropContext(System.Workflow.ComponentModel.Design.HitTestInfo dropLocation) { if (this.draggedActivities.Count == 0) { return(false); } if ((dropLocation == null) || (dropLocation.AssociatedDesigner == null)) { return(false); } CompositeActivityDesigner associatedDesigner = dropLocation.AssociatedDesigner as CompositeActivityDesigner; if (associatedDesigner == null) { return(false); } if (!associatedDesigner.IsEditable || !associatedDesigner.CanInsertActivities(dropLocation, new List <Activity>(this.draggedActivities).AsReadOnly())) { return(false); } if (!this.wasCtrlKeyPressed && (this.existingDraggedActivities.Count > 0)) { if (!DesignerHelpers.AreAssociatedDesignersMovable(this.draggedActivities)) { return(false); } if (this.IsRecursiveDropOperation(dropLocation.AssociatedDesigner)) { return(false); } foreach (DictionaryEntry entry in Helpers.PairUpCommonParentActivities(this.draggedActivities)) { CompositeActivityDesigner designer = ActivityDesigner.GetDesigner(entry.Key as Activity) as CompositeActivityDesigner; Activity[] collection = (Activity[])((ArrayList)entry.Value).ToArray(typeof(Activity)); if ((designer != null) && !designer.CanMoveActivities(dropLocation, new List <Activity>(collection).AsReadOnly())) { return(false); } } } return(true); }
private void OnStatusPaste(object sender, EventArgs e) { MenuCommand command = (MenuCommand)sender; command.Enabled = false; 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) { IDesignerHost host = this.serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost; IToolboxService service = (IToolboxService)this.serviceProvider.GetService(typeof(IToolboxService)); IDataObject dataObject = Clipboard.GetDataObject(); if (((dataObject != null) && (host != null)) && ((dataObject.GetDataPresent("CF_WINOEDESIGNERCOMPONENTS") || (service == null)) || service.IsSupported(dataObject, host))) { 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); } } ICollection activities = null; try { activities = CompositeActivityDesigner.DeserializeActivitiesFromDataObject(this.serviceProvider, dataObject); } catch (CheckoutException exception) { if (exception != CheckoutException.Canceled) { throw exception; } } command.Enabled = ((activities != null) && (insertLocation != null)) && parentDesigner.CanInsertActivities(insertLocation, new List <Activity>(Helpers.GetTopLevelActivities(activities)).AsReadOnly()); } } }
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); } }