/// <summary> /// Event handler for the "Add Tab" verb. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="ea"> /// Some <see cref="EventArgs"/>. /// </param> private void AddTab(object sender, EventArgs ea) { IDesignerHost dh = (IDesignerHost)GetService(typeof(IDesignerHost)); if (dh != null) { int selTab = _tabControl.SelectedIndex; string name = GetNewTabName(); ImageTabPage itp = dh.CreateComponent(typeof(ImageTabPage), name) as ImageTabPage; itp._index = _tabControl.TabPages.Count;// (_tabControl.Controls as ImageTabControl.ControlCollection).Count; itp.Text = "Tab" + itp._index; _tabControl.TabPages.Add(itp); //_tabControl.Controls.Add(itp); //ytp.Name = _tabControl.Name + "_Tab" + _tabControl.Controls.Count; //ytp.Text = "Tab"+_tabControl.TabPages.Count; //(_tabControl.Controls as ImageTabControl.ControlCollection).Add(itp); _tabControl.CalculateTabLengths(); if (_tabControl.SelectedIndex < 0) { _tabControl.SelectedIndex = itp.Index; //MessageBox.Show("index:" + ytp.Index); RaiseComponentChanging(TypeDescriptor.GetProperties(Control)["SelectedIndex"]); RaiseComponentChanged(TypeDescriptor.GetProperties(Control)["SelectedIndex"], selTab, _tabControl.SelectedIndex); } dh.Activate(); } }
/// <summary> /// Load the markup file and add the workflow to the designer /// </summary> /// <param name="serializationManager"></param> protected override void PerformLoad( IDesignerSerializationManager serializationManager) { base.PerformLoad(serializationManager); Activity workflow = null; if (!String.IsNullOrEmpty(MarkupFileName)) { //load a workflow from markup workflow = DeserializeFromMarkup(MarkupFileName); } else if (NewWorkflowType != null) { //create a new workflow workflow = CreateNewWorkflow( NewWorkflowType, NewWorkflowName); } if (workflow != null) { IDesignerHost designer = (IDesignerHost)GetService(typeof(IDesignerHost)); //add the workfow definition to the designer AddWorkflowToDesigner(designer, workflow); //activate the designer designer.Activate(); } }
private void Initialize() { // Initialise service container and designer host serviceContainer = new ServiceContainer(); serviceContainer.AddService(typeof(INameCreationService), new NameCreationService()); serviceContainer.AddService(typeof(IUIService), new UIService(this)); host = new DesignerHost(serviceContainer); // Add toolbox service serviceContainer.AddService(typeof(IToolboxService), lstToolbox); lstToolbox.designPanel = pnlViewHost; PopulateToolbox(lstToolbox); // Add menu command service menuService = new MenuCommandService(); serviceContainer.AddService(typeof(IMenuCommandService), menuService); // Start the designer host off with a Form to design form = (Form)host.CreateComponent(typeof(Form)); form.TopLevel = false; form.Text = "Form1"; // Get the root designer for the form and add its design view to this form rootDesigner = (IRootDesigner)host.GetDesigner(form); view = (Control)rootDesigner.GetView(ViewTechnology.Default);//.WindowsForms); view.Dock = DockStyle.Fill; pnlViewHost.Controls.Add(view); // Subscribe to the selectionchanged event and activate the designer ISelectionService s = (ISelectionService)serviceContainer.GetService(typeof(ISelectionService)); s.SelectionChanged += new EventHandler(OnSelectionChanged); host.Activate(); }
/// <summary> /// Load the workflow : This will create the activity tree and its corresponding Designer tree /// </summary> /// <param name="serializationManager"></param> protected override void PerformLoad(IDesignerSerializationManager serializationManager) { base.PerformLoad(serializationManager); IDesignerHost designerHost = (IDesignerHost)GetService(typeof(IDesignerHost)); // get the root activity and add the corresponding object graph to the designer host XmlReader reader = new XmlTextReader(new StringReader(xoml)); Activity rootActivity = null; try { WorkflowMarkupSerializer xomlSerializer = new WorkflowMarkupSerializer(); rootActivity = xomlSerializer.Deserialize(reader) as Activity; } finally { reader.Close(); } if (rootActivity != null && designerHost != null) { AddObjectGraphToDesignerHost(designerHost, rootActivity); string companionType = rootActivity.GetValue(WorkflowMarkupSerializer.XClassProperty) as string; if (!string.IsNullOrEmpty(companionType)) { SetBaseComponentClassName(companionType); } } designerHost.Activate(); // Read from rules file if one exists //string rulesFile = Path.Combine(Path.GetDirectoryName(this.xoml), Path.GetFileNameWithoutExtension(this.xoml) + ".rules"); //if (File.Exists(rulesFile)) //{ // this.tempRulesStream = new StringBuilder(RuleSetXml); //} }
protected override bool OnDragDrop(DragEventArgs eventArgs) { //Invalidate the entire rectangle so that we draw active placement glyphs on connectors WorkflowView parentView = ParentView; parentView.InvalidateClientRectangle(Rectangle.Empty); //By default we do not allow any drag drop operation eventArgs.Effect = DragDropEffects.None; DestroyDragFeedbackImages(); //Get the coordinates Point clientPoint = parentView.PointToClient(new Point(eventArgs.X, eventArgs.Y)); Point logicalPoint = parentView.ScreenPointToLogical(new Point(eventArgs.X, eventArgs.Y)); //Now we check if the drag drop was in any valid area, if not then do not proceed further if (!parentView.IsClientPointInActiveLayout(clientPoint)) { if (this.dropTargetDesigner != null) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave(); } this.wasCtrlKeyPressed = false; this.dropTargetDesigner = null; this.draggedActivities.Clear(); return(false); } //Now we have a potential for successful drag drop, so construct drag event arguments with logical coordinates this.wasCtrlKeyPressed = ((eventArgs.KeyState & 8) == 8); ActivityDragEventArgs dragdropEventArgs = new ActivityDragEventArgs(eventArgs, this.dragInitiationPoint, logicalPoint, this.draggedActivities); //Now check which designer is under the cursor, if we have the same designer as the old one //If not then we set the new one as drop target and pump in messages HitTestInfo hitTestInfo = MessageHitTestContext; if (this.dropTargetDesigner != hitTestInfo.AssociatedDesigner) { if (this.dropTargetDesigner != null) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave(); this.dropTargetDesigner = null; } if (hitTestInfo.AssociatedDesigner != null) { this.dropTargetDesigner = hitTestInfo.AssociatedDesigner; if (this.dropTargetDesigner != null) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragEnter(dragdropEventArgs); } } } //We now have appropriate droptarget designer try { if (this.dropTargetDesigner != null) { //We do not allow recursive drag and drop if (!this.wasCtrlKeyPressed && IsRecursiveDropOperation(this.dropTargetDesigner) || (this.dropTargetDesigner is CompositeActivityDesigner && !((CompositeActivityDesigner)this.dropTargetDesigner).IsEditable)) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave(); dragdropEventArgs.Effect = DragDropEffects.None; } else { // IMPORTANT: Don't use draggedActivities variable, because components which are // there may not be created using the assembly references added to ITypeResultionService // this.workflowView.time the components will be created using the assembly references got added to the project List <Activity> droppedActivities = new List <Activity>(); string transactionDescription = SR.GetString(SR.DragDropActivities); //This means that we are trying to move activities so we use the same activities for drop if (!this.wasCtrlKeyPressed && this.existingDraggedActivities.Count > 0) { droppedActivities.AddRange(this.existingDraggedActivities); if (droppedActivities.Count > 1) { transactionDescription = SR.GetString(SR.MoveMultipleActivities, droppedActivities.Count); } else if (droppedActivities.Count == 1) { transactionDescription = SR.GetString(SR.MoveSingleActivity, droppedActivities[0].GetType()); } } else { droppedActivities.AddRange(CompositeActivityDesigner.DeserializeActivitiesFromDataObject(ParentView, eventArgs.Data, true)); if (droppedActivities.Count > 0) { transactionDescription = SR.GetString(SR.CreateActivityFromToolbox, droppedActivities[0].GetType()); } } //Now that we have what needs to be dropped, we start the actual drag and drop IDesignerHost designerHost = GetService(typeof(IDesignerHost)) as IDesignerHost; DesignerTransaction transaction = null; if (droppedActivities.Count > 0) { transaction = designerHost.CreateTransaction(transactionDescription); } dragdropEventArgs = new ActivityDragEventArgs(eventArgs, this.dragInitiationPoint, logicalPoint, droppedActivities); try { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragDrop(dragdropEventArgs); if (dragdropEventArgs.Effect == DragDropEffects.Move) { this.existingDraggedActivities.Clear(); } if (transaction != null) { transaction.Commit(); } } catch (Exception e) { if (transaction != null) { transaction.Cancel(); } throw e; } //We deserialize the designers and try to store the designer states if (droppedActivities.Count > 0) { Stream componentStateStream = eventArgs.Data.GetData(DragDropManager.CF_DESIGNERSTATE) as Stream; if (componentStateStream != null) { Helpers.DeserializeDesignersFromStream(droppedActivities, componentStateStream); } //Set the current selection ISelectionService selectionService = (ISelectionService)GetService(typeof(ISelectionService)); if (selectionService != null) { selectionService.SetSelectedComponents(droppedActivities, SelectionTypes.Replace); } } //Active the design surface if (designerHost != null) { designerHost.Activate(); } } } } catch (Exception ex) { //We purposely consume application thrown exception which are result of user cancelling the action //during dragdrop where we popup UI Wizards during drag drop. Ref: InvokeWebService ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave(); dragdropEventArgs.Effect = DragDropEffects.None; string dragDropException = ex.Message; if (ex.InnerException != null && !String.IsNullOrEmpty(ex.InnerException.Message)) { dragDropException = ex.InnerException.Message; } string errorMessage = DR.GetString(DR.Error_FailedToDeserializeComponents); errorMessage += "\r\n" + DR.GetString(DR.Error_Reason, dragDropException); DesignerHelpers.ShowError(ParentView, errorMessage); if (ex != CheckoutException.Canceled) { throw new Exception(errorMessage, ex); } } finally { //Make sure that mouse over designer is set to null this.wasCtrlKeyPressed = false; this.draggedActivities.Clear(); this.dropTargetDesigner = null; this.exceptionInDragDrop = false; eventArgs.Effect = dragdropEventArgs.Effect; } return(true); }
public void DoOleDragDrop(DragEventArgs de) { // ASURT 43757: By the time we come here, it means that the user completed the drag-drop and // we compute the new location/size of the controls if needed and set the property values. // We have to stop freezePainting right here, so that controls can get a chance to validate // their new rects. // freezePainting = false; if (selectionHandler == null) { Debug.Fail("selectionHandler should not be null"); de.Effect = DragDropEffects.None; return; } // make sure we've actually moved if ((localDrag && de.X == dragBase.X && de.Y == dragBase.Y) || de.AllowedEffect == DragDropEffects.None || (!localDrag && !dragOk)) { de.Effect = DragDropEffects.None; return; } bool localMoveOnly = ((int)de.AllowedEffect & AllowLocalMoveOnly) != 0 && localDragInside; // if we are dragging inside the local dropsource/target, and and AllowLocalMoveOnly flag is set, // we just consider this a normal move. // bool moveAllowed = (de.AllowedEffect & DragDropEffects.Move) != DragDropEffects.None || localMoveOnly; bool copyAllowed = (de.AllowedEffect & DragDropEffects.Copy) != DragDropEffects.None; if ((de.Effect & DragDropEffects.Move) != 0 && !moveAllowed) { // Try copy instead? de.Effect = DragDropEffects.Copy; } // make sure the copy is allowed if ((de.Effect & DragDropEffects.Copy) != 0 && !copyAllowed) { // if copy isn't allowed, don't do anything de.Effect = DragDropEffects.None; return; } if (localMoveOnly && (de.Effect & DragDropEffects.Move) != 0) { de.Effect |= (DragDropEffects)AllowLocalMoveOnly | DragDropEffects.Move; } else if ((de.Effect & DragDropEffects.Copy) != 0) { de.Effect = DragDropEffects.Copy; } if (forceDrawFrames || localDragInside) { // undraw the drag rect localDragOffset = DrawDragFrames(dragComps, localDragOffset, localDragEffect, Point.Empty, DragDropEffects.None, forceDrawFrames); forceDrawFrames = false; } Cursor oldCursor = Cursor.Current; try { Cursor.Current = Cursors.WaitCursor; if (dragOk || (localDragInside && de.Effect == DragDropEffects.Copy)) { // add em to this parent. IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost)); IContainer container = host.RootComponent.Site.Container; object[] components; IDataObject dataObj = de.Data; bool updateLocation = false; if (dataObj is ComponentDataObjectWrapper) { dataObj = ((ComponentDataObjectWrapper)dataObj).InnerData; ComponentDataObject cdo = (ComponentDataObject)dataObj; // if we're moving ot a different container, do a full serialization // to make sure we pick up design time props, etc. // IComponent dragOwner = GetDragOwnerComponent(de.Data); bool newContainer = dragOwner == null || client.Component == null || dragOwner.Site.Container != client.Component.Site.Container; bool collapseChildren = false; if (de.Effect == DragDropEffects.Copy || newContainer) { // this causes new elements to be created // cdo.Deserialize(serviceProvider, (de.Effect & DragDropEffects.Copy) == 0); } else { collapseChildren = true; } updateLocation = true; components = cdo.Components; if (collapseChildren) { components = GetTopLevelComponents(components); } } else { object serializationData = dataObj.GetData(DataFormat, true); if (serializationData == null) { Debug.Fail("data object didn't return any data, so how did we allow the drop?"); components = Array.Empty <IComponent>(); } else { dataObj = new ComponentDataObject(client, serviceProvider, serializationData); components = ((ComponentDataObject)dataObj).Components; updateLocation = true; } } // now we need to offset the components locations from the drop mouse // point to the parent, since their current locations are relative // the the mouse pointer if (components != null && components.Length > 0) { Debug.Assert(container != null, "Didn't get a container from the site!"); string name; IComponent comp = null; DesignerTransaction trans = null; try { trans = host.CreateTransaction(SR.DragDropDropComponents); if (!localDrag) { host.Activate(); } ArrayList selectComps = new ArrayList(); for (int i = 0; i < components.Length; i++) { comp = components[i] as IComponent; if (comp == null) { comp = null; continue; } try { name = null; if (comp.Site != null) { name = comp.Site.Name; } Control oldDesignerControl = null; if (updateLocation) { oldDesignerControl = client.GetDesignerControl(); User32.SendMessageW(oldDesignerControl.Handle, User32.WM.SETREDRAW); } Point dropPt = client.GetDesignerControl().PointToClient(new Point(de.X, de.Y)); // First check if the component we are dropping have a TrayLocation, and if so, use it PropertyDescriptor loc = TypeDescriptor.GetProperties(comp)["TrayLocation"]; if (loc == null) { // it didn't, so let's check for the regular Location loc = TypeDescriptor.GetProperties(comp)["Location"]; } if (loc != null && !loc.IsReadOnly) { Rectangle bounds = new Rectangle(); Point pt = (Point)loc.GetValue(comp); bounds.X = dropPt.X + pt.X; bounds.Y = dropPt.Y + pt.Y; bounds = selectionHandler.GetUpdatedRect(Rectangle.Empty, bounds, false); } if (!client.AddComponent(comp, name, false)) { // this means that we just moved the control // around in the same designer. de.Effect = DragDropEffects.None; } else { // make sure the component was added to this client if (client.GetControlForComponent(comp) == null) { updateLocation = false; } } if (updateLocation) { ParentControlDesigner parentDesigner = client as ParentControlDesigner; if (parentDesigner != null) { Control c = client.GetControlForComponent(comp); dropPt = parentDesigner.GetSnappedPoint(c.Location); c.Location = dropPt; } } if (oldDesignerControl != null) { //((ComponentDataObject)dataObj).ShowControls(); User32.SendMessageW(oldDesignerControl.Handle, User32.WM.SETREDRAW, (IntPtr)1); oldDesignerControl.Invalidate(true); } if (TypeDescriptor.GetAttributes(comp).Contains(DesignTimeVisibleAttribute.Yes)) { selectComps.Add(comp); } } catch (CheckoutException ceex) { if (ceex == CheckoutException.Canceled) { break; } throw; } } if (host != null) { host.Activate(); } // select the newly added components ISelectionService selService = (ISelectionService)GetService(typeof(ISelectionService)); selService.SetSelectedComponents((object[])selectComps.ToArray(typeof(IComponent)), SelectionTypes.Replace); localDragInside = false; } finally { if (trans != null) { trans.Commit(); } } } } if (localDragInside) { ISelectionUIService selectionUISvc = (ISelectionUIService)GetService(typeof(ISelectionUIService)); Debug.Assert(selectionUISvc != null, "Unable to get selection ui service when adding child control"); if (selectionUISvc != null) { // We must check to ensure that UI service is still in drag mode. It is // possible that the user hit escape, which will cancel drag mode. // if (selectionUISvc.Dragging && moveAllowed) { Rectangle offset = new Rectangle(de.X - dragBase.X, de.Y - dragBase.Y, 0, 0); selectionUISvc.DragMoved(offset); } } } dragOk = false; } finally { Cursor.Current = oldCursor; } }
public IComponent[] CreateTool(ToolboxItem tool, Control parent, int x, int y, int width, int height, bool hasLocation, bool hasSize, ToolboxSnapDragDropEventArgs e) { // Services we will need // IToolboxService toolboxSvc = (IToolboxService)GetService(typeof(IToolboxService)); ISelectionService selSvc = (ISelectionService)GetService(typeof(ISelectionService)); IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost)); IComponent[] comps = Array.Empty <IComponent>(); Cursor oldCursor = Cursor.Current; Cursor.Current = Cursors.WaitCursor; DesignerTransaction trans = null; try { try { if (host != null) { trans = host.CreateTransaction(string.Format(SR.DesignerBatchCreateTool, tool.ToString())); } } catch (CheckoutException cxe) { if (cxe == CheckoutException.Canceled) { return(comps); } throw; } try { try { // First check if we are currently in localization mode (i.e., language is non-default). // If so, we should not permit addition of new components. This is an intentional // change from Everett - see VSWhidbey #292249. if (host != null && CurrentlyLocalizing(host.RootComponent)) { IUIService uiService = (IUIService)GetService(typeof(IUIService)); if (uiService != null) { uiService.ShowMessage(SR.LocalizingCannotAdd); } comps = Array.Empty <IComponent>(); return(comps); } // Create a dictionary of default values that the designer can // use to initialize a control with. Hashtable defaultValues = new Hashtable(); if (parent != null) { defaultValues["Parent"] = parent; } // adjust the location if we are in a mirrored parent. That is because the origin // will then be in the upper right rather than upper left. if (parent != null && parent.IsMirrored) { x += width; } if (hasLocation) { defaultValues["Location"] = new Point(x, y); } if (hasSize) { defaultValues["Size"] = new Size(width, height); } //store off extra behavior drag/drop information if (e != null) { defaultValues["ToolboxSnapDragDropEventArgs"] = e; } comps = tool.CreateComponents(host, defaultValues); } catch (CheckoutException checkoutEx) { if (checkoutEx == CheckoutException.Canceled) { comps = Array.Empty <IComponent>(); } else { throw; } } catch (ArgumentException argumentEx) { IUIService uiService = (IUIService)GetService(typeof(IUIService)); if (uiService != null) { uiService.ShowError(argumentEx); } } catch (Exception ex) { IUIService uiService = (IUIService)GetService(typeof(IUIService)); string exceptionMessage = string.Empty; if (ex.InnerException != null) { exceptionMessage = ex.InnerException.ToString(); } if (string.IsNullOrEmpty(exceptionMessage)) { exceptionMessage = ex.ToString(); } if (ex is InvalidOperationException) { exceptionMessage = ex.Message; } if (uiService != null) { uiService.ShowError(ex, string.Format(SR.FailedToCreateComponent, tool.DisplayName, exceptionMessage)); } else { throw; } } if (comps == null) { comps = Array.Empty <IComponent>(); } } finally { if (toolboxSvc != null && tool.Equals(toolboxSvc.GetSelectedToolboxItem(host))) { toolboxSvc.SelectedToolboxItemUsed(); } } } finally { if (trans != null) { trans.Commit(); } Cursor.Current = oldCursor; } // Finally, select the newly created components. // if (selSvc != null && comps.Length > 0) { if (host != null) { host.Activate(); } ArrayList selectComps = new ArrayList(comps); for (int i = 0; i < comps.Length; i++) { if (!TypeDescriptor.GetAttributes(comps[i]).Contains(DesignTimeVisibleAttribute.Yes)) { selectComps.Remove(comps[i]); } } selSvc.SetSelectedComponents(selectComps.ToArray(), SelectionTypes.Replace); } codemarkers.CodeMarker((int)CodeMarkerEvent.perfFXDesignCreateComponentEnd); return(comps); }
private void PerformDragEnter(DragEventArgs de, IDesignerHost host) { if (host != null) { host.Activate(); } if ((de.AllowedEffect & DragDropEffects.Move) != DragDropEffects.None) { de.Effect = DragDropEffects.Move; } else { de.Effect = DragDropEffects.Copy; } if (this.InheritanceAttribute == InheritanceAttribute.InheritedReadOnly) { de.Effect = DragDropEffects.None; } else { ISelectionService service = (ISelectionService) this.GetService(typeof(ISelectionService)); if (service != null) { service.SetSelectedComponents(new object[] { base.Component }, SelectionTypes.Replace); } } }
protected override bool OnDragDrop(DragEventArgs eventArgs) { WorkflowView parentView = base.ParentView; parentView.InvalidateClientRectangle(Rectangle.Empty); eventArgs.Effect = DragDropEffects.None; this.DestroyDragFeedbackImages(); Point clientPoint = parentView.PointToClient(new Point(eventArgs.X, eventArgs.Y)); Point point = parentView.ScreenPointToLogical(new Point(eventArgs.X, eventArgs.Y)); if (!parentView.IsClientPointInActiveLayout(clientPoint)) { if (this.dropTargetDesigner != null) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave(); } this.wasCtrlKeyPressed = false; this.dropTargetDesigner = null; this.draggedActivities.Clear(); return(false); } this.wasCtrlKeyPressed = (eventArgs.KeyState & 8) == 8; ActivityDragEventArgs e = new ActivityDragEventArgs(eventArgs, this.dragInitiationPoint, point, this.draggedActivities); System.Workflow.ComponentModel.Design.HitTestInfo messageHitTestContext = base.MessageHitTestContext; if (this.dropTargetDesigner != messageHitTestContext.AssociatedDesigner) { if (this.dropTargetDesigner != null) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave(); this.dropTargetDesigner = null; } if (messageHitTestContext.AssociatedDesigner != null) { this.dropTargetDesigner = messageHitTestContext.AssociatedDesigner; if (this.dropTargetDesigner != null) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragEnter(e); } } } try { if (this.dropTargetDesigner != null) { if ((!this.wasCtrlKeyPressed && this.IsRecursiveDropOperation(this.dropTargetDesigner)) || ((this.dropTargetDesigner is CompositeActivityDesigner) && !((CompositeActivityDesigner)this.dropTargetDesigner).IsEditable)) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave(); e.Effect = DragDropEffects.None; } else { List <Activity> draggedActivities = new List <Activity>(); string description = SR.GetString("DragDropActivities"); if (!this.wasCtrlKeyPressed && (this.existingDraggedActivities.Count > 0)) { draggedActivities.AddRange(this.existingDraggedActivities); if (draggedActivities.Count > 1) { description = SR.GetString("MoveMultipleActivities", new object[] { draggedActivities.Count }); } else if (draggedActivities.Count == 1) { description = SR.GetString("MoveSingleActivity", new object[] { draggedActivities[0].GetType() }); } } else { draggedActivities.AddRange(CompositeActivityDesigner.DeserializeActivitiesFromDataObject(base.ParentView, eventArgs.Data, true)); if (draggedActivities.Count > 0) { description = SR.GetString("CreateActivityFromToolbox", new object[] { draggedActivities[0].GetType() }); } } IDesignerHost host = base.GetService(typeof(IDesignerHost)) as IDesignerHost; DesignerTransaction transaction = null; if (draggedActivities.Count > 0) { transaction = host.CreateTransaction(description); } e = new ActivityDragEventArgs(eventArgs, this.dragInitiationPoint, point, draggedActivities); try { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragDrop(e); if (e.Effect == DragDropEffects.Move) { this.existingDraggedActivities.Clear(); } if (transaction != null) { transaction.Commit(); } } catch (Exception exception) { if (transaction != null) { transaction.Cancel(); } throw exception; } if (draggedActivities.Count > 0) { Stream data = eventArgs.Data.GetData("CF_WINOEDESIGNERCOMPONENTSSTATE") as Stream; if (data != null) { Helpers.DeserializeDesignersFromStream(draggedActivities, data); } ISelectionService service = (ISelectionService)base.GetService(typeof(ISelectionService)); if (service != null) { service.SetSelectedComponents(draggedActivities, SelectionTypes.Replace); } } if (host != null) { host.Activate(); } } } } catch (Exception exception2) { ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave(); e.Effect = DragDropEffects.None; string message = exception2.Message; if ((exception2.InnerException != null) && !string.IsNullOrEmpty(exception2.InnerException.Message)) { message = exception2.InnerException.Message; } string str3 = DR.GetString("Error_FailedToDeserializeComponents", new object[0]) + "\r\n" + DR.GetString("Error_Reason", new object[] { message }); DesignerHelpers.ShowError(base.ParentView, str3); if (exception2 != CheckoutException.Canceled) { throw new Exception(str3, exception2); } } finally { this.wasCtrlKeyPressed = false; this.draggedActivities.Clear(); this.dropTargetDesigner = null; this.exceptionInDragDrop = false; eventArgs.Effect = e.Effect; } return(true); }