private void InitiateDragDrop() { WorkflowView parentView = ParentView; ISelectionService selectionService = (ISelectionService)GetService(typeof(ISelectionService)); IDesignerHost designerHost = (IDesignerHost)GetService(typeof(IDesignerHost)); if (selectionService == null || designerHost == null) { return; } // check if we are cutting root component ICollection components = selectionService.GetSelectedComponents(); if (components == null || components.Count < 1 || selectionService.GetComponentSelected(designerHost.RootComponent) || !Helpers.AreAllActivities(components)) { return; } DragDropEffects effects = DragDropEffects.None; try { // get component serialization service this.existingDraggedActivities.AddRange(Helpers.GetTopLevelActivities(components)); //IMPORTANT: FOR WITHIN DESIGNER COMPONENT MOVE WE REMOVE THE ACTIVITIES BEFORE WE ADD THEM WHICH IS IN //ONDRAGDROP FUNCTION. ALTHOUGH THIS VIOLATES THE DODRAGDROP FUNCTION SIMANTICS, WE NEED TO DO THIS //SO THAT WE CAN USE THE SAME IDS FOR THE ACTIVITIES DragDropEffects allowedEffects = (DesignerHelpers.AreAssociatedDesignersMovable(this.existingDraggedActivities)) ? DragDropEffects.Move | DragDropEffects.Copy : DragDropEffects.Copy; IDataObject dataObject = CompositeActivityDesigner.SerializeActivitiesToDataObject(ParentView, this.existingDraggedActivities.ToArray()); effects = parentView.DoDragDrop(dataObject, allowedEffects); // } catch (Exception e) { DesignerHelpers.ShowError(ParentView, e.Message); } finally { //This means drag drop occurred across designer if (effects == DragDropEffects.Move && this.existingDraggedActivities.Count > 0) { string transactionDescription = String.Empty; if (this.existingDraggedActivities.Count > 1) { transactionDescription = SR.GetString(SR.MoveMultipleActivities, this.existingDraggedActivities.Count); } else { transactionDescription = SR.GetString(SR.MoveSingleActivity, this.existingDraggedActivities[0].GetType()); } CompositeActivityDesigner.RemoveActivities(ParentView, this.existingDraggedActivities.AsReadOnly(), transactionDescription); } this.existingDraggedActivities.Clear(); } }
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); }
private void InitiateDragDrop() { WorkflowView parentView = base.ParentView; ISelectionService service = (ISelectionService)base.GetService(typeof(ISelectionService)); IDesignerHost host = (IDesignerHost)base.GetService(typeof(IDesignerHost)); if ((service != null) && (host != null)) { ICollection selectedComponents = service.GetSelectedComponents(); if (((selectedComponents != null) && (selectedComponents.Count >= 1)) && (!service.GetComponentSelected(host.RootComponent) && Helpers.AreAllActivities(selectedComponents))) { DragDropEffects none = DragDropEffects.None; try { this.existingDraggedActivities.AddRange(Helpers.GetTopLevelActivities(selectedComponents)); DragDropEffects allowedEffects = DesignerHelpers.AreAssociatedDesignersMovable(this.existingDraggedActivities) ? (DragDropEffects.Move | DragDropEffects.Copy) : DragDropEffects.Copy; IDataObject data = CompositeActivityDesigner.SerializeActivitiesToDataObject(base.ParentView, this.existingDraggedActivities.ToArray()); none = parentView.DoDragDrop(data, allowedEffects); } catch (Exception exception) { DesignerHelpers.ShowError(base.ParentView, exception.Message); } finally { if ((none == DragDropEffects.Move) && (this.existingDraggedActivities.Count > 0)) { string transactionDescription = string.Empty; if (this.existingDraggedActivities.Count > 1) { transactionDescription = SR.GetString("MoveMultipleActivities", new object[] { this.existingDraggedActivities.Count }); } else { transactionDescription = SR.GetString("MoveSingleActivity", new object[] { this.existingDraggedActivities[0].GetType() }); } CompositeActivityDesigner.RemoveActivities(base.ParentView, this.existingDraggedActivities.AsReadOnly(), transactionDescription); } this.existingDraggedActivities.Clear(); } } } }
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 OnMenuCut(object sender, EventArgs e) { IDesignerHost service = this.serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost; if ((service == null) || !this.selectionService.GetComponentSelected(service.RootComponent)) { ICollection selectedComponents = this.selectionService.GetSelectedComponents(); if (Helpers.AreAllActivities(selectedComponents) && DesignerHelpers.AreAssociatedDesignersMovable(selectedComponents)) { this.OnMenuCopy(sender, e); string description = string.Empty; if (selectedComponents.Count > 1) { description = SR.GetString("CutMultipleActivities", new object[] { selectedComponents.Count }); } else { ArrayList list = new ArrayList(selectedComponents); if (list.Count > 0) { description = SR.GetString("CutSingleActivity", new object[] { (list[0] as Activity).Name }); } else { description = SR.GetString("CutActivity"); } } DesignerTransaction transaction = service.CreateTransaction(description); try { this.OnMenuDelete(sender, e); transaction.Commit(); } catch { transaction.Cancel(); } } } }