VSIP Addin Custom CommandBars

Creating Addin's and using ones you download is alot of fun, and very productive. However, there are lot's of things one needs to find along the way to accomplish their goals. For example, if you need to target your command for one of the command bars, you need to know where it goes. Here is a list of useful ones I have found so far.

 

   1:   public class CommanBarNames
   2:      {
   3:          private CommanBarNames() { }
   4:          public readonly static string Standard = "Standard";
   5:          public readonly static string ClassViewItem = "Class View Item";
   6:          public readonly static string WebItem = "Web Item";
   7:          public readonly static string MultiItem = "Cross Project Multi Item";
   8:          public readonly static string WebFolder = "Web Folder";
   9:          public readonly static string ProjectNode = "Project Node";
  10:          public readonly static string Item = "Item";
  11:          public readonly static string Folder = "Folder";
  12:          public readonly static string Project = "Project";
  13:          public readonly static string Solution = "Solution";
  14:          public readonly static string MenuBar = "MenuBar";
  15:          public readonly static string ToolsMenuBar = "Tools";
  16:          public readonly static string StandardMenuBar = "Standard";
  17:          public readonly static string CodeWindowMenuBar = "Code Window";
  18:      }
 
You can use them doing something like this.
 
   1:  #region Standard Commandbars
   2:  CommandBar vsCmdBarMainMenuBar = cmdBars[CommanBarNames.MenuBar];
   3:  CommandBar vsCmdBarToolsBar = cmdBars[CommanBarNames.ToolsMenuBar];
   4:  CommandBar vsCmdBarItem = cmdBars[CommanBarNames.Item];
   5:  CommandBar vsCmdBarWebItem = cmdBars[CommanBarNames.WebItem];
   6:  CommandBar vsCmdBarMultiItem = cmdBars[CommanBarNames.MultiItem];
   7:  CommandBar vsCmdBarFolder = cmdBars[CommanBarNames.Folder];
   8:  CommandBar vsCmdBarWebFolder = cmdBars[CommanBarNames.WebFolder];
   9:  CommandBar vsCmdBarProject = cmdBars[CommanBarNames.Project];
  10:  CommandBar vsCmdBarProjectNode = cmdBars[CommanBarNames.ProjectNode];
  11:  CommandBar vsCmdBarstandardCommandBar = cmdBars[CommanBarNames.Standard];
  12:  CommandBar vsCmdBarSolution = cmdBars[CommanBarNames.Solution];
  13:  #endregion
Now, so what we want to do, is add a new section to the standard menu.
Which then can be used to add new commands to.
 
   1:  CommandBarPopup popUp = (CommandBarPopup)vsCmdBarStandard.Controls.Add(
   2:         MsoControlType.msoControlPopup, oMissing, oMissing,
   3:         (vsBarstandardCommandBar.Controls.Count+1), oMissing);
   4:  popUp.Caption = "COMMANDBARNAME";
   5:  CommandBar _ourNewCommandBar = popUp.CommandBar;
A few notes, we must cast the added control to a CommandBarPopup
which allows us to easily name and get the command bar access for it.
There may be another way, but this was the most reliable one I tried. I am
up for suggestions.
Now, between popup, and ourcommandbar, we have options to create any custom
menu system we want, placed as the final element on the standard commandbar
(the one with save and all those).

Visual studio addin already has a sample of adding something to the Tools menu.
If you wanted a top level menu item you can replace vsBarstandardCommandBar with
vsCmdBarMainMenuBar and set the index to Controls.Count-1 so your button is towards the back.
I will probably write more on this topic later on.
Published Monday, June 26, 2006 1:28 AM by jminond
Filed under: ,

Comments

# DNS - .NET Blog

Tuesday, June 27, 2006 3:25 PM by Jonathan's Blog

I have a new additional blog, that will be focused more on .NET specifics, as well as Extensibility and automation as opposed to this blog that is more Rainbow and Application geared.

# VSIP Addin Custom CommandBars - jonathan's blog

Friday, March 21, 2008 1:03 PM by adamga's WebLog

For some reason, the list below (thanks Jonathan ) was eluding me when I was creating my "OpenInBlend"