Ejemplo n.º 1
0
 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));
     }
 }
Ejemplo n.º 2
0
 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());
             }
         }
     }
 }
Ejemplo n.º 3
0
 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));
 }
Ejemplo n.º 4
0
 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]);
 }