added some development tools
[windows-sources.git] / developer / VSSDK / VisualStudioIntegration / Common / Source / CSharp / Shell90 / ProvideToolboxPageAttribute.cs
blob1c1496a0652a1b382b897ba92d2368f59461e309
1 //------------------------------------------------------------------------------
2 // <copyright file="ProvideToolboxPageAttribute.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 // </copyright>
5 //------------------------------------------------------------------------------
7 namespace Microsoft.VisualStudio.Shell {
9 using System;
10 using System.Globalization;
12 /// <include file='doc\ProvideToolboxPageAttribute.uex' path='docs/doc[@for="ProvideToolboxPageAttribute"]' />
13 /// <devdoc>
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.
20 /// </devdoc>
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"]' />
28 /// <devdoc>
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.
34 /// </devdoc>
35 public ProvideToolboxPageAttribute(Type pageType, short nameResourceID) : this(pageType, nameResourceID, 0) {
38 /// <include file='doc\ProvideToolboxPageAttribute.uex' path='docs/doc[@for="ProvideToolboxPageAttribute.TypeId"]' />
39 /// <devdoc>
40 /// Identity of this instance of the attribute.
41 /// </devdoc>
42 public override object TypeId {
43 get {
44 return this;
48 /// <include file='doc\ProvideToolboxPageAttribute.uex' path='docs/doc[@for="ProvideToolboxPageAttribute.ProvideToolboxPageAttribute1"]' />
49 /// <devdoc>
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
57 /// toolbox pages.
58 /// </devdoc>
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"]' />
63 /// <devdoc>
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
71 /// toolbox pages.
72 /// Helpkeyword is a keyword exposed to F1 help (support for this was added by joshs -- reference VS Whidbey#262176)
73 /// </devdoc>
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"]' />
82 /// <devdoc>
83 /// Returns the help keyword associated with this toolbox page.
84 /// </devdoc>
85 public string HelpKeyword {
86 get {
87 return _helpKeyword;
91 /// <include file='doc\ProvideToolboxPageAttribute.uex' path='docs/doc[@for="ProvideToolboxPageAttribute.PageOrder"]' />
92 /// <devdoc>
93 /// The sort order of the page or zero if this page should be left unsorted.
94 /// </devdoc>
95 public short PageOrder {
96 get {
97 return _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"]' />
107 /// <devdoc>
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.
114 /// </devdoc>
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"]' />
133 /// <devdoc>
134 /// Called to remove this attribute from the given context.
135 /// </devdoc>
136 public override void Unregister(RegistrationContext context)
138 context.RemoveKey(ToolboxPageRegKey);