added some development tools
[windows-sources.git] / developer / VSSDK / Samples / Source_Code_Control_Provider / C# / ProvideToolsOptionsPageVisibility.cs
bloba8ecaa5601b9c9639cc19acefefdf46783542dc8
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 ***************************************************************************/
11 using System;
12 using System.Globalization;
13 using MsVsShell = Microsoft.VisualStudio.Shell;
15 namespace Microsoft.Samples.VisualStudio.SourceControlIntegration.SccProvider
17 /// <summary>
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.
22 /// </summary>
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;
30 /// <summary>
31 /// Constructor
32 /// </summary>
33 public ProvideToolsOptionsPageVisibility(string categoryName, string pageName, string commandUIGuid)
35 _categoryName = categoryName;
36 _pageName = pageName;
37 _commandUIGuid = new Guid(commandUIGuid);
40 /// <summary>
41 /// The programmatic name for this category (non localized).
42 /// </summary>
43 public string CategoryName
45 get { return _categoryName; }
48 /// <summary>
49 /// The programmatic name for this page (non localized).
50 /// </summary>
51 public string PageName
53 get { return _pageName; }
56 /// <summary>
57 /// Get the command UI guid controlling the visibility of the page.
58 /// </summary>
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); }
69 /// <summary>
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.
73 /// </summary>
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);
87 /// <summary>
88 /// Unregister this visibility entry.
89 /// </summary>
90 public override void Unregister(RegistrationContext context)
92 context.RemoveValue(RegistryPath, CommandUIGuid.ToString("B"));