/// <summary></summary> public CommandBarPopup AddCommandBarPopup(CommandBarPopup parent, string name, string caption) { var popup = (CommandBarPopup)parent.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, 1, true); popup.CommandBar.Name = name; popup.Caption = caption; return popup; }
public static ICommandBarPopup Create <TParent>(TParent parent, int?beforeIndex = null) where TParent : ICommandBarControls { return(CommandBarPopup.FromCommandBarControl(beforeIndex.HasValue ? parent.Add(ControlType.Popup, beforeIndex.Value) : parent.Add(ControlType.Popup))); }
public void RecreateMenu(VBProject project) { int windowMenuId = 30038; var menuBarControls = _app.IDE.CommandBars[1].Controls; var beforeIndex = FindMenuInsertionIndex(menuBarControls, windowMenuId); if (_menu != null) { UnsubsribeCommandBarButtonClickEvents(); beforeIndex = _menu.Index; _menu.Delete(); } _menu = menuBarControls.Add(MsoControlType.msoControlPopup, Before: beforeIndex, Temporary: true) as CommandBarPopup; _menu.Tag = "VBAGit"; _menu.Caption = VBAGitUI.VBAGitMenu; if (_app.GetVBProjectRepository(project) != null) { _gitSync = AddButton(_menu, VBAGitUI.VBAGitMenu_Sync, false, OnGitSync, "git_sync"); _gitCommit = AddButton(_menu, VBAGitUI.VBAGitMenu_Commit, false, OnGitCommit, "git_commit"); _gitPull = AddButton(_menu, VBAGitUI.VBAGitMenu_Pull, true, OnGitPull, "git_pull"); _gitFetch = AddButton(_menu, VBAGitUI.VBAGitMenu_Fecth, false, OnGitFetch, "git_pull"); _gitPush = AddButton(_menu, VBAGitUI.VBAGitMenu_Push, false, OnGitPush, "git_push"); AddVBAGitMenu(true); } else { _gitCreate = AddButton(_menu, VBAGitUI.VBAGitMenu_Create, false, OnGitCreate, "create_repo"); AddVBAGitMenu(false); } }
/// <summary> /// /// </summary> /// <param name="json"></param> /// <returns></returns> public bool startup(string json) { object[] contextGUIDS = new object[] { }; Commands2 commands = _dte.Commands as Commands2; CommandBar menuBar = (_dte.CommandBars as CommandBars)["MenuBar"]; try { int index = 9; foreach (CommandBarControl control in menuBar.Controls) { if (control.Type == MsoControlType.msoControlPopup) { CommandBarPopup temp = control as CommandBarPopup; if (temp.CommandBar.Name == "Tools") { index = temp.Index + 1; break; } } } CommandBarPopup popup = menuBar.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, index, true) as CommandBarPopup; popup.CommandBar.Name = "Emmet"; popup.Caption = "E&mmet"; CommandBar commandBar = popup.CommandBar; Command command = null; CommandBarButton button = null; DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Action[])); MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(json)); Action[] actions = serializer.ReadObject(stream) as Action[]; foreach (var action in actions) { if (action.type == "action") { command = commands.AddNamedCommand2(_addIn, action.name, action.label, action.label, false, Type.Missing, ref contextGUIDS, 1); button = command.AddControl(commandBar, commandBar.Controls.Count + 1) as CommandBarButton; } else { CommandBar control = commands.AddCommandBar(action.name, vsCommandBarType.vsCommandBarTypeMenu, commandBar, commandBar.Controls.Count + 1) as CommandBar; if (action.items != null) { foreach (var item in action.items) { command = commands.AddNamedCommand2(_addIn, item.name, item.label, item.label, false, Type.Missing, ref contextGUIDS, 1); button = command.AddControl(control, control.Controls.Count + 1) as CommandBarButton; } } } } popup.Visible = true; } catch { return false; } return true; }
private void AddVBAGitMenu(bool hasRepo) { _vbaGitMenu = _menu.Controls.Add(MsoControlType.msoControlPopup, Temporary: true) as CommandBarPopup; _vbaGitMenu.BeginGroup = true; _vbaGitMenu.Caption = VBAGitUI.VBAGitMenu_VBAGit; if (hasRepo) { _gitDiff = AddButton(_vbaGitMenu, VBAGitUI.VBAGitMenu_Diff, false, OnGitDiff, "VBAGit_diff"); _gitShowLog = AddButton(_vbaGitMenu, VBAGitUI.VBAGitMenu_ShowLog, true, OnGitShowLog, "VBAGit_showlog"); _gitRepoBrowser = AddButton(_vbaGitMenu, VBAGitUI.VBAGitMenu_RepoBrowser, false, OnGitRepoBrowser, "VBAGit_repobrowser"); _gitCheckMod = AddButton(_vbaGitMenu, VBAGitUI.VBAGitMenu_CheckForModifications, false, OnGitCheckForModifications, "VBAGit_checkmod"); _gitRebase = AddButton(_vbaGitMenu, VBAGitUI.VBAGitMenu_Rebase, false, OnGitRebase, "VBAGit_rebase"); _gitResolve = AddButton(_vbaGitMenu, VBAGitUI.VBAGitMenu_Resolve, true, OnGitResolve, "VBAGit_resolve"); _gitRevert = AddButton(_vbaGitMenu, VBAGitUI.VBAGitMenu_Revert, false, OnGitRevert, "VBAGit_revert"); _gitCleanUp = AddButton(_vbaGitMenu, VBAGitUI.VBAGitMenu_CleanUp, false, OnGitCleanUp, "VBAGit_cleanup"); _gitCheckout = AddButton(_vbaGitMenu, VBAGitUI.VBAGitMenu_Checkout, true, OnGitCheckout, "VBAGit_checkout"); _gitMerge = AddButton(_vbaGitMenu, VBAGitUI.VBAGitMenu_Merge, false, OnGitMerge, "VBAGit_merge"); _gitCreateBranch = AddButton(_vbaGitMenu, VBAGitUI.VBAGitMenu_CreateBranch, false, OnGitCreateBranch, "VBAGit_createbranch"); _gitExport = AddButton(_vbaGitMenu, VBAGitUI.VBAGitMenu_Export, false, OnGitExport, "VBAGit_export"); } _gitSettings = AddButton(_vbaGitMenu, VBAGitUI.VBAGitMenu_Settings, true, OnGitSettings, "VBAGit_settings"); _gitAbout = AddButton(_vbaGitMenu, VBAGitUI.VBAGitMenu_About, false, OnGitAbout, "VBAGit_about"); }
/// <summary> /// Setups the reviewPal menu item. /// </summary> private void SetupReviewPalMenuItem() { const string toolsMenuName = "Tools"; //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: CommandBar menuBarCommandBar = ((CommandBars)_visualStudioInstance.CommandBars)["MenuBar"]; //Find the Tools command bar on the MenuBar command bar: CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName]; CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl; CommandBar commandBar = toolsPopup.GetType().InvokeMember("CommandBar", BindingFlags.Instance | BindingFlags.GetProperty, null, toolsPopup, null) as CommandBar; //This try/catch block can be duplicated if you wish to add multiple commands to be handled by your Add-in, // just make sure you also update the QueryStatus/Exec method to include the new command names. try { AddCommand("ReviewPal", "Review Pal", "Opens up the ReviewPal review list", 1, commandBar, 1, false, null); } catch (ArgumentException ex) { //If we are here, then the exception is probably because a command with that name // already exists. If so there is no need to recreate the command and we can // safely ignore the exception. } }
/// <summary> /// Adds the command bar. /// </summary> /// <param name="commandName">Name of the command.</param> /// <returns>The command bar.</returns> public CommandBar AddCommandBar(string commandName) { TraceService.WriteLine("CommandManager::AddCommandBar commandName=" + commandName); Commands2 commands = (Commands2)this.VSInstance.ApplicationObject.Commands; CommandBarPopup toolsMenuPopUp = this.VSInstance.ApplicationObject.GetToolsMenuPopUp(); CommandBar commandBar = null; for (int i = 1; i <= toolsMenuPopUp.CommandBar.Controls.Count; i++) { if (toolsMenuPopUp.CommandBar.Controls[i].Caption == commandName) { TraceService.WriteLine("CommandManager::AddCommandBar commandFound in collection"); CommandBarPopup commandBarPopup = (CommandBarPopup)toolsMenuPopUp.CommandBar.Controls[i]; commandBar = commandBarPopup.CommandBar; break; } } if (commandBar == null) { TraceService.WriteLine("CommandManager::AddCommandBar creating command"); return((CommandBar)commands.AddCommandBar(commandName, vsCommandBarType.vsCommandBarTypeMenu, toolsMenuPopUp.CommandBar)); } return(commandBar); }
//private bool CommandExistInBar(Command command, CommandBar bar) //{ // bool result = false; // foreach (CommandBarControl barControl in bar.Controls) // { // if (barControl is CommandBarButton) // { // CommandBarButton button = (CommandBarButton)barControl; // button.get_accName // Command tempCmd = (Command)barControl.Control; // if (tempCmd.Name.Equals(command.Name, StringComparison.InvariantCultureIgnoreCase)) // { // result = true; // break; // } // } // } // return result; //} public void RemoveCommands(CommandBar projectBar, string nameSpace) { List <Command> commandsToDelete = new List <Command>(); List <CommandBarControl> commandBarsToDelete = new List <CommandBarControl>(); foreach (Command command in ApplicationObject.Commands) { if (command.Name.StartsWith(nameSpace, StringComparison.InvariantCulture)) { commandsToDelete.Add(command); } } foreach (Command command in commandsToDelete) { command.Delete(); } //CommandBar menuBar = ((CommandBars)ApplicationObject.CommandBars)["MenuBar"]; foreach (CommandBarControl control in projectBar.Controls) { if (control is CommandBarPopup) { CommandBarPopup popup = (CommandBarPopup)control; if (popup.CommandBar.Name.StartsWith("WSPBuilder", StringComparison.InvariantCultureIgnoreCase)) { commandBarsToDelete.Add(popup); } } } foreach (CommandBarControl barControl in commandBarsToDelete) { barControl.Delete(null); } }
/// <summary> /// 从菜单或工具条中删除指定的命令 /// </summary> /// <param name="CmdName"></param> /// <param name="SubItemName"></param> /// <param name="Name"></param> /// <param name="Caption"></param> /// <returns></returns> /// <remarks></remarks> public static Exception DeleteCommand(string CmdName, string SubItemName, string Name, string Caption) { //CmdName 工具条名称, SubItemName 工具条子项目名称,Name 要添加的项目名称, //Caption 要添加的项目标题.此方法内用于删除该按钮/项 Exception e = null; Commands2 Cmds = (Commands2)chDTE.Commands; CommandBars CmdBars = (CommandBars)chDTE.CommandBars; CommandBar mnuBarCmdBar = CmdBars[CmdName]; //菜单 CommandBarControl CmdCtrl = mnuBarCmdBar.Controls[SubItemName]; CommandBarPopup CmdPopup = (CommandBarPopup)CmdCtrl; try { Cmds.Item("KeelKit.Commands." + Name, 0).Delete(); } catch (Exception ex) { e = ex; } try { CommandBarControl chCmdConfig = CmdPopup.Controls[Caption]; chCmdConfig.Delete(null); } catch (Exception ex) { e = ex; } return(e); }
/////////////////////////////////////////////////////////////////////// // // MENU ITEMS CREATION // /////////////////////////////////////////////////////////////////////// /// <summary> /// Adds the command. /// </summary> /// <param name="menu">The popup menu.</param> /// <param name="cmd">The command.</param> /// <param name="position">The position in the menu.</param> public void AddCommandMenu(CommandBarPopup popupMenu, CommandBase cmd, int position) { CommandBarControl menuItem = AddMenuItem(popupMenu, cmd, position); AddClickEventHandler(menuItem); AddCommandToList(cmd); }
private void AddChildren(ToolStripMenuItem tsmiParent, CommandBarPopup cbpParent) { foreach (var control in cbpParent.Controls) { if (control is CommandBarComboBox) { // TODO } else { var newItem = new ToolStripMenuItem(control.Caption); if (control is CommandBarButton) { //newItem.Image = ((CommandBarButton)control).Picture; newItem.Image = newItem.Image = ((CommandBarButton)control).Picture; var but = (CommandBarButton)control; string onAction = "OnAction: " + but.OnAction + "\rParameter: " + but.Parameter; newItem.Click += new EventHandler((s, ev) => { MessageBox.Show(onAction); }); } tsmiParent.DropDownItems.Add(newItem); if (control is CommandBarPopup) { AddChildren(newItem, (CommandBarPopup)control); } } control.Dispose(); } }
public void AddPopupCommand(CommandBarPopup popup, string commandName, string caption, string tooltip, int iconIndex, int insertIndex) { // Do not try to add commands to a null menu if (popup == null) { return; } // Get commands collection var commands = (Commands2)m_application.Commands; var contextGUIDS = new object[] {}; // Add command Command command = GetCommand(commandName); if (!m_visualStudioCommands.ContainsKey(commandName)) { if (command == null) { if (iconIndex > 0) { try { command = commands.AddNamedCommand2(m_addIn, commandName, caption, tooltip, false, iconIndex, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); m_visualStudioCommands[commandName] = command; } catch { } } if (command == null) { command = commands.AddNamedCommand2(m_addIn, commandName, caption, tooltip, true, -1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); m_visualStudioCommands[commandName] = command; } } } if (command != null && popup != null) { if (!HasCommand(popup.CommandBar, caption)) { OutputPane.OutputString("Add popup command: " + caption + Environment.NewLine); command.AddControl(popup.CommandBar, insertIndex); } } }
/// <summary> /// Implements the OnStartupComplete method of the IDTExtensibility2 interface. /// Receives notification that the host application has completed loading. /// </summary> /// <param term='custom'> /// Array of parameters that are host application specific. /// </param> /// <seealso class='IDTExtensibility2' /> public void OnStartupComplete(ref System.Array custom) { RemoveMenuItems(); // remove the old ones before we add... try { CommandBar menuBar = projectApp.CommandBars["Menu Bar"]; CommandBarControl helpMenu = menuBar.Controls["&Help"]; // put it before the Help item CommandBarPopup popup = (CommandBarPopup)menuBar.Controls.Add(10, Type.Missing, Type.Missing, helpMenu.Index, false); popup.Caption = "&RoundTable"; bnBuildSched = (CommandBarButton)popup.Controls.Add(MsoControlType.msoControlButton, Type.Missing, Type.Missing, Type.Missing, false); bnBuildSched.Caption = "&Build a Schedule from RoundTable"; bnEditSettings = (CommandBarButton)popup.Controls.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing, false); bnEditSettings.Caption = "&Edit Settings"; bnAbout = (CommandBarButton)popup.Controls.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing, false); bnAbout.Caption = "&About RoundTable Connected Services for Microsoft Project 2003"; bnBuildSched.Click += new _CommandBarButtonEvents_ClickEventHandler(bnBuildSched_Click); bnEditSettings.Click += new _CommandBarButtonEvents_ClickEventHandler(bnEditSettings_Click); bnAbout.Click += new _CommandBarButtonEvents_ClickEventHandler(bnAbout_Click); //RoundTableSettings rtc = new RoundTableSettings(); //rtc.load(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private CommandBarButton AddButton(CommandBarPopup parentMenu, string caption) { var button = parentMenu.Controls.Add(MsoControlType.msoControlButton, Temporary: true) as CommandBarButton; button.Caption = caption; return button; }
private void AddMenuBar(string name) { Logger.Write("Attempting to create menu item for AutoTest.NET plugin"); //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: CommandBar menuBarCommandBar = ((CommandBars)_applicationObject.CommandBars)["MenuBar"]; CommandBarControl toolsControl; var commands = (Commands2)_applicationObject.Commands; try { Logger.Write("Trying to retrieve menu item"); toolsControl = menuBarCommandBar.Controls[name]; } catch { Logger.Write("Menu item not found.. trying to create"); var command = (CommandBar) commands.AddCommandBar(name, vsCommandBarType.vsCommandBarTypeMenu, menuBarCommandBar, 31); toolsControl = menuBarCommandBar.Controls[name]; } toolsControl.Enabled = true; CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl; }
/// <summary> /// Deletes the command. /// </summary> /// <param name="commandName">Name of the command.</param> protected void DeleteCommand(string commandName) { TraceService.WriteLine("CommandManager::DeleteCommand commandName=" + commandName); try { Commands2 commands = (Commands2)this.VsInstance.ApplicationObject.Commands; CommandBarPopup toolsMenuPopUp = this.VsInstance.ApplicationObject.GetToolsMenuPopUp(); CommandBar commandBar = null; for (int i = 1; i <= toolsMenuPopUp.CommandBar.Controls.Count; i++) { if (toolsMenuPopUp.CommandBar.Controls[i].Caption == commandName) { TraceService.WriteLine("CommandManager::DeleteCommand commandFound in collection commandName=" + commandName); CommandBarPopup commandBarPopup = (CommandBarPopup)toolsMenuPopUp.CommandBar.Controls[i]; commandBar = commandBarPopup.CommandBar; break; } } if (commandBar != null) { TraceService.WriteLine("Command found and will be deleted ommandName=" + commandName); commandBar.Delete(); } } catch (Exception exception) { TraceService.WriteError("exception=" + exception.Message); TraceService.WriteError("stackTrace=" + exception.StackTrace); } }
protected CommandBarButton AddButton(CommandBarPopup parentMenu, string caption, bool beginGroup, CommandBarButtonClickEvent buttonClickHandler, int faceId) { var button = AddButton(parentMenu, caption, beginGroup, buttonClickHandler); button.FaceId = faceId; return button; }
public CommandBarPopup CreateCommandBarPopup(string name, string title, bool beginGroup, int position, CommandBar parentCommandBar) { object nullPar = Type.Missing; CommandBarPopup result = GetCommandBarPopup(parentCommandBar, title); if (result == null) { result = (CommandBarPopup)parentCommandBar.Controls.Add( MsoControlType.msoControlPopup, nullPar, nullPar, position, true); result.CommandBar.Name = name; result.Caption = title; result.BeginGroup = beginGroup; result.Visible = true; } else { result.Visible = true; } CustomBarPopups.Add(result); return(result); }
protected CommandBarButton AddButton(CommandBarPopup parentMenu, string caption, bool beginGroup, CommandBarButtonClickEvent buttonClickHandler, Bitmap image) { var button = AddButton(parentMenu, caption, beginGroup, buttonClickHandler); SetButtonImage(button, image); return button; }
private void RemoveCommandBarPopup(CommandBarPopup commandBarPopup) { if (commandBarPopup != null) { commandBarPopup.Delete(true); } }
private void CreateMenuItems() { object[] contextGUIDS = new object[] { }; Commands2 commands = (Commands2)_applicationObject.Commands; string toolsMenuName = "Tools"; //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: Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"]; //Find the Tools command bar on the MenuBar command bar: CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName]; CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl; //This try/catch block can be duplicated if you wish to add multiple commands to be handled by your Add-in, // just make sure you also update the QueryStatus/Exec method to include the new command names. try { //Add a command to the Commands collection: Command command = commands.AddNamedCommand2(_addInInstance, "Sync", "Sync Quick Test with Code", "Executes the command for QuickTestVS", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported | (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); //Add a control for the command to the tools menu: if ((command != null) && (toolsPopup != null)) { var button = command.AddControl(toolsPopup.CommandBar, 2) as CommandBarButton; button.BeginGroup = true; } } catch (System.ArgumentException) { //If we are here, then the exception is probably because a command with that name // already exists. If so there is no need to recreate the command and we can // safely ignore the exception. } }
/// <summary> /// Gets the menu bar with the specified english name. /// </summary> /// <seealso cref="http://www.mztools.com/articles/2007/mz2007002.aspx">HOWTO: Locate commandbars in international versions of Visual Studio</seealso> /// <param name="application">The visual studio application object.</param> /// <param name="menuBarName">Then english name of the menu bar, e.g. Tools, Data, Window...</param> /// <returns> /// The menu bar with the specified english name or <c>null</c> /// if the menu bar was not found. /// </returns> public static bool TryGetMenuBar(this _DTE application, string menuBarName, out CommandBar menuBar) { CommandBars commandBars = (CommandBars)application.CommandBars; CommandBar mainMenuBar = (CommandBar)commandBars["MenuBar"]; foreach (CommandBarControl ctrl in mainMenuBar.Controls) { MsoControlType type = ctrl.Type; if (type != MsoControlType.msoControlPopup) { continue; } CommandBarPopup ctrlPopup = (CommandBarPopup)ctrl; menuBar = ctrlPopup.CommandBar; string subMenuName = menuBar.Name; if (subMenuName.Equals(menuBarName, StringComparison.InvariantCultureIgnoreCase)) { return(true); } } Debug.WriteLine("VsApplicationExtensions.GetMenuBar - Menu bar not found: " + menuBarName); menuBar = null; return(false); }
//private CommandBar GetCommandBar(string name) //{ // CommandBar menuBarCommandBar = ((CommandBars)ApplicationObject.CommandBars)["MenuBar"]; // CommandBar result = null; // string localName = this.GetLocalizedName(name); // foreach (CommandBarControl control in menuBarCommandBar.Controls) // { // if (control is CommandBar) // { // CommandBar bar = (CommandBar)control; // if (localName.Equals(bar.NameLocal, StringComparison.InvariantCultureIgnoreCase)) // { // result = bar; // break; // } // } // } // return result; //} public CommandBar GetCommandBar(MenuItemDefinition menuDefinition) { CommandBar bar = null; try { bar = GetCommandBar(menuDefinition.GuidID, menuDefinition.ID); } catch { try { CommandBar menuBarCommandBar = ((CommandBars)ApplicationObject.CommandBars)["MenuBar"]; CommandBarPopup toolsPopup = GetCommandBarPopup(menuDefinition.Name, menuBarCommandBar); bar = toolsPopup.CommandBar; } catch (Exception ex) { MessageBox.Show("Unable to get commandbar : " + menuDefinition.Name); #if DEBUG MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace); #endif throw; } } return(bar); }
private void AddControlToToolsMenu(Command command, CommandBarPopup toolsPopup) { if (command != null && toolsPopup != null) { command.AddControl(toolsPopup.CommandBar, 1); } }
private void AddMenuButton() { DTE dte = (DTE)this.GetService(typeof(SDTE)); CommandBar mainMenu = ((CommandBars)dte.CommandBars)["MenuBar"]; CommandBarPopup toolMenu = (CommandBarPopup)mainMenu.Controls["Tools"]; CommandBarPopup macroMenu = (CommandBarPopup)toolMenu.Controls["Macros"]; if (macroMenu != null) { try { List <CommandBarButton> buttons = new List <CommandBarButton>() { (CommandBarButton)macroMenu.Controls["Start Recording"], (CommandBarButton)macroMenu.Controls["Playback"], (CommandBarButton)macroMenu.Controls["Playback Multiple Times"] }; foreach (var item in buttons) { if (item != null) { this.imageButtons.Add(item); } } } catch (ArgumentException) { // nothing to do } } }
/// <summary> /// Creates the popup menu. /// </summary> /// <param name="popupMenu">The popup menu.</param> /// <param name="subPopupMenuName">Name of the sub popup menu.</param> /// <param name="position">The position.</param> public CommandBarPopup CreatePopupMenu(CommandBarPopup popupMenu, string subPopupMenuName, int position) { CommandBarPopup menu = (CommandBarPopup)popupMenu.Controls.Add(MsoControlType.msoControlPopup, 1, "", position, true); menu.Caption = subPopupMenuName; menu.TooltipText = ""; return menu; }
public CommandBarPopup GetCommandBarPopup(CommandBar parentCommandBar, string name) { CommandBarPopup result = null; string localName = this.GetLocalizedName(name); foreach (CommandBarControl control in parentCommandBar.Controls) { if (control is CommandBarPopup) { CommandBarPopup popup = (CommandBarPopup)control; if (!String.IsNullOrEmpty(popup.CommandBar.Name)) { Debug.WriteLine("CommandBarPopup.Name: " + popup.CommandBar.Name); string commandBarName = popup.CommandBar.Name.Replace("&", ""); if (popup.CommandBar.Name.Equals(localName, StringComparison.InvariantCultureIgnoreCase)) { result = popup; Debug.WriteLine("CommandBarPopup found: " + result.CommandBar.Name); break; } } } } return(result); }
public static Command add_NamedCommand(this CommandBarPopup commandBarPopup, DTE2 dte2, AddIn addIn, string Name, string ButtonText, string ToolTip, bool MSOButton, object Bitmap) { object[] contextGUIDS = new object[] { }; Commands2 commands = (Commands2)dte2.Commands; Command command = commands.AddNamedCommand2(addIn, Name, ButtonText, ToolTip, MSOButton, Bitmap, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); //Add a control for the command to the tools menu: if ((command != null) && (commandBarPopup != null)) { command.AddControl(commandBarPopup.CommandBar, 1); return(command); } return(null); }
private void RemoveAddinCommands() { CommandBarPopup toolsPopup = GetToolsPopup(); Command command1; //remove all commands foreach (command1 in this._applicationObject.Commands) { if (command1.Name // ERROR: Unknown binary operator Like ) { try { command1.Delete(); } catch (Exception ex) { } } } //remove MenuGroup foreach (CommandBarControl ctrl in toolsPopup.Controls) { if (ctrl.Caption == "Econ NetVert") { ctrl.Delete(); break; // TODO: might not be correct. Was : Exit For } } }
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _applicationObject = (DTE2)application; _addInInstance = (AddIn)addInInst; if (connectMode == ext_ConnectMode.ext_cm_UISetup) { object [] contextGUIDS = new object[] { }; Commands2 commands = (Commands2)_applicationObject.Commands; string toolsMenuName = "Tools"; Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"]; CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName]; CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl; try { Command command = commands.AddNamedCommand2(_addInInstance, "SPProjectServiceAddIn", "SPProjectServiceAddIn", "Executes the command for SPProjectServiceAddIn", true, 59, 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) { } } TestSPService(); }
private void RemoveMenuItems() { // remove the RoundTable menu items try { // get the main menu bar CommandBar menuBar = projectApp.CommandBars["Menu Bar"]; //if(menuBar == null) // menuBar = appOutlook.ActiveExplorer().CommandBars["Menu Bar"]; if (menuBar == null) { return; } // check for the Dommoni popup menu item foreach (CommandBarControl menuItem in menuBar.Controls) { if (menuItem.Caption == "&RoundTable") //Utils.MENU_ITEM_ROUNDTABLE) { try { CommandBarPopup popup = (CommandBarPopup)menuItem; try { foreach (CommandBarControl item in popup.Controls) { item.Delete(false); } } catch (System.Exception) { // ignore. just means there are no sub items, perhaps // due to a previously failed cleanup } popup.Delete(false); } catch (System.Exception ex) { //ErrorHandler.PublishError(ex,logger); // TODO: Put back when this is solved //ErrorHandler.PublishError(ex); } } } } catch (System.Exception ex) { //ErrorHandler.PublishError(ex, logger); // TODO: Put back when this is solved // TODO: Make one of these... //ErrorHandler.PublishError(ex); } }
private void CreateRibbonBar() { RibbonBar ribbonBar = axCommandBars.AddRibbonBar("DemoSoft Team Ribbon"); ribbonBar.EnableDocking(XTPToolBarFlags.xtpFlagStretched); // 系统菜单 CommandBarPopup popupSystem = ribbonBar.AddSystemButton(); popupSystem.IconId = ResourceId.ID_SYSTEM_ICON; popupSystem.CommandBar.Controls.Add(XTPControlType.xtpControlButton, ResourceId.ID_CONFIG_STOCK, "配置程序(&O)", false, false); CommandBarControl controlSystem = popupSystem.CommandBar.Controls.Add(XTPControlType.xtpControlButton, ResourceId.ID_APP_HIDE, "退出(&E)", false, false); controlSystem.BeginGroup = true; popupSystem.CommandBar.SetIconSize(32, 32); // 关于菜单 CommandBarControl controlAbout = ribbonBar.Controls.Add(XTPControlType.xtpControlButton, ResourceId.ID_APP_ABOUT, "关于(&A)", false, false); controlAbout.Flags = XTPControlFlags.xtpFlagRightAlign; // 主页 RibbonTab primarySR = ribbonBar.InsertTab(0, "主页(&H)"); primarySR.Id = ResourceId.ID_HOME; // 配置 -> 配置程序 RibbonGroup groupConfig = primarySR.Groups.AddGroup("配置(&C)", ResourceId.ID_CONFIG_BUILD); CommandBarControl controlConfigApp = groupConfig.Add(XTPControlType.xtpControlButton, ResourceId.ID_CONFIG_STOCK, "配置程序(&O)", false, false); // 生成SR -> 创建SR报表 RibbonGroup groupPrimaryStockBuild = primarySR.Groups.AddGroup("生成SR(&B)", ResourceId.ID_SR_BUILD); CommandBarControl controlBuildPrimaryReportS = groupPrimaryStockBuild.Add(XTPControlType.xtpControlSplitButtonPopup, ResourceId.ID_NEW_SR, "创建SR报表(&C)", false, false); controlBuildPrimaryReportS.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ResourceId.ID_LOAD_SR_FILE, "读取SR报表(&L)", false, false); controlBuildPrimaryReportS.CommandBar.Controls.Add(XtremeCommandBars.XTPControlType.xtpControlButton, ResourceId.ID_LOAD_SR_CONFIG, "读取SR策略(&L)", false, false); // 视图 RibbonTab tabView = ribbonBar.InsertTab(3, "视图(&V)"); tabView.Id = ResourceId.ID_TAB_VIEW; // 视图 -> 报表 RibbonGroup groupShow = tabView.Groups.AddGroup("报表(&D)", ResourceId.ID_GROUP_SHOW); CommandBarControl controlWorkspace = groupShow.Add(XTPControlType.xtpControlCheckBox, ResourceId.ID_SHOW_WORKSPACE, "工作区(&W)", false, false); groupShow.Add(XTPControlType.xtpControlCheckBox, ResourceId.ID_SHOW_STATUS, "状态栏(&S)", false, false); // 工具 RibbonTab tabTools = ribbonBar.InsertTab(4, "工具(&T)"); tabTools.Id = ResourceId.ID_TAB_TOOLS; // 工具 -> 内部工具 RibbonGroup groupTools = tabTools.Groups.AddGroup("内部工具(&I)", ResourceId.ID_GROUP_TOOLS); // Welcome To DemoSoft Team ribbonBar.QuickAccessControls.Add(XTPControlType.xtpControlButton, ResourceId.ID_WELCOME, " Home ", false, false); }
protected CommandBarButton AddButton(CommandBarPopup parentMenu, string caption, bool beginGroup, CommandBarButtonClickEvent buttonClickHandler) { var button = AddButton(parentMenu, caption); button.BeginGroup = beginGroup; button.Click += buttonClickHandler; return button; }
protected CommandBarButton AddButton(CommandBarPopup parentMenu, string caption, bool beginGroup, CommandBarButtonClickEvent buttonClickHandler, Bitmap image) { var button = AddButton(parentMenu, caption, beginGroup, buttonClickHandler); SetButtonImage(button, image); return(button); }
protected CommandBarButton AddButton(CommandBarPopup parentMenu, string caption, bool beginGroup, CommandBarButtonClickEvent buttonClickHandler, int faceId) { var button = AddButton(parentMenu, caption, beginGroup, buttonClickHandler); button.FaceId = faceId; return(button); }
private CommandBarButton AddButton(CommandBarPopup parentMenu, string caption) { var button = parentMenu.Controls.Add(MsoControlType.msoControlButton, Temporary: true) as CommandBarButton; button.Caption = caption; return(button); }
public CommandBarButton AddButtonToPopup(CommandBarPopup popup, int beforeIndex, string caption, string tooltip) { CommandBarButton button = popup.Controls.Add(MsoControlType.msoControlButton, Type.Missing, Type.Missing, beforeIndex, true) as CommandBarButton; button.Caption = caption; button.TooltipText = tooltip; return button; }
public CommandBarButton CreateButton(CommandBarPopup dest, string shortName, bool beginGroup, int position) { Commands2 commands = dte.Commands as Commands2; Command command = commands.GetCommand(commands.GetFullname(addIn, shortName)); if (command != null) { CommandBarButton button = command.AddControl(dest.CommandBar, position) as CommandBarButton; if (button != null) { createdControls.Add(button); button.BeginGroup = beginGroup; return button; } } return null; }
/// <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) { _application = (DTE2)application; _addInInstance = (AddIn)addInInst; _contextMenu = ((CommandBars)_application.CommandBars)["Code Window"]; _encoderizer = (CommandBarPopup)_contextMenu.Controls.Add(MsoControlType.msoControlPopup, Missing.Value, Missing.Value, 1, true); _encoderizer.Caption = "VS Encoderizer"; _javascriptStringEncode = _encoderizer.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, 1, true); _javascriptStringEncode.Caption = "Javascript String Encode"; _javascriptStringEncodeEvents = (CommandBarEvents)_application.Events.CommandBarEvents[_javascriptStringEncode]; _javascriptStringEncodeEvents.Click += JavaScriptStringEncode; _urlPathEncode = _encoderizer.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, 1, true); _urlPathEncode.Caption = "Url Path Encode"; _urlPathEncodeEvents = (CommandBarEvents)_application.Events.CommandBarEvents[_urlPathEncode]; _urlPathEncodeEvents.Click += UrlPathEncode; _urlDecode = _encoderizer.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, 1, true); _urlDecode.Caption = "Url Decode"; _urlDecodeEvents = (CommandBarEvents)_application.Events.CommandBarEvents[_urlDecode]; _urlDecodeEvents.Click += UrlDecode; _urlEncode = _encoderizer.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, 1, true); _urlEncode.Caption = "Url Encode"; _urlEncodeEvents = (CommandBarEvents)_application.Events.CommandBarEvents[_urlEncode]; _urlEncodeEvents.Click += UrlEncode; _htmlAttributeEncode = _encoderizer.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, 1, true); _htmlAttributeEncode.Caption = "Html Attribute Encode"; _htmlAttributeEncodeEvents = (CommandBarEvents)_application.Events.CommandBarEvents[_htmlAttributeEncode]; _htmlAttributeEncodeEvents.Click += HtmlAttributeEncode; _htmlDecode = _encoderizer.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, 1, true); _htmlDecode.Caption = "Html Decode"; _htmlDecodeEvents = (CommandBarEvents)_application.Events.CommandBarEvents[_htmlDecode]; _htmlDecodeEvents.Click += HtmlDecode; _htmlEncode = _encoderizer.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, 1, true); _htmlEncode.Caption = "Html Encode"; _htmlEncodeEvents = (CommandBarEvents)_application.Events.CommandBarEvents[_htmlEncode]; _htmlEncodeEvents.Click += HtmlEncode; }
public MenuBuilder(VisualStudio visualStudio) { this.visualStudio = visualStudio; try { CommandBars commandBars = (CommandBars)visualStudio.ApplicationObject.CommandBars; CommandBar itemCommandBar = commandBars["Item"]; CommandBar webItemCommandBar = commandBars["Web Item"]; CommandBar projectCommandBar = commandBars["Project"]; CommandBar webProjectCommandBar = commandBars["Web Project Folder"]; CommandBar toolsCommandBar = commandBars["Tools"]; subMenuPopup = (CommandBarPopup)itemCommandBar.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, 1, true); subMenuPopup.Caption = "WSCF.blue"; subMenuCommandBar = subMenuPopup.CommandBar; webSubMenuPopup = (CommandBarPopup)webItemCommandBar.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, 1, true); webSubMenuPopup.Caption = "WSCF.blue"; webSubMenuCommandBar = webSubMenuPopup.CommandBar; projectSubMenuPopup = (CommandBarPopup)projectCommandBar.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, 1, true); projectSubMenuPopup.Caption = "WSCF.blue"; projectSubMenuCommandBar = projectSubMenuPopup.CommandBar; webProjectSubMenuPopup = (CommandBarPopup)webProjectCommandBar.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, 1, true); webProjectSubMenuPopup.Caption = "WSCF.blue"; webProjectSubMenuCommandBar = webProjectSubMenuPopup.CommandBar; toolsSubMenuPopup = (CommandBarPopup)toolsCommandBar.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, 1, true); toolsSubMenuPopup.Caption = "WSCF.blue"; toolsSubMenuCommandBar = toolsSubMenuPopup.CommandBar; selectionEvents = visualStudio.ApplicationObject.Events.SelectionEvents; selectionEvents.OnChange += OnSelectionChanged; } catch (Exception ex) { AppLog.LogMessage(ex.ToString()); } }
private void InitializeRefactorContextMenu() { var beforeItem = IDE.CommandBars["Code Window"].Controls.Cast<CommandBarControl>().First(control => control.Id == 2529).Index; _refactorCodePaneContextMenu = IDE.CommandBars["Code Window"].Controls.Add(Type: MsoControlType.msoControlPopup, Temporary: true, Before:beforeItem) as CommandBarPopup; _refactorCodePaneContextMenu.BeginGroup = true; _refactorCodePaneContextMenu.Caption = RubberduckUI.RubberduckMenu_Refactor; _extractMethodContextButton = AddButton(_refactorCodePaneContextMenu, RubberduckUI.RefactorMenu_ExtractMethod, false, OnExtractMethodButtonClick); SetButtonImage(_extractMethodContextButton, Resources.ExtractMethod_6786_32, Resources.ExtractMethod_6786_32_Mask); _renameContextButton = AddButton(_refactorCodePaneContextMenu, RubberduckUI.RefactorMenu_Rename, false, OnRenameButtonClick); _reorderParametersContextButton = AddButton(_refactorCodePaneContextMenu, RubberduckUI.RefactorMenu_ReorderParameters, false, OnReorderParametersButtonClick); SetButtonImage(_reorderParametersContextButton, Resources.ReorderParameters_6780_32, Resources.ReorderParameters_6780_32_Mask); _removeParametersContextButton = AddButton(_refactorCodePaneContextMenu, RubberduckUI.RefactorMenu_RemoveParameter, false, OnRemoveParameterButtonClick); SetButtonImage(_removeParametersContextButton, Resources.RemoveParameters_6781_32, Resources.RemoveParameters_6781_32_Mask); InitializeFindReferencesContextMenu(); //todo: untangle that mess... InitializeFindImplementationsContextMenu(); //todo: untangle that mess... InitializeFindSymbolContextMenu(); }
public void OnStartupComplete(ref System.Array custom) { CommandBars oCommandBars; CommandBar oStandardBar; object omissing = System.Reflection.Missing.Value; app = (Word._Application)applicationObject; app.CustomizationContext = app.NormalTemplate; try { oCommandBars = (CommandBars)applicationObject.GetType().InvokeMember("CommandBars", BindingFlags.GetProperty, null, applicationObject, null); } catch (Exception) { return; } // Set up a custom button on the "Standard" commandbar. try { oStandardBar = oCommandBars["Menu Bar"]; } catch (Exception) { return; } CommandBarControls controls = oStandardBar.Controls; // remove old menus... foreach (CommandBarControl control in controls) { String caption = control.Caption; if ( caption.EndsWith("Remote Documents") || caption.EndsWith("Remote documents")) { control.Delete(null); } } eXoMenu = (CommandBarPopup)oStandardBar.Controls.Add(MsoControlType.msoControlPopup, omissing, omissing, omissing, true); eXoMenu.Caption = "Remote Documents"; eXoMenu.Tag = eXoMenu.Caption; Open = (CommandBarButton)eXoMenu.Controls.Add(1, omissing, omissing, omissing, omissing); Open.Caption = "Open..."; Open.Tag = Open.Caption; Save = (CommandBarButton)eXoMenu.Controls.Add(1, omissing, omissing, omissing, omissing); Save.Caption = "Save"; Save.Tag = Save.Caption; SaveAs = (CommandBarButton)eXoMenu.Controls.Add(1, omissing, omissing, omissing, omissing); SaveAs.Caption = "Save As..."; SaveAs.Tag = SaveAs.Caption; Search = (CommandBarButton)eXoMenu.Controls.Add(1, omissing, omissing, omissing, omissing); Search.Caption = "Search..."; Search.Tag = Search.Caption; Settings = (CommandBarButton)eXoMenu.Controls.Add(1, omissing, omissing, omissing, omissing); Settings.Caption = "Settings..."; Settings.Tag = Settings.Caption; About = (CommandBarButton)eXoMenu.Controls.Add(1, omissing, omissing, omissing, omissing); About.Caption = "About..."; About.Tag = About.Caption; Open.Visible = true; Open.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.Open_Click); Save.Visible = true; //Save.Enabled = false; Save.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.Save_Click); SaveAs.Visible = true; //SaveAs.Enabled = false; SaveAs.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.SaveAs_Click); //CompareWithBase.Visible = true; //CompareWithBase.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.compareWithBase_Click); Search.Visible = true; Search.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.Search_Click); Settings.Visible = true; Settings.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.Settings_Click); About.Visible = true; About.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.About_Click); object oName = applicationObject.GetType().InvokeMember("Name", BindingFlags.GetProperty, null, applicationObject, null); oStandardBar = null; oCommandBars = null; clearRepository(); }
public void AddPopupCommand(CommandBarPopup popup, string commandName, string caption, string tooltip, int iconIndex, int insertIndex) { // Do not try to add commands to a null menu if (popup == null) return; // Get commands collection var commands = (Commands2)m_application.Commands; var contextGUIDS = new object[] { }; // Add command Command command = GetCommand(commandName); if (!m_visualStudioCommands.ContainsKey(commandName)) { if (command == null) { if (iconIndex > 0) { try { command = commands.AddNamedCommand2(m_addIn, commandName, caption, tooltip, false, iconIndex, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); } catch { } } if (command == null) { command = commands.AddNamedCommand2(m_addIn, commandName, caption, tooltip, true, -1, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); } } if (command != null) { m_visualStudioCommands[commandName] = command; } } if (command != null && popup != null) { if (!HasCommand(popup.CommandBar, caption)) { OutputPane.OutputString("Add popup command: " + caption + Environment.NewLine); command.AddControl(popup.CommandBar, insertIndex); } } }
/// <summary>Implements the OnDisconnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being unloaded.</summary> /// <param term='disconnectMode'>Describes how the Add-in is being unloaded.</param> /// <param term='custom'>Array of parameters that are host application specific.</param> /// <seealso class='IDTExtensibility2' /> public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom) { try { //This function Aborts the current session CloseAllToolWindows(); } catch (Exception oEx) { LoggingHelper.HandleException(oEx); } try { if (oPopup != null) { oPopup.Delete(null); oPopup = null; } } catch (System.Runtime.InteropServices.InvalidComObjectException oEx) { oEx.ToString(); // Ignore } catch (Exception oEx) { LoggingHelper.HandleException(oEx); } try { if (omToolbar != null) omToolbar.Delete(); } catch (System.Runtime.InteropServices.InvalidComObjectException oEx) { oEx.ToString(); // Ignore } catch (Exception oEx) { LoggingHelper.HandleException(oEx); } }
/// <summary> /// Add the menu item to the popup menu /// </summary> /// <param name="menu">The menu.</param> /// <param name="cmd">The CMD.</param> /// <param name="position">The position.</param> /// <returns></returns> private CommandBarControl AddMenuItem(CommandBarPopup menu, CommandBase cmd, int position) { CommandBarControl menuItem = menu.Controls.Add(MsoControlType.msoControlButton, 1, "", position, true); menuItem.Tag = cmd.Id.ToString(); menuItem.Caption = cmd.Caption; menuItem.TooltipText = cmd.TooltipText; return menuItem; }
/////////////////////////////////////////////////////////////////////// // // MENU ITEMS CREATION // /////////////////////////////////////////////////////////////////////// /// <summary> /// Adds the command. /// </summary> /// <param name="menu">The popup menu.</param> /// <param name="cmd">The command.</param> /// <param name="position">The position in the menu.</param> public void AddCommandMenu(CommandBarPopup popupMenu, CommandBase cmd, int position) { CommandBarControl menuItem = AddMenuItem(popupMenu, cmd, position); AddClickEventHandler(menuItem); AddCommandToList(cmd); }
public void AddCommand() { try { if (string.IsNullOrEmpty(this.MenuName)) { // No menu required return; } Command cmdTmp; CommandBars cmdBars = (CommandBars)appObj.CommandBars; // Check any old versions of the command are not still hanging around try { cmdTmp = appObj.Commands.Item(this.CommandName, UNKNOWN_CMD_ID); cmdTmp.Delete(); } catch { } // this is an empty array for passing into the AddNamedCommand method object[] contextUIGUIDs = null; cmdTmp = appObj.Commands.AddNamedCommand( this.addIn, this.GetType().Name, this.ButtonText, this.ToolTip, true, this.Bitmap, ref contextUIGUIDs, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled); foreach (string sMenuName in this.MenuName.Split(',')) { CommandBar pluginCmdBar = null; if (_cachedCommandBars.ContainsKey(sMenuName)) { pluginCmdBar = _cachedCommandBars[sMenuName]; } else { #if DENALI //in VS2010, performance of cmdBars[sMenuName] is terrible: http://www.mztools.com/articles/2011/MZ2011005.aspx //plus looking up cmdBars["Other Windows"] failsof the ones we're looking for are there //performs better when you look at the root level of the CommandBars since most foreach (CommandBar bar in cmdBars) { if (bar.Name == sMenuName) { pluginCmdBar = bar; break; } } //if not yet found, then recurse if (pluginCmdBar == null) { foreach (CommandBar bar in cmdBars) { pluginCmdBar = RecurseCommandBarToFindCommandBarByName(bar, sMenuName); if (pluginCmdBar != null) break; } } #else pluginCmdBar = cmdBars[sMenuName]; #endif } if (pluginCmdBar == null) { System.Windows.Forms.MessageBox.Show("Cannot get the " + this.MenuName + " menubar"); } else { if (!_cachedCommandBars.ContainsKey(sMenuName)) { _cachedCommandBars.Add(sMenuName, pluginCmdBar); } pluginCmd = cmdTmp; CommandBarButton btn; if (sMenuName == "Tools") { if (toolsCommandBarPopup == null) { toolsCommandBarPopup = (CommandBarPopup)pluginCmdBar.Controls.Add(MsoControlType.msoControlPopup, System.Type.Missing, System.Type.Missing, 1, true); toolsCommandBarPopup.CommandBar.Name = "BIDSHelperToolsCommandBarPopup"; toolsCommandBarPopup.Caption = "BIDS Helper"; } btn = pluginCmd.AddControl(toolsCommandBarPopup.CommandBar, 1) as CommandBarButton; SetCustomIcon(btn); btn.BeginGroup = BeginMenuGroup; toolsCommandBarPopup.Visible = true; } else if (AddCommandToMultipleMenus) { //note, this doesn't look recursively through command bars, so non-top level command bars like "Other Windows" won't work using this option foreach (CommandBar bar in (CommandBars)(appObj.CommandBars)) { if (bar.Name == sMenuName) { if (!ShouldPositionAtEnd) { btn = pluginCmd.AddControl(bar, 1) as CommandBarButton; } else { btn = pluginCmd.AddControl(bar, bar.Controls.Count - 1) as CommandBarButton; } SetCustomIcon(btn); btn.BeginGroup = BeginMenuGroup; } } } else { if (!ShouldPositionAtEnd) { btn = pluginCmd.AddControl(pluginCmdBar, 1) as CommandBarButton; } else { btn = pluginCmd.AddControl(pluginCmdBar, pluginCmdBar.Controls.Count - 1) as CommandBarButton; } SetCustomIcon(btn); btn.BeginGroup = BeginMenuGroup; } } } } catch (System.Exception e) { MessageBox.Show("Problem registering " + this.FullName + " command: " + e.Message + "\r\n" + e.StackTrace); } }
public void OnBeginShutdown(ref System.Array custom) { object omissing = System.Reflection.Missing.Value; Open.Delete(omissing); Open = null; eXoMenu.Delete(omissing); eXoMenu = null; Search.Delete(omissing); Search = null; Settings.Delete(omissing); Save.Delete(omissing); }
public CommandBarButton CreateButton(CommandBarPopup dest, string shortName, bool beginGroup) { return CreateButton(dest, shortName, beginGroup, dest.CommandBar.Controls.Count + 1); }
public CommandBarPopup CreatePopup(CommandBarPopup parent, string shortName, string caption, bool beginGroup, int position) { System.Diagnostics.Debug.Assert(parent != null); CommandBarPopup popup = (CommandBarPopup)parent.Controls.Add(MsoControlType.msoControlPopup, System.Type.Missing, System.Type.Missing, position, true); if (popup != null) { createdControls.Add(popup); popup.CommandBar.Name = shortName; popup.Caption = caption; popup.BeginGroup = beginGroup; } return popup; }
private int AddSubMenu(out CommandBarControl menuItem, CommandBarPopup parent, out CommandBarEvents eventHandler, int position, string caption, string imagePath, string maskedImagePath) { menuItem = parent.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, position, true); menuItem.Caption = caption; eventHandler = (CommandBarEvents)_applicationObject.Events.get_CommandBarEvents(menuItem); if (!string.IsNullOrEmpty(imagePath)) { Helper.SetPicture(Assembly.GetExecutingAssembly(), (CommandBarButton) menuItem.Control, imagePath, maskedImagePath); } else if (string.Equals(caption, DB4O_HOMEPAGE)) { menuItem.BeginGroup = true; } return position + 1; }
private void addTemporaryButtonTo(Command command, CommandBarPopup popup, string caption) { CommandBarButton button = (CommandBarButton)command.AddControl(popup.CommandBar, popup.Controls.Count + 1); button.Caption = caption; button.Style = MsoButtonStyle.msoButtonCaption; button.BeginGroup = false; button.Visible = true; _buttons.Add(button); }
/// <summary> /// Creates Menu & Submenus under Tools menu. /// </summary> private void CreateMenu() { try { #region Creates ObjectManager Enterprise Menu item try { CommandBar oCommandBar = ((CommandBars)_applicationObject.CommandBars)[TOOLS]; oPopup = (CommandBarPopup)oCommandBar.Controls.Add(MsoControlType.msoControlPopup, Missing.Value, Missing.Value, 1, true); oPopup.Caption = Helper.GetResourceString(OMControlLibrary.Common.Constants.PRODUCT_CAPTION); } catch (Exception oEx) { LoggingHelper.HandleException(oEx); } #endregion #region Creates submenu for Connect/Disconnect int position = AddSubMenu(out connectDatabaseMenu, oPopup, out dbConnectControlHandler, 1, CONNECT, IMAGE_CONNECT, IMAGE_CONNECT_MASKED); dbConnectControlHandler.Click += dbConnectControlHandler_Click; #endregion #region Creates submenu for XtremeConnect position = AddSubMenu(out reqConsultationControl, oPopup, out reqConsultationControlHandler, position, XTREME_CONNECT, IMAGE_XTREMECONNECT, IMAGE_XTREMECONNECT_MASKED); reqConsultationControlHandler.Click += reqConsultationControlHandler_Click; #endregion #region Creates submenu for Support Cases position = AddSubMenu(out salesForceControl, oPopup, out salesForceControlHandler, position, SUPPORT_CASES, IMAGE_SUPPORTCASES, IMAGE_SUPPORTCASES_MASKED); salesForceControlHandler.Click += salesForceControlHandler_Click; #endregion #region Creates submenu for Maintainance CommandBarPopup oPopupMaintainance = (CommandBarPopup)oPopup.Controls.Add(MsoControlType.msoControlPopup, Missing.Value, Missing.Value, position, true); oPopupMaintainance.Caption = MAINTAINANCE; #endregion #region Creates submenu for Backup under Maintainance AddSubMenu(out omBackupControl, oPopupMaintainance, out omBackupControlHandler, 1, BACKUP); omBackupControlHandler.Click += omBackupControlHandler_Click; omBackupControl.Enabled = false; #endregion #region Creates submenu for db4objects Homepage CommandBarControl db4oHomePageControl; position = AddSubMenu(out db4oHomePageControl, oPopup, out db4oControlHandler, position, DB4O_HOMEPAGE); db4oControlHandler.Click += db4oControlHandler_Click; #endregion #region Creates submenu for db4objects Developer Community position = AddSubMenu(out db4oDeveloperControl, oPopup, out db4oDeveloperControlHandler, position, DB4O_DEVELOPER_COMMUNITY); db4oDeveloperControlHandler.Click += db4oDeveloperControlHandler_Click; #endregion #region Creates submenu for db4objects Downloads position = AddSubMenu(out db4oDnldControl, oPopup, out db4oDnldControlHandler, position, DB4O_DOWNLOADS); db4oDnldControlHandler.Click += db4oDnldControlHandler_Click; #endregion #region Creates submenu for Help position = AddSubMenu(out omHelpControl, oPopup, out omHelpControlHandler, position, DB4O_HELP, IMAGE_HELP, IMAGE_HELP_MASKED); omHelpControlHandler.Click += omHelpControlHandler_Click; #endregion #region Creates submenu for ObjectManager Enterprise About Box position = AddSubMenu(out omAboutControl, oPopup, out omAboutControlHandler, position, ABOUT_OME); omAboutControlHandler.Click += omAboutControlHandler_Click; #endregion #region Creates submenu for Creating demo db position = AddSubMenu(out dbCreateDemoDbControl, oPopup, out dbCreateDemoDbControlHandler, position, CREATE_DEMO_DB); dbCreateDemoDbControlHandler.Click += dbCreateDemoDbControlHandler_Click; dbCreateDemoDbControl.Enabled = true; #endregion #region Creates submenu for Options CommandBarPopup oPopupOptions = (CommandBarPopup)oPopup.Controls.Add(MsoControlType.msoControlPopup, Missing.Value, Missing.Value, position, true); oPopupOptions.Caption = OPTIONS; #endregion #region Creates submenu for Proxy Configurations under Maintainance AddSubMenu(out omProxyConfigControl, oPopupOptions, out omProxyConfigHandler, 1, PROXYCONFIGURATIONS); omProxyConfigHandler.Click += omProxyConfigHandler_Click; omProxyConfigControl.Enabled = true; #endregion #region Creates submenu for Assembly Search Path configuration CommandBarControl omAssemblySearchPathControl; AddSubMenu(out omAssemblySearchPathControl, oPopupOptions, out omAssemblySearchPathHandler, 2, ASSEMBLY_SEARCH_PATH_CONFIG); omAssemblySearchPathHandler.Click += ShowAssemblySearchPathDialog; #endregion } catch (Exception oEx) { LoggingHelper.HandleException(oEx); } }
public void Initialize(CommandBarPopup parentMenu) { _codeExplorerButton = AddButton(parentMenu, RubberduckUI.RubberduckMenu_CodeExplorer, true, new CommandBarButtonClickEvent(OnCodeExplorerButtonClick), 3039); }
private void AddCommandToWindow(Command copyCommand, string windowType) { var commandBars = (CommandBars)Application.CommandBars; var codeWindowCommandBar = commandBars[windowType]; _featureCopy = (CommandBarPopup) codeWindowCommandBar.Controls.Add(MsoControlType.msoControlPopup, Type.Missing, Type.Missing, Type.Missing, Type.Missing); _featureCopy.Caption = "Feature"; var copyButton = (CommandBarControl)copyCommand.AddControl(_featureCopy.CommandBar, _featureCopy.Controls.Count + 1); copyButton.Caption = "Copy"; copyButton.TooltipText = "Copy's all feature resources to main application"; Logger.Log("Menu has been initailized"); }
private void registerCommandBar() { try { CommandBar menuCmdBar = cmdBars["MenuBar"]; if (qtPopup == null) { int targetIndex = 5; try { foreach (CommandBarControl objCommandBarControl in menuCmdBar.Controls) { if (objCommandBarControl.Type == MsoControlType.msoControlPopup) { // See mztools article http://www.mztools.com/articles/2007/MZ2007002.aspx // "HOWTO: Locate commandbars in international versions of Visual Studio" // CommandBar.Name is always the English name. The localized name is stored // in CommandBar.NameLocal. CommandBarPopup objCommandBarPopup = (CommandBarPopup)objCommandBarControl; if (objCommandBarPopup.CommandBar.Name == "View") { targetIndex = objCommandBarPopup.Index + 1; break; } } } } catch { } qtPopup = menuCmdBar.Controls.Add (MsoControlType.msoControlPopup, System.Type.Missing, System.Type.Missing, targetIndex, true) as CommandBarPopup; qtPopup.CommandBar.Name = Res.CommandBarName; qtPopup.Caption = "&Qt5"; } qtPopup.Visible = true; } catch { } }
private int AddSubMenu(out CommandBarControl menuItem, CommandBarPopup parent, out CommandBarEvents eventHandler, int position, string caption) { return AddSubMenu(out menuItem, parent, out eventHandler, position, caption, string.Empty, string.Empty); }
public CommandBarPopupNodeFactory(CommandBarPopup popup) : base(popup, true) { _popup = popup; }
public void OnStartupComplete(ref System.Array custom) { CommandBars oCommandBars; CommandBar oStandardBar; object omissing = System.Reflection.Missing.Value; Thread.Sleep(50); app = (Microsoft.Office.Interop.Excel._Application)applicationObject; try { oCommandBars = (CommandBars)applicationObject.GetType().InvokeMember("CommandBars", BindingFlags.GetProperty, null, applicationObject, null); } catch (Exception) { return; } // Set up a custom button on the "Standard" commandbar. try { oStandardBar = oCommandBars["Worksheet Menu Bar"]; } catch (Exception) { return; } CommandBarControls controls = oStandardBar.Controls; // remove old menus... foreach (CommandBarControl control in controls) { String caption = control.Caption; if (caption.EndsWith("Remote Documents") || caption.EndsWith("Remote documents")) { control.Delete(null); } } // In case the button was not deleted, use the exiting one. try { eXoMenu = (CommandBarPopup)oStandardBar.Controls["Remote documents"]; Open = (CommandBarButton)eXoMenu.Controls["Open"]; Save = (CommandBarButton)eXoMenu.Controls["Save"]; SaveAs = (CommandBarButton)eXoMenu.Controls["SaveAs"]; Search = (CommandBarButton)eXoMenu.Controls["Search"]; Settings = (CommandBarButton)eXoMenu.Controls["Settings"]; About = (CommandBarButton)eXoMenu.Controls["About"]; } catch (Exception) { eXoMenu = (CommandBarPopup)oStandardBar.Controls.Add(MsoControlType.msoControlPopup, omissing, omissing, omissing, true); eXoMenu.Caption = "Remote Documents"; eXoMenu.Tag = eXoMenu.Caption; Open = (CommandBarButton)eXoMenu.Controls.Add(1, omissing, omissing, omissing, omissing); Open.Caption = "Open..."; Open.Tag = Open.Caption; Save = (CommandBarButton)eXoMenu.Controls.Add(1, omissing, omissing, omissing, omissing); Save.Caption = "Save"; Save.Tag = Save.Caption; SaveAs = (CommandBarButton)eXoMenu.Controls.Add(1, omissing, omissing, omissing, omissing); SaveAs.Caption = "Save As..."; SaveAs.Tag = SaveAs.Caption; Search = (CommandBarButton)eXoMenu.Controls.Add(1, omissing, omissing, omissing, omissing); Search.Caption = "Search..."; Search.Tag = Search.Caption; Settings = (CommandBarButton)eXoMenu.Controls.Add(1, omissing, omissing, omissing, omissing); Settings.Caption = "Settings..."; Settings.Tag = Settings.Caption; About = (CommandBarButton)eXoMenu.Controls.Add(1, omissing, omissing, omissing, omissing); About.Caption = "About..."; About.Tag = About.Caption; } Open.Visible = true; Open.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.Open_Click); Save.Visible = true; Save.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.Save_Click); SaveAs.Visible = true; SaveAs.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.SaveAs_Click); Search.Visible = true; Search.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.Search_Click); Settings.Visible = true; Settings.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.Settings_Click); About.Visible = true; About.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.About_Click); object oName = applicationObject.GetType().InvokeMember("Name", BindingFlags.GetProperty, null, applicationObject, null); oStandardBar = null; oCommandBars = null; clearRepository(); }
private void CreateRibbonBar() { RibbonBar ribbonBar = axCommandBars.AddRibbonBar( "DemoSoft Team Ribbon" ); ribbonBar.EnableDocking( XTPToolBarFlags.xtpFlagStretched ); // 系统菜单 CommandBarPopup popupSystem = ribbonBar.AddSystemButton(); popupSystem.IconId = ResourceId.ID_SYSTEM_ICON; popupSystem.CommandBar.Controls.Add( XTPControlType.xtpControlButton, ResourceId.ID_FILE_CONFIG_POLICY, "配置策略(&P)", false, false ); popupSystem.CommandBar.Controls.Add( XTPControlType.xtpControlButton, ResourceId.ID_FILE_CONFIG_TASK, "配置任务(&T)", false, false ); CommandBarControl controlSystem = popupSystem.CommandBar.Controls.Add( XTPControlType.xtpControlButton, ResourceId.ID_APP_HIDE, "退出(&E)", false, false ); controlSystem.BeginGroup = true; popupSystem.CommandBar.SetIconSize( 32, 32 ); // 关于菜单 CommandBarControl controlAbout = ribbonBar.Controls.Add( XTPControlType.xtpControlButton, ResourceId.ID_APP_ABOUT, "关于(&A)", false, false ); controlAbout.Flags = XTPControlFlags.xtpFlagRightAlign; // 开始 RibbonTab tabHome = ribbonBar.InsertTab( 0, "开始(&H)" ); tabHome.Id = ResourceId.ID_TAB_HOME; // 开始 -> 文件 RibbonGroup groupFile = tabHome.Groups.AddGroup( "文件(&F)", ResourceId.ID_GROUP_FILE ); CommandBarPopup controlConfig = (CommandBarPopup)groupFile.Add( XTPControlType.xtpControlSplitButtonPopup, ResourceId.ID_FILE_CONFIG_POLICY, "配置策略(&P)", false, false ); controlConfig.CommandBar.Controls.Add( XtremeCommandBars.XTPControlType.xtpControlButton, ResourceId.ID_FILE_CONFIG_NEW_POLICY, "新建策略(&N)", false, false ); CommandBarPopup controlConfig1 = (CommandBarPopup)groupFile.Add( XTPControlType.xtpControlSplitButtonPopup, ResourceId.ID_FILE_CONFIG_TASK, "配置任务(&T)", false, false ); controlConfig1.CommandBar.Controls.Add( XtremeCommandBars.XTPControlType.xtpControlButton, ResourceId.ID_FILE_CONFIG_NEW_TASK, "新建任务(&N)", false, false ); //CommandBarPopup controlConfig2 = (CommandBarPopup)groupFile.Add( XTPControlType.xtpControlButtonPopup, ResourceId.ID_FILE_SCAN_TASK, "扫描任务(&T)", false, false ); //controlConfig2.CommandBar.Controls.Add( XtremeCommandBars.XTPControlType.xtpControlButton, ResourceId.ID_FILE_SCAN_ALL_TASK, "扫描全部(&N)", false, false ); // 开始 -> 报表 RibbonGroup groupReport = tabHome.Groups.AddGroup( "报表(&R)", ResourceId.ID_GROUP_FILE ); m_ControlOpen = (CommandBarPopup)groupReport.Add( XTPControlType.xtpControlButtonPopup, ResourceId.ID_FILE_OPEN, "打开报表(&O)", false, false ); m_ControlClose = (CommandBarPopup)groupReport.Add( XTPControlType.xtpControlButtonPopup, ResourceId.ID_FILE_CLOSE, "关闭报表(&C)", false, false ); U50GlobalSetting.LoadingTaskSetting += new EventHandler( U50GlobalSetting_LoadingTaskSetting ); U50GlobalSetting.LoadedTaskSetting += new EventHandler( U50GlobalSetting_LoadedTaskSetting ); TaskManager.Instance.AddedTaskInfo += new EventHandler( U50GlobalSetting_LoadedTaskSetting ); TaskManager.Instance.RemoveTaskInfo += new EventHandler( U50GlobalSetting_LoadedTaskSetting ); TaskManager.Instance.RefreshTaskInfo += new EventHandler( U50GlobalSetting_LoadedTaskSetting ); U50GlobalSetting_LoadedTaskSetting(this, EventArgs.Empty ); // 视图 RibbonTab tabView = ribbonBar.InsertTab( 2, "视图(&V)" ); tabView.Id = ResourceId.ID_TAB_VIEW; // 视图 -> 显示 RibbonGroup groupShow = tabView.Groups.AddGroup( "显示(&D)", ResourceId.ID_GROUP_SHOW ); CommandBarControl controlWorkspace = groupShow.Add( XTPControlType.xtpControlCheckBox, ResourceId.ID_SHOW_WORKSPACE, "工作区(&W)", false, false ); controlWorkspace.Checked = true; groupShow.Add( XTPControlType.xtpControlCheckBox, ResourceId.ID_SHOW_STATUS, "状态栏(&S)", false, false ); // 视图 -> 图表 RibbonGroup groupGraph = tabView.Groups.AddGroup( "图表(&D)", ResourceId.ID_GROUP_GRAPH ); groupGraph.Add( XTPControlType.xtpControlCheckBox, ResourceId.ID_GRAPH_WORKSPACE, "主升浪幅度线(&W)", false, false ); groupGraph.Add( XTPControlType.xtpControlCheckBox, ResourceId.ID_GRAPH_STATUS, "下跌浪幅度线(&S)", false, false ); groupGraph.Add( XTPControlType.xtpControlCheckBox, ResourceId.ID_GRAPH_STATUS, "盘整浪幅度线(&S)", false, false ); groupGraph.Add( XTPControlType.xtpControlCheckBox, ResourceId.ID_GRAPH_STATUS, "整理区幅度线(&S)", false, false ); // 工具 RibbonTab tabTools = ribbonBar.InsertTab( 3, "工具(&T)" ); tabTools.Id = ResourceId.ID_TAB_TOOLS; // 工具 -> 内部工具 RibbonGroup groupTools = tabTools.Groups.AddGroup( "内部工具(&I)", ResourceId.ID_GROUP_TOOLS ); // Welcome To DemoSoft Team ribbonBar.QuickAccessControls.Add( XTPControlType.xtpControlButton, ResourceId.ID_WELCOME, "Welcome", false, false ); ribbonBar.QuickAccessControls.Add( XTPControlType.xtpControlButton, ResourceId.ID_TO, "To", false, false ); ribbonBar.QuickAccessControls.Add( XTPControlType.xtpControlButton, ResourceId.ID_DEMO_SOFT, "DemoSoft", false, false ); ribbonBar.QuickAccessControls.Add( XTPControlType.xtpControlButton, ResourceId.ID_TEAM, "Team", false, false ); }