Skip to content

Latest commit

 

History

History
41 lines (30 loc) · 2.97 KB

selection-context-objects.md

File metadata and controls

41 lines (30 loc) · 2.97 KB
title description ms.date ms.topic helpviewer_keywords author ms.author manager ms.subservice
Selection Context Objects
Learn about the internals of how the Visual Studio IDE uses a global selection context object to determine what should be displayed in the IDE.
11/04/2016
reference
selection, tracking
selection, context objects
maiak
maiak
mijacobs
extensibility-integration

Selection Context Objects

The Visual Studio integrated development environment (IDE) uses a global selection context object to determine what should be displayed in the IDE. Each window in the IDE can have its own selection context object pushed to the global selection context. The IDE updates the global selection context with values from a window when that window has the focus. For more information, see Feedback to the User.

Each window frame or site in the IDE has a service called xref:Microsoft.VisualStudio.Shell.Interop.STrackSelection. The object created by your VSPackage that is sited in the window frame must call the QueryService method to get a pointer to the xref:Microsoft.VisualStudio.Shell.Interop.ITrackSelection interface.

Frame windows can keep portions of their selection context information from being propagated to the global selection context when they are started. This ability is useful for tool windows that may have to start with an empty selection.

Modifying the global selection context triggers events that VSPackages can monitor. VSPackages can perform the following tasks by implementing IVsTrackSelectionEx and xref:Microsoft.VisualStudio.Shell.Interop.IVsMonitorSelection interfaces:

  • Update the currently active file in a hierarchy.

  • Monitor changes to certain types of elements. For example, if your VSPackage uses a special Properties window, you can monitor changes in the active Properties window and restart yours when required.

    The following sequence shows the typical course of selection tracking.

  1. The IDE retrieves the selection context from the newly opened window and puts it in the global selection context. If the selection context uses HIERARCHY_DONTPROPAGATE or SELCONTAINER_DONTPROPAGATE, that information is not propagated to the global context. For more information, see Feedback to the User.

  2. Notification events are broadcast to any VSPackage that requested them.

  3. The VSPackage acts on the events it receives by performing activities such as updating a hierarchy, reactivating a tool, or other similar tasks.

See also