1 //------------------------------------------------------------------------------
2 // <copyright file="ProvideToolboxPageAttribute.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
7 namespace Microsoft
.VisualStudio
.Shell
{
10 using System
.Globalization
;
12 /// <include file='doc\ProvideToolboxPageAttribute.uex' path='docs/doc[@for="ProvideToolboxPageAttribute"]' />
14 /// This attribute declares that a package offers one or more toolbox pages. Toolbox pages are
15 /// exposed to the user through Visual Studio's customize toolbox dialog. A toolbox page must
16 /// derive from DialogPage. Toolbox page
17 /// attributes are read by the package class when Visual Studio requests a particular property
18 /// page GUID. Package will walk the attributes and try to match the requested GUID to a
19 /// GUID on a type in the package.
21 [AttributeUsage(AttributeTargets
.Class
, AllowMultiple
=true, Inherited
=true)]
22 public sealed class ProvideToolboxPageAttribute
: ProvideOptionDialogPageAttribute
{
24 private short _pageOrder
;
25 private string _helpKeyword
;
27 /// <include file='doc\ProvideToolboxPageAttribute.uex' path='docs/doc[@for="ProvideToolboxPageAttribute.ProvideToolboxPageAttribute"]' />
29 /// The page type is a type that implements
30 /// IWin32Window. The nameResourceID
31 /// parameter specifies a Win32 resource ID in the
32 /// stored in the native UI resource satellite
33 /// that describes the name of this page.
35 public ProvideToolboxPageAttribute(Type pageType
, short nameResourceID
) : this(pageType
, nameResourceID
, 0) {
38 /// <include file='doc\ProvideToolboxPageAttribute.uex' path='docs/doc[@for="ProvideToolboxPageAttribute.TypeId"]' />
40 /// Identity of this instance of the attribute.
42 public override object TypeId
{
48 /// <include file='doc\ProvideToolboxPageAttribute.uex' path='docs/doc[@for="ProvideToolboxPageAttribute.ProvideToolboxPageAttribute1"]' />
50 /// The page type is a type that implements
51 /// IWin32Window. The nameResourceID
52 /// parameter specifies a Win32 resource ID in the
53 /// stored in the native UI resource satellite
54 /// that describes the name of this page. Page order is
55 /// optional and defaults to zero. If non-zero, a registry entry will be
56 /// created named DefaultTbx, which specifies the sort order of the
59 public ProvideToolboxPageAttribute(Type pageType
, short nameResourceID
, short pageOrder
) : this(pageType
, nameResourceID
, pageOrder
, null) {
62 /// <include file='doc\ProvideToolboxPageAttribute.uex' path='docs/doc[@for="ProvideToolboxPageAttribute.ProvideToolboxPageAttribute1"]' />
64 /// The page type is a type that implements
65 /// IWin32Window. The nameResourceID
66 /// parameter specifies a Win32 resource ID in the
67 /// stored in the native UI resource satellite
68 /// that describes the name of this page. Page order is
69 /// optional and defaults to zero. If non-zero, a registry entry will be
70 /// created named DefaultTbx, which specifies the sort order of the
72 /// Helpkeyword is a keyword exposed to F1 help (support for this was added by joshs -- reference VS Whidbey#262176)
74 public ProvideToolboxPageAttribute(Type pageType
, short nameResourceID
, short pageOrder
, string helpKeyword
)
75 : base(pageType
, "#"+nameResourceID
.ToString()) {
77 _pageOrder
= pageOrder
;
78 _helpKeyword
= helpKeyword
;
81 /// <include file='doc\ProvideToolboxPageAttribute.uex' path='docs/doc[@for="ProvideToolboxPageAttribute.HelpKeyword"]' />
83 /// Returns the help keyword associated with this toolbox page.
85 public string HelpKeyword
{
91 /// <include file='doc\ProvideToolboxPageAttribute.uex' path='docs/doc[@for="ProvideToolboxPageAttribute.PageOrder"]' />
93 /// The sort order of the page or zero if this page should be left unsorted.
95 public short PageOrder
{
101 private string ToolboxPageRegKey
103 get { return string.Format(CultureInfo.InvariantCulture, "ToolboxPages\\{0}
", PageType.FullName); }
106 /// <include file='doc\ProvideToolboxPageAttribute.uex' path='docs/doc[@for="Register
"]' />
108 /// Called to register this attribute with the given context. The context
109 /// contains the location where the registration inforomation should be placed.
110 /// it also contains such as the type being registered, and path information.
112 /// This method is called both for registration and unregistration. The difference is
113 /// that unregistering just uses a hive that reverses the changes applied to it.
115 public override void Register(RegistrationContext context) {
116 context.Log.WriteLine(string.Format(Resources.Culture, Resources.Reg_NotifyToolboxPage, PageType.Name));
118 using (Key childKey = context.CreateKey(ToolboxPageRegKey))
120 childKey.SetValue(string.Empty, PageNameResourceId);
121 childKey.SetValue("Package
", context.ComponentType.GUID.ToString("B
"));
122 childKey.SetValue("Page
", PageType.GUID.ToString("B
"));
123 if (PageOrder != 0) {
124 childKey.SetValue("DefaultTbx
", PageOrder);
126 if (_helpKeyword != null && _helpKeyword.Length > 0) {
127 childKey.SetValue("HelpKeyword
", _helpKeyword);
132 /// <include file='doc\ProvideToolboxPageAttribute.uex' path='docs/doc[@for="Unregister
"]' />
134 /// Called to remove this attribute from the given context.
136 public override void Unregister(RegistrationContext context)
138 context.RemoveKey(ToolboxPageRegKey);