예제 #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.
            }
        }
예제 #2
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.
            }
        }
예제 #3
0
 public DTE_Commands(DTE_Main InMain, EnvDTE.Commands InCmds)
 {
     mMain = InMain;
     mCmds = InCmds;
 }
예제 #4
0
        public static void Main()
        {
            string  outputFile = @"D:\shortcuts.txt";
            Process proc;

#if VSを起動してアタッチ
            string vs2017 = @"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv.exe";
            var    proc   = Process.Start(vs2017);
            proc.WaitForInputIdle();
            while (string.IsNullOrEmpty(proc.MainWindowTitle))
            {
                Thread.Sleep(10);
                proc = Process.GetProcessById(proc.Id);
            }
#else
            // 現在デバッグ実行している VS にアタッチ
            proc = Process.GetProcessesByName("devenv").FirstOrDefault();
#endif
            WindowsAppFriend app = new WindowsAppFriend(proc);
            app.LoadAssembly(typeof(Program).Assembly);

            // https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.shell.package.getglobalservice
            AppVar obj = app.Type().Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(EnvDTE._DTE));

            using (var sw = File.CreateText(outputFile))
            {
                sw.WriteLine("Guid\tID\tName\tLocalizedName\t#\tShortcut");
                Console.Clear();

                // https://docs.microsoft.com/en-us/dotnet/api/envdte80.dte2
                // https://docs.microsoft.com/en-us/dotnet/api/envdte80.dte2.commands
                EnvDTE80.DTE2   dte2     = obj.Pin <EnvDTE80.DTE2>();
                EnvDTE.Commands commands = dte2.Commands;

                int count = commands.Count;
                for (int i = 1; i <= count; i++)
                {
                    Console.SetCursorPosition(0, 0);
                    Console.Write($"進捗 {i,7:N0} / {count,-7:N0}");

                    // https://docs.microsoft.com/en-us/dotnet/api/envdte.commands.item
                    // https://docs.microsoft.com/en-us/dotnet/api/envdte.command
                    EnvDTE.Command cmd = commands.Item(i, -1);

                    if (string.IsNullOrEmpty(cmd.Name))
                    {
                        continue;
                    }
                    if (string.IsNullOrEmpty(cmd.LocalizedName))
                    {
                        continue;
                    }

                    // https://docs.microsoft.com/en-us/dotnet/api/envdte.command.bindings
                    int b = 0;
                    foreach (string bind in cmd.Bindings)
                    {
                        sw.WriteLine($"{cmd.Guid}\t{cmd.ID}\t{cmd.Name}\t{cmd.LocalizedName}\t{++b}\t{bind}");
                    }
                }
            }
            Console.WriteLine("列挙完了");
            Process.Start(outputFile);
        }