DXCore Services – Context
The Context service is responsible for the DXCore contexts system. It provides access to context providers and methods that report whether specified context is satisfied.
The Context service is responsible for the DXCore contexts system. It provides access to context providers and methods that report whether specified context is satisfied.
The context determines if a particular feature is appropriate for use when working inside Visual Studio IDE. It is useful for distinguishing conditions where a feature should be available. If a feature with a specified context is available, then it means that the context is satisfied. For example, you may apply a context for a feature to be available while editing a source code, but not while IDE is in design-time or a model dialog is open.
The ContextPicker component allows users to specify sophisticated context expressions. It is populated from the context providers registered in the DXCore. For example, take a look at the Shortcuts options page and the context picker used on this page where you can bind a context for any shortcut available.
The ContextProvider component provides a new context entry for the ContextPicker component. Context is automatically registered in the DXCore when a plug-in containing the corresponding ContextProvider is loaded.
You can drop the ContextProvider onto your plug-in design surface from the “DXCore: Extensions & Providers” category of Visual Studio Toolbox:
Here’s a sample code of how to programmatically verify a particular context inside of your DXCore plug-in. You may achieve this using the Context service like this:
CSharp code:
ContextResult result = CodeRush.Context.Satisfied(@"Focus\Documents\Source\Code Editor"); bool editorHasFocus = result == ContextResult.Satisfied;