Ejemplo n.º 1
0
        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();
            }
        }
        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();
                    }
                }
            }
        }
Ejemplo n.º 3
0
        protected override bool OnKeyDown(KeyEventArgs eventArgs)
        {
            if (eventArgs != null && (eventArgs.KeyCode == Keys.PageUp || eventArgs.KeyCode == Keys.PageDown))
            {
                UpdateViewOnPageUpDown(eventArgs.KeyCode == Keys.PageUp);
            }
            ISelectionService selectionService = ((IServiceProvider)this.ParentView).GetService(typeof(ISelectionService)) as ISelectionService;

            //enter key (
            if (eventArgs.KeyCode == Keys.Enter)
            {
                // on enter key we want to do DoDefault of the designer
                IDesigner designer = ActivityDesigner.GetDesigner(selectionService.PrimarySelection as Activity) as IDesigner;
                if (designer != null)
                {
                    designer.DoDefaultAction();
                    eventArgs.Handled = true;
                }
            }
            else if (eventArgs.KeyCode == Keys.Escape)
            {
                if (!eventArgs.Handled)
                {
                    CompositeActivityDesigner parentDesigner = ActivityDesigner.GetParentDesigner(selectionService.PrimarySelection);
                    if (parentDesigner != null)
                    {
                        selectionService.SetSelectedComponents(new object[] { parentDesigner.Activity }, SelectionTypes.Replace);
                    }

                    eventArgs.Handled = true;
                }
            }
            else if (eventArgs.KeyCode == Keys.Delete)
            {
                // check if we are cutting root component
                IDesignerHost designerHost = ((IServiceProvider)this.ParentView).GetService(typeof(IDesignerHost)) as IDesignerHost;
                if (!(designerHost == null || selectionService.GetComponentSelected(designerHost.RootComponent)))
                {
                    //Check that we are cutting all activities
                    //Check if we are in writable context
                    ICollection components = selectionService.GetSelectedComponents();
                    if (DesignerHelpers.AreComponentsRemovable(components))
                    {
                        // check if we can delete these
                        List <Activity> topLevelActivities     = new List <Activity>(Helpers.GetTopLevelActivities(selectionService.GetSelectedComponents()));
                        bool            needToDelete           = (topLevelActivities.Count > 0);
                        IDictionary     commonParentActivities = Helpers.PairUpCommonParentActivities(topLevelActivities);
                        foreach (DictionaryEntry entry in commonParentActivities)
                        {
                            CompositeActivityDesigner compositeActivityDesigner = ActivityDesigner.GetDesigner(entry.Key as Activity) as CompositeActivityDesigner;
                            if (compositeActivityDesigner != null && !compositeActivityDesigner.CanRemoveActivities(new List <Activity>((Activity[])((ArrayList)entry.Value).ToArray(typeof(Activity))).AsReadOnly()))
                            {
                                needToDelete = false;
                            }
                        }

                        if (needToDelete)
                        {
                            List <ConnectorHitTestInfo> connectors = new List <ConnectorHitTestInfo>();
                            foreach (object component in components)
                            {
                                ConnectorHitTestInfo connector = component as ConnectorHitTestInfo;
                                if (connector != null)
                                {
                                    connectors.Add(connector);
                                }
                            }

                            //cache selcted connectors before calling this func
                            CompositeActivityDesigner.RemoveActivities((IServiceProvider)this.ParentView, topLevelActivities.AsReadOnly(), SR.GetString(SR.DeletingActivities));

                            //add connectors back to the selection service
                            if (selectionService != null && connectors.Count > 0)
                            {
                                selectionService.SetSelectedComponents(connectors, SelectionTypes.Add);
                            }

                            eventArgs.Handled = true;
                        }
                    }
                }
            }
            //navigation (left, right, up, down, tab, shift-tab)
            else if (eventArgs.KeyCode == Keys.Left || eventArgs.KeyCode == Keys.Right || eventArgs.KeyCode == Keys.Up || eventArgs.KeyCode == Keys.Down || eventArgs.KeyCode == Keys.Tab)
            {
                //we'll pass it to the parent designer of the primary selected designer
                //sequential designers just navigate between their children
                //free form designers may move their children on arrow keys and navigate on tab
                ActivityDesigner designer = ActivityDesigner.GetDesigner(selectionService.PrimarySelection as Activity) as ActivityDesigner;
                if (designer != null && designer.ParentDesigner != null)
                {
                    //we will let the parent see if it wants to handle the event,
                    //otherwise the selected designer itself will be called from a designer message filter below
                    ((IWorkflowDesignerMessageSink)designer.ParentDesigner).OnKeyDown(eventArgs);
                    eventArgs.Handled = true;
                }
            }

            if (!eventArgs.Handled)
            {
                ActivityDesigner designerWithFocus = GetDesignerWithFocus();
                if (designerWithFocus != null)
                {
                    ((IWorkflowDesignerMessageSink)designerWithFocus).OnKeyDown(eventArgs);
                }
            }

            return(eventArgs.Handled);
        }
Ejemplo n.º 4
0
        protected override bool OnKeyDown(KeyEventArgs eventArgs)
        {
            if ((eventArgs != null) && ((eventArgs.KeyCode == Keys.PageUp) || (eventArgs.KeyCode == Keys.Next)))
            {
                this.UpdateViewOnPageUpDown(eventArgs.KeyCode == Keys.PageUp);
            }
            ISelectionService service = ((IServiceProvider)base.ParentView).GetService(typeof(ISelectionService)) as ISelectionService;

            if (eventArgs.KeyCode == Keys.Enter)
            {
                IDesigner designer = ActivityDesigner.GetDesigner(service.PrimarySelection as Activity);
                if (designer != null)
                {
                    designer.DoDefaultAction();
                    eventArgs.Handled = true;
                }
            }
            else if (eventArgs.KeyCode == Keys.Escape)
            {
                if (!eventArgs.Handled)
                {
                    CompositeActivityDesigner parentDesigner = ActivityDesigner.GetParentDesigner(service.PrimarySelection);
                    if (parentDesigner != null)
                    {
                        service.SetSelectedComponents(new object[] { parentDesigner.Activity }, SelectionTypes.Replace);
                    }
                    eventArgs.Handled = true;
                }
            }
            else if (eventArgs.KeyCode == Keys.Delete)
            {
                IDesignerHost host = ((IServiceProvider)base.ParentView).GetService(typeof(IDesignerHost)) as IDesignerHost;
                if ((host != null) && !service.GetComponentSelected(host.RootComponent))
                {
                    ICollection selectedComponents = service.GetSelectedComponents();
                    if (DesignerHelpers.AreComponentsRemovable(selectedComponents))
                    {
                        List <Activity> activities = new List <Activity>(Helpers.GetTopLevelActivities(service.GetSelectedComponents()));
                        bool            flag       = activities.Count > 0;
                        foreach (DictionaryEntry entry in Helpers.PairUpCommonParentActivities(activities))
                        {
                            CompositeActivityDesigner designer3 = ActivityDesigner.GetDesigner(entry.Key as Activity) as CompositeActivityDesigner;
                            if ((designer3 != null) && !designer3.CanRemoveActivities(new List <Activity>((Activity[])((ArrayList)entry.Value).ToArray(typeof(Activity))).AsReadOnly()))
                            {
                                flag = false;
                            }
                        }
                        if (flag)
                        {
                            List <ConnectorHitTestInfo> components = new List <ConnectorHitTestInfo>();
                            foreach (object obj2 in selectedComponents)
                            {
                                ConnectorHitTestInfo item = obj2 as ConnectorHitTestInfo;
                                if (item != null)
                                {
                                    components.Add(item);
                                }
                            }
                            CompositeActivityDesigner.RemoveActivities(base.ParentView, activities.AsReadOnly(), SR.GetString("DeletingActivities"));
                            if ((service != null) && (components.Count > 0))
                            {
                                service.SetSelectedComponents(components, SelectionTypes.Add);
                            }
                            eventArgs.Handled = true;
                        }
                    }
                }
            }
            else if (((eventArgs.KeyCode == Keys.Left) || (eventArgs.KeyCode == Keys.Right)) || (((eventArgs.KeyCode == Keys.Up) || (eventArgs.KeyCode == Keys.Down)) || (eventArgs.KeyCode == Keys.Tab)))
            {
                ActivityDesigner designer4 = ActivityDesigner.GetDesigner(service.PrimarySelection as Activity);
                if ((designer4 != null) && (designer4.ParentDesigner != null))
                {
                    ((IWorkflowDesignerMessageSink)designer4.ParentDesigner).OnKeyDown(eventArgs);
                    eventArgs.Handled = true;
                }
            }
            if (!eventArgs.Handled)
            {
                ActivityDesigner designerWithFocus = this.GetDesignerWithFocus();
                if (designerWithFocus != null)
                {
                    ((IWorkflowDesignerMessageSink)designerWithFocus).OnKeyDown(eventArgs);
                }
            }
            return(eventArgs.Handled);
        }
Ejemplo n.º 5
0
        public static void SetBaseTypeName(string typeName, IServiceProvider serviceProvider)
        {
            if (string.IsNullOrEmpty(typeName))
            {
                throw new ArgumentNullException("typeName");
            }

            IDesignerHost host = serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost;

            if (host == null)
            {
                throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(IDesignerHost).FullName));
            }

            IMemberCreationService memberCreationService = serviceProvider.GetService(typeof(IMemberCreationService)) as IMemberCreationService;

            if (memberCreationService == null)
            {
                throw new InvalidOperationException(SR.GetString("General_MissingService", typeof(IMemberCreationService).FullName));
            }

            // Validate the base type (this will throw an exception if the type name isn't valid
            Type newBaseType = ValidateBaseType(typeName, serviceProvider);

            //Warn the user of the change
            Type oldBaseType = host.RootComponent.GetType();

            if (oldBaseType == newBaseType)
            {
                return;
            }

            // If we're switch to a base type that is not derived from CompositeActivity, make sure
            // we dont's support events or exceptions
            if (!TypeProvider.IsAssignable(typeof(CompositeActivity), newBaseType))
            {
                PropertyDescriptor supportsEventsPropDesc = TypeDescriptor.GetProperties(host.RootComponent)["SupportsEvents"];
                if (supportsEventsPropDesc != null && ((bool)supportsEventsPropDesc.GetValue(host.RootComponent)) == true)
                {
                    supportsEventsPropDesc.SetValue(host.RootComponent, false);
                }

                PropertyDescriptor supportsExceptionsPropDesc = TypeDescriptor.GetProperties(host.RootComponent)["SupportsExceptions"];
                if (supportsExceptionsPropDesc != null && ((bool)supportsExceptionsPropDesc.GetValue(host.RootComponent)) == true)
                {
                    supportsExceptionsPropDesc.SetValue(host.RootComponent, false);
                }
            }

            PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(host.RootComponent);

            if (host.RootComponent is CompositeActivity && ((CompositeActivity)host.RootComponent).Activities.Count > 0)
            {
                // Warn user first if there are any children that can not be re-parented to the new root.
                IUIService uiService = serviceProvider.GetService(typeof(IUIService)) as IUIService;
                if (uiService != null)
                {
                    if (DialogResult.OK != uiService.ShowMessage(SR.GetString(SR.NoChildActivities_Message),
                                                                 SR.GetString(SR.NoChildActivities_Caption), MessageBoxButtons.OKCancel))
                    {
                        return;
                    }
                }

                // Remove the children first. This would cause the component removed event to be fired,
                // thus remove the generated field from the designer.cs file.
                List <Activity>           activitiesToRemove = new List <Activity>(((CompositeActivity)host.RootComponent).Activities);
                CompositeActivityDesigner rootDesigner       = host.GetDesigner(host.RootComponent) as CompositeActivityDesigner;
                if (rootDesigner != null)
                {
                    rootDesigner.RemoveActivities(activitiesToRemove.AsReadOnly());
                }
            }

            //Also, clear all properties of original base. That will allow undo to set old values back.
            foreach (PropertyDescriptor propertyDescriptor in properties)
            {
                if (!propertyDescriptor.Name.Equals("BaseActivityType", StringComparison.Ordinal) &&
                    !propertyDescriptor.Name.Equals("Name", StringComparison.Ordinal) &&
                    propertyDescriptor.CanResetValue(host.RootComponent))
                {
                    propertyDescriptor.ResetValue(host.RootComponent);
                }
            }

            PropertyDescriptor realBaseActivityTypePropertyDescriptor = properties["BaseActivityType"];
            PropertyDescriptor baseActivityTypePropertyDescriptor     = TypeDescriptor.CreateProperty(realBaseActivityTypePropertyDescriptor.ComponentType, realBaseActivityTypePropertyDescriptor, DesignerSerializationVisibilityAttribute.Visible);

            IComponentChangeService changeService = serviceProvider.GetService(typeof(IComponentChangeService)) as IComponentChangeService;

            if (changeService != null)
            {
                changeService.OnComponentChanging(host.RootComponent, baseActivityTypePropertyDescriptor);
            }

            ((Activity)host.RootComponent).UserData[UserDataKeys.NewBaseType] = newBaseType;

            memberCreationService.UpdateBaseType(host.RootComponentClassName, newBaseType);

            if (changeService != null)
            {
                changeService.OnComponentChanged(host.RootComponent, baseActivityTypePropertyDescriptor, baseActivityTypePropertyDescriptor.GetValue(host.RootComponent), typeName);
            }

            //Work around: Force update of the host by raising idle.This is to ensure undo events work on updated host.
            Application.RaiseIdle(new EventArgs());
        }
        public static void SetBaseTypeName(string typeName, IServiceProvider serviceProvider)
        {
            if (string.IsNullOrEmpty(typeName))
            {
                throw new ArgumentNullException("typeName");
            }
            IDesignerHost host = serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost;

            if (host == null)
            {
                throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(IDesignerHost).FullName }));
            }
            IMemberCreationService service = serviceProvider.GetService(typeof(IMemberCreationService)) as IMemberCreationService;

            if (service == null)
            {
                throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(IMemberCreationService).FullName }));
            }
            System.Type fromType = ValidateBaseType(typeName, serviceProvider);
            if (host.RootComponent.GetType() != fromType)
            {
                if (!TypeProvider.IsAssignable(typeof(CompositeActivity), fromType))
                {
                    PropertyDescriptor descriptor = TypeDescriptor.GetProperties(host.RootComponent)["SupportsEvents"];
                    if ((descriptor != null) && ((bool)descriptor.GetValue(host.RootComponent)))
                    {
                        descriptor.SetValue(host.RootComponent, false);
                    }
                    PropertyDescriptor descriptor2 = TypeDescriptor.GetProperties(host.RootComponent)["SupportsExceptions"];
                    if ((descriptor2 != null) && ((bool)descriptor2.GetValue(host.RootComponent)))
                    {
                        descriptor2.SetValue(host.RootComponent, false);
                    }
                }
                PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(host.RootComponent);
                if ((host.RootComponent is CompositeActivity) && (((CompositeActivity)host.RootComponent).Activities.Count > 0))
                {
                    IUIService service2 = serviceProvider.GetService(typeof(IUIService)) as IUIService;
                    if ((service2 != null) && (DialogResult.OK != service2.ShowMessage(SR.GetString("NoChildActivities_Message"), SR.GetString("NoChildActivities_Caption"), MessageBoxButtons.OKCancel)))
                    {
                        return;
                    }
                    List <Activity>           list     = new List <Activity>(((CompositeActivity)host.RootComponent).Activities);
                    CompositeActivityDesigner designer = host.GetDesigner(host.RootComponent) as CompositeActivityDesigner;
                    if (designer != null)
                    {
                        designer.RemoveActivities(list.AsReadOnly());
                    }
                }
                foreach (PropertyDescriptor descriptor3 in properties)
                {
                    if ((!descriptor3.Name.Equals("BaseActivityType", StringComparison.Ordinal) && !descriptor3.Name.Equals("Name", StringComparison.Ordinal)) && descriptor3.CanResetValue(host.RootComponent))
                    {
                        descriptor3.ResetValue(host.RootComponent);
                    }
                }
                PropertyDescriptor      oldPropertyDescriptor = properties["BaseActivityType"];
                PropertyDescriptor      member   = TypeDescriptor.CreateProperty(oldPropertyDescriptor.ComponentType, oldPropertyDescriptor, new Attribute[] { DesignerSerializationVisibilityAttribute.Visible });
                IComponentChangeService service3 = serviceProvider.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
                if (service3 != null)
                {
                    service3.OnComponentChanging(host.RootComponent, member);
                }
                ((Activity)host.RootComponent).UserData[UserDataKeys.NewBaseType] = fromType;
                service.UpdateBaseType(host.RootComponentClassName, fromType);
                if (service3 != null)
                {
                    service3.OnComponentChanged(host.RootComponent, member, member.GetValue(host.RootComponent), typeName);
                }
                Application.RaiseIdle(new EventArgs());
            }
        }