public fmWCFServerWzd(DTE2 aDTE2, AddIn aAddIn, EEPWizard aEEPWizard) { InitializeComponent(); FServerData = new TWCFServerData(this); FDTE2 = aDTE2; FAddIn = aAddIn; FEEPWizard = aEEPWizard; //PrepareWizardService(); lvwColumnSorter = new ListViewColumnSorter(); this.lvSelectedFields.ListViewItemSorter = lvwColumnSorter; }
/// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary> /// <param term='application'>Root object of the host application.</param> /// <param term='connectMode'>Describes how the Add-in is being loaded.</param> /// <param term='addInInst'>Object representing this Add-in.</param> /// <seealso class='IDTExtensibility2' /> public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { //EEP Wizard if (connectMode == ext_ConnectMode.ext_cm_Startup) { applicationObject = (DTE2)application; addInInstance = (AddIn)addInInst; FEEPWizard = new MWizard.EEPWizard(applicationObject, addInInstance); addInInstance.Object = FEEPWizard; GlobalObject.EEPWizardInstance = FEEPWizard; object[] contextGUIDS = new object[] { }; Commands2 commands = (Commands2)applicationObject.Commands; try { Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar; CommandBarControl toolsControl; CommandBarPopup toolsPopup; CommandBarControl commandBarControl; //Add a command to the Commands collection: Command command = commands.AddNamedCommand2( addInInstance, "EEPWizard", "EEP Wizard", "Executes the command for EEP Wizard", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); String toolsMenuName = "Tools"; try { //If you would like to move the command to a different menu, change the word "Tools" to the // English version of the menu. This code will take the culture, append on the name of the menu // then add the command to that menu. You can find a list of all the top-level menus in the file // CommandBar.resx. System.Resources.ResourceManager resourceManager = new System.Resources.ResourceManager("EEPServerWizard.CommandBar", System.Reflection.Assembly.GetExecutingAssembly()); System.Threading.Thread thread = System.Threading.Thread.CurrentThread; System.Globalization.CultureInfo cultureInfo = thread.CurrentCulture; if (applicationObject.LocaleID == 1028 || applicationObject.LocaleID == 2052) { toolsMenuName = "工具"; // toolsMenuName = resourceManager.GetString(String.Concat(cultureInfo.TwoLetterISOLanguageName, "工具")); } else { // toolsMenuName = resourceManager.GetString(String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools")); toolsMenuName = "Tools"; } // toolsMenuName = resourceManager.GetString(String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools"));//??? //toolsMenuName = resourceManager.GetString(String.Concat(cultureInfo.TwoLetterISOLanguageName, "工具"));//??? } catch (Exception e) { //We tried to find a localized version of the word Tools, but one was not found. // Default to the en-US word, which may work for the current culture. //if (applicationObject.LocaleID == 1028 || applicationObject.LocaleID == 2056) //{ // toolsMenuName = "工具"; //} //else //{ // toolsMenuName = "tools"; //} throw e; } //Place the command on the tools menu. //Find the MenuBar command bar, which is the top-level command bar holding all the main menu items: menuBarCommandBar = ((CommandBars)applicationObject.CommandBars)["MenuBar"]; //Find the Tools command bar on the MenuBar command bar: toolsControl = menuBarCommandBar.Controls[toolsMenuName]; toolsPopup = (CommandBarPopup)toolsControl; //Find the appropriate command bar on the MenuBar command bar: commandBarControl = (CommandBarControl)command.AddControl(toolsPopup.CommandBar, 1); } catch { //這邊的錯誤要忽略,不然會引起錯誤"A Command with that name already exists." //MessageBox.Show(E.Message); //throw; } } }