Export (0) Print
Expand All

ColorableItem Class

Provides a default implementation of the VSIP interface IVsColorableItem.

This API is not CLS-compliant. 

System.Object
  Microsoft.VisualStudio.Package.ColorableItem

Namespace:  Microsoft.VisualStudio.Package
Assemblies:   Microsoft.VisualStudio.Package.LanguageService.9.0 (in Microsoft.VisualStudio.Package.LanguageService.9.0.dll)
  Microsoft.VisualStudio.Package.LanguageService (in Microsoft.VisualStudio.Package.LanguageService.dll)
  Microsoft.VisualStudio.Package.LanguageService.11.0 (in Microsoft.VisualStudio.Package.LanguageService.11.0.dll)
  Microsoft.VisualStudio.Package.LanguageService.10.0 (in Microsoft.VisualStudio.Package.LanguageService.10.0.dll)
  Microsoft.VisualStudio.Package.LanguageService.12.0 (in Microsoft.VisualStudio.Package.LanguageService.12.0.dll)

[ComVisibleAttribute(true)]
[CLSCompliantAttribute(false)]
public class ColorableItem : IVsColorableItem, 
	IVsHiColorItem, IVsMergeableUIItem

The ColorableItem type exposes the following members.

  NameDescription
Public methodColorableItemInitializes the ColorableItem class and accepts all the information needed to describe a colorable item.
Top

  NameDescription
Public methodEqualsDetermines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetCanonicalNameGets the canonical name of a colorable item.
Public methodGetColorDataGet the specified high color foreground or background element.
Public methodGetDefaultColorsReturns the foreground and background color for this colorable item.
Public methodGetDefaultFontFlagsReturns the font attributes for this colorable item.
Public methodGetDescriptionReturns a description for this colorable item.
Public methodGetDisplayNameReturns the name of this colorable item.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetMergingPriorityReturns the priority this colorable item has when compared to other colorable items of the same name.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

This class is used for defining custom colors used by the language service for syntax highlighting. The GetColorableItem method on your implementation of the LanguageService class returns a specified IVsColorableItem object.

Notes to Implementers

This class can be used to implement the IVsColorableItem interface. Just construct a new instance of this class for each custom color you wish to implement, and then return the appropriate colorable item from the GetColorableItem method.

The ideal place to construct an array of custom colors is in the constructor of your implementation of the LanguageService class. If you support customization of the colors, then you would initialize this array in LanguageService.CreateDocumentProperties after the DocumentProperties object was created.

Notes to Callers

This class is typically used by the Colorizer class in its implementation of ColorizeLine.

This shows an example of the LanguageService implementation that supports two custom colors (more can be easily added). Note that the first colorable item is never actually referenced and is used as a placeholder (all color indices passed to GetColorableItem start at 1).

[C#]
namespace MyLanguagePackage
{
    [Guid("B614A40A-80D9-4fac-A6AD-FC2868FFF7CD")]
    public class MyLanguageService : LanguageService
    {
        private ColorableItem[] m_colorableItems;

        public MyLanguageService()
            : base()
        {
                m_colorableItems = new ColorableItem[] {
                    new ColorableItem("Text",
                                      COLORINDEX.CI_SYSPLAINTEXT_FG,
                                      COLORINDEX.CI_SYSPLAINTEXT_BK,
                                      System.Drawing.Color.Empty,
                                      System.Drawing.Color.Empty,
                                      FONTFLAGS.FF_DEFAULT),
                    new ColorableItem("Keyword",
                                      COLORINDEX.CI_MAROON,
                                      COLORINDEX.CI_SYSPLAINTEXT_BK,
                                      System.Drawing.Color.Empty,
                                      System.Drawing.Color.Empty,
                                      FONTFLAGS.FF_BOLD),
                    new ColorableItem("Comment",
                                      COLORINDEX.CI_GREEN,
                                      COLORINDEX.CI_SYSPLAINTEXT_BK,
                                      System.Drawing.Color.Empty,
                                      System.Drawing.Color.Empty,
                                      FONTFLAGS.FF_DEFAULT)
                };
        }
    }
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft