From ed35bc128fa24e6562f18e876721c686d4b7f1fc Mon Sep 17 00:00:00 2001 From: Tom Meschter Date: Tue, 12 Oct 2021 16:37:40 -0700 Subject: [PATCH] Add Rules from code Define a type that defines `Rule` instances in code (rather than loading them from XAML) and dynamically adds and removes them from the project based on capabilities. --- .../PropertyPages/PropertyPageRuleProvider.cs | 110 ++++++++++++++++++ .../Resources.Designer.cs | 20 +++- .../Resources.resx | 6 + .../xlf/Resources.cs.xlf | 10 ++ .../xlf/Resources.de.xlf | 10 ++ .../xlf/Resources.es.xlf | 10 ++ .../xlf/Resources.fr.xlf | 10 ++ .../xlf/Resources.it.xlf | 10 ++ .../xlf/Resources.ja.xlf | 10 ++ .../xlf/Resources.ko.xlf | 10 ++ .../xlf/Resources.pl.xlf | 10 ++ .../xlf/Resources.pt-BR.xlf | 10 ++ .../xlf/Resources.ru.xlf | 10 ++ .../xlf/Resources.tr.xlf | 10 ++ .../xlf/Resources.zh-Hans.xlf | 10 ++ .../xlf/Resources.zh-Hant.xlf | 10 ++ 16 files changed, 265 insertions(+), 1 deletion(-) create mode 100644 src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Rules/PropertyPages/PropertyPageRuleProvider.cs diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Rules/PropertyPages/PropertyPageRuleProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Rules/PropertyPages/PropertyPageRuleProvider.cs new file mode 100644 index 0000000000..dc8e1d0994 --- /dev/null +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Rules/PropertyPages/PropertyPageRuleProvider.cs @@ -0,0 +1,110 @@ +ο»Ώ// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information. + +using System; +using System.ComponentModel.Composition; +using System.Threading.Tasks; +using Microsoft.Build.Framework.XamlTypes; +using Microsoft.VisualStudio.ProjectSystem.Properties; + +namespace Microsoft.VisualStudio.ProjectSystem.Rules.PropertyPages +{ + /// + /// We want to provide certain rules when the "MyCapability" capability is present, but remove them if it goes away. + /// The is designed specifically for these situations. + /// + [Export(ExportContractNames.Scopes.UnconfiguredProject, typeof(IProjectDynamicLoadComponent))] + [AppliesTo("MyCapability")] + internal class PropertyPageRuleProvider : IProjectDynamicLoadComponent + { + /// + /// A CPS-provided service that supports adding and removing in-memory s. + /// + private readonly IAdditionalRuleDefinitionsService _additionalRuleDefinitionsService; + /// + /// Use a so we don't create the until we need it. + /// Technically this is unnecessary, since the constructor won't be called until the first + /// time the capabilities are satisified, and will be called shortly + /// after that. As such, making this lazy really just makes it very clear that it definitely + /// won't be created until it is needed, and will only be created once. + /// + private readonly Lazy _rule; + + [ImportingConstructor] + public PropertyPageRuleProvider( + IAdditionalRuleDefinitionsService additionalRuleDefinitionsService) + { + _additionalRuleDefinitionsService = additionalRuleDefinitionsService; + _rule = new Lazy(CreateRule); + } + + /// + /// Called when the specified capabilities are satisfied. + /// We can add our rules. + /// + public Task LoadAsync() + { + _additionalRuleDefinitionsService.AddRuleDefinition(_rule.Value, context: "Project"); + + return Task.CompletedTask; + } + + /// + /// Called when the specified capabilities are no longer satisfied. + /// We can remove our rules. + /// + public Task UnloadAsync() + { + _additionalRuleDefinitionsService.RemoveRuleDefinition(_rule.Value); + + return Task.CompletedTask; + } + + private Rule CreateRule() + { + Rule rule = new(); + + // Rule implements ISupportInitialize; we need to be sure to call BeginInit and EndInit. + rule.BeginInit(); + + // Basic information + + rule.Name = "MyInMemoryPropertyPage"; + rule.Description = "A Rule that is defined in memory and dynamically loaded and unloaded"; + rule.DisplayName = Resources.MyPropertyPage_DisplayName; + rule.PageTemplate = "generic"; + rule.Order = 10; + + // Metadata + + // (no metadata) + + // Categories + + rule.Categories.Add(new Category { Name = "General", DisplayName = "General" }); + rule.Categories.Add(new Category { Name = "OtherSettings", DisplayName = "Other Settings" }); + + // Data source + + rule.DataSource = new DataSource + { + Persistence = "ProjectFile", + SourceOfDefaultValue = DefaultValueSourceLocation.AfterContext, + HasConfigurationCondition = false, + }; + + // Properties + + rule.Properties.Add(new StringProperty + { + Name = "MyProperty", + DisplayName = "My Property", + Description = Resources.MyPropertyPage_PropertyDescription, + Category = "OtherSettings" + }); + + rule.EndInit(); + + return rule; + } + } +} diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Resources.Designer.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Resources.Designer.cs index 592cbdbd18..ee12ca5a36 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Resources.Designer.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace Microsoft.VisualStudio { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { @@ -159,6 +159,24 @@ internal static string MsBuildMissingValueToRename { } } + /// + /// Looks up a localized string similar to My In-Memory Page πŸ˜€. + /// + internal static string MyPropertyPage_DisplayName { + get { + return ResourceManager.GetString("MyPropertyPage_DisplayName", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰. + /// + internal static string MyPropertyPage_PropertyDescription { + get { + return ResourceManager.GetString("MyPropertyPage_PropertyDescription", resourceCulture); + } + } + /// /// Looks up a localized string similar to {0} - {1}. /// diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Resources.resx b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Resources.resx index 6889690e8a..2b1b66b741 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Resources.resx +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Resources.resx @@ -194,4 +194,10 @@ This project was loaded using the wrong project type, likely as a result of rena (None) Special value to show in the project property pages when a property has no value. + + My In-Memory Page πŸ˜€ + + + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + \ No newline at end of file diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.cs.xlf b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.cs.xlf index 1192b9ddb9..edd0783762 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.cs.xlf +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.cs.xlf @@ -12,6 +12,16 @@ Importy + + My In-Memory Page πŸ˜€ + My In-Memory Page πŸ˜€ + + + + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + + {0} - {1} {0} – {1} diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.de.xlf b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.de.xlf index 5ccaf819a4..0f3725b41a 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.de.xlf +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.de.xlf @@ -12,6 +12,16 @@ Importe + + My In-Memory Page πŸ˜€ + My In-Memory Page πŸ˜€ + + + + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + + {0} - {1} {0} – {1} diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.es.xlf b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.es.xlf index c74a7c5a24..5a9e2f4f8a 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.es.xlf +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.es.xlf @@ -12,6 +12,16 @@ Importaciones + + My In-Memory Page πŸ˜€ + My In-Memory Page πŸ˜€ + + + + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + + {0} - {1} {0} - {1} diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.fr.xlf b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.fr.xlf index 0348e940b3..81531b86b2 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.fr.xlf +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.fr.xlf @@ -12,6 +12,16 @@ Importations + + My In-Memory Page πŸ˜€ + My In-Memory Page πŸ˜€ + + + + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + + {0} - {1} {0} - {1} diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.it.xlf b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.it.xlf index ddb50cd2fa..8ecde8972d 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.it.xlf +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.it.xlf @@ -12,6 +12,16 @@ Importazioni + + My In-Memory Page πŸ˜€ + My In-Memory Page πŸ˜€ + + + + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + + {0} - {1} {0} - {1} diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.ja.xlf b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.ja.xlf index 64d154295c..d2fbd3a472 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.ja.xlf +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.ja.xlf @@ -12,6 +12,16 @@ γ‚€γƒ³γƒγƒΌγƒˆ + + My In-Memory Page πŸ˜€ + My In-Memory Page πŸ˜€ + + + + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + + {0} - {1} {0} - {1} diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.ko.xlf b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.ko.xlf index da658818c4..79a2fe5b5f 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.ko.xlf +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.ko.xlf @@ -12,6 +12,16 @@ κ°€μ Έμ˜€κΈ° + + My In-Memory Page πŸ˜€ + My In-Memory Page πŸ˜€ + + + + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + + {0} - {1} {0} - {1} diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.pl.xlf b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.pl.xlf index fe9e52e975..2a741124ed 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.pl.xlf +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.pl.xlf @@ -12,6 +12,16 @@ Importy + + My In-Memory Page πŸ˜€ + My In-Memory Page πŸ˜€ + + + + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + + {0} - {1} {0} β€” {1} diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.pt-BR.xlf b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.pt-BR.xlf index bcdb893603..53f7356f64 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.pt-BR.xlf +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.pt-BR.xlf @@ -12,6 +12,16 @@ ImportaΓ§Γ΅es + + My In-Memory Page πŸ˜€ + My In-Memory Page πŸ˜€ + + + + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + + {0} - {1} {0} – {1} diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.ru.xlf b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.ru.xlf index efbb415ccc..58885d81e8 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.ru.xlf +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.ru.xlf @@ -12,6 +12,16 @@ Π˜ΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΡƒΠ΅Ρ‚ + + My In-Memory Page πŸ˜€ + My In-Memory Page πŸ˜€ + + + + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + + {0} - {1} {0}Β β€” {1} diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.tr.xlf b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.tr.xlf index 0e91ba39fd..5bce3ade3e 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.tr.xlf +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.tr.xlf @@ -12,6 +12,16 @@ Almalar + + My In-Memory Page πŸ˜€ + My In-Memory Page πŸ˜€ + + + + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + + {0} - {1} {0} - {1} diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.zh-Hans.xlf b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.zh-Hans.xlf index bd3099e9e2..74ac60b47e 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.zh-Hans.xlf +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.zh-Hans.xlf @@ -12,6 +12,16 @@ ε―Όε…₯ + + My In-Memory Page πŸ˜€ + My In-Memory Page πŸ˜€ + + + + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + + {0} - {1} {0} - {1} diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.zh-Hant.xlf b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.zh-Hant.xlf index 6aeb91c86a..b17ef4fa5c 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.zh-Hant.xlf +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/xlf/Resources.zh-Hant.xlf @@ -12,6 +12,16 @@ 匯ε…₯ + + My In-Memory Page πŸ˜€ + My In-Memory Page πŸ˜€ + + + + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + πŸŽ‰ Put anything you want here! It doesn't matter! πŸŽ‰ + + {0} - {1} {0} - {1}