forked from yysun/Git-Source-Control-Provider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProvideToolsOptionsPageVisibility.cs
95 lines (83 loc) · 3.55 KB
/
ProvideToolsOptionsPageVisibility.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/***************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
This code is licensed under the Visual Studio SDK license terms.
THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
***************************************************************************/
using System;
using System.Globalization;
using MsVsShell = Microsoft.VisualStudio.Shell;
namespace GitScc
{
/// <summary>
/// This attribute registers the visibility of a Tools/Options property page.
/// While Microsoft.VisualStudio.Shell allow registering a tools options page
/// using the ProvideOptionPageAttribute attribute, currently there is no better way
/// of declaring the options page visibility, so a custom attribute needs to be used.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
public sealed class ProvideToolsOptionsPageVisibility : MsVsShell.RegistrationAttribute
{
private string _categoryName = null;
private string _pageName = null;
private Guid _commandUIGuid;
/// <summary>
/// </summary>
public ProvideToolsOptionsPageVisibility(string categoryName, string pageName, string commandUIGuid)
{
_categoryName = categoryName;
_pageName = pageName;
_commandUIGuid = new Guid(commandUIGuid);
}
/// <summary>
/// The programmatic name for this category (non localized).
/// </summary>
public string CategoryName
{
get { return _categoryName; }
}
/// <summary>
/// The programmatic name for this page (non localized).
/// </summary>
public string PageName
{
get { return _pageName; }
}
/// <summary>
/// Get the command UI guid controlling the visibility of the page.
/// </summary>
public Guid CommandUIGuid
{
get { return _commandUIGuid; }
}
private string RegistryPath
{
get { return string.Format(CultureInfo.InvariantCulture, "ToolsOptionsPages\\{0}\\{1}\\VisibilityCmdUIContexts", CategoryName, PageName); }
}
/// <summary>
/// Called to register this attribute with the given context. The context
/// contains the location where the registration inforomation should be placed.
/// It also contains other information such as the type being registered and path information.
/// </summary>
public override void Register(RegistrationContext context)
{
// Write to the context's log what we are about to do
context.Log.WriteLine(String.Format(CultureInfo.CurrentCulture, "Opt.Page Visibility:\t{0}\\{1}, {2}\n", CategoryName, PageName, CommandUIGuid.ToString("B")));
// Create the visibility key.
using (Key childKey = context.CreateKey(RegistryPath))
{
// Set the value for the command UI guid.
childKey.SetValue(CommandUIGuid.ToString("B"), 1);
}
}
/// <summary>
/// Unregister this visibility entry.
/// </summary>
public override void Unregister(RegistrationContext context)
{
context.RemoveValue(RegistryPath, CommandUIGuid.ToString("B"));
}
}
}