How the Availability of Commands is Determined by IDE Context

The current context of the Visual Studio integrated development environment (IDE) is the combination of the features and files that are currently active. When the combination of active features and files is changed, the current context is also changed. Current context determines which commands are available. Changes in the IDE, VSPackages, projects, editors, tool windows, or file type can the availability of commands.

Command Availability Concepts

These are the key concepts for command availability in the current context:

  • The active project determines which project commands are currently available in the IDE. The active project is the project that is currently selected, or contains the file that is currently selected, in Solution Explorer.

  • The commands from only one editor can be currently available in the IDE.

  • Commands that open tool windows are always available.

The IDE displays the union of all IDE commands, VSPackage commands, active project commands, active editor commands, and tool window commands. For more information, see Command Routing Algorithm. Command availability can be further controlled by creating entries in the VisibilityConstraints Element section of the .vsct file.

All commands that are registered in Visual Studio appear in the list of commands in the Customize dialog box. Some command enabling and disabling is automatically handled when the IDE calls the interfaces that are implemented in your code. For example, the build command (GUID:ID guidVSStd97:cmdidBuildCtx) is enabled when your project implements the IVsBuildableProjectCfg interface.

Command Availability Contexts

When a command applies to the current context, it is displayed in the user interface (UI) as follows, depending on location. If the command does not apply to the current context, it is hidden.

  • IDE: Commands provided by the IDE are always available.

  • VSPackage: Implements features and commands that are added to the IDE. Many of the features that are included in Visual Studio are implemented as VSPackages.

  • Project: A container for various kinds of data from which a discrete deliverable can be built. Project commands appear only for the currently selected project. Project commands for inactive projects are hidden. For information about how UI commands can be hidden or displayed automatically, see VisibilityItem Element.

  • Editor: A software component that has at least one window that lets users modify project code or other data. Only one editor at a time can be active. An editor can provide its own UI, but its command set must participate in the IDE. Commands from the active editor are available, but commands from other editors are hidden.

    An editor works closely with a language service. The language service must process its commands in the context of the associated editor.

  • File type: An editor can load more than one type of file, and the editor UI can be programmed to change depending on the file type.

  • Tool window: The command to open a tool window is registered on the View menu in Visual Studio. After a tool window is registered, it is always available on the View menu.

See Also

Concepts

Selection Context Objects

How VSPackages Add User Interface Elements to the IDE

Other Resources

Command Routing in VSPackages

Command Table Configuration (.Ctc) Files