added some development tools
[windows-sources.git] / developer / VSSDK / VisualStudioIntegration / Common / Source / CSharp / Shell90 / ProvideLanguageEditorOptionPageAttribute.cs
blob02491e82ac7d499beef09e71bc7d2b74071b64c7
1 //////////////////////////////////////////////////////////////////////////////
2 // RegisterLanguageServiceAttribute
3 //
4 // Provide a general method for setting a language service's editor tool
5 // option page.
6 //
7 // This information is stored in the registry key
8 // <RegistrationRoot>\Languages\Language Services\[language]\EditorToolsOptions
9 // where [language] is the name of the language.
11 // Under EditorToolsOptions is a tree of pages and sub-pages that can
12 // nest any number of levels. These pages correspond to options pages
13 // displayed in the Visual Studio Tools Options for editors (where the
14 // language name is displayed under which is a tree of option pages, each
15 // page containing appropriate options).
17 // Each key in this option page list contains a resoure id or literal
18 // string containing the localized name of the page (this is what is
19 // actually shown in the Tools Options dialog). In addition, it also
20 // contains a package GUID and optionally a GUID of an option page.
22 // If there is no option page GUID then the key is considered a node in the
23 // tree of options and has no associated page. Otherwise, the key is
24 // a leaf in the tree and its option page will be shown.
26 // Example:
27 // root base key: HKLM\Software\Microsoft\VisualStudio\8.0
28 // Languages\
29 // Language Services\
30 // CSharp\
31 // EditorToolsOptions\
32 // Formatting\ = sz:#242
33 // General\ = sz:#255
34 // Package = sz:{GUID}
35 // Page = sz:{GUID}
36 // Indentation\ = sz:#250
37 // Package = sz:{GUID}
38 // Page = sz:{GUID}
40 // Goal:
41 // LanguageEditorOptionPage("CSharp","Formatting","#242");
42 // LanguageEditorOptionPage("CSharp","Formatting\General","#255","{PAGE GUID}");
43 // LanguageEditorOptionPage("CSharp","Formatting\Indentation","#250","{PAGE GUID}");
45 //////////////////////////////////////////////////////////////////////////////
47 #region Using directives
49 using System;
50 using System.Diagnostics;
51 using System.Collections;
52 using System.Globalization;
53 using System.Runtime.InteropServices;
54 using System.ComponentModel.Design;
55 using Microsoft.Win32;
56 using Microsoft.VisualStudio.Shell.Interop;
57 using Microsoft.VisualStudio.OLE.Interop;
58 using Microsoft.VisualStudio.Shell;
59 using MSVSIP = Microsoft.VisualStudio.Shell;
61 #endregion
63 namespace Microsoft.VisualStudio.Shell
65 internal class LanguageToolsOptionCreator {
66 // This class is used only to expose some static member, so we declare a private constructor
67 // to avoid the creation of any instance of it.
68 private LanguageToolsOptionCreator() { }
70 private static string FormatRegKey(string languageName, string categoryName) {
72 string strRegKey =
73 string.Format(CultureInfo.InvariantCulture,
74 "{0}\\{1}\\{2}\\{3}",
75 RegistryPaths.languageServices,
76 languageName,
77 RegistryPaths.editorToolsOptions,
78 categoryName);
79 return strRegKey;
82 internal static void CreateRegistryEntries(RegistrationAttribute.RegistrationContext context, string languageName, string categoryName, string categoryResourceId, Guid pageGuid)
85 using (RegistrationAttribute.Key serviceKey = context.CreateKey(FormatRegKey(languageName, categoryName))) {
86 // Add specific entries corresponding to arguments to
87 // constructor.
88 serviceKey.SetValue(string.Empty, categoryResourceId);
89 serviceKey.SetValue(RegistryPaths.package, context.ComponentType.GUID.ToString("B"));
90 if (pageGuid != Guid.Empty) {
91 serviceKey.SetValue(RegistryPaths.page, pageGuid.ToString("B"));
96 internal static void RemoveRegistryEntries(RegistrationAttribute.RegistrationContext context, string languageName, string categoryName) {
98 context.RemoveKey(FormatRegKey(languageName, categoryName));
102 /// <include file='doc\ProvideLanguageEditorOptionPageAttribute.uex' path='docs/doc[@for="ProvideLanguageEditorToolsOptionCategoryAttribute"]' />
103 /// <devdoc>
104 /// This attribute is used to declare a ToolsOption category for a language.
105 /// </devdoc>
106 [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
107 public sealed class ProvideLanguageEditorToolsOptionCategoryAttribute : RegistrationAttribute {
108 private string languageName;
109 private string categoryName;
110 private string categoryResourceId;
112 /// <include file='doc\ProvideLanguageEditorOptionPageAttribute.uex' path='docs/doc[@for="ProvideLanguageEditorToolsOptionCategoryAttribute.ProvideLanguageEditorToolsOptionCategoryAttribute"]' />
113 /// <devdoc>
114 /// Creates a new ProvideLanguageEditorToolsOptionCategory attribute for a given language and category.
115 /// </devdoc>
116 /// <param name="languageName">The name of the language.</param>
117 /// <param name="categoryName">The name of the category.</param>
118 /// <param name="categoryResourceId">The id of the resource with the localized name for the category.</param>
119 public ProvideLanguageEditorToolsOptionCategoryAttribute(string languageName, string categoryName, string categoryResourceId) {
120 this.languageName = languageName;
121 this.categoryName = categoryName;
122 this.categoryResourceId = categoryResourceId;
125 /// <include file='doc\ProvideLanguageEditorOptionPageAttribute.uex' path='docs/doc[@for="ProvideLanguageEditorToolsOptionCategoryAttribute.Register"]' />
126 public override void Register(RegistrationAttribute.RegistrationContext context) {
127 context.Log.WriteLine(string.Format(Resources.Culture, Resources.Reg_NotifyLanguageOptionCategory, languageName, categoryName));
129 // Create the registry entries using the creator object.
130 LanguageToolsOptionCreator.CreateRegistryEntries(context, languageName, categoryName, categoryResourceId, Guid.Empty);
133 /// <include file='doc\ProvideLanguageEditorOptionPageAttribute.uex' path='docs/doc[@for="ProvideLanguageEditorToolsOptionCategoryAttribute.Unregister"]' />
134 public override void Unregister(RegistrationAttribute.RegistrationContext context) {
135 // Remove the entries using the creator object.
136 LanguageToolsOptionCreator.RemoveRegistryEntries(context, languageName, categoryName);
140 /// <include file='doc\ProvideLanguageEditorOptionPageAttribute.uex' path='docs/doc[@for="ProvideLanguageEditorOptionPageAttribute"]' />
141 [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
142 public sealed class ProvideLanguageEditorOptionPageAttribute : ProvideOptionDialogPageAttribute
144 private string languageName;
145 private string pageName;
146 private string category;
148 /// <include file='doc\ProvideLanguageEditorOptionPageAttribute.uex' path='docs/doc[@for="ProvideLanguageEditorOptionPageAttribute.ProvideLanguageEditorOptionPageAttribute"]' />
149 /// <devdoc>
150 /// Constructor for node with child option pages (to be added with
151 /// additional ProvideLanguageEditorOptionPageAttribute).
152 /// </devdoc>
153 public ProvideLanguageEditorOptionPageAttribute(
154 Type pageType,
155 string languageName,
156 string category,
157 string pageName,
158 string pageNameResourceId
159 ) : base(pageType, pageNameResourceId)
161 this.languageName = languageName;
162 this.pageName = pageName;
163 this.category = category;
166 //////////////////////////////////////////////////////////////////////
167 // Properties.
169 /// <include file='doc\ProvideLanguageEditorOptionPageAttribute.uex' path='docs/doc[@for="ProvideLanguageEditorOptionPageAttribute.LanguageName"]' />
170 public string LanguageName
172 get { return languageName; }
175 /// <include file='doc\ProvideLanguageEditorOptionPageAttribute.uex' path='docs/doc[@for="ProvideLanguageEditorOptionPageAttribute.PageGuid"]' />
176 public Guid PageGuid
178 get { return PageType.GUID; }
181 private string FullPathToPage {
182 get {
183 if (string.IsNullOrEmpty(category))
184 return pageName;
185 return string.Format("{0}\\{1}", category, pageName);
188 //////////////////////////////////////////////////////////////////////
189 // Public methods.
191 /// <include file='doc\ProvideLanguageEditorOptionPageAttribute.uex' path='docs/doc[@for="ProvideLanguageEditorOptionPageAttribute.Register"]' />
192 public override void Register(RegistrationAttribute.RegistrationContext context)
194 context.Log.WriteLine(string.Format(Resources.Culture, Resources.Reg_NotifyLanguageOptionPage, LanguageName, PageNameResourceId));
196 // Create the registry entries using the creator object.
197 LanguageToolsOptionCreator.CreateRegistryEntries(context, LanguageName, FullPathToPage, PageNameResourceId, PageGuid);
200 /// <include file='doc\ProvideLanguageEditorOptionPageAttribute.uex' path='docs/doc[@for="ProvideLanguageEditorOptionPageAttribute.Unregister"]' />
201 public override void Unregister(RegistrationAttribute.RegistrationContext context)
203 // Remove the registry entries for this page.
204 LanguageToolsOptionCreator.RemoveRegistryEntries(context, LanguageName, FullPathToPage);