Visual Studio插件

下載地址:https://github.com/leation/Visual-Studio-Addin 
    基於Microsoft Visual Studio 2008 環境(具體項目類型爲「其餘項目類型」→「擴展性」→「Visual Studio 外接程序」),用C#語言開發實現的Visual Studio擴展 插件,對.NET項目開發頗有用,能夠批量執行任務,包括摺疊和展開全部項目,批量修改項目的目標平臺、輸出路徑、生成事件和.NET版本,批量建立和加 載項目,快速智能修改項目的dll引用、添加dll引用、拷貝項目依賴項、查看項目dll引用、提交dll到Lib庫、檢查Lib庫是否有重複dll、生 成SQL語句和生成GUID等,在搭建項目和發佈系統時頗有用,有了它能夠避免不少沒必要要的問題,同時也能夠減小不少重複的工做,尤爲是在發佈系統時能夠 保證程序的正確性。在給用戶編譯發佈程序的時候不少人都沒有意識到目標平臺(x8六、x64和Any CPU)和.net版本(2.0或3.5等)的選擇 對用戶可能帶來的不良用戶體驗(一般程序報錯,運行不了,或者某個模塊運行不了),即使意識到了這一點也很難保證在不一樣解決方案配置下(debug和 release等)程序的目標平臺、.Net版本和dll版本的正確性,一般debug沒有問題,可是一旦發佈release版本就會出現不少問題,同時 若是要手工修改相關配置工做量也很大。該插件絕對是世界上獨一無二的,固然若是須要更多批處理功能,聰明的你也能夠繼續發揮哦……
    插件基 於Microsoft Visual Studio 2008環境進行開發,因此插件能夠在Microsoft Visual Studio 2008以 上版本的Microsoft Visual Studio 環境中使用,目前測試過Microsoft Visual Studio 200八、 Microsoft Visual Studio 20十、Microsoft Visual Studio 2012和 Microsoft Visual Studio 2013。git

using System;
using Extensibility;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio.CommandBars;
using System.Resources;
using System.Reflection;
using System.Globalization;
using System.Windows.Forms;

namespace Leation.VSAddin
{
	/// 用於實現外接程序的對象。
	/// 
	public class Connect : IDTExtensibility2, IDTCommandTarget
	{
        private DTE2 _app;
        private AddIn _addIn;

        /// 實現外接程序對象的構造函數。請將您的初始化代碼置於此方法內。
		public Connect()
		{
		}

		/// 實現 IDTExtensibility2 接口的 OnConnection 方法。接收正在加載外接程序的通知。
		/// 宿主應用程序的根對象。
		/// 描述外接程序的加載方式。
		/// 表示此外接程序的對象。
		/// 
		public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
		{            
            _app = (DTE2)application;
			_addIn = (AddIn)addInInst;

            if (connectMode == ext_ConnectMode.ext_cm_UISetup||connectMode== ext_ConnectMode.ext_cm_AfterStartup||connectMode== ext_ConnectMode.ext_cm_Startup)
            {
                object[] contextGUIDS = new object[] { };
                Commands2 commands = (Commands2)_app.Commands;

                Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_app.CommandBars)["MenuBar"];

                CommandBarControl cmdCtr = this.GetExistCommandBarControl(menuBarCommandBar, "李仙偉");
                if (cmdCtr != null)
                {
                    cmdCtr.Visible = true;
                    return;
                }
                CommandBarControl myToolsControl = menuBarCommandBar.Controls.Add(MsoControlType.msoControlPopup, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
                myToolsControl.Caption = "李仙偉";

                CommandBarPopup toolsPopup = (CommandBarPopup)myToolsControl;

                //若是但願添加多個由您的外接程序處理的命令,能夠重複此 try/catch 塊,
                //  只需確保更新 QueryStatus/Exec 方法,使其包含新的命令名。
                try
                {
                    //將一個命令添加到 Commands 集合:
                    Command command = this.GetExistCommand(commands, "PlatformSetting");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "PlatformSetting", "目標平臺設置(&P)", "批量修改目標平臺", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    //將對應於該命令的控件添加到「李仙偉」菜單:
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 1);
                    }
                }
                catch (System.ArgumentException)
                {
                    //若是出現此異常,緣由極可能是因爲具備該名稱的命令
                    //  已存在。若是確實如此,則無需從新建立此命令,而且
                    //  能夠放心忽略此異常。
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "OutPathSetting");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "OutPathSetting", "輸出路徑設置(&O)", "批量修改輸出路徑設置", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 2);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "BuildEventSetting");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "BuildEventSetting", "生成事件設置(&E)", "批量修改生成事件", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 3);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "NetFrameweorkSetting");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "NetFrameweorkSetting", ".NET版本設置(&N)", "批量修改.NET版本", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 4);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "CollapseAll");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "CollapseAll", "摺疊全部項目(&C)", "摺疊全部項目", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 5);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "ExpandAll");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "ExpandAll", "展開全部項目(&X)", "展開全部項目", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 6);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "MultiLoadProjects");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "MultiLoadProjects", "批量加載項目", "批量加載項目", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 7);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "MultiCreateProjects");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "MultiCreateProjects", "批量建立項目", "批量建立項目", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 8);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "DllRefConfig");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "DllRefConfig", "修改項目dll引用", "修改項目dll引用", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 9);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "DllRefFileCopy");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "DllRefFileCopy", "拷貝dll的引用(依賴項)", "拷貝dll的引用(依賴項)", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 10);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "Dll2Lib");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "Dll2Lib", "更新dll到Lib", "更新dll到Lib", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 11);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "SQLCreator");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "SQLCreator", "SQL語句生成器", "SQL語句生成器", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 12);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "GuidCreator");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "GuidCreator", "Guid生成器", "Guid生成器", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 13);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "CheckRepeatDll");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "CheckRepeatDll", "檢查Lib庫重複的dll", "檢查Lib庫重複的dll", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 14);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "Selection2Upper");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "Selection2Upper", "Selection2Upper", "Selection2Upper", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 15);
                    }
                }
                catch (System.ArgumentException)
                {
                }
                try
                {
                    Command command = this.GetExistCommand(commands, "AboutMe");
                    if (command == null)
                    {
                        command = commands.AddNamedCommand2(_addIn, "AboutMe", "關於(&A)", "關於", false, 1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                    }
                    if ((command != null) && (toolsPopup != null))
                    {
                        command.AddControl(toolsPopup.CommandBar, 16);
                    }
                }
                catch (System.ArgumentException)
                {
                }
            }

            //清理臨時文件
            DllRefReflectUtility.ClearTempFiles();
		}

		/// 實現 IDTExtensibility2 接口的 OnDisconnection 方法。接收正在卸載外接程序的通知。
		/// 描述外接程序的卸載方式。
		/// 特定於宿主應用程序的參數數組。
		/// 
		public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom)
		{
            if (_app == null)
            {
                return;
            }
            CommandBar menuBarCommandBar = ((CommandBars)_app.CommandBars)["MenuBar"];
            CommandBarControl cmdCtr = this.GetExistCommandBarControl(menuBarCommandBar, "李仙偉");
            if (cmdCtr != null)
            {
                cmdCtr.Visible = false;
            }          
		}

		/// 實現 IDTExtensibility2 接口的 OnAddInsUpdate 方法。當外接程序集合已發生更改時接收通知。
		/// 特定於宿主應用程序的參數數組。
		/// 		
		public void OnAddInsUpdate(ref Array custom)
        {           

		}

		/// 實現 IDTExtensibility2 接口的 OnStartupComplete 方法。接收宿主應用程序已完成加載的通知。
		/// 特定於宿主應用程序的參數數組。
		/// 
		public void OnStartupComplete(ref Array custom)
        {          

		}

		/// 實現 IDTExtensibility2 接口的 OnBeginShutdown 方法。接收正在卸載宿主應用程序的通知。
		/// 特定於宿主應用程序的參數數組。
		/// 
		public void OnBeginShutdown(ref Array custom)
		{
		}

        /// 實現 IDTCommandTarget 接口的 QueryStatus 方法。此方法在更新該命令的可用性時調用
        /// 要肯定其狀態的命令的名稱。
        /// 該命令所需的文本。
        /// 該命令在用戶界面中的狀態。
        /// neededText 參數所要求的文本。
        /// 
        public void QueryStatus(string commandName, vsCommandStatusTextWanted neededText, ref vsCommandStatus status, ref object commandText)
        {
            if (neededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone)
            {
                if (commandName == "Leation.VSAddin.Connect.PlatformSetting")
                {
                    status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.OutPathSetting")
                {
                    status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.BuildEventSetting")
                {
                    status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.NetFrameweorkSetting")
                {
                    status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.CollapseAll")
                {
                    status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.ExpandAll")
                {
                    status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.MultiLoadProjects")
                {
                    status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.MultiCreateProjects")
                {
                    status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.DllRefConfig")
                {
                    status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.DllRefFileCopy")
                {
                    status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.Dll2Lib")
                {
                    status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.SQLCreator")
                {
                    status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.GuidCreator")
                {
                    status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.CheckRepeatDll")
                {
                    status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.Selection2Upper")
                {
                    status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.AboutMe")
                {
                    status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
                    return;
                }
            }
        }

        /// 實現 IDTCommandTarget 接口的 Exec 方法。此方法在調用該命令時調用。
        /// 要執行的命令的名稱。
        /// 描述該命令應如何運行。
        /// 從調用方傳遞到命令處理程序的參數。
        /// 從命令處理程序傳遞到調用方的參數。
        /// 通知調用方此命令是否已被處理。
        /// 
        public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
        {
            handled = false;
            if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
            {
                if (commandName == "Leation.VSAddin.Connect.PlatformSetting")
                {
                    frmPlatformSetting frm = new frmPlatformSetting(_app);
                    frm.ShowDialog();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.OutPathSetting")
                {
                    frmOutPathSetting frm = new frmOutPathSetting(_app);
                    frm.ShowDialog();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.BuildEventSetting")
                {
                    frmBuildEventSetting frm = new frmBuildEventSetting(_app);
                    frm.ShowDialog();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.NetFrameweorkSetting")
                {
                    frmNetFrameworkSetting frm = new frmNetFrameworkSetting(_app);
                    frm.ShowDialog();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.CollapseAll")
                {
                    SolutionExployerUtility utility = new SolutionExployerUtility(_app);
                    utility.CollapseAll();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.ExpandAll")
                {
                    SolutionExployerUtility utility = new SolutionExployerUtility(_app);
                    utility.ExpandAll();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.MultiLoadProjects")
                {
                    frmMultiLoadProjects frm = new frmMultiLoadProjects(_app);
                    frm.ShowDialog();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.MultiCreateProjects")
                {
                    frmMultiCreateProjects frm = new frmMultiCreateProjects(_app);
                    frm.ShowDialog();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.DllRefConfig")
                {
                    frmDllRefSetting frm = new  frmDllRefSetting(_app);
                    frm.ShowDialog();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.DllRefFileCopy")
                {
                    frmDllRefFileCopy frm = new frmDllRefFileCopy(_app);
                    frm.ShowDialog();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.Dll2Lib")
                {
                    frmDll2Lib frm = new frmDll2Lib(_app);
                    frm.ShowDialog();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.SQLCreator")
                {
                    Form frm = new Form();
                    frm.FormBorderStyle = FormBorderStyle.Sizable;
                    frm.ShowIcon = false;
                    frm.Width = 800;
                    frm.Height = 520;
                    frm.StartPosition = FormStartPosition.CenterScreen;
                    frm.Text = "SQL語句生成器";
                    SQLCreatorUI ctr = new SQLCreatorUI();
                    ctr.Dock = DockStyle.Fill;
                    frm.Controls.Add(ctr);
                    frm.ShowDialog();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.GuidCreator")
                {
                    Form frm = new Form();
                    frm.FormBorderStyle = FormBorderStyle.Sizable;
                    frm.ShowIcon = false;
                    frm.Width = 800;
                    frm.Height = 520;
                    frm.StartPosition = FormStartPosition.CenterScreen;
                    frm.Text = "Guid生成器";
                    GuidCreatorUI ctr = new GuidCreatorUI();
                    ctr.Dock = DockStyle.Fill;
                    frm.Controls.Add(ctr);
                    frm.ShowDialog();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.CheckRepeatDll")
                {
                    frmCheckRepeatDll frm = new frmCheckRepeatDll(_app);
                    frm.WindowState = FormWindowState.Maximized;
                    frm.ShowDialog();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.Selection2Upper")
                {
                    frmSelection2Upper frm = new frmSelection2Upper();

                    frm.BtnSelection2Upper.Click += delegate(object sender, EventArgs e)
                    {
                        try
                        {
                            TextSelection txtSelection = _app.ActiveDocument.Selection as TextSelection;
                            if (txtSelection != null)
                            {
                                txtSelection.Text = txtSelection.Text.ToUpper();
                            }
                        }
                        catch (Exception ex)
                        {
                            MsgBox.ShowTip(ex.Message);
                        }
                    };
                    frm.BtnSelection2Lower.Click += delegate(object sender, EventArgs e)
                    {
                        try
                        {
                            TextSelection txtSelection = _app.ActiveDocument.Selection as TextSelection;
                            if (txtSelection != null)
                            {
                                txtSelection.Text = txtSelection.Text.ToLower();
                            }
                        }
                        catch (Exception ex)
                        {
                            MsgBox.ShowTip(ex.Message);
                        }
                    };
                    frm.Show();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.AboutMe")
                {
                    MsgBox.ShowTip("李仙偉rnQQ:744757242rnCopyright(c)2013 Leation");
                    
                    handled = true;
                    return;
                }
            }
        }

        /// 
        /// 查找已經存在的命令
        /// 
        /// Commands2對象
        /// 命令的Name
        /// 
        private Command GetExistCommand(Commands2 commands,string name)
        {
            foreach (Command cmd in commands)
            {
                if (cmd.Name == "Leation.VSAddin.Connect." + name)
                {
                    return cmd;
                }
            }
            return null;
        }

        /// 
        /// 查找已經存在的菜單項
        /// 
        /// 菜單項CommandBar對象
        /// 菜單項的標題
        /// 
        private CommandBarControl GetExistCommandBarControl(CommandBar cmdBar, string caption)
        {
            string toolsMenuName;

            try
            {
                //若要將此命令移動到另外一個菜單,則將「工具」一詞更改成此菜單的英文版。
                //  此代碼將獲取區域性,將其追加到菜單名中,而後將此命令添加到該菜單中。
                //  您會在此文件中看到所有頂級菜單的列表
                //  CommandBar.resx.
                string resourceName;
                ResourceManager resourceManager = new ResourceManager("MyAddin2.CommandBar", Assembly.GetExecutingAssembly());
                CultureInfo cultureInfo = new CultureInfo(_app.LocaleID);

                if (cultureInfo.TwoLetterISOLanguageName == "zh")
                {
                    System.Globalization.CultureInfo parentCultureInfo = cultureInfo.Parent;
                    resourceName = String.Concat(parentCultureInfo.Name, caption);
                }
                else
                {
                    resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, caption);
                }
                toolsMenuName = resourceManager.GetString(resourceName);
            }
            catch
            {
                //咱們試圖查找「工具」一詞的本地化版本,但未能找到。
                //  默認值爲 en-US 單詞,該值可能適用於當前區域性。
                toolsMenuName = "李仙偉";
            }
            foreach (CommandBarControl cmdCtr in cmdBar.Controls)
            {
                if (cmdCtr.Caption == caption)
                {
                    return cmdCtr;
                }
            }
            return null;
        }
    }
}

相關文章
相關標籤/搜索