Support for Options Pages

Clicking Options on the Tools menu opens the Options dialog box. The options in this dialog box are collectively referred to as options pages. The tree control in the navigation pane includes options categories, and every category has options pages. When you select a page, its options appear in the right pane. These pages let you change the values of the options that determine the state of a VSPackage.

The Package class provides support for creating options pages and options categories. The DialogPage class implements an options page.

The default implementation of DialogPage offers its public properties to a user in a generic grid of properties. You can customize this behavior by overriding various methods on the page to create a custom options page that has its own user interface (UI). For more information, see Walkthrough: Creating an Options Page.

The DialogPage class implements IProfileManager, which provides persistence for options pages and also for user settings. The default implementations of the LoadSettingsFromStorage and SaveSettingsToStorage methods persist property changes into a user section of the registry if the property can be converted to and from a string.

By default, the registry path of the properties managed by an options page is determined by combining UserRegistryRoot, the word DialogPage, and the type name of the options page class. For example, an options page class might be defined as follows.

namespace Company.OptionsPage
    public class OptionsPageGeneral : DialogPage

If the UserRegistryRoot is HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0Exp, then the property name and value pairs are subkeys of HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0Exp\DialogPage\Company.OptionsPage.OptionsPageGeneral.

The registry path of the options page itself is determined by combining ApplicationRegistryRoot, the word, ToolsOptionsPages, and the options page category and name. For example, if the Custom options page has the category, My Option Pages, and the ApplicationRegistryRoot is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0Exp, then the options page has the registry key, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0Exp\ToolsOptionsPages\My Option Pages\Custom.

The ProvideOptionPageAttribute attribute determines the grouping of custom options pages into categories in the navigation tree of the Options dialog box. The ProvideOptionPageAttribute attribute associates an options page with the VSPackage that provides the interface. Consider the following code fragment:

[ProvideOptionPage(typeof(OptionsPageGeneral),"My Option Pages", "General", 101, 106, true)]
[ProvideOptionPage(typeof(OptionsPageCustom), "My Option Pages", "Custom", 101, 107, true)]
public class MyPackage : Package

This declares that MyPackage provides two options pages, OptionsPageGeneral and OptionsPageCustom. In the Options dialog box, both options pages appear in the My Option Pages category as General and Custom, respectively.

The user interface (UI) that the page provides determines the appearance of options in a custom options page. The layout, labeling, and description of options in a generic options page are determined by the following attributes:

Consider the following code fragment:

[Category("My Options")]
[DisplayName("Integer Option")]
[Description("My integer option")]
public int OptionInteger { get; set; }

The OptionInteger option appears on the options page as Integer Option in the My Options category. If the option is selected, the description, My integer option, appears in the description box.

A VSPackage that hosts and manages an options page can be programmatically accessed from another VSPackage by using the automation model. For example, in the following code a VSPackage is registered as hosting an option page.

[ProvideOptionPage(typeof(MyOptionPage), "My Category", "My Grid Page", 0, 0, true)]
public sealed class MyToolsOptions : Package

The following code fragment gets the value of OptionInteger from MyOptionPage:

DTE dte = (DTE)GetService(typeof(DTE));
EnvDTE.Properties props = dte.get_Properties("My Category", "My Grid Page");
int n = (int)props.Item("OptionInteger").Value;

When the ProvideOptionPageAttribute attribute registers an options page, the page is registered under the AutomationProperties key if the SupportsAutomation argument of the attribute is true. Automation examines this registry entry to find the associated VSPackage, and automation then accesses the property through the hosted options page, in this case, My Grid Page.

The registry path of the automation property is determined by combining ApplicationRegistryRoot, the word, AutomationProperties, and the options page category and name. For example, if the options page has the My Category category, the My Grid Page name, and the ApplicationRegistryRoot, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0Exp, then the automation property has the registry key, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0Exp\AutomationProperties\My Category\My Grid Page.

Note Note

The canonical name, My Category.My Grid Page, is the value of the Name subkey of this key.