コード例 #1
0
        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());
                }
            }
        }
コード例 #2
0
        private ActivityDesigner GetDesignerWithFocus()
        {
            ActivityDesigner  designer = null;
            ISelectionService service  = base.GetService(typeof(ISelectionService)) as ISelectionService;

            if (service == null)
            {
                return(designer);
            }
            object primarySelection = service.PrimarySelection;

            if (primarySelection is Activity)
            {
                return(ActivityDesigner.GetDesigner(primarySelection as Activity));
            }
            return(ActivityDesigner.GetParentDesigner(primarySelection));
        }
コード例 #3
0
ファイル: WindowManager.cs プロジェクト: dox0/DotNet471RS3
        private ActivityDesigner GetDesignerWithFocus()
        {
            ActivityDesigner designerWithFocus = null;

            ISelectionService selectionService = GetService(typeof(ISelectionService)) as ISelectionService;

            if (selectionService != null)
            {
                object primarySelection = selectionService.PrimarySelection;
                if (primarySelection is Activity)
                {
                    designerWithFocus = ActivityDesigner.GetDesigner(primarySelection as Activity);
                }
                else
                {
                    designerWithFocus = ActivityDesigner.GetParentDesigner(primarySelection);
                }
            }

            return(designerWithFocus);
        }
コード例 #4
0
        protected override bool OnMouseMove(MouseEventArgs eventArgs)
        {
            bool retval = base.OnMouseMove(eventArgs);

            if (eventArgs.Button == MouseButtons.None)
            {
                bool showMoveCursor = false;
                showMoveCursor |= (MessageHitTestContext != null && MessageHitTestContext.AssociatedDesigner != null && ActivityDesigner.GetParentDesigner(MessageHitTestContext.AssociatedDesigner.Activity) is FreeformActivityDesigner && (MessageHitTestContext.HitLocation & HitTestLocations.ActionArea) == 0);
                UpdateCursor(showMoveCursor);
            }
            return(retval);
        }
コード例 #5
0
        public override object GetNextSelectableObject(object current, DesignerNavigationDirection navigate)
        {
            object           activity = null;
            ArrayList        list     = new ArrayList(this.ContainedDesigners);
            ActivityDesigner designer = (current is Activity) ? ActivityDesigner.GetDesigner(current as Activity) : ActivityDesigner.GetParentDesigner(current);
            int num = (designer != null) ? list.IndexOf(designer) : -1;

            if (((navigate == DesignerNavigationDirection.Left) || (navigate == DesignerNavigationDirection.Up)) && ((num >= 0) && (num < list.Count)))
            {
                return(((ActivityDesigner)list[(num > 0) ? (num - 1) : (list.Count - 1)]).Activity);
            }
            if (((navigate == DesignerNavigationDirection.Right) || (navigate == DesignerNavigationDirection.Down)) && (num <= (list.Count - 1)))
            {
                activity = ((ActivityDesigner)list[(num < (list.Count - 1)) ? (num + 1) : 0]).Activity;
            }
            return(activity);
        }
コード例 #6
0
ファイル: WindowManager.cs プロジェクト: dox0/DotNet471RS3
        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);
        }
コード例 #7
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);
        }
コード例 #8
0
        protected override bool OnMouseMove(MouseEventArgs eventArgs)
        {
            bool flag = base.OnMouseMove(eventArgs);

            if (eventArgs.Button == MouseButtons.None)
            {
                bool showMoveCursor = false;
                showMoveCursor |= (((base.MessageHitTestContext != null) && (base.MessageHitTestContext.AssociatedDesigner != null)) && (ActivityDesigner.GetParentDesigner(base.MessageHitTestContext.AssociatedDesigner.Activity) is FreeformActivityDesigner)) && ((base.MessageHitTestContext.HitLocation & HitTestLocations.ActionArea) == HitTestLocations.None);
                this.UpdateCursor(showMoveCursor);
            }
            return(flag);
        }
コード例 #9
0
        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);
            }
        }