Ejemplo n.º 1
0
        public void DoAction(string command)
        {
            if (string.IsNullOrEmpty(command))
            {
                return;
            }

            IMenuCommandService ims = this.GetService(typeof(IMenuCommandService)) as IMenuCommandService;

            if (null == ims)
            {
                return;
            }


            try
            {
                switch (command.ToUpper())
                {
                case "CUT":
                    ims.GlobalInvoke(StandardCommands.Cut);
                    break;

                case "COPY":
                    ims.GlobalInvoke(StandardCommands.Copy);
                    break;

                case "PASTE":
                    ims.GlobalInvoke(StandardCommands.Paste);
                    break;

                case "DELETE":
                    ims.GlobalInvoke(StandardCommands.Delete);
                    break;

                default:
                    // do nothing;
                    break;
                }        //end_switch
            }            //end_try
            catch (Exception exx)
            {
                Debug.WriteLine(exx.Message);
                if (null != exx.InnerException)
                {
                    Debug.WriteLine(exx.InnerException.Message);
                }

                throw;
            } //end_catch
        }
Ejemplo n.º 2
0
        public void ExecuteCommand(CommandID id)
        {
            IServiceContainer   sc  = host as IServiceContainer;
            IMenuCommandService mcs = sc.GetService(typeof(IMenuCommandService)) as IMenuCommandService;

            mcs.GlobalInvoke(id);
        }
Ejemplo n.º 3
0
        public static void Paste(HostSurface hostSurface)
        {
            IMenuCommandService ims = hostSurface.GetService(typeof(IMenuCommandService)) as IMenuCommandService;

            if (ims != null)
            {
                ims.GlobalInvoke(StandardCommands.Paste);
            }
        }
Ejemplo n.º 4
0
 private DesignerVerb StandartVerb(string text, CommandID commandID)
 {
     return(new DesignerVerb(text, delegate(object o, EventArgs e)
     {
         IMenuCommandService ms = GetService(typeof(IMenuCommandService)) as IMenuCommandService;
         bool success = ms.GlobalInvoke(commandID);
     }
                             ));
 }
Ejemplo n.º 5
0
 public virtual void HideTabOrder()
 {
     if (IsTabOrderMode)
     {
         IMenuCommandService menuCommandService = (IMenuCommandService)designSurface.GetService(typeof(IMenuCommandService));
         menuCommandService.GlobalInvoke(StandardCommands.TabOrder);
         tabOrderMode = false;
     }
 }
        public void InvokeStandardCommand(CommandID cmd)
        {
            IMenuCommandService menuService = GetService(typeof(IMenuCommandService)) as IMenuCommandService;

            if (menuService != null)
            {
                menuService.GlobalInvoke(cmd);
            }
        }
Ejemplo n.º 7
0
        public override void Run()
        {
            ReportDesignerView formDesigner = ReportDesigner;

            if (formDesigner != null && CanExecuteCommand(formDesigner.Host))
            {
                IMenuCommandService menuCommandService = (IMenuCommandService)formDesigner.Host.GetService(typeof(IMenuCommandService));
                menuCommandService.GlobalInvoke(CommandID);
            }
        }
Ejemplo n.º 8
0
 public bool PreFilterMessage(ref Message m)
 {
     if (m.Msg == 0x100)
     {
         if (WorkbenchSingleton.Workbench.ActiveContent == null)
         {
             return(false);
         }
         if (!WorkbenchSingleton.Workbench.IsActiveWindow)
         {
             return(false);
         }
         FormsDesignerViewContent activeContent = WorkbenchSingleton.Workbench.ActiveContent as FormsDesignerViewContent;
         if (activeContent == null)
         {
             return(false);
         }
         Keys keyPressed = ((Keys)m.WParam.ToInt32()) | Control.ModifierKeys;
         if ((keyPressed == Keys.Escape) && activeContent.IsTabOrderMode)
         {
             activeContent.HideTabOrder();
             return(true);
         }
         CommandWrapper wrapper = (CommandWrapper)this.keyTable[keyPressed];
         if (wrapper != null)
         {
             if ((wrapper.CommandID == StandardCommands.Delete) && !activeContent.EnableDelete)
             {
                 return(false);
             }
             //LoggingService.Debug("Run menu command: " + wrapper.CommandID);
             Control             activeControl      = WorkbenchSingleton.ActiveControl;
             IMenuCommandService service            = (IMenuCommandService)activeContent.Host.GetService(typeof(IMenuCommandService));
             ISelectionService   service2           = (ISelectionService)activeContent.Host.GetService(typeof(ISelectionService));
             ICollection         selectedComponents = service2.GetSelectedComponents();
             if (selectedComponents.Count == 1)
             {
                 foreach (IComponent component in selectedComponents)
                 {
                     if (this.HandleMenuCommand(activeContent, component, keyPressed))
                     {
                         return(false);
                     }
                 }
             }
             service.GlobalInvoke(wrapper.CommandID);
             if (wrapper.RestoreSelection)
             {
                 service2.SetSelectedComponents(selectedComponents);
             }
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 9
0
        internal bool ExecuteCommand(CommandID commandId)
        {
            bool result = false;
            IMenuCommandService menuCommandService = this.templatePage.TemplateSurface.GetService(typeof(IMenuCommandService)) as IMenuCommandService;

            if (menuCommandService != null && commandId != null)
            {
                result = menuCommandService.GlobalInvoke(commandId);
            }
            return(result);
        }
Ejemplo n.º 10
0
 public void PerformAction(CommandID cmd)
 {
     try
     {
         ServiceMenuCommand.GlobalInvoke(cmd);
     }
     catch
     {
         //    this.OutputWindow.RichTextBox.Text+="Error in performing the action: "+text.Replace( "&" , "" );
     }
 }
Ejemplo n.º 11
0
 private DesignerVerb StandartVerb(string text, CommandID commandID)
 {
     return(new DesignerVerb(text,
                             delegate(object o, EventArgs e)
     {
         IMenuCommandService ms =
             GetService(typeof(IMenuCommandService)) as IMenuCommandService;
         Debug.Assert(ms != null);
         ms.GlobalInvoke(commandID);
     }
                             ));
 }
Ejemplo n.º 12
0
        public void DoCommandID(CommandID command)
        {
            IMenuCommandService ims = this.GetService(typeof(IMenuCommandService)) as IMenuCommandService;

            try
            {
                ims.GlobalInvoke(command);
            }//end_try
            catch (Exception ex)
            {
                throw new Exception("DoAction() - Exception: error in performing the action: " + command + "(see Inner Exception)", ex);
            }
        }
Ejemplo n.º 13
0
 public override void Run()
 {
     try {
         FormsDesignerViewContent formDesigner = FormDesigner;
         if (formDesigner != null && CanExecuteCommand(formDesigner.Host))
         {
             IMenuCommandService menuCommandService = (IMenuCommandService)formDesigner.Host.GetService(typeof(IMenuCommandService));
             menuCommandService.GlobalInvoke(CommandID);
         }
     } catch (Exception e) {
         MessageService.ShowException(e);
     }
 }
Ejemplo n.º 14
0
 public void Refresh()
 {
     try
     {
         IMenuCommandService menuService =
             (IMenuCommandService)GetService(typeof(IMenuCommandService));
         if (menuService != null)
         {
             CommandID r = new CommandID(new Guid("{5efc7975-14bc-11cf-9b2b-00aa00573819}"), 189);
             menuService.GlobalInvoke(r);
         }
     }
     catch { }
 }
Ejemplo n.º 15
0
        //- do some Edit menu command using the MenuCommandService
        public void DoAction(string command)
        {
            if (string.IsNullOrEmpty(command))
            {
                return;
            }

            IMenuCommandService ims = this.GetService(typeof(IMenuCommandService)) as IMenuCommandService;

            try {
                switch (command.ToUpper())
                {
                case "CUT":
                    ims.GlobalInvoke(StandardCommands.Cut);
                    break;

                case "COPY":
                    ims.GlobalInvoke(StandardCommands.Copy);
                    break;

                case "PASTE":
                    ims.GlobalInvoke(StandardCommands.Paste);
                    break;

                case "DELETE":
                    ims.GlobalInvoke(StandardCommands.Delete);
                    break;

                default:
                    // do nothing;
                    break;
                } //end_switch
            }     //end_try
            catch (Exception ex) {
                throw new Exception(_Name_ + "::DoAction() - Exception: error in performing the action: " + command + "(see Inner Exception)", ex);
            } //end_catch
        }
Ejemplo n.º 16
0
 public void InvokeStandardCommand(CommandID cmd)
 {
     try
     {
         IMenuCommandService menuService = GetService(typeof(IMenuCommandService)) as IMenuCommandService;
         if (menuService != null)
         {
             menuService.GlobalInvoke(cmd);
         }
     }
     catch
     {
         //We eat exceptions as some of the operations are not supported in samples
     }
 }
Ejemplo n.º 17
0
 public void DoAction(CommandID command)
 {
     try
     {
         IMenuCommandService ims = this.GetService(typeof(IMenuCommandService)) as IMenuCommandService;
         ims?.GlobalInvoke(command);
     }
     catch (Exception exx)
     {
         Debug.WriteLine(exx.Message);
         if (null != exx.InnerException)
         {
             Debug.WriteLine(exx.InnerException.Message);
         }
         throw;
     }
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Perform all the Edit menu options using the MenuCommandService
        /// </summary>
        private void PerformAction(string text)
        {
            if (this.CurrentDocumentsHostControl == null)
            {
                return;
            }

            IMenuCommandService ims = this.CurrentDocumentsHostControl.HostSurface.GetService(typeof(IMenuCommandService)) as IMenuCommandService;

            try
            {
                switch (text)
                {
                case "&Lefts":
                    ims.GlobalInvoke(StandardCommands.AlignLeft);
                    break;

                case "&Centers":
                    ims.GlobalInvoke(StandardCommands.AlignHorizontalCenters);
                    break;

                case "&Rights":
                    ims.GlobalInvoke(StandardCommands.AlignRight);
                    break;

                case "&Tops":
                    ims.GlobalInvoke(StandardCommands.AlignTop);
                    break;

                case "&Middles":
                    ims.GlobalInvoke(StandardCommands.AlignVerticalCenters);
                    break;

                case "&Bottoms":
                    ims.GlobalInvoke(StandardCommands.AlignBottom);
                    break;

                default:
                    break;
                }
            }
            catch
            {
            }
        }
Ejemplo n.º 19
0
        public static void SelectAll(HostSurface hostSurface)
        {
            IMenuCommandService ims = hostSurface.GetService(typeof(IMenuCommandService)) as IMenuCommandService;

            ims.GlobalInvoke(StandardCommands.SelectAll);
        }
Ejemplo n.º 20
0
        public void SelectAll()
        {
            IMenuCommandService menuCommandService = (IMenuCommandService)designSurface.GetService(typeof(IMenuCommandService));

            menuCommandService.GlobalInvoke(StandardCommands.SelectAll);
        }
Ejemplo n.º 21
0
        public void Delete()
        {
            IMenuCommandService menuCommandService = (IMenuCommandService)designSurface.GetService(typeof(IMenuCommandService));

            menuCommandService.GlobalInvoke(StandardCommands.Delete);
        }
Ejemplo n.º 22
0
        /// The rest of the MenuItem click events are handled here. Most of these MenuItems
        /// require a loaded host to have any applicable use--thus they are disabled
        /// if there isn't one.
        private void menuItem_Click(object sender, System.EventArgs e)
        {
            // The IMenuCommandService makes doing common commands easy.
            // It keeps track of what commands and verbs the designer supports
            // and can invoke them given members of the MenuCommands enum (CommandID's).
            IServiceContainer   sc  = host as IServiceContainer;
            IMenuCommandService mcs = sc.GetService(typeof(IMenuCommandService)) as IMenuCommandService;

            switch ((sender as MenuItem).Text)
            {
            case "Cu&t": mcs.GlobalInvoke(StandardCommands.Cut);
                break;

            case "&Copy": mcs.GlobalInvoke(StandardCommands.Copy);
                break;

            case "&Paste": mcs.GlobalInvoke(StandardCommands.Paste);
                break;

            case "&Delete": mcs.GlobalInvoke(StandardCommands.Delete);
                break;

            case "Select &All": mcs.GlobalInvoke(StandardCommands.SelectAll);
                break;

            case "&Service Requests":
                if (serviceRequests == null)
                {
                    serviceRequests         = new ServiceRequests();
                    serviceRequests.Closed += new EventHandler(OnServiceRequestsClosed);

                    // Our designer host looks for this service to announce the success / failure
                    // of service requests.
                    hostingServiceContainer.AddService(typeof(ServiceRequests), serviceRequests);
                    serviceRequests.Show();
                }
                serviceRequests.Activate();
                break;

            case "&Design": tabControl.SelectedTab = tabDesign;
                break;

            case "&C# Source": tabControl.SelectedTab = tabCS;
                break;

            case "&VB Source": tabControl.SelectedTab = tabVB;
                break;

            case "&XML": tabControl.SelectedTab = tabXML;
                break;

            case "&Properties": mcs.GlobalInvoke(MenuCommands.Properties);
                break;

            case "Show &Grid":
                mcs.GlobalInvoke(StandardCommands.ShowGrid);
                menuItemShowGrid.Checked = !menuItemShowGrid.Checked;
                break;

            case "S&nap to Grid":
                mcs.GlobalInvoke(StandardCommands.SnapToGrid);
                menuItemSnapToGrid.Checked = !menuItemSnapToGrid.Checked;
                break;

            case "&Lefts": mcs.GlobalInvoke(StandardCommands.AlignLeft);
                break;

            case "&Rights": mcs.GlobalInvoke(StandardCommands.AlignRight);
                break;

            case "&Tops": mcs.GlobalInvoke(StandardCommands.AlignTop);
                break;

            case "&Bottoms": mcs.GlobalInvoke(StandardCommands.AlignBottom);
                break;

            case "&Middles": mcs.GlobalInvoke(StandardCommands.AlignHorizontalCenters);
                break;

            case "&Centers": mcs.GlobalInvoke(StandardCommands.AlignVerticalCenters);
                break;

            case "to &Grid": mcs.GlobalInvoke(StandardCommands.AlignToGrid);
                break;

            case "&Horizontally": mcs.GlobalInvoke(StandardCommands.CenterHorizontally);
                break;

            case "&Vertically": mcs.GlobalInvoke(StandardCommands.CenterVertically);
                break;

            case "&Control": mcs.GlobalInvoke(StandardCommands.SizeToControl);
                break;

            case "Control &Width": mcs.GlobalInvoke(StandardCommands.SizeToControlWidth);
                break;

            case "Control &Height": mcs.GlobalInvoke(StandardCommands.SizeToControlHeight);
                break;

            case "&Grid": mcs.GlobalInvoke(StandardCommands.SizeToGrid);
                break;

            case "&Bring to Front": mcs.GlobalInvoke(StandardCommands.BringToFront);
                break;

            case "&Send to Back": mcs.GlobalInvoke(StandardCommands.SendToBack);
                break;

            case "&Tab Order": mcs.GlobalInvoke(StandardCommands.TabOrder);
                break;
            }
        }
Ejemplo n.º 23
0
 private void KopierenToolStripMenuItem_Click(object sender, EventArgs e)
 {
     mcs.GlobalInvoke(StandardCommands.Cut);
 }
Ejemplo n.º 24
0
        public bool PreFilterMessage(ref Message m)
        {
            if (host == null)
            {
                return(false);
            }

            if (m.Msg == 256 /*0x0100 WM_KEYDOWN*/)
            {
                IMenuCommandService mcs = host.GetService(typeof(IMenuCommandService)) as IMenuCommandService;

                switch (((int)m.WParam) | ((int)Control.ModifierKeys))
                {
                case (int)Keys.Up: mcs.GlobalInvoke(MenuCommands.KeyMoveUp);
                    return(true);

                case (int)Keys.Down: mcs.GlobalInvoke(MenuCommands.KeyMoveDown);
                    return(true);

                case (int)Keys.Right: mcs.GlobalInvoke(MenuCommands.KeyMoveRight);
                    return(true);

                case (int)Keys.Left: mcs.GlobalInvoke(MenuCommands.KeyMoveLeft);
                    return(true);

                case (int)Keys.Enter:
                    ITU.enterKeyPressed = true;
                    return(false);

                case (int)(Keys.Control | Keys.Up): mcs.GlobalInvoke(MenuCommands.KeyNudgeUp);
                    return(true);

                case (int)(Keys.Control | Keys.Down): mcs.GlobalInvoke(MenuCommands.KeyNudgeDown);
                    return(true);

                case (int)(Keys.Control | Keys.Right): mcs.GlobalInvoke(MenuCommands.KeyNudgeRight);
                    return(true);

                case (int)(Keys.Control | Keys.Left): mcs.GlobalInvoke(MenuCommands.KeyNudgeLeft);
                    return(true);

                case (int)(Keys.Shift | Keys.Up): mcs.GlobalInvoke(MenuCommands.KeySizeHeightDecrease);
                    return(true);

                case (int)(Keys.Shift | Keys.Down): mcs.GlobalInvoke(MenuCommands.KeySizeHeightIncrease);
                    return(true);

                case (int)(Keys.Shift | Keys.Right): mcs.GlobalInvoke(MenuCommands.KeySizeWidthIncrease);
                    return(true);

                case (int)(Keys.Shift | Keys.Left): mcs.GlobalInvoke(MenuCommands.KeySizeWidthDecrease);
                    return(true);

                case (int)(Keys.Control | Keys.Shift | Keys.Up): mcs.GlobalInvoke(MenuCommands.KeyNudgeHeightDecrease);
                    return(true);

                case (int)(Keys.Control | Keys.Shift | Keys.Down): mcs.GlobalInvoke(MenuCommands.KeyNudgeHeightIncrease);
                    return(true);

                case (int)(Keys.Control | Keys.Shift | Keys.Right): mcs.GlobalInvoke(MenuCommands.KeyNudgeWidthIncrease);
                    return(true);

                case (int)(Keys.ControlKey | Keys.Shift | Keys.Left): mcs.GlobalInvoke(MenuCommands.KeyNudgeWidthDecrease);
                    return(true);
                }
            }
            else if (m.Msg == 257 /*0x0101 WM_KEYUP*/)
            {
                switch (((int)m.WParam) | ((int)Control.ModifierKeys))
                {
                case (int)Keys.Enter:
                    ITU.enterKeyPressed = false;
                    return(false);
                }
            }
            return(false);
        }
Ejemplo n.º 25
0
        // Loads the new ITypeDescriptorFilterService and reloads the
        // designers for each button.
        public override void Initialize(System.ComponentModel.IComponent component)
        {
            base.Initialize(component);

            // Loads the custom service if it has not been loaded already
            LoadService();

            // Build list of buttons from Container.Components.
            ArrayList buttons = new ArrayList();

            foreach (IComponent c in this.Component.Site.Container.Components)
            {
                if (c.GetType() == typeof(System.Windows.Forms.Button))
                {
                    buttons.Add((System.Windows.Forms.Button)c);
                }
            }
            if (buttons.Count > 0)
            {
                // Tests each Button for an existing
                // ColorCycleButtonDesigner;
                // if it has no designer of type
                // ColorCycleButtonDesigner, adds a designer.
                foreach (System.Windows.Forms.Button b in buttons)
                {
                    bool loaddesigner = true;
                    // Gets the attributes for each button.
                    AttributeCollection ac = TypeDescriptor.GetAttributes(b);
                    for (int i = 0; i < ac.Count; i++)
                    {
                        // If designer attribute is not for a
                        // ColorCycleButtonDesigner, adds a new
                        // ColorCycleButtonDesigner.
                        if (ac[i] is DesignerAttribute)
                        {
                            DesignerAttribute da = (DesignerAttribute)ac[i];
                            if (da.DesignerTypeName.Substring(da.DesignerTypeName.LastIndexOf(".") + 1) == "ColorCycleButtonDesigner")
                            {
                                loaddesigner = false;
                            }
                        }
                    }
                    if (loaddesigner)
                    {
                        // Saves the button location so that it
                        // can be repositioned.
                        Point p = b.Location;

                        // Gets an IMenuCommandService to cut and
                        // paste control in order to register with
                        // selection and movement interface after
                        // designer is changed without reloading.
                        IMenuCommandService imcs = (IMenuCommandService)this.GetService(typeof(IMenuCommandService));
                        if (imcs == null)
                        {
                            throw new Exception("Could not obtain IMenuCommandService interface.");
                        }
                        // Gets an ISelectionService to select the
                        // button so that it can be cut and pasted.
                        ISelectionService iss = (ISelectionService)this.GetService(typeof(ISelectionService));
                        if (iss == null)
                        {
                            throw new Exception("Could not obtain ISelectionService interface.");
                        }
                        iss.SetSelectedComponents(new IComponent[] { b }, SelectionTypes.Auto);
                        // Invoke Cut and Paste.
                        imcs.GlobalInvoke(StandardCommands.Cut);
                        imcs.GlobalInvoke(StandardCommands.Paste);
                        // Regains reference to button from
                        // selection service.
                        System.Windows.Forms.Button b2 = (System.Windows.Forms.Button)iss.PrimarySelection;
                        iss.SetSelectedComponents(null);
                        // Refreshes TypeDescriptor properties of
                        // button to load new attributes from
                        // ButtonDesignerFilterService.
                        TypeDescriptor.Refresh(b2);
                        b2.Location = p;
                        b2.Focus();
                    }
                }
            }
        }
        public bool PreFilterMessage(ref Message m)
        {
            // Catch WM_KEYCHAR if the designerView has focus
            if ((m.Msg == 0x0100) && (((XDesignerHost)host).View.Focused))
            {
                IMenuCommandService mcs = host.GetService(typeof(IMenuCommandService)) as IMenuCommandService;

                // WM_KEYCHAR only tells us the last key pressed. Thus we check
                // Control for modifier keys (Control, Shift, etc.)
                //
                switch (((int)m.WParam) | ((int)Control.ModifierKeys))
                {
                case (int)Keys.Up: mcs.GlobalInvoke(MenuCommands.KeyMoveUp);
                    break;

                case (int)Keys.Down: mcs.GlobalInvoke(MenuCommands.KeyMoveDown);
                    break;

                case (int)Keys.Right: mcs.GlobalInvoke(MenuCommands.KeyMoveRight);
                    break;

                case (int)Keys.Left: mcs.GlobalInvoke(MenuCommands.KeyMoveLeft);
                    break;

                case (int)(Keys.Control | Keys.Up): mcs.GlobalInvoke(MenuCommands.KeyNudgeUp);
                    break;

                case (int)(Keys.Control | Keys.Down): mcs.GlobalInvoke(MenuCommands.KeyNudgeDown);
                    break;

                case (int)(Keys.Control | Keys.Right): mcs.GlobalInvoke(MenuCommands.KeyNudgeRight);
                    break;

                case (int)(Keys.Control | Keys.Left): mcs.GlobalInvoke(MenuCommands.KeyNudgeLeft);
                    break;

                case (int)(Keys.Shift | Keys.Up): mcs.GlobalInvoke(MenuCommands.KeySizeHeightIncrease);
                    break;

                case (int)(Keys.Shift | Keys.Down): mcs.GlobalInvoke(MenuCommands.KeySizeHeightDecrease);
                    break;

                case (int)(Keys.Shift | Keys.Right): mcs.GlobalInvoke(MenuCommands.KeySizeWidthIncrease);
                    break;

                case (int)(Keys.Shift | Keys.Left): mcs.GlobalInvoke(MenuCommands.KeySizeWidthDecrease);
                    break;

                case (int)(Keys.Control | Keys.Shift | Keys.Up): mcs.GlobalInvoke(MenuCommands.KeyNudgeHeightIncrease);
                    break;

                case (int)(Keys.Control | Keys.Shift | Keys.Down): mcs.GlobalInvoke(MenuCommands.KeyNudgeHeightDecrease);
                    break;

                case (int)(Keys.Control | Keys.Shift | Keys.Right): mcs.GlobalInvoke(MenuCommands.KeyNudgeWidthIncrease);
                    break;

                case (int)(Keys.ControlKey | Keys.Shift | Keys.Left): mcs.GlobalInvoke(MenuCommands.KeyNudgeWidthDecrease);
                    break;

                case (int)(Keys.Escape): mcs.GlobalInvoke(MenuCommands.KeyCancel);
                    break;

                case (int)(Keys.Shift | Keys.Escape): mcs.GlobalInvoke(MenuCommands.KeyReverseCancel);
                    break;

                case (int)(Keys.Enter): mcs.GlobalInvoke(MenuCommands.KeyDefaultAction);
                    break;
                }
            }
            // Never filter the message
            return(false);
        }
Ejemplo n.º 27
0
        private void PerformAction(string text)
        {
            if (this.GetCurrentHost() == null)
            {
                return;
            }

            IMenuCommandService ims = this.GetCurrentHost().HostSurface.GetService(typeof(IMenuCommandService)) as IMenuCommandService;

            try
            {
                switch (text)
                {
                case "剪切(&T)":
                    ims.GlobalInvoke(StandardCommands.Cut);
                    break;

                case "复制(&C)":
                    ims.GlobalInvoke(StandardCommands.Copy);
                    break;

                case "粘贴(&P)":
                    ims.GlobalInvoke(StandardCommands.Paste);
                    break;

                case "撤消(&U)":
                    ims.GlobalInvoke(StandardCommands.Undo);
                    break;

                case "重复(&R)":
                    ims.GlobalInvoke(StandardCommands.Redo);
                    break;

                case "删除(&D)":
                    ims.GlobalInvoke(StandardCommands.Delete);
                    break;

                case "删除":
                    ims.GlobalInvoke(StandardCommands.Delete);
                    break;

                case "全选(&S)":
                    ims.GlobalInvoke(StandardCommands.SelectAll);
                    break;

                case "左对齐":
                    ims.GlobalInvoke(StandardCommands.AlignLeft);
                    break;

                case "居中对齐":
                    ims.GlobalInvoke(StandardCommands.AlignHorizontalCenters);
                    break;

                case "右对齐":
                    ims.GlobalInvoke(StandardCommands.AlignRight);
                    break;

                case "顶端对齐":
                    ims.GlobalInvoke(StandardCommands.AlignTop);
                    break;

                case "中间对齐":
                    ims.GlobalInvoke(StandardCommands.AlignVerticalCenters);
                    break;

                case "底端对齐":
                    ims.GlobalInvoke(StandardCommands.AlignBottom);
                    break;

                case "垂直间距相等":
                    ims.GlobalInvoke(StandardCommands.VertSpaceMakeEqual);
                    break;

                case "水平间距相等":
                    ims.GlobalInvoke(StandardCommands.HorizSpaceMakeEqual);
                    break;

                default:
                    break;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "错误");
            }
        }
 public bool GlobalInvoke(CommandID commandId)
 {
     return(_menuCommandService.GlobalInvoke(commandId));
 }
Ejemplo n.º 29
0
        private void menuItem_Click(object sender, EventArgs e)
        {
            IMenuCommandService mcs = ((IServiceProvider)this.host).GetService(typeof(IMenuCommandService)) as IMenuCommandService;

            switch ((sender as MenuItem).Text)
            {
            case "Cu&t":
                mcs.GlobalInvoke(StandardCommands.Cut);
                break;

            case "&Copy":
                mcs.GlobalInvoke(StandardCommands.Copy);
                break;

            case "&Paste":
                mcs.GlobalInvoke(StandardCommands.Paste);
                break;

            case "&Delete":
                mcs.GlobalInvoke(StandardCommands.Delete);
                break;

            case "Select &All":
                mcs.GlobalInvoke(StandardCommands.SelectAll);
                break;

            case "&Service Requests":
                if (this.serviceRequests == null)
                {
                    this.serviceRequests         = new ServiceRequests();
                    this.serviceRequests.Closed += new EventHandler(this.OnServiceRequestsClosed);
                    this.hostingServiceContainer.AddService(typeof(ServiceRequests), this.serviceRequests);
                    this.serviceRequests.Show();
                }
                this.serviceRequests.Activate();
                break;

            case "&Design":
                this.tabControl.SelectedTab = this.tabDesign;
                break;

            case "&C# Source":
                this.tabControl.SelectedTab = this.tabCS;
                break;

            case "&VB Source":
                this.tabControl.SelectedTab = this.tabVB;
                break;

            case "&XML":
                this.tabControl.SelectedTab = this.tabXML;
                break;

            case "&Properties":
                mcs.GlobalInvoke(StandardCommands.Properties);
                break;

            case "Show &Grid":
                mcs.GlobalInvoke(StandardCommands.ShowGrid);
                this.menuItemShowGrid.Checked = !this.menuItemShowGrid.Checked;
                break;

            case "S&nap to Grid":
                mcs.GlobalInvoke(StandardCommands.SnapToGrid);
                this.menuItemSnapToGrid.Checked = !this.menuItemSnapToGrid.Checked;
                break;

            case "&Lefts":
                mcs.GlobalInvoke(StandardCommands.AlignLeft);
                break;

            case "&Rights":
                mcs.GlobalInvoke(StandardCommands.AlignRight);
                break;

            case "&Tops":
                mcs.GlobalInvoke(StandardCommands.AlignTop);
                break;

            case "&Bottoms":
                mcs.GlobalInvoke(StandardCommands.AlignBottom);
                break;

            case "&Middles":
                mcs.GlobalInvoke(StandardCommands.AlignHorizontalCenters);
                break;

            case "&Centers":
                mcs.GlobalInvoke(StandardCommands.AlignVerticalCenters);
                break;

            case "to &Grid":
                mcs.GlobalInvoke(StandardCommands.AlignToGrid);
                break;

            case "&Horizontally":
                mcs.GlobalInvoke(StandardCommands.CenterHorizontally);
                break;

            case "&Vertically":
                mcs.GlobalInvoke(StandardCommands.CenterVertically);
                break;

            case "&Control":
                mcs.GlobalInvoke(StandardCommands.SizeToControl);
                break;

            case "Control &Width":
                mcs.GlobalInvoke(StandardCommands.SizeToControlWidth);
                break;

            case "Control &Height":
                mcs.GlobalInvoke(StandardCommands.SizeToControlHeight);
                break;

            case "&Grid":
                mcs.GlobalInvoke(StandardCommands.SizeToGrid);
                break;

            case "&Bring to Front":
                mcs.GlobalInvoke(StandardCommands.BringToFront);
                break;

            case "&Send to Back":
                mcs.GlobalInvoke(StandardCommands.SendToBack);
                break;

            case "&Tab Order":
                mcs.GlobalInvoke(StandardCommands.TabOrder);
                break;
            }
        }
Ejemplo n.º 30
0
        public bool PreFilterMessage(ref Message m)
        {
            if (m.Msg != keyPressedMessage /*&& m.Msg != leftMouseButtonDownMessage*/)
            {
                return(false);
            }

            FormsDesignerViewContent formDesigner = WorkbenchSingleton.Workbench.ActiveContent as FormsDesignerViewContent;

            if (formDesigner == null || formDesigner.Host == null)
            {
                return(false);
            }
            if (formDesigner.UserContent != null && !((Control)formDesigner.UserContent).ContainsFocus)
            {
                return(false);
            }

            Control originControl = Control.FromChildHandle(m.HWnd);

            if (originControl != null && formDesigner.UserContent != null && !(formDesigner.UserContent == originControl || formDesigner.UserContent.Contains(originControl)))
            {
                // Ignore if message origin not in forms designer
                // (e.g. navigating the main menu)
                return(false);
            }

            Keys keyPressed = (Keys)m.WParam.ToInt32() | Control.ModifierKeys;

            if (keyPressed == Keys.Escape)
            {
                if (formDesigner.IsTabOrderMode)
                {
                    formDesigner.HideTabOrder();
                    return(true);
                }
            }

            CommandWrapper commandWrapper;

            if (keyTable.TryGetValue(keyPressed, out commandWrapper))
            {
                if (commandWrapper.CommandID == MenuCommands.Delete)
                {
                    // Check Delete menu is enabled.
                    if (!formDesigner.EnableDelete)
                    {
                        return(false);
                    }
                }
                LoggingService.Debug("Run menu command: " + commandWrapper.CommandID);

                IMenuCommandService menuCommandService = (IMenuCommandService)formDesigner.Host.GetService(typeof(IMenuCommandService));
                ISelectionService   selectionService   = (ISelectionService)formDesigner.Host.GetService(typeof(ISelectionService));
                ICollection         components         = selectionService.GetSelectedComponents();
                if (components.Count == 1)
                {
                    foreach (IComponent component in components)
                    {
                        if (HandleMenuCommand(formDesigner, component, keyPressed))
                        {
                            return(false);
                        }
                    }
                }

                menuCommandService.GlobalInvoke(commandWrapper.CommandID);

                if (commandWrapper.RestoreSelection)
                {
                    selectionService.SetSelectedComponents(components);
                }
                return(true);
            }

            return(false);
        }