private CommandID GetCommandID(Configuration.CommandBar commandBar) { if (commandBar.NameSpecified) { return(ShellCmdDef.GetPredefinedCommandID(commandBar.Name)); } else if (!string.IsNullOrEmpty(commandBar.Menu)) { if (menus.ContainsKey(commandBar.Menu)) { MenuGroup menuGroup = (MenuGroup)menus[commandBar.Menu]; return(menuGroup.Group); } else { throw new InvalidOperationException( String.Format(Properties.Resources.CTC_MenuDoesNotExist, commandBar.Menu)); } } else { int commandId = 0; Guid guid = ShellCmdDef.guidSHLMainMenu; if (commandBar.IDSpecified) { commandId = commandBar.ID; } if (commandBar.Guid != null) { guid = new Guid(commandBar.Guid); } return(new CommandID(guid, commandId)); } }
private void AddCommand(Button button, Configuration.RecipeHostData hostData) { buttons.Add(button); //Uncomment if you need to support visibility for a command //visibilities.Add(new Visibility(button.Command, new Guid(UIContextGuids.SolutionExists))); if (hostData != null && hostData.CommandBar != null) { if (hostData.CommandBar.Length == 0) { // Check that we always get at least one command bar return; } Dictionary <CommandID, string> installedBars = new Dictionary <CommandID, string>(); for (int iCommand = 0; iCommand < hostData.CommandBar.Length; iCommand++) { Configuration.CommandBar configCommandBar = hostData.CommandBar[iCommand]; CommandID commandBar = GetCommandID(configCommandBar); CommandID parentCommandBar = GetCommandParentID(configCommandBar); if (installedBars.ContainsKey(parentCommandBar)) { throw new InvalidOperationException( String.Format(Properties.Resources.CTC_RepeatedCommandBar, parentCommandBar.ToString())); } else { AddGroupPlacement(button, commandBar); installedBars.Add(parentCommandBar, commandBar.ToString()); } } } }
private CommandID GetCommandParentID(Configuration.CommandBar commandBar) { while (!string.IsNullOrEmpty(commandBar.Menu)) { bool found = false; foreach (Configuration.Menu menu in guidancePackage.HostData.Menu) { if (menu.Name.Equals(commandBar.Menu, StringComparison.InvariantCultureIgnoreCase)) { commandBar = menu.CommandBar; found = true; break; } } if (!found) { throw new InvalidOperationException( String.Format(Properties.Resources.CTC_MenuDoesNotExist, commandBar.Menu)); } } return(GetCommandID(commandBar)); }
private MenuGroup AddMenuGroup(string menuName, string menuText, int priority, Configuration.CommandBar commandBar) { if (!menus.ContainsKey(menuName)) { CommandID commandID = GetCommandID(commandBar); NewGroup newGroup = CreateNewGroup(commandID.ToString(), priority, commandID); CommandID newMenuCommand = new CommandID(guidRecipeFrameworkPkgCmdSet, this.menuCounter++); MenuGroup myNewMenu = new MenuGroup( newMenuCommand, newGroup.Group, priority, CommandType.MenuContext, menuName, menuText); menus.Add(menuName, myNewMenu); } return(menus[menuName]); }