1 /***************************************************************************
3 Copyright (c) Microsoft Corporation. All rights reserved.
4 THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
5 ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
6 IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
7 PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
9 ***************************************************************************/
12 using System
.Globalization
;
13 using MsVsShell
= Microsoft
.VisualStudio
.Shell
;
15 namespace Microsoft
.Samples
.VisualStudio
.SourceControlIntegration
.SccProvider
18 /// This attribute registers the visibility of a Tools/Options property page.
19 /// While Microsoft.VisualStudio.Shell allow registering a tools options page
20 /// using the ProvideOptionPageAttribute attribute, currently there is no better way
21 /// of declaring the options page visibility, so a custom attribute needs to be used.
23 [AttributeUsage(AttributeTargets
.Class
, AllowMultiple
= true, Inherited
= true)]
24 public sealed class ProvideToolsOptionsPageVisibility
: MsVsShell
.RegistrationAttribute
26 private string _categoryName
= null;
27 private string _pageName
= null;
28 private Guid _commandUIGuid
;
33 public ProvideToolsOptionsPageVisibility(string categoryName
, string pageName
, string commandUIGuid
)
35 _categoryName
= categoryName
;
37 _commandUIGuid
= new Guid(commandUIGuid
);
41 /// The programmatic name for this category (non localized).
43 public string CategoryName
45 get { return _categoryName; }
49 /// The programmatic name for this page (non localized).
51 public string PageName
53 get { return _pageName; }
57 /// Get the command UI guid controlling the visibility of the page.
59 public Guid CommandUIGuid
61 get { return _commandUIGuid; }
64 private string RegistryPath
66 get { return string.Format(CultureInfo.InvariantCulture, "ToolsOptionsPages\\{0}
\\{1}
\\VisibilityCmdUIContexts
", CategoryName, PageName); }
70 /// Called to register this attribute with the given context. The context
71 /// contains the location where the registration inforomation should be placed.
72 /// It also contains other information such as the type being registered and path information.
74 public override void Register(RegistrationContext context)
76 // Write to the context's log what we are about to do
77 context.Log.WriteLine(string.Format(CultureInfo.CurrentCulture, "Opt
.Page Visibility
:\t{0}
\\{1}
, {2}
\n", CategoryName, PageName, CommandUIGuid.ToString("B
")));
79 // Create the visibility key.
80 using (Key childKey = context.CreateKey(RegistryPath))
82 // Set the value for the command UI guid.
83 childKey.SetValue(CommandUIGuid.ToString("B
"), 1);
88 /// Unregister this visibility entry.
90 public override void Unregister(RegistrationContext context)
92 context.RemoveValue(RegistryPath, CommandUIGuid.ToString("B
"));