Share via


ColorableItem Class

Provides a default implementation of the VSIP interface IVsColorableItem.

This API is not CLS-compliant. 

Inheritance Hierarchy

System.Object
  Microsoft.VisualStudio.Package.ColorableItem

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

Syntax

'Declaration
<ComVisibleAttribute(True)> _
<CLSCompliantAttribute(False)> _
Public Class ColorableItem _
    Implements IVsColorableItem, IVsHiColorItem, IVsMergeableUIItem
[ComVisibleAttribute(true)]
[CLSCompliantAttribute(false)]
public class ColorableItem : IVsColorableItem, 
    IVsHiColorItem, IVsMergeableUIItem
[ComVisibleAttribute(true)]
[CLSCompliantAttribute(false)]
public ref class ColorableItem : IVsColorableItem, 
    IVsHiColorItem, IVsMergeableUIItem
[<ComVisibleAttribute(true)>]
[<CLSCompliantAttribute(false)>]
type ColorableItem =  
    class
        interface IVsColorableItem
        interface IVsHiColorItem
        interface IVsMergeableUIItem
    end
public class ColorableItem implements IVsColorableItem, IVsHiColorItem, IVsMergeableUIItem

The ColorableItem type exposes the following members.

Constructors

  Name Description
Public method ColorableItem Initializes the ColorableItem class and accepts all the information needed to describe a colorable item.

Top

Methods

  Name Description
Public method Equals Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetCanonicalName Gets the canonical name of a colorable item.
Public method GetColorData Get the specified high color foreground or background element.
Public method GetDefaultColors Returns the foreground and background color for this colorable item.
Public method GetDefaultFontFlags Returns the font attributes for this colorable item.
Public method GetDescription Returns a description for this colorable item.
Public method GetDisplayName Returns the name of this colorable item.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetMergingPriority Returns the priority this colorable item has when compared to other colorable items of the same name.
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

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.

Examples

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)
                };
        }
    }
}

Thread Safety

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

See Also

Reference

Microsoft.VisualStudio.Package Namespace