Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

Application Server

Register and invoke commands

  • Last UpdatedJul 23, 2024
  • 2 minute read

In order for an IDE extension to handle a command, the extension public class must implement “IaaCommandTarget” interface from the “Extensibility” assembly.

The first thing extensions need to do is to register the command target for the command it is interested in. Using the command provider site the extension can query for “IaaCommands” service and register its command target by calling “Register” method on this interface. In the same manner, extensions can un-register command target for a command by calling “Unregister” method on the same interface. Typically extensions register their command targets in “IaaSnapin.Initialize” method, whereas un-register them in “IaaSnapin.Uninitialize” method. The following is how the sample extension registers its commands.

void IaaSnapin.Initialize(IaaServiceProvider site)

{

m_site = site;

IaaCommands cmds = m_site.Services[typeof(IaaCommands)] as

IaaCommands;

// This class itself is the command target

cmds["cmdTestCheckin"].Register(this);

cmds["cmdTestCheckout"].Register(this);

}

After the command target is registered, the IDE uses this interface to communicate with the extensions to update command UI vectors and to process invoked commands. The “IaaCommandTarget” interface has two methods as explained below.

  • OnUpdate – The IDE calls this method to give command target a chance to update command and command UI vectors. If the command is context sensitive, the method is called every time a selection in the active view changes.

  • OnInvoke – The IDE calls this method to give command target chance to process the command when it is invoked.

When calling “OnUpdate” or “OnInvoke” methods, IDE passes an instance of command being processed in the form of “IaaCommandInstance” interface. The IDE Extension can probe this interface to get handle to the actual command, command arguments, what command UI this command is invoked through, and states of the command. Following is a sample “OnUpdate” implementation, which changes command and various command UI states.

public void OnUpdate(IaaCommandInstance cmd)

{

// Applicable command state property indicates, whether it should

// be shown/hidden when context menu is invoked.

cmd.State.Applicable = true;

cmd.State.Enabled = true; // Indicates command is enabled.

cmd.State.Checked = true; // Indicates command is checked.

}

If there is more than one extension that registers for a command, IDE framework uses the following order to determine the extension, which will be notified for command update and invocation.

  • The active view extension the user is currently working with.

  • Any extension that overrides the command.

  • The extension that defined the command.

Please see the sample example extension for command handling command updates and invocation in detail.

TitleResults for “How to create a CRG?”Also Available in