Tabs Studio Blog (organizing Visual Studio document tabs)

August 22, 2009

Visual Studio commands support for add-ins

Filed under: Uncategorized — Tags: — Sergey Vlasov @ 3:17 pm

In upcoming SDK, an add-in for Tabs Studio can add Visual Studio commands that are accessible via menu, toolbars and keyboard shortcuts in Visual Studio IDE.

To add new command get EnvDTE80.Commands2 object and call AddNamedCommand2 function:

EnvDTE80.Commands2 commands = dte.Commands as EnvDTE80.Commands2;
commands.AddNamedCommand2(addin, "NavigateToNextTab", ...

AddNamedCommand2 function requires EnvDTE.AddIn parameter that you can get from the new ITabsStudioEngine.GetAddIn function. During testing you may want to delete your experimental command from Visual Studio:

commands.Item("TabsStudio.Connect.NavigateToNextTab", 0).Delete();

Note that you add new command with a short name (“NavigateToNextTab”), but delete, execute and set command status using the full name (“TabsStudio.Connect.NavigateToNextTab”).

To execute command and set command availability status your main add-in class must implement the EnvDTE.IDTCommandTarget interface (Exec and QueryStatus methods):

public class Navigator : TabsStudioExt.ITabsStudioAddin, EnvDTE.IDTCommandTarget

You will find complete code sample utilizing commands in my next Navigator add-in.

Blog at WordPress.com.

%d bloggers like this: