Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Deconstructing Add-In Architecture in Visual Studio .NET : Page 6

The Visual Studio .NET extensibility model included with the IDE allows any developer to design and compile value-adding custom add-ins right out-of-the-box. No additional APIs or tools are required. Visual Studio .NET even provides a starting point for add-in developers with the Visual Studio .NET Add-In Project type.


advertisement
Implementing Named Commands
Use the IDTCommandTargetinterface only if you intend to provide one or more custom named commands. A named command with Visual Studio .NET is merely a piece of functional code that is assigned a well-known name within the context of the entire collection of commands (or macros) programmatically accessible, or also invoked directly through the IDE's Command window. Almost every action a developer can initiate within the IDE is made available in the form of a named command. To see this in action, open the Command window and type View.FullScreen. This will change your IDE configuration to the Full Screen mode.

The benefit of exposing add-in functionality as a named command will be two-fold. As a convenience, or for programmatic accessibility of your add-in's functionality, a named command is the standard mechanism the developer will use. The second benefit will stem from the ease of adding menu items to context menus or command bars through use of the AddControlmethod of the EnvDTE.Command object.

Dim oAI As AddIn = CType(addInInst, AddIn) Dim oCmd As Command Try oCmd = IDE.Commands.AddNamedCommand( _ oAI, "CmdName", "ButtonText", _ "Tooltip", True, 59, Nothing, _ 1 + 2) oCmd.AddControl( _ IDE.CommandBars.Item("Tools")) Catch e As System.Exception End Try

The IDTCommandTargetinterface exposes two method members, Exec and QueryStatus, which you will implement. You will need to implement both so that you can respond properly to the IDE when Visual Studio .NET invokes your named commands. The QueryStatus method implementation provided by your add-in will be called in three scenarios:
  • Your named command is manually entered into the Command window
  • The ExecuteCommand method of the core EnvDTE.DTE object is used to request your named command
  • The IDE needs to draw a menu item associated with your named command through the original call to AddControl.
You should assign a value from the vsCommandStatus enumeration to the statusOption parameter being passed by reference. Your value should indicate the command is both available (vsCommandStatusEnabled) and supported (vsCommandStatusSupported). This will instruct the IDE to invoke the Exec method, providing your add-in the chance to handle the command request.

StatusOption = CType( _ vsCommandStatus.vsCommandStatusEnabled + _ vsCommandStatus.vsCommandStatusSupported, _ vsCommandStatus)

You should place the necessary named command implementation code within the Exec method. You need a logic check to guarantee that the proper code is executed for the command being requested.


If cmdName = "FromScratch.MyAddIn.CmdName" Then handled = True Exit Sub End If

The actual name of your command will be a combination of the ProgID set with the ProgIdAttribute class applied to your add-in class and the second parameter passed into the AddNamedCommand.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date