Share via


How to: Create Custom Text Markers

VSPackages needing to create a custom text marker, to be used by an instance of the Core Editor to emphasize or organize code, must

  • Register the new text marker, so that other tools can access it.

  • Provide a default implementation and configuration of the text marker.

Create a service which can be used by other processes to make use of the text marker. For details on how to apply a text marker to a region of code, see How to: Use Text Markers.

To register a custom marker

  1. Create a registry entry as follows:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\<Version>\Text Editor\External Markers\<MarkerGUID>

    where <MarkerGUID>is a GUID used to identify the marker being added and <Version> is the version of Visual Studio, for example 8.0 and <PackageGUID> is the GUID of the VSPackage implementing the automation object.

    Note

    The root path of HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\<Version> can be overridden with an alternate root when the Visual Studio shell is initialized, for more information see, Command-Line Switches (Visual Studio SDK).

  2. Create four values under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\<Version>\Text Editor\External Markers\<MarkerGUID>

    • (Default)

    • Service

    • DisplayName

    • Package

    The structure of the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\<Version>\Text Editor\External Markers\<MarkerGUID> entry is:

    HKLM\Software\Microsoft\VisualStudio\<Version>\ToolsOptionsPages\

          <MarkerGUID>       = s 'Example of Marker'

                Service            = s '{XXXXXX XXXX XXXX XXXX XXXXXXXXX}'

                DisplayName    = s '#YYYY'

                Package           = s '{ZZZZZZ ZZZZ ZZZZ ZZZZ ZZZZZZZZZ}'

    Where:

    • Default is an optional entry of type REG_SZ. When set, the value of the entry is a string containing some useful identifying information. In the case above it is the string Example of Marker.

    • Service is an entry of type REG_SZ containing a string containing the GUID of the service providing the custom text marker by proffering IVsTextMarkerTypeProvider.

    • DisplayName is an entry of type REG_SZ. The display name contains a string with either the name of the custom marker, or the string ID of the name of the custom text marker in the satellite DLL of the VSPackage providing the custom text marker.

    • Package is entry of type REG_SZ containing the GUID of VSPackage providing the service which provided the custom text marker.

To create a custom text marker

  1. Implement the IVsPackageDefinedTextMarkerType interface.

    Your implementation of this interface defines the behavior and appearance of your custom marker type.

    This interface is called when

    1. A user starts the IDE for the first time.

    2. A user selects the Reset Defaults button under the Fonts and Colors property page in the Environment folder, located on the left pane of the Options dialog box obtained from the Tools menu of the IDE.

  2. Implement the GetTextMarkerType method, specifying which IVsPackageDefinedTextMarkerType implementation should be returned based on the marker type GUID specified in the method call.

    The environment calls this method the first time your custom marker type is created, and specifies a GUID identifying the custom marker type.

To proffer your marker type as a service

  1. Call the QueryService method for SProfferService.

    A pointer to IProfferService is returned.

  2. Call the ProfferService method, specifying the GUID identifying your custom marker type service and providing a pointer to your implementation of the IServiceProvider interface. Your IServiceProvider implementation should return a pointer to your implementation of IVsTextMarkerTypeProvider interface.

    A unique cookie identifying that your service is returned. You can later use this cookie to revoke your custom marker type service by calling the RevokeService method of the IProfferService interface specifying this cookie value.

After you have created a custom marker type, you need to proffer this marker type as a service in the environment using the following procedure.

See Also

Tasks

How to: Add Standard Text Markers

How to: Implement Error Markers

Concepts

How to: Use Text Markers

Other Resources

Text Markers in the Editor