Ejemplo n.º 1
0
        /// <summary>
        /// Registers a command and places it onto the context menu for the editor
        /// window.
        /// </summary>
        public void OnConnection(EnvDTE._DTE application, Extensibility.ext_ConnectMode connectMode, EnvDTE.AddIn addIn)
        {
            m_applicationObject = (EnvDTE._DTE)application;
            m_addInInstance     = (EnvDTE.AddIn)addIn;

            m_strCommandName = "MarkCodeForExtraction";
            m_strName        = AMResources.GetLocalizedString("CodeMarkerName");
            m_strItemText    = AMResources.GetLocalizedString("CodeMarkerItemText");

            string description = AMResources.GetLocalizedString("CodeMarkerDescription");

            EnvDTE.Commands commands = null;
            EnvDTE.Command  command  = null;
            Microsoft.Office.Core._CommandBars      officeCommandBars    = null;
            Microsoft.Office.Core.CommandBar        officeCommandBar     = null;
            Microsoft.Office.Core.CommandBarControl officeCommandControl = null;
            Microsoft.Office.Core.CommandBar        officeAcademic       = null;
            object [] contextGuids;
            contextGuids = new object[] { };

            commands = m_applicationObject.Commands;
            try
            {
                command = commands.AddNamedCommand(m_addInInstance, m_strCommandName, m_strName, description,
                                                   true, 12, ref contextGuids, (int)(EnvDTE.vsCommandStatus.vsCommandStatusEnabled | EnvDTE.vsCommandStatus.vsCommandStatusSupported));

                // Add the new command to the top-level context menu for the editor
                // code window, if possible.
                officeCommandBars            = m_applicationObject.CommandBars;
                officeCommandBar             = (CommandBar)officeCommandBars["Code Window"];
                officeCommandControl         = command.AddControl((object)officeCommandBar, 1);
                officeCommandControl.Caption = m_strItemText;

                string amFacultyMenuItem = AMResources.GetLocalizedString("AMFacultyMenuItem");
                // Also attempt to add it to the Tools menu as well, for accessibility.
                try
                {
                    officeAcademic = (CommandBar)officeCommandBars[amFacultyMenuItem];
                }
                catch
                {
                }
                if (officeAcademic == null)
                {
                    officeCommandBar = (CommandBar)officeCommandBars["Tools"];
                    officeAcademic   = (CommandBar)m_applicationObject.Commands.AddCommandBar(amFacultyMenuItem, EnvDTE.vsCommandBarType.vsCommandBarTypeMenu, officeCommandBar, 1);
                }

                officeCommandControl         = command.AddControl((object)officeAcademic, 1);
                officeCommandControl.Caption = AMResources.GetLocalizedString("CodeMarkerToolsMenuItemText");
            }
            catch (System.Exception /*e*/)
            {
                // Falling into this simply means that the command was already registered.
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Test method
 /// </summary>
 /// <param name="ctrl"></param>
 private void Explore(Office.CommandBarControl ctrl)
 {
     MessageBox.Show(ctrl.Caption);
     if (ctrl is Office.CommandBarPopup)
     {
         foreach (Office.CommandBarControl mi in (ctrl as Office.CommandBarPopup).Controls)
         {
             Explore(mi);
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Registers a command and places it on the Tools menu.
        /// </summary>
        public void OnConnection(EnvDTE._DTE application, Extensibility.ext_ConnectMode connectMode, EnvDTE.AddIn addIn)
        {
            m_applicationObject = (EnvDTE._DTE)application;
            m_addInInstance     = (EnvDTE.AddIn)addIn;

            m_strCommandName = "AMStudentGotoHomePage";
            m_strName        = AMResources.GetLocalizedString("AMStudentGotoHomePageName");
            m_strItemText    = AMResources.GetLocalizedString("AMStudentGotoHomePageItemText");
            m_strHomePageUrl = "vs:/default.htm?tab=" + AMResources.GetLocalizedString("AMStudentGotoHomePagePageName");

            string strDescription = AMResources.GetLocalizedString("GotoHomePageDescription");

            EnvDTE.Commands commands = null;
            EnvDTE.Command  command  = null;
            Microsoft.Office.Core._CommandBars      officeCommandBars    = null;
            Microsoft.Office.Core.CommandBar        officeCommandBar     = null;
            Microsoft.Office.Core.CommandBarControl officeCommandControl = null;
            Microsoft.Office.Core.CommandBar        officeAcademic       = null;
            object [] contextGuids;
            contextGuids = new object[] { };

            commands = m_applicationObject.Commands;
            try
            {
                command = commands.AddNamedCommand(m_addInInstance, m_strCommandName, m_strName, strDescription,
                                                   false, 108, ref contextGuids, (int)(EnvDTE.vsCommandStatus.vsCommandStatusEnabled | EnvDTE.vsCommandStatus.vsCommandStatusSupported));

                // Add the new command to the tools menu
                officeCommandBars = m_applicationObject.CommandBars;
                string amStudentMenuItem = AMResources.GetLocalizedString("AMStudentMenuItem");
                try
                {
                    officeAcademic = (CommandBar)officeCommandBars[amStudentMenuItem];
                }
                catch
                {
                }
                if (officeAcademic == null)
                {
                    officeCommandBar = (CommandBar)officeCommandBars["Tools"];
                    officeAcademic   = (CommandBar)m_applicationObject.Commands.AddCommandBar(amStudentMenuItem, EnvDTE.vsCommandBarType.vsCommandBarTypeMenu, officeCommandBar, 1);
                }
                officeCommandControl         = command.AddControl((object)officeAcademic, 1);
                officeCommandControl.Caption = m_strItemText;
            }
            catch (System.Exception /*e*/)
            {
                // Falling into this simply means that the command was already registered.
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Cette fonction permet de désactiver/activer le menu contexte d'Excel. Lorqu'on clique droit sur une cellule.
        /// </summary>
        /// <param name="isDisable"></param>
        public void DisableExcelContextMenuItems(bool isDisable = true)
        {
            if (this.Office.GetCurrentProgID() == EXCEL_ID)
            {
                Excel._Application          xlApp       = this.Office.GetApplication() as Excel._Application;
                OfficeProperties.CommandBar contextMenu = xlApp.CommandBars["Cell"];

                for (int i = contextMenu.Controls.Count; i > 0; i--)
                {
                    OfficeProperties.CommandBarControl control = contextMenu.Controls[i];
                    control.Enabled = !isDisable;
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Cette fonction permet de désactiver/activer le menu contextuel d'une feuille.
        /// Lorsqu'on clique-droit sur une feuille.
        /// </summary>
        /// <param name="isDisable"></param>
        public void DisableExcelSheetContextMenuItems(bool isDisable = true)
        {
            if (this.Office.GetCurrentProgID() == EXCEL_ID)
            {
                Excel._Application xlApp = this.Office.GetApplication() as Excel._Application;

                OfficeProperties.CommandBar sheetMenu = xlApp.ActiveWorkbook.Application.CommandBars["Ply"];

                for (int j = sheetMenu.Controls.Count; j > 0; j--)
                {
                    OfficeProperties.CommandBarControl control = sheetMenu.Controls[j];
                    control.Enabled = !isDisable;
                }
            }
        }
Ejemplo n.º 6
0
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            // 初始化右侧解析框
            UCForRichText richTextBox = new UCForRichText();
            _MyCustomTaskPane = this.CustomTaskPanes.Add(richTextBox, "解析结果");
            _MyCustomTaskPane.Width = 800;
            _MyCustomTaskPane.Visible = false;

            //获取右键菜单对象mzBar
            Office.CommandBar mzBar = Application.CommandBars["Text"];
            //重置菜单
            mzBar.Reset();
            //获取右键菜单的控制对象
            Office.CommandBarControls bars = mzBar.Controls;

            /*已被mzBar.Reset();替代,用于除去其余标签为"autoAnswer"的菜单项
            foreach (Office.CommandBarControl temp_contrl in bars)
            {
                string t = temp_contrl.Tag.Trim();
                if (t.Equals("autoAnswer"))
                {
                    temp_contrl.Delete();
                }
            }
            */

            //在右键菜单列表添加新的菜单项
            Office.CommandBarControl comControl = bars.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true); //添加自己的菜单项
            //将该菜单项转为按钮可点击模式
            Office.CommandBarButton comButton = comControl as Office.CommandBarButton;
            if (comControl != null)
            {
                comButton.Tag = "autoAnswer";//添加标签"autoAnswer"
                comButton.Caption = "选择答案";//设置文本
                comButton.Style = Office.MsoButtonStyle.msoButtonIconAndCaption;
                comButton.Enabled = false;//设置不可点击
                //name = comButton.accName;
                //comButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(_RightBtn_Click);

            }

            Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
            vstoDoc.BeforeDoubleClick += new Microsoft.Office.Tools.Word.ClickEventHandler(ThisDocument_BeforeDoubleClick);

            this.Application.WindowBeforeRightClick += new Word.ApplicationEvents4_WindowBeforeRightClickEventHandler(Application_WindowBeforeRightClick);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Active/désactive un menu item du menu contextuel d'excel.
 /// </summary>
 /// <param name="active"></param>
 public void ActivateExcelContextMenuItem(bool active, string label)
 {
     if (this.Office.GetCurrentProgID() == EXCEL_ID)
     {
         Excel.Application           xlApp       = this.Office.GetApplication() as Excel.Application;
         OfficeProperties.CommandBar contextMenu = xlApp.CommandBars["Cell"];
         int j = 1;
         for (int i = contextMenu.Controls.Count; i > 0; i--)
         {
             OfficeProperties.CommandBarControl control = contextMenu.Controls[j];
             if (control.Caption == label)
             {
                 control.Enabled = active;
                 break;
             }
             j++;
         }
     }
 }
        private void RemoveCutCopyPasteMenuItems()
        {
            Office.CommandBar contextMenu = GetCellContextMenu();

            for (int i = contextMenu.Controls.Count; i > 0; i--)
            {
                Office.CommandBarControl control = contextMenu.Controls[i];

                if (control.Caption == "Cu&t")
                {
                    control.Delete();                                 // Sample code: remove cut menu item
                }
                else if (control.Caption == "&Copy")
                {
                    control.Delete();                                       // Sample code: remove copy menu item
                }
                else if (control.accDescription.Contains("Paste"))
                {
                    control.Delete();                                                    // Sample code: remove any paste menu items
                }
            }
        }
Ejemplo n.º 9
0
 private void GetCommandBarControls(Office.CommandBarControl ctrl, String tab, List <String> result)
 {
     tab += "\t";
     result.Add(ctrl.Id + "|" + ctrl.Caption + "|" + ctrl.Parent.Name + "|" + ctrl.Control);
 }
Ejemplo n.º 10
0
        public string GetCBCtlType(ref Office.CommandBarControl ctlCBarControl)
        {
            // Returns a string representing the command bar control's type.

            string strType = null;

            //INSTANT C# NOTE: The following VB 'Select Case' included range-type or non-constant 'Case' expressions and was converted to C# 'if-else' logic:
            //			Select Case ctlCBarControl.Type
            //ORIGINAL LINE: Case MsoControlType.msoControlCustom
            if (ctlCBarControl.Type == Office.MsoControlType.msoControlCustom)
            {
                strType = "Custom";
            }
            //ORIGINAL LINE: Case MsoControlType.msoControlButton
            else if (ctlCBarControl.Type == Office.MsoControlType.msoControlButton)
            {
                strType = "Button";
            }
            //ORIGINAL LINE: Case MsoControlType.msoControlEdit
            else if (ctlCBarControl.Type == Office.MsoControlType.msoControlEdit)
            {
                strType = "Edit";
            }
            //ORIGINAL LINE: Case MsoControlType.msoControlDropdown
            else if (ctlCBarControl.Type == Office.MsoControlType.msoControlDropdown)
            {
                strType = "Dropdown";
            }
            //ORIGINAL LINE: Case MsoControlType.msoControlComboBox
            else if (ctlCBarControl.Type == Office.MsoControlType.msoControlComboBox)
            {
                strType = "Combobox";
            }
            //ORIGINAL LINE: Case MsoControlType.msoControlButtonDropdown
            else if (ctlCBarControl.Type == Office.MsoControlType.msoControlButtonDropdown)
            {
                strType = "ButtonDropdown";
            }
            //ORIGINAL LINE: Case MsoControlType.msoControlSplitDropdown
            else if (ctlCBarControl.Type == Office.MsoControlType.msoControlSplitDropdown)
            {
                strType = "SplitDropdown";
            }
            //ORIGINAL LINE: Case MsoControlType.msoControlOCXDropdown
            else if (ctlCBarControl.Type == Office.MsoControlType.msoControlOCXDropdown)
            {
                strType = "OCXDropdown";
            }
            //ORIGINAL LINE: Case MsoControlType.msoControlGenericDropdown
            else if (ctlCBarControl.Type == Office.MsoControlType.msoControlGenericDropdown)
            {
                strType = "GenericDropdown";
            }
            //ORIGINAL LINE: Case MsoControlType.msoControlGraphicDropdown
            else if (ctlCBarControl.Type == Office.MsoControlType.msoControlGraphicDropdown)
            {
                strType = "GraphicDropdown";
            }
            //ORIGINAL LINE: Case MsoControlType.msoControlPopup
            else if (ctlCBarControl.Type == Office.MsoControlType.msoControlPopup)
            {
                strType = "Popup";
            }
            //ORIGINAL LINE: Case MsoControlType.msoControlGraphicPopup
            else if (ctlCBarControl.Type == Office.MsoControlType.msoControlGraphicPopup)
            {
                strType = "GraphicPopup";
            }
            //ORIGINAL LINE: Case MsoControlType.msoControlButtonPopup
            else if (ctlCBarControl.Type == Office.MsoControlType.msoControlButtonPopup)
            {
                strType = "ButtonPopup";
            }
            //ORIGINAL LINE: Case MsoControlType.msoControlSplitButtonPopup
            else if (ctlCBarControl.Type == Office.MsoControlType.msoControlSplitButtonPopup)
            {
                strType = "SplitButtonPopup";
            }
            //ORIGINAL LINE: Case MsoControlType.msoControlSplitButtonMRUPopup
            else if (ctlCBarControl.Type == Office.MsoControlType.msoControlSplitButtonMRUPopup)
            {
                strType = "SplitButtonMRUPopup";
            }
            //ORIGINAL LINE: Case MsoControlType.msoControlLabel
            else if (ctlCBarControl.Type == Office.MsoControlType.msoControlLabel)
            {
                strType = "Label";
            }
            //ORIGINAL LINE: Case MsoControlType.msoControlExpandingGrid
            else if (ctlCBarControl.Type == Office.MsoControlType.msoControlExpandingGrid)
            {
                strType = "ExpandingGrid";
            }
            //ORIGINAL LINE: Case MsoControlType.msoControlSplitExpandingGrid
            else if (ctlCBarControl.Type == Office.MsoControlType.msoControlSplitExpandingGrid)
            {
                strType = "SplitExpandingGrid";
            }
            //ORIGINAL LINE: Case MsoControlType.msoControlGrid
            else if (ctlCBarControl.Type == Office.MsoControlType.msoControlGrid)
            {
                strType = "Grid";
            }
            //ORIGINAL LINE: Case MsoControlType.msoControlGauge
            else if (ctlCBarControl.Type == Office.MsoControlType.msoControlGauge)
            {
                strType = "Gauge";
            }
            //ORIGINAL LINE: Case MsoControlType.msoControlGraphicCombo
            else if (ctlCBarControl.Type == Office.MsoControlType.msoControlGraphicCombo)
            {
                strType = "GraphicCombo";
            }
            //ORIGINAL LINE: Case MsoControlType.msoControlPane
            else if (ctlCBarControl.Type == Office.MsoControlType.msoControlPane)
            {
                strType = "Pane";
            }

            return(strType);
        }