Beispiel #1
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());
             }
         }
     }
 }
Beispiel #2
0
        private void AddTemplateCommand(IVsTemplate template)
        {
            if (template.Kind == TemplateKind.Solution)
            {
                return;
            }
            Configuration.RecipeHostData hostData = null;
            if (template.ExtensionData != null && !string.IsNullOrEmpty(template.ExtensionData.Recipe))
            {
                Configuration.Recipe recipeConfig = GetRecipeConfig(template.ExtensionData.Recipe);
                if (recipeConfig != null && recipeConfig.HostData != null && recipeConfig.HostData.CommandBar != null)
                {
                    hostData = recipeConfig.HostData;
                    // Set the host data to null to avoid registering two commands
                    recipeConfig.HostData = null;
                }
            }
            int       priority = CTCBuilder.defaultPriority;
            CommandID icon     = CreateBitmap(template);

            if (hostData != null)
            {
                hostData.Icon      = new Configuration.Icon();
                hostData.Icon.Guid = icon.Guid.ToString();
                hostData.Icon.ID   = icon.ID;
                priority           = hostData.Priority;
            }
            ;
            Button myButton = new Button(template.Command,
                                         this.PackageGroup.Group,
                                         priority,
                                         icon,
                                         CommandType.Button,
                                         Util.DisabledDefault,
                                         guidancePackage.Caption + "." + template.Name);

            AddCommand(myButton, hostData);
            if (hostData == null)
            {
                // Add the template command in the standard places
                CommandID parentCommand = null;
                if (template.Kind == TemplateKind.ProjectItem)
                {
                    parentCommand = ShellCmdDef.GetPredefinedCommandID(Configuration.CommandBarName.ProjectAdd);
                    AddGroupPlacement(myButton, parentCommand);
                }
                else if (template.Kind == TemplateKind.Project)
                {
                    parentCommand = ShellCmdDef.GetPredefinedCommandID(Configuration.CommandBarName.SolutionAdd);
                    AddGroupPlacement(myButton, parentCommand);
                }
                parentCommand = ShellCmdDef.GetPredefinedCommandID(Configuration.CommandBarName.SolutionFolderAdd);
                AddGroupPlacement(myButton, parentCommand);
            }
        }