提交 03cf34c3 编写于 作者: D David Poeschl 提交者: GitHub

Merge pull request #14514 from dpoeschl/NamingStylesRedo

Convert Naming Styles to a grid-based UI
......@@ -77,6 +77,20 @@ public async Task TestPascalCaseMethod_PropertyAccessorsAreIgnored()
@"class C
{
public int P { [|get|]; set; }
}",
options: MethodNamesArePascalCase);
}
[WpfFact, Trait(Traits.Feature, Traits.Features.NamingStyle)]
public async Task TestPascalCaseMethod_IndexerNameIsIgnored()
{
await TestMissingAsync(
@"class C
{
public int [|this|][int index]
{
get { return 1; }
}
}",
options: MethodNamesArePascalCase);
}
......
......@@ -27,16 +27,14 @@ public partial class NamingStylesTests : AbstractCSharpDiagnosticProviderBasedUs
return options;
}
[WpfFact, Trait(Traits.Feature, Traits.Features.NamingStyle)]
private string ClassNamesArePascalCaseOptionString()
{
var symbolSpecification = new SymbolSpecification(
Guid.NewGuid(),
"Name",
Guid.NewGuid(),
"Name",
SpecializedCollections.SingletonEnumerable(new SymbolSpecification.SymbolKindOrTypeKind(TypeKind.Class)).ToList(),
SpecializedCollections.EmptyList<SymbolSpecification.AccessibilityKind>(),
SpecializedCollections.EmptyList<SymbolSpecification.ModifierKind>(),
SpecializedCollections.EmptyList<string>());
SpecializedCollections.EmptyList<SymbolSpecification.ModifierKind>());
var namingStyle = new NamingStyle();
namingStyle.CapitalizationScheme = Capitalization.PascalCase;
......@@ -50,7 +48,6 @@ private string ClassNamesArePascalCaseOptionString()
namingRule.SymbolSpecificationID = symbolSpecification.ID;
namingRule.NamingStyleID = namingStyle.ID;
namingRule.EnforcementLevel = DiagnosticSeverity.Error;
namingRule.Title = "Title";
var info = new SerializableNamingStylePreferencesInfo();
info.SymbolSpecifications.Add(symbolSpecification);
......@@ -60,7 +57,6 @@ private string ClassNamesArePascalCaseOptionString()
return info.CreateXElement().ToString();
}
[WpfFact, Trait(Traits.Feature, Traits.Features.NamingStyle)]
private string MethodNamesArePascalCaseOptionString()
{
var symbolSpecification = new SymbolSpecification(
......@@ -68,8 +64,7 @@ private string MethodNamesArePascalCaseOptionString()
"Name",
SpecializedCollections.SingletonEnumerable(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Method)).ToList(),
SpecializedCollections.EmptyList<SymbolSpecification.AccessibilityKind>(),
SpecializedCollections.EmptyList<SymbolSpecification.ModifierKind>(),
SpecializedCollections.EmptyList<string>());
SpecializedCollections.EmptyList<SymbolSpecification.ModifierKind>());
var namingStyle = new NamingStyle();
namingStyle.CapitalizationScheme = Capitalization.PascalCase;
......@@ -83,7 +78,6 @@ private string MethodNamesArePascalCaseOptionString()
namingRule.SymbolSpecificationID = symbolSpecification.ID;
namingRule.NamingStyleID = namingStyle.ID;
namingRule.EnforcementLevel = DiagnosticSeverity.Error;
namingRule.Title = "Title";
var info = new SerializableNamingStylePreferencesInfo();
info.SymbolSpecifications.Add(symbolSpecification);
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using Microsoft.CodeAnalysis.SymbolCategorization;
namespace Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles
{
internal class NamingRule
{
public readonly string Title;
public readonly ImmutableArray<NamingRule> Children;
public readonly SymbolSpecification SymbolSpecification;
public readonly NamingStyle NamingStyle;
public readonly DiagnosticSeverity EnforcementLevel;
public NamingRule(string title, ImmutableArray<NamingRule> children, SymbolSpecification symbolSpecification, NamingStyle namingStyle, DiagnosticSeverity enforcementLevel)
public NamingRule(SymbolSpecification symbolSpecification, NamingStyle namingStyle, DiagnosticSeverity enforcementLevel)
{
Title = title;
Children = children;
SymbolSpecification = symbolSpecification;
NamingStyle = namingStyle;
EnforcementLevel = enforcementLevel;
}
public bool AppliesTo(ISymbol symbol, ISymbolCategorizationService categorizationService)
{
return SymbolSpecification.AppliesTo(symbol, categorizationService);
}
internal NamingRule GetBestMatchingRule(ISymbol symbol, ISymbolCategorizationService categorizationService)
{
Debug.Assert(SymbolSpecification.AppliesTo(symbol, categorizationService));
var matchingChild = Children.FirstOrDefault(r => r.AppliesTo(symbol, categorizationService));
return matchingChild?.GetBestMatchingRule(symbol, categorizationService) ?? this;
}
public bool AppliesTo(ISymbol symbol)
=> SymbolSpecification.AppliesTo(symbol);
public bool IsNameCompliant(string name, out string failureReason)
{
return NamingStyle.IsNameCompliant(name, out failureReason);
}
=> NamingStyle.IsNameCompliant(name, out failureReason);
}
}
\ No newline at end of file
......@@ -4,7 +4,6 @@
using System.Linq;
using System.Xml.Linq;
using Microsoft.CodeAnalysis.Simplification;
using Microsoft.CodeAnalysis.SymbolCategorization;
namespace Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles
{
......@@ -47,8 +46,6 @@ public override void Initialize(AnalysisContext context)
private void CompilationStartAction(CompilationStartAnalysisContext context)
{
var workspace = (context.Options as WorkspaceAnalyzerOptions)?.Workspace;
var categorizationService = workspace.Services.GetService<ISymbolCategorizationService>();
var optionSet = (context.Options as WorkspaceAnalyzerOptions)?.Workspace.Options;
var currentValue = optionSet.GetOption(SimplificationOptions.NamingPreferences, context.Compilation.Language);
......@@ -62,15 +59,15 @@ private void CompilationStartAction(CompilationStartAnalysisContext context)
var viewModel = SerializableNamingStylePreferencesInfo.FromXElement(XElement.Parse(currentValue));
var preferencesInfo = viewModel.GetPreferencesInfo();
context.RegisterSymbolAction(
symbolContext => SymbolAction(symbolContext, preferencesInfo, categorizationService),
symbolContext => SymbolAction(symbolContext, preferencesInfo),
_symbolKinds);
}
}
private void SymbolAction(SymbolAnalysisContext context, NamingStylePreferencesInfo preferences, ISymbolCategorizationService categorizationService)
private void SymbolAction(SymbolAnalysisContext context, NamingStylePreferencesInfo preferences)
{
NamingRule applicableRule;
if (preferences.TryGetApplicableRule(context.Symbol, categorizationService, out applicableRule))
if (preferences.TryGetApplicableRule(context.Symbol, out applicableRule))
{
string failureReason;
if (applicableRule.EnforcementLevel != DiagnosticSeverity.Hidden &&
......@@ -78,7 +75,7 @@ private void SymbolAction(SymbolAnalysisContext context, NamingStylePreferencesI
{
var descriptor = new DiagnosticDescriptor(IDEDiagnosticIds.NamingRuleId,
s_localizableTitleNamingStyle,
string.Format(FeaturesResources._0_naming_violation_1, applicableRule.Title, failureReason),
string.Format(FeaturesResources.Naming_rule_violation_0, failureReason),
DiagnosticCategory.Style,
applicableRule.EnforcementLevel,
isEnabledByDefault: true);
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis.SymbolCategorization;
namespace Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles
{
......@@ -16,7 +14,7 @@ public NamingStylePreferencesInfo(ImmutableArray<NamingRule> namingRules)
NamingRules = namingRules;
}
internal bool TryGetApplicableRule(ISymbol symbol, ISymbolCategorizationService categorizationService, out NamingRule applicableRule)
internal bool TryGetApplicableRule(ISymbol symbol, out NamingRule applicableRule)
{
if (NamingRules == null)
{
......@@ -29,24 +27,38 @@ internal bool TryGetApplicableRule(ISymbol symbol, ISymbolCategorizationService
applicableRule = null;
return false;
}
var matchingRule = NamingRules.FirstOrDefault(r => r.AppliesTo(symbol, categorizationService));
if (matchingRule == null)
foreach (var namingRule in NamingRules)
{
applicableRule = null;
return false;
if (namingRule.AppliesTo(symbol))
{
applicableRule = namingRule;
return true;
}
}
applicableRule = matchingRule.GetBestMatchingRule(symbol, categorizationService);
return true;
applicableRule = null;
return false;
}
private bool IsSymbolNameAnalyzable(ISymbol symbol)
{
var methodSymbol = symbol as IMethodSymbol;
if (methodSymbol != null && methodSymbol.MethodKind != MethodKind.Ordinary)
if (symbol.Kind == SymbolKind.Method)
{
return false;
var methodSymbol = symbol as IMethodSymbol;
if (methodSymbol != null && methodSymbol.MethodKind != MethodKind.Ordinary)
{
return false;
}
}
if (symbol.Kind == SymbolKind.Property)
{
var propertySymbol = symbol as IPropertySymbol;
if (propertySymbol != null && propertySymbol.IsIndexer)
{
return false;
}
}
return true;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
namespace Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles
{
internal interface INamingStyle
{
Guid ID { get; }
string CreateName(IEnumerable<string> words);
IEnumerable<string> MakeCompliant(string name);
bool IsNameCompliant(string name, out string failureReason);
}
}
\ No newline at end of file
......@@ -8,7 +8,7 @@
namespace Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles
{
internal class NamingStyle : INamingStyle
internal class NamingStyle
{
public Guid ID { get; set; }
public string Name { get; set; }
......@@ -116,7 +116,7 @@ public bool IsNameCompliant(string name, out string failureReason)
{
if (!char.IsLower(words.First()[0]))
{
failureReason = FeaturesResources.The_first_word_0_must_begin_with_a_lower_case_character;
failureReason = string.Format(FeaturesResources.The_first_word_0_must_begin_with_a_lower_case_character, words.First());
}
var violations = words.Skip(1).Where(w => !char.IsUpper(w[0]));
......@@ -296,9 +296,9 @@ internal XElement CreateXElement()
return new XElement(nameof(NamingStyle),
new XAttribute(nameof(ID), ID),
new XAttribute(nameof(Name), Name),
new XAttribute(nameof(Prefix), Prefix),
new XAttribute(nameof(Suffix), Suffix),
new XAttribute(nameof(WordSeparator), WordSeparator),
new XAttribute(nameof(Prefix), Prefix ?? string.Empty),
new XAttribute(nameof(Suffix), Suffix ?? string.Empty),
new XAttribute(nameof(WordSeparator), WordSeparator ?? string.Empty),
new XAttribute(nameof(CapitalizationScheme), CapitalizationScheme));
}
......
......@@ -10,22 +10,13 @@ namespace Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles
{
internal class SerializableNamingRule
{
public string Title;
public List<SerializableNamingRule> Children;
public Guid SymbolSpecificationID;
public Guid NamingStyleID;
public DiagnosticSeverity EnforcementLevel;
internal SerializableNamingRule()
{
Children = new List<SerializableNamingRule>();
}
public NamingRule GetRule(SerializableNamingStylePreferencesInfo info)
{
return new NamingRule(
Title,
Children.Select(c => c.GetRule(info)).ToImmutableArray(),
info.GetSymbolSpecification(SymbolSpecificationID),
info.GetNamingStyle(NamingStyleID),
EnforcementLevel);
......@@ -34,33 +25,19 @@ public NamingRule GetRule(SerializableNamingStylePreferencesInfo info)
internal XElement CreateXElement()
{
var element = new XElement(nameof(SerializableNamingRule),
new XAttribute(nameof(Title), Title),
new XAttribute(nameof(SymbolSpecificationID), SymbolSpecificationID),
new XAttribute(nameof(NamingStyleID), NamingStyleID),
new XAttribute(nameof(EnforcementLevel), EnforcementLevel));
foreach (var child in Children)
{
element.Add(child.CreateXElement());
}
return element;
}
internal static SerializableNamingRule FromXElement(XElement namingRuleElement)
{
var result = new SerializableNamingRule();
result.Title = namingRuleElement.Attribute(nameof(Title)).Value;
result.EnforcementLevel = (DiagnosticSeverity)Enum.Parse(typeof(DiagnosticSeverity), namingRuleElement.Attribute(nameof(EnforcementLevel)).Value);
result.NamingStyleID = Guid.Parse(namingRuleElement.Attribute(nameof(NamingStyleID)).Value);
result.SymbolSpecificationID = Guid.Parse(namingRuleElement.Attribute(nameof(SymbolSpecificationID)).Value);
result.Children = new List<SerializableNamingRule>();
foreach (var childElement in namingRuleElement.Elements(nameof(SerializableNamingRule)))
{
result.Children.Add(FromXElement(childElement));
}
return result;
}
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.Simplification;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
......@@ -19,7 +20,7 @@ internal class SerializableNamingStylePreferencesInfo
public List<SymbolSpecification> SymbolSpecifications;
public List<NamingStyle> NamingStyles;
public List<SerializableNamingRule> NamingRules;
private readonly static int _serializationVersion = 1;
private readonly static int _serializationVersion = 3;
internal SerializableNamingStylePreferencesInfo()
{
......@@ -92,6 +93,12 @@ internal static SerializableNamingStylePreferencesInfo FromXElement(XElement nam
{
var namingPreferencesInfo = new SerializableNamingStylePreferencesInfo();
var serializationVersion = int.Parse(namingPreferencesInfoElement.Attribute("SerializationVersion").Value);
if (serializationVersion != _serializationVersion)
{
namingPreferencesInfoElement = XElement.Parse(SimplificationOptions.NamingPreferences.DefaultValue);
}
namingPreferencesInfo.SetSymbolSpecificationListFromXElement(namingPreferencesInfoElement.Element(nameof(SymbolSpecifications)));
namingPreferencesInfo.SetNamingStyleListFromXElement(namingPreferencesInfoElement.Element(nameof(NamingStyles)));
namingPreferencesInfo.SetNamingRuleTreeFromXElement(namingPreferencesInfoElement.Element(nameof(NamingRules)));
......
......@@ -6,7 +6,6 @@
using System.Xml.Linq;
using Microsoft.CodeAnalysis.Editing;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.SymbolCategorization;
namespace Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles
{
......@@ -14,10 +13,10 @@ internal class SymbolSpecification
{
public Guid ID { get; private set; }
public string Name { get; private set; }
public IList<SymbolKindOrTypeKind> ApplicableSymbolKindList { get; private set; }
public IList<AccessibilityKind> ApplicableAccessibilityList { get; private set; }
public IList<ModifierKind> RequiredModifierList { get; private set; }
public IList<string> RequiredCustomTagList { get; private set; }
internal SymbolSpecification()
{
......@@ -51,27 +50,28 @@ internal SymbolSpecification()
};
RequiredModifierList = new List<ModifierKind>();
RequiredCustomTagList = new List<string>();
}
public SymbolSpecification(Guid id, string symbolSpecName, IList<SymbolKindOrTypeKind> symbolKindList, IList<AccessibilityKind> accessibilityKindList, IList<ModifierKind> modifierList, IList<string> customTagList)
public SymbolSpecification(Guid id, string symbolSpecName,
IList<SymbolKindOrTypeKind> symbolKindList,
IList<AccessibilityKind> accessibilityKindList,
IList<ModifierKind> modifiers)
{
ID = id;
Name = symbolSpecName;
ApplicableAccessibilityList = accessibilityKindList;
RequiredModifierList = modifierList;
RequiredModifierList = modifiers;
ApplicableSymbolKindList = symbolKindList;
RequiredCustomTagList = customTagList;
}
internal bool AppliesTo(ISymbol symbol, ISymbolCategorizationService categorizationService)
internal bool AppliesTo(ISymbol symbol)
{
if (ApplicableSymbolKindList.Any() && !ApplicableSymbolKindList.Any(k => k.AppliesTo(symbol)))
{
return false;
}
// Modifiers must match exactly
if (!RequiredModifierList.All(m => m.MatchesSymbol(symbol)))
{
return false;
......@@ -82,25 +82,17 @@ internal bool AppliesTo(ISymbol symbol, ISymbolCategorizationService categorizat
return false;
}
// TODO: More efficient to find the categorizers that are relevant and only check those
var applicableCategories = categorizationService.GetCategorizers().SelectMany(c => c.Categorize(symbol));
if (!RequiredCustomTagList.All(t => applicableCategories.Contains(t)))
{
return false;
}
return true;
}
internal XElement CreateXElement()
{
return new XElement(nameof(SymbolSpecification),
return new XElement(nameof(SymbolSpecification),
new XAttribute(nameof(ID), ID),
new XAttribute(nameof(Name), Name),
CreateSymbolKindsXElement(),
CreateAccessibilitiesXElement(),
CreateModifiersXElement(),
CreateCustomTagsXElement());
CreateModifiersXElement());
}
private XElement CreateSymbolKindsXElement()
......@@ -139,18 +131,6 @@ private XElement CreateModifiersXElement()
return modifiersElement;
}
private XElement CreateCustomTagsXElement()
{
var customTagsElement = new XElement(nameof(RequiredCustomTagList));
foreach (var customTag in RequiredCustomTagList)
{
customTagsElement.Add(new XElement("CustomTag", customTag));
}
return customTagsElement;
}
internal static SymbolSpecification FromXElement(XElement symbolSpecificationElement)
{
var result = new SymbolSpecification();
......@@ -160,32 +140,33 @@ internal static SymbolSpecification FromXElement(XElement symbolSpecificationEle
result.PopulateSymbolKindListFromXElement(symbolSpecificationElement.Element(nameof(ApplicableSymbolKindList)));
result.PopulateAccessibilityListFromXElement(symbolSpecificationElement.Element(nameof(ApplicableAccessibilityList)));
result.PopulateModifierListFromXElement(symbolSpecificationElement.Element(nameof(RequiredModifierList)));
result.PopulateCustomTagListFromXElement(symbolSpecificationElement.Element(nameof(RequiredCustomTagList)));
return result;
}
private void PopulateSymbolKindListFromXElement(XElement symbolKindListElement)
{
ApplicableSymbolKindList = new List<SymbolKindOrTypeKind>();
var applicableSymbolKindList = new List<SymbolKindOrTypeKind>();
foreach (var symbolKindElement in symbolKindListElement.Elements(nameof(SymbolKind)))
{
ApplicableSymbolKindList.Add(SymbolKindOrTypeKind.AddSymbolKindFromXElement(symbolKindElement));
applicableSymbolKindList.Add(SymbolKindOrTypeKind.AddSymbolKindFromXElement(symbolKindElement));
}
foreach (var typeKindElement in symbolKindListElement.Elements(nameof(TypeKind)))
{
ApplicableSymbolKindList.Add(SymbolKindOrTypeKind.AddTypeKindFromXElement(typeKindElement));
applicableSymbolKindList.Add(SymbolKindOrTypeKind.AddTypeKindFromXElement(typeKindElement));
}
ApplicableSymbolKindList = applicableSymbolKindList;
}
private void PopulateAccessibilityListFromXElement(XElement accessibilityListElement)
{
ApplicableAccessibilityList = new List<AccessibilityKind>();
var applicableAccessibilityList = new List<AccessibilityKind>();
foreach (var accessibilityElement in accessibilityListElement.Elements(nameof(AccessibilityKind)))
{
ApplicableAccessibilityList.Add(AccessibilityKind.FromXElement(accessibilityElement));
applicableAccessibilityList.Add(AccessibilityKind.FromXElement(accessibilityElement));
}
ApplicableAccessibilityList = applicableAccessibilityList;
}
private void PopulateModifierListFromXElement(XElement modifierListElement)
......@@ -197,15 +178,6 @@ private void PopulateModifierListFromXElement(XElement modifierListElement)
}
}
private void PopulateCustomTagListFromXElement(XElement customTagListElement)
{
RequiredCustomTagList = new List<string>();
foreach (var customTag in customTagListElement.Elements("CustomTag"))
{
RequiredCustomTagList.Add(customTag.Value);
}
}
public class SymbolKindOrTypeKind
{
public SymbolKind? SymbolKind { get; set; }
......@@ -256,7 +228,7 @@ internal static SymbolKindOrTypeKind AddTypeKindFromXElement(XElement typeKindEl
return new SymbolKindOrTypeKind((TypeKind)Enum.Parse(typeof(TypeKind), typeKindElement.Value));
}
}
public class AccessibilityKind
{
public Accessibility Accessibility { get; set; }
......@@ -384,7 +356,6 @@ internal static ModifierKind FromXElement(XElement modifierElement)
return new ModifierKind((ModifierKindEnum)(ModifierKindEnum)Enum.Parse((Type)typeof(ModifierKindEnum), (string)modifierElement.Value));
}
}
public enum ModifierKindEnum
{
IsAbstract,
......
......@@ -296,10 +296,8 @@
<Compile Include="Structure\Syntax\AbstractSyntaxStructureProvider.cs" />
<Compile Include="Structure\Syntax\AbstractSyntaxTriviaStructureProvider.cs" />
<Compile Include="Structure\Syntax\BlockSpanCollector.cs" />
<Compile Include="SymbolCategorization\ISymbolCategorizer.cs" />
<Compile Include="Diagnostics\Analyzers\NamingStyles\NamingRule.cs" />
<Compile Include="Diagnostics\Analyzers\NamingStyles\NamingStylePreferencesInfo.cs" />
<Compile Include="Diagnostics\Analyzers\NamingStyles\Serialization\INamingStyle.cs" />
<Compile Include="Diagnostics\Analyzers\NamingStyles\Serialization\NamingStyle.cs" />
<Compile Include="Diagnostics\Analyzers\NamingStyles\Serialization\SerializableNamingRule.cs" />
<Compile Include="Diagnostics\Analyzers\NamingStyles\Serialization\SerializableNamingStylePreferencesInfo.cs" />
......@@ -664,10 +662,6 @@
<Compile Include="SolutionCrawler\WorkCoordinator.WorkItem.cs" />
<Compile Include="SolutionCrawler\SolutionCrawlerRegistrationService.cs" />
<Compile Include="SpellCheck\AbstractSpellCheckCodeFixProvider.cs" />
<Compile Include="SymbolCategorization\ExportSymbolCategorizerAttribute.cs" />
<Compile Include="SymbolCategorization\ISymbolCategorizationService.cs" />
<Compile Include="SymbolCategorization\SymbolCategorizationService.cs" />
<Compile Include="SymbolCategorization\ThreadLocalSymbolCategorizer.cs" />
<Compile Include="Common\SymbolDisplayPartKindTags.cs" />
<Compile Include="UseAutoProperty\AbstractUseAutoPropertyCodeFixProvider.cs" />
<Compile Include="UseAutoProperty\AbstractUseAutoPropertyAnalyzer.cs" />
......
......@@ -79,15 +79,6 @@ internal class FeaturesResources {
}
}
/// <summary>
/// Looks up a localized string similar to &apos;{0}&apos; naming violation - {1}.
/// </summary>
internal static string _0_naming_violation_1 {
get {
return ResourceManager.GetString("_0_naming_violation_1", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Accessing captured variable &apos;{0}&apos; that hasn&apos;t been accessed before in {1} will prevent the debug session from continuing..
/// </summary>
......@@ -347,6 +338,24 @@ internal class FeaturesResources {
}
}
/// <summary>
/// Looks up a localized string similar to All lowercase.
/// </summary>
internal static string All_lowercase {
get {
return ResourceManager.GetString("All_lowercase", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to All uppercase.
/// </summary>
internal static string All_uppercase {
get {
return ResourceManager.GetString("All_uppercase", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to An active statement has been removed from its original method. You must revert your changes to continue or restart the debugging session..
/// </summary>
......@@ -495,6 +504,15 @@ internal class FeaturesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Camel Case.
/// </summary>
internal static string Camel_Case {
get {
return ResourceManager.GetString("Camel_Case", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to can&apos;t not construct final tree.
/// </summary>
......@@ -1026,6 +1044,15 @@ internal class FeaturesResources {
}
}
/// <summary>
/// Looks up a localized string similar to First word capitalized.
/// </summary>
internal static string First_word_capitalized {
get {
return ResourceManager.GetString("First_word_capitalized", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Fix all occurrences.
/// </summary>
......@@ -1948,6 +1975,15 @@ internal class FeaturesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Naming rule violation: {0}.
/// </summary>
internal static string Naming_rule_violation_0 {
get {
return ResourceManager.GetString("Naming_rule_violation_0", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Naming Styles.
/// </summary>
......@@ -2076,6 +2112,15 @@ internal class FeaturesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Pascal Case.
/// </summary>
internal static string Pascal_Case {
get {
return ResourceManager.GetString("Pascal_Case", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to &lt;Pending&gt;.
/// </summary>
......
......@@ -897,8 +897,8 @@ Do you want to continue?</value>
<data name="Fix_Name_Violation_colon_0" xml:space="preserve">
<value>Fix Name Violation: {0}</value>
</data>
<data name="_0_naming_violation_1" xml:space="preserve">
<value>'{0}' naming violation - {1}</value>
<data name="Naming_rule_violation_0" xml:space="preserve">
<value>Naming rule violation: {0}</value>
<comment>{0} is the rule title, {1} is the way in which the rule was violated</comment>
</data>
<data name="The_first_word_0_must_begin_with_a_lower_case_character" xml:space="preserve">
......@@ -1139,4 +1139,19 @@ This version used in: {2}</value>
<data name="Snippets" xml:space="preserve">
<value>Snippets</value>
</data>
<data name="All_lowercase" xml:space="preserve">
<value>All lowercase</value>
</data>
<data name="All_uppercase" xml:space="preserve">
<value>All uppercase</value>
</data>
<data name="Camel_Case" xml:space="preserve">
<value>Camel Case</value>
</data>
<data name="First_word_capitalized" xml:space="preserve">
<value>First word capitalized</value>
</data>
<data name="Pascal_Case" xml:space="preserve">
<value>Pascal Case</value>
</data>
</root>
\ No newline at end of file
using System;
using System.Composition;
namespace Microsoft.CodeAnalysis.SymbolCategorization
{
[MetadataAttribute]
[AttributeUsage(AttributeTargets.Class)]
internal sealed class ExportSymbolCategorizerAttribute : ExportAttribute
{
public ExportSymbolCategorizerAttribute() : base(typeof(ISymbolCategorizer))
{
}
}
}
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Host;
namespace Microsoft.CodeAnalysis.SymbolCategorization
{
internal interface ISymbolCategorizationService : IWorkspaceService
{
ImmutableArray<ISymbolCategorizer> GetCategorizers();
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
namespace Microsoft.CodeAnalysis.SymbolCategorization
{
internal interface ISymbolCategorizer
{
/// <summary>
/// Returns the set of categories that this categorizer is capable of producing.
/// </summary>
ImmutableArray<string> SupportedCategories { get; }
/// <summary>
/// Returns the set of categories that apply to the given symbol.
/// </summary>
ImmutableArray<string> Categorize(ISymbol symbol);
}
}
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
namespace Microsoft.CodeAnalysis.SymbolCategorization
{
[ExportWorkspaceServiceFactory(typeof(ISymbolCategorizationService)), Shared]
internal class SymbolCategorizationServiceFactory : IWorkspaceServiceFactory
{
private readonly SymbolCategorizationService service;
[ImportingConstructor]
public SymbolCategorizationServiceFactory([ImportMany] IEnumerable<ISymbolCategorizer> symbolCategorizers)
{
service = new SymbolCategorizationService(symbolCategorizers);
}
public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)
{
return service;
}
internal class SymbolCategorizationService : ISymbolCategorizationService
{
private ImmutableArray<ISymbolCategorizer> _symbolCategorizers;
public SymbolCategorizationService(IEnumerable<ISymbolCategorizer> symbolCategorizers)
{
this._symbolCategorizers = symbolCategorizers.ToImmutableArray();
}
public ImmutableArray<ISymbolCategorizer> GetCategorizers()
{
return _symbolCategorizers;
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.Linq;
namespace Microsoft.CodeAnalysis.SymbolCategorization
{
// Motivating example for ISymbolCategorizer
// [ExportSymbolCategorizer, Shared]
internal class ThreadLocalSymbolCategorizer : ISymbolCategorizer
{
private const string _threadLocalCategoryName = "[ThreadStatic]";
private readonly ImmutableArray<string> matchingCategoryArray = new[] { _threadLocalCategoryName }.ToImmutableArray();
public ImmutableArray<string> SupportedCategories
{
get
{
return matchingCategoryArray;
}
}
public ImmutableArray<string> Categorize(ISymbol symbol)
{
return symbol.GetAttributes().Any(a => a.AttributeClass.MetadataName.Contains("ThreadStatic"))
? matchingCategoryArray
: ImmutableArray<string>.Empty;
}
}
}
......@@ -92,6 +92,7 @@
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Core" />
<Reference Include="System.Design" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" />
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.LanguageServices.Implementation.Options;
using Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences;
using Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style;
namespace Microsoft.VisualStudio.LanguageServices.CSharp.Options
{
[Guid(Guids.CSharpOptionPageNamingStyleIdString)]
internal class NamingStylesOptionPage : AbstractOptionPage
{
private NamingStyleOptionPageControl _grid;
private INotificationService _notificationService;
protected override AbstractOptionPageControl CreateOptionPage(IServiceProvider serviceProvider)
{
return new NamingStylesOptionPageControl(serviceProvider, LanguageNames.CSharp);
var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));
var workspace = componentModel.GetService<VisualStudioWorkspace>();
_notificationService = workspace.Services.GetService<INotificationService>();
_grid = new NamingStyleOptionPageControl(serviceProvider, _notificationService, LanguageNames.CSharp);
return _grid;
}
protected override void OnDeactivate(CancelEventArgs e)
{
if (_grid.ContainsErrors())
{
e.Cancel = true;
_notificationService.SendNotification(ServicesVSResources.Some_naming_rules_are_incomplete_Please_complete_or_remove_them);
}
base.OnDeactivate(e);
}
}
}
......@@ -451,15 +451,6 @@ internal class ServicesVSResources {
}
}
/// <summary>
/// Looks up a localized string similar to Custom Tags (must match all).
/// </summary>
internal static string Custom_Tags_must_match_all {
get {
return ResourceManager.GetString("Custom_Tags_must_match_all", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Debugger.
/// </summary>
......@@ -977,6 +968,24 @@ internal class ServicesVSResources {
}
}
/// <summary>
/// Looks up a localized string similar to Manage specifications.
/// </summary>
internal static string Manage_specifications {
get {
return ResourceManager.GetString("Manage_specifications", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Manage styles.
/// </summary>
internal static string Manage_styles {
get {
return ResourceManager.GetString("Manage_styles", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Maximum number of documents are open..
/// </summary>
......@@ -1488,6 +1497,15 @@ internal class ServicesVSResources {
}
}
/// <summary>
/// Looks up a localized string similar to Reorder.
/// </summary>
internal static string Reorder {
get {
return ResourceManager.GetString("Reorder", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Required Prefix:.
/// </summary>
......@@ -1569,6 +1587,15 @@ internal class ServicesVSResources {
}
}
/// <summary>
/// Looks up a localized string similar to Severity.
/// </summary>
internal static string Severity {
get {
return ResourceManager.GetString("Severity", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Severity:.
/// </summary>
......@@ -1632,6 +1659,33 @@ internal class ServicesVSResources {
}
}
/// <summary>
/// Looks up a localized string similar to Some naming rules are incomplete. Please complete or remove them..
/// </summary>
internal static string Some_naming_rules_are_incomplete_Please_complete_or_remove_them {
get {
return ResourceManager.GetString("Some_naming_rules_are_incomplete_Please_complete_or_remove_them", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Specification.
/// </summary>
internal static string Specification {
get {
return ResourceManager.GetString("Specification", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Style.
/// </summary>
internal static string Style {
get {
return ResourceManager.GetString("Style", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Summary:.
/// </summary>
......@@ -1769,6 +1823,15 @@ internal class ServicesVSResources {
}
}
/// <summary>
/// Looks up a localized string similar to This item cannot be deleted because it is used by an existing Naming Rule..
/// </summary>
internal static string This_item_cannot_be_deleted_because_it_is_used_by_an_existing_Naming_Rule {
get {
return ResourceManager.GetString("This_item_cannot_be_deleted_because_it_is_used_by_an_existing_Naming_Rule", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to This workspace only supports opening documents on the UI thread..
/// </summary>
......
......@@ -567,9 +567,6 @@ Use the dropdown to view and switch to other projects this file may belong to.</
<data name="Pascal_Case_Name" xml:space="preserve">
<value>Pascal Case Name</value>
</data>
<data name="Custom_Tags_must_match_all" xml:space="preserve">
<value>Custom Tags (must match all)</value>
</data>
<data name="Severity_colon" xml:space="preserve">
<value>Severity:</value>
</data>
......@@ -762,4 +759,28 @@ Additional information: {1}</value>
<data name="Prefer_inlined_variable_declaration" xml:space="preserve">
<value>Prefer inlined variable declaration</value>
</data>
<data name="Some_naming_rules_are_incomplete_Please_complete_or_remove_them" xml:space="preserve">
<value>Some naming rules are incomplete. Please complete or remove them.</value>
</data>
<data name="Manage_specifications" xml:space="preserve">
<value>Manage specifications</value>
</data>
<data name="Manage_styles" xml:space="preserve">
<value>Manage styles</value>
</data>
<data name="Reorder" xml:space="preserve">
<value>Reorder</value>
</data>
<data name="Severity" xml:space="preserve">
<value>Severity</value>
</data>
<data name="Specification" xml:space="preserve">
<value>Specification</value>
</data>
<data name="Style" xml:space="preserve">
<value>Style</value>
</data>
<data name="This_item_cannot_be_deleted_because_it_is_used_by_an_existing_Naming_Rule" xml:space="preserve">
<value>This item cannot be deleted because it is used by an existing Naming Rule.</value>
</data>
</root>
\ No newline at end of file
......@@ -10,14 +10,14 @@ internal abstract class AbstractOptionPage : UIElementDialogPage
{
protected abstract AbstractOptionPageControl CreateOptionPage(IServiceProvider serviceProvider);
private AbstractOptionPageControl _pageControl;
protected AbstractOptionPageControl pageControl;
private bool _needsLoadOnNextActivate = true;
private void EnsureOptionPageCreated()
{
if (_pageControl == null)
if (pageControl == null)
{
_pageControl = CreateOptionPage(this.Site);
pageControl = CreateOptionPage(this.Site);
}
}
......@@ -26,7 +26,7 @@ protected override System.Windows.UIElement Child
get
{
EnsureOptionPageCreated();
return _pageControl;
return pageControl;
}
}
......@@ -35,7 +35,7 @@ protected override void OnActivate(System.ComponentModel.CancelEventArgs e)
if (_needsLoadOnNextActivate)
{
EnsureOptionPageCreated();
_pageControl.LoadSettings();
pageControl.LoadSettings();
_needsLoadOnNextActivate = false;
}
......@@ -61,7 +61,7 @@ public override void LoadSettingsFromStorage()
public override void SaveSettingsToStorage()
{
EnsureOptionPageCreated();
_pageControl.SaveSettings();
pageControl.SaveSettings();
// Make sure we load the next time the page is activated, in case if options changed
// programmatically between now and the next time the page is activated
......@@ -72,9 +72,9 @@ protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
if (_pageControl != null)
if (pageControl != null)
{
_pageControl.Close();
pageControl.Close();
}
}
}
......
......@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
......@@ -19,11 +20,20 @@ public abstract class AbstractOptionPageControl : UserControl
public AbstractOptionPageControl(IServiceProvider serviceProvider)
{
var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));
InitializeStyles();
if (DesignerProperties.GetIsInDesignMode(this))
{
return;
}
var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));
var workspace = componentModel.GetService<VisualStudioWorkspace>();
this.OptionService = workspace.Services.GetService<IOptionService>();
}
private void InitializeStyles()
{
var groupBoxStyle = new System.Windows.Style(typeof(GroupBox));
groupBoxStyle.Setters.Add(new Setter(GroupBox.PaddingProperty, new Thickness() { Left = 7, Right = 7, Top = 7 }));
groupBoxStyle.Setters.Add(new Setter(GroupBox.MarginProperty, new Thickness() { Bottom = 3 }));
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.CodeAnalysis;
using Microsoft.VisualStudio.Imaging;
using Microsoft.VisualStudio.Imaging.Interop;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.ObjectModel;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences
{
internal interface IManageNamingStylesInfoDialogViewModel
{
ObservableCollection<INamingStylesInfoDialogViewModel> Items { get; }
string DialogTitle { get; }
void AddItem();
void RemoveItem(INamingStylesInfoDialogViewModel item);
void EditItem(INamingStylesInfoDialogViewModel item);
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Internal.VisualStudio.PlatformUI;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences
{
partial class NamingRuleTreeItemViewModel : IInteractionPatternProvider
internal interface INamingStylesInfoDialogViewModel
{
TPattern IInteractionPatternProvider.GetPattern<TPattern>()
{
return this as TPattern;
}
string ItemName { get; set; }
bool CanBeDeleted { get; set; }
}
}
}
\ No newline at end of file
<vs:DialogWindow x:Uid="NamingStyle"
x:Class="Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences.ManageNamingStylesInfoDialog"
x:ClassModifier="internal"
x:Name="dialog"
xmlns:local="clr-namespace:Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences"
xmlns:vs="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.14.0"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:imaging="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.Imaging"
xmlns:imagingPlatformUI="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Imaging"
xmlns:imagecatalog="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.ImageCatalog"
xmlns:s="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.14.0"
mc:Ignorable="d"
d:DesignHeight="400" d:DesignWidth="300"
Height="400" Width="300"
MinHeight="400" MinWidth="300"
Title="{Binding DialogTitle}"
HasHelpButton="False"
ResizeMode="CanResizeWithGrip"
ShowInTaskbar="False"
HasDialogFrame="True"
WindowStartupLocation="CenterOwner">
<Window.Resources>
<vs:NegateBooleanConverter x:Key="NegateBooleanConverter"/>
<Style TargetType="ListBoxItem">
<Setter Property="IsTabStop"
Value="False" />
</Style>
<Thickness x:Key="okCancelButtonPadding">9,2,9,2</Thickness>
</Window.Resources>
<Grid Margin="5,6,11,11">
<Grid.Resources>
<Style x:Key="DataGridStyle" TargetType="DataGrid">
<Setter Property="CellStyle">
<Setter.Value>
<Style TargetType="DataGridCell">
<Setter Property="BorderThickness" Value="1" />
</Style>
</Setter.Value>
</Setter>
</Style>
<Thickness x:Key="cellPadding">8 0 8 0</Thickness>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<DataGrid
Grid.Row="0"
Grid.ColumnSpan="4"
x:Uid="NamingStylesInfo"
x:Name="NamingStylesInfo"
Margin="0,5,0,0"
ItemsSource="{Binding Items, Mode=OneWay}"
AutoGenerateColumns="False"
CanUserReorderColumns="False"
CanUserSortColumns="False"
CanUserAddRows="False"
CanUserDeleteRows="False"
CanUserResizeRows="False"
CanUserResizeColumns="False"
IsReadOnly="True"
BorderThickness="1"
BorderBrush="Gray"
RowHeaderWidth="0"
GridLinesVisibility="None"
VerticalAlignment="Stretch"
SelectionMode="Single"
SelectionUnit="FullRow"
HorizontalAlignment="Stretch"
HeadersVisibility="None"
Style="{StaticResource ResourceKey=DataGridStyle}">
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="MinHeight" Value="26"/>
<Setter Property="Background" Value="Transparent"/>
</Style>
</DataGrid.RowStyle>
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="IsTabStop" Value="False"/>
</Style>
</DataGrid.CellStyle>
<DataGrid.Resources>
<Style x:Key="GroupHeaderStyle" TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<StackPanel>
<TextBlock Margin="5" Text="{Binding Name}"/>
<ItemsPresenter/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="DataGridCellStyle" TargetType="{x:Type DataGridCell}">
<Setter Property="IsTabStop" Value="False"/>
</Style>
</DataGrid.Resources>
<DataGrid.GroupStyle>
<GroupStyle ContainerStyle="{StaticResource GroupHeaderStyle}">
<GroupStyle.Panel>
<ItemsPanelTemplate>
<DataGridRowsPresenter/>
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
</DataGrid.GroupStyle>
<DataGrid.Columns>
<DataGridTemplateColumn
x:Name="ItemName"
Width="3*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding ItemName}" Margin="5" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn
x:Name="Edit"
Width="30">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Click="EditButton_Click" Height="Auto" Width="Auto" Margin="5, 0, 0, 0"
VerticalContentAlignment="Center"
HorizontalContentAlignment="Center"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<imaging:CrispImage
Moniker="{x:Static imagecatalog:KnownMonikers.Edit}"
Height="16"
Width="16" />
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn
x:Name="Delete"
Width="30">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Click="RemoveButton_Click" Height="Auto" Width="Auto" Margin="5, 0, 0, 0"
VerticalContentAlignment="Center"
HorizontalContentAlignment="Center"
HorizontalAlignment="Center"
VerticalAlignment="Center"
IsEnabled="{Binding CanBeDeleted}"
ToolTip="{Binding ElementName=dialog, Path=CannotBeDeletedExplanation}"
ToolTipService.IsEnabled="{Binding Path=IsEnabled, RelativeSource={RelativeSource Self}, Converter={StaticResource NegateBooleanConverter}}"
ToolTipService.ShowOnDisabled="True">
<imaging:CrispImage
Moniker="{x:Static imagecatalog:KnownMonikers.DeleteListItem}"
Grayscale="{Binding CanBeDeleted, Converter={StaticResource NegateBooleanConverter}}"
Height="16"
Width="16"/>
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
<Button Name="AddButton"
Grid.Row="1"
DockPanel.Dock="Left"
Click="AddButton_Click"
AutomationProperties.Name="{Binding AddItemAutomationText}"
AutomationProperties.AutomationId="Add"
Height="24" Width="24"
Margin="0 7 0 0">
<imaging:CrispImage Name="AddButtonImage"
Height="16"
Width="16"
Moniker="{x:Static imagecatalog:KnownMonikers.Add}" />
</Button>
<vs:DialogButton x:Uid="OkButton"
Grid.Row="1"
Grid.Column="2"
Click="OK_Click"
Content="{Binding ElementName=dialog, Path=OK}"
Margin="0, 7, 0, 0"
Padding="{StaticResource ResourceKey=okCancelButtonPadding}"
IsDefault="True"
MinWidth="73"
MinHeight="21"/>
<vs:DialogButton x:Uid="CancelButton"
Grid.Row="1"
Grid.Column="3"
Click="Cancel_Click"
Content="{Binding ElementName=dialog, Path=Cancel}"
Margin="7, 7, 0, 0"
Padding="{StaticResource ResourceKey=okCancelButtonPadding}"
IsCancel="True"
MinWidth="73"
MinHeight="21"/>
</Grid>
</vs:DialogWindow>
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Windows;
using System.Windows.Controls;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.VisualStudio.PlatformUI;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences
{
/// <summary>
/// Interaction logic for NamingStyleDialog.xaml
/// </summary>
internal partial class ManageNamingStylesInfoDialog : DialogWindow
{
private readonly IManageNamingStylesInfoDialogViewModel _viewModel;
public string OK => ServicesVSResources.OK;
public string Cancel => ServicesVSResources.Cancel;
public string CannotBeDeletedExplanation => ServicesVSResources.This_item_cannot_be_deleted_because_it_is_used_by_an_existing_Naming_Rule;
internal ManageNamingStylesInfoDialog(IManageNamingStylesInfoDialogViewModel viewModel)
{
_viewModel = viewModel;
InitializeComponent();
DataContext = viewModel;
}
private void AddButton_Click(object sender, RoutedEventArgs e)
{
_viewModel.AddItem();
}
private void RemoveButton_Click(object sender, RoutedEventArgs e)
{
var button = (Button)sender;
var item = button.DataContext as INamingStylesInfoDialogViewModel;
_viewModel.RemoveItem(item);
}
private void EditButton_Click(object sender, RoutedEventArgs e)
{
var button = (Button)sender;
var item = button.DataContext as INamingStylesInfoDialogViewModel;
_viewModel.EditItem(item);
}
private void OK_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
}
private void Cancel_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
}
}
}
<vs:DialogWindow x:Uid="NamingStyle"
x:Class="Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences.NamingRuleDialog"
x:ClassModifier="internal"
x:Name="dialog"
xmlns:vs="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.14.0"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:imaging="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.Imaging"
xmlns:imagecatalog="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.ImageCatalog"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:s="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.14.0"
mc:Ignorable="d"
d:DesignHeight="240" d:DesignWidth="480"
Height="240" Width="480"
MinHeight="240" MinWidth="480"
Title="{Binding ElementName=dialog, Path=DialogTitle}"
HasHelpButton="False"
FocusManager.FocusedElement="{Binding ElementName=NamingRuleTitle}"
ResizeMode="CanResizeWithGrip"
ShowInTaskbar="False"
HasDialogFrame="True"
WindowStartupLocation="CenterOwner">
<Window.Resources>
<Style TargetType="ListBoxItem">
<Setter Property="IsTabStop"
Value="False" />
</Style>
<Thickness x:Key="labelPadding">0, 5, 0, 2</Thickness>
<Thickness x:Key="okCancelButtonPadding">9,2,9,2</Thickness>
<Thickness x:Key="selectDeselectButtonPadding">9,2,9,2</Thickness>
<Thickness x:Key="textboxPadding">2</Thickness>
</Window.Resources>
<Grid Margin="6,6,11,11">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*" />
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="50"/>
<ColumnDefinition MinWidth="250" Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<!-- Row 0 -->
<Label Grid.Row="0" Grid.Column="0" Content="{Binding ElementName=dialog, Path=NameLabelText}"/>
<TextBox x:Name="NamingRuleTitle" Text="{Binding Title, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="3" VerticalContentAlignment="Center"/>
<!-- Row 1 -->
<Label Grid.Row="1" Grid.Column="0" Margin="0 5 0 0" Content="{Binding ElementName=dialog, Path=SymbolSpecificationLabelText}"/>
<ComboBox ItemsSource="{Binding Path=SymbolSpecificationList}"
DisplayMemberPath="SymbolSpecName"
VerticalContentAlignment="Center"
SelectedIndex="{Binding Path=SelectedSymbolSpecificationIndex}"
Grid.Row="1" Grid.Column="1" Margin="0 5 0 0"/>
<Button Click="CreateSymbolSpecification" Margin="9 5 0 0" Grid.Row="1" Grid.Column="2" Height="24" Width="24">
<imaging:CrispImage Height="16"
Width="16"
Moniker="{x:Static imagecatalog:KnownMonikers.Add}"/>
</Button>
<Button Click="ConfigureSymbolSpecifications" Margin="9 5 0 0" Grid.Row="1" Grid.Column="3" Height="24" Width="24">
<imaging:CrispImage Height="16"
Width="16"
Moniker="{x:Static imagecatalog:KnownMonikers.Settings}"/>
</Button>
<!-- Row 2 -->
<Label Grid.Row="2" Grid.Column="0" Margin="0 5 0 0" Content="{Binding ElementName=dialog, Path=NamingStyleLabelText}"/>
<ComboBox ItemsSource="{Binding Path=NamingStyleList}"
DisplayMemberPath="NamingConventionName"
VerticalContentAlignment="Center"
SelectedIndex="{Binding Path=NamingStyleIndex}"
Grid.Row="2" Grid.Column="1" Margin="0 5 0 0"/>
<Button Click="CreateNamingStyle" Margin="9 5 0 0" Grid.Row="2" Grid.Column="2" Height="24" Width="24">
<imaging:CrispImage Height="16"
Width="16"
Moniker="{x:Static imagecatalog:KnownMonikers.Add}"/>
</Button>
<Button Click="ConfigureNamingStyles" Margin="9 5 0 0" Grid.Row="2" Grid.Column="3" Height="24" Width="24">
<imaging:CrispImage Height="16"
Width="16"
Moniker="{x:Static imagecatalog:KnownMonikers.Settings}"/>
</Button>
<!-- Row 3 -->
<Label Grid.Row="3" Grid.Column="0" Margin="0 5 0 0" Content="{Binding ElementName=dialog, Path=ParentRuleLabelText}"/>
<ComboBox ItemsSource="{Binding Path=ParentRuleList}"
DisplayMemberPath="Title"
VerticalContentAlignment="Center"
SelectedIndex="{Binding Path=ParentRuleIndex}"
Grid.Row="3" Grid.Column="1" Margin="0 5 0 0"/>
<!-- Row 4 -->
<Label Grid.Row="4" Grid.Column="0" Margin="0 5 0 0" Content="{Binding ElementName=dialog, Path=EnforcementLevelsLabelText}"/>
<ComboBox ItemsSource="{Binding Path=EnforcementLevelsList}"
VerticalContentAlignment="Center"
SelectedIndex="{Binding Path=EnforcementLevelIndex}"
Grid.Row="4" Grid.Column="1" Margin="0 5 0 0">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<imaging:CrispImage Moniker="{Binding Moniker}" />
<TextBlock Text="{Binding Name}" Margin="5 0 0 0" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<!-- Row 5 empty for expandability -->
<!-- Row 6 -->
<StackPanel Grid.Row="6"
Grid.ColumnSpan="4"
HorizontalAlignment="Right"
Margin="0, 11, 0, 0"
Orientation="Horizontal">
<Button x:Uid="OkButton"
Content="{Binding ElementName=dialog, Path=OK}"
Click="OK_Click"
Margin="0, 0, 0, 0"
Padding="{StaticResource ResourceKey=okCancelButtonPadding}"
IsDefault="True"
MinWidth="73"
MinHeight="21"/>
<Button x:Uid="CancelButton"
Click="Cancel_Click"
Content="{Binding ElementName=dialog, Path=Cancel}"
Margin="7, 0, 0, 0"
Padding="{StaticResource ResourceKey=okCancelButtonPadding}"
IsCancel="True"
MinWidth="73"
MinHeight="21"/>
</StackPanel>
</Grid>
</vs:DialogWindow>
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.Windows;
using Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.VisualStudio.PlatformUI;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences
{
/// <summary>
/// Interaction logic for NamingRuleDialog.xaml
/// </summary>
internal partial class NamingRuleDialog : DialogWindow
{
private readonly NamingRuleDialogViewModel _viewModel;
private readonly NamingStylesOptionPageControlViewModel _namingStylesViewModel;
private readonly INotificationService _notificationService;
private readonly ImmutableArray<string> _categories;
public string DialogTitle => ServicesVSResources.Naming_Rule;
public string NameLabelText => ServicesVSResources.Name_colon2;
public string SymbolSpecificationLabelText => ServicesVSResources.Symbol_Specification_colon;
public string NamingStyleLabelText => ServicesVSResources.Naming_Style_colon;
public string ParentRuleLabelText => ServicesVSResources.Parent_Rule_colon;
public string EnforcementLevelsLabelText => ServicesVSResources.Severity_colon;
public string OK => ServicesVSResources.OK;
public string Cancel => ServicesVSResources.Cancel;
internal NamingRuleDialog(NamingRuleDialogViewModel viewModel, NamingStylesOptionPageControlViewModel outerViewModel, ImmutableArray<string> categories, INotificationService notificationService)
{
_notificationService = notificationService;
_categories = categories;
_viewModel = viewModel;
_namingStylesViewModel = outerViewModel;
InitializeComponent();
DataContext = viewModel;
}
private void OK_Click(object sender, RoutedEventArgs e)
{
if (_viewModel.TrySubmit())
{
DialogResult = true;
}
}
private void CreateSymbolSpecification(object sender, RoutedEventArgs e)
{
var newSymbolSpecificationViewModel = new SymbolSpecificationViewModel(_namingStylesViewModel.LanguageName, _categories, _notificationService);
var dialog = new SymbolSpecificationDialog(newSymbolSpecificationViewModel);
var result = dialog.ShowModal();
if (result == true)
{
_namingStylesViewModel.AddSymbolSpecification(newSymbolSpecificationViewModel);
_viewModel.SelectedSymbolSpecificationIndex = _viewModel.SymbolSpecificationList.IndexOf(newSymbolSpecificationViewModel);
}
}
private void ConfigureSymbolSpecifications(object sender, RoutedEventArgs e)
{
if (_viewModel.SelectedSymbolSpecificationIndex >= 0)
{
var symbolSpecificationViewModel = _viewModel.SymbolSpecificationList.GetItemAt(_viewModel.SelectedSymbolSpecificationIndex) as SymbolSpecificationViewModel;
var symbolSpecificationClone = new SymbolSpecificationViewModel(_namingStylesViewModel.LanguageName, _categories, symbolSpecificationViewModel.GetSymbolSpecification(), _notificationService);
var dialog = new SymbolSpecificationDialog(symbolSpecificationClone);
var result = dialog.ShowModal();
if (result == true)
{
symbolSpecificationViewModel.ModifierList = symbolSpecificationClone.ModifierList;
symbolSpecificationViewModel.SymbolKindList = symbolSpecificationClone.SymbolKindList;
symbolSpecificationViewModel.AccessibilityList = symbolSpecificationClone.AccessibilityList;
symbolSpecificationViewModel.SymbolSpecName = symbolSpecificationClone.SymbolSpecName;
symbolSpecificationViewModel.CustomTagList = symbolSpecificationClone.CustomTagList;
}
}
}
private void CreateNamingStyle(object sender, RoutedEventArgs e)
{
var newNamingStyleViewModel = new NamingStyleViewModel(new NamingStyle(), _notificationService);
var dialog = new NamingStyleDialog(newNamingStyleViewModel);
var result = dialog.ShowModal();
if (result == true)
{
_namingStylesViewModel.AddNamingStyle(newNamingStyleViewModel);
_viewModel.NamingStyleIndex = _viewModel.NamingStyleList.IndexOf(newNamingStyleViewModel);
}
}
private void ConfigureNamingStyles(object sender, RoutedEventArgs e)
{
if (_viewModel.NamingStyleIndex >= 0)
{
var namingStyleMutable = _viewModel.NamingStyleList.GetItemAt(_viewModel.NamingStyleIndex) as NamingStyleViewModel;
var style = namingStyleMutable.GetNamingStyle();
var styleClone = style.Clone();
var namingStyleClone = new NamingStyleViewModel(styleClone, _notificationService);
var dialog = new NamingStyleDialog(namingStyleClone);
var result = dialog.ShowModal();
if (result == true)
{
namingStyleMutable.NamingConventionName = namingStyleClone.NamingConventionName;
namingStyleMutable.RequiredPrefix = namingStyleClone.RequiredPrefix;
namingStyleMutable.RequiredSuffix = namingStyleClone.RequiredSuffix;
namingStyleMutable.WordSeparator = namingStyleClone.WordSeparator;
namingStyleMutable.FirstWordGroupCapitalization = namingStyleClone.FirstWordGroupCapitalization;
}
}
}
private void Cancel_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Linq;
using System.Windows.Data;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.VisualStudio.Imaging;
using Microsoft.VisualStudio.LanguageServices.Implementation.Utilities;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences
{
internal partial class NamingRuleDialogViewModel : AbstractNotifyPropertyChanged
{
private readonly INotificationService _notificationService;
public NamingRuleDialogViewModel(
string title,
SymbolSpecificationViewModel symbolSpecification,
IList<SymbolSpecificationViewModel> symbolSpecificationList,
NamingStyleViewModel namingStyle,
IList<NamingStyleViewModel> namingStyleList,
NamingRuleTreeItemViewModel parent,
IList<NamingRuleTreeItemViewModel> allowableParentList,
EnforcementLevel enforcementLevel,
INotificationService notificationService)
{
this._notificationService = notificationService;
this._title = title;
this._symbolSpecificationList = new CollectionView(symbolSpecificationList);
this._selectedSymbolSpecificationIndex = symbolSpecificationList.IndexOf(symbolSpecification);
this._namingStyleList = new CollectionView(namingStyleList);
this._namingStyleIndex = namingStyleList.IndexOf(namingStyle);
allowableParentList.Insert(0, new NamingRuleTreeItemViewModel("-- None --"));
this._parentRuleList = new CollectionView(allowableParentList);
this._parentRuleIndex = parent != null ? allowableParentList.IndexOf(parent) : 0;
if (_parentRuleIndex < 0)
{
_parentRuleIndex = 0;
}
_enforcementLevelsList = new List<EnforcementLevel>
{
new EnforcementLevel(DiagnosticSeverity.Hidden),
new EnforcementLevel(DiagnosticSeverity.Info),
new EnforcementLevel(DiagnosticSeverity.Warning),
new EnforcementLevel(DiagnosticSeverity.Error),
};
_enforcementLevelIndex = _enforcementLevelsList.IndexOf(_enforcementLevelsList.Single(e => e.Value == enforcementLevel.Value));
}
private string _title;
public string Title
{
get { return this._title; }
set
{
this.SetProperty(ref this._title, value);
}
}
private CollectionView _symbolSpecificationList;
public CollectionView SymbolSpecificationList
{
get { return _symbolSpecificationList; }
}
private int _selectedSymbolSpecificationIndex;
public int SelectedSymbolSpecificationIndex
{
get
{
return _selectedSymbolSpecificationIndex;
}
set
{
SetProperty(ref _selectedSymbolSpecificationIndex, value);
}
}
private CollectionView _namingStyleList;
public CollectionView NamingStyleList
{
get { return _namingStyleList; }
}
private int _namingStyleIndex;
public int NamingStyleIndex
{
get
{
return _namingStyleIndex;
}
set
{
SetProperty(ref _namingStyleIndex, value);
}
}
private NamingRuleTreeItemViewModel _parentRule;
private CollectionView _parentRuleList;
public CollectionView ParentRuleList
{
get { return _parentRuleList; }
}
private int _parentRuleIndex;
public int ParentRuleIndex
{
get
{
return _parentRuleIndex;
}
set
{
_parentRuleIndex = value;
}
}
public NamingRuleTreeItemViewModel Parent
{
get
{
return this._parentRule;
}
private set
{
this.SetProperty(ref this._parentRule, value);
}
}
private IList<EnforcementLevel> _enforcementLevelsList;
public IList<EnforcementLevel> EnforcementLevelsList
{
get
{
return _enforcementLevelsList;
}
}
private int _enforcementLevelIndex;
public int EnforcementLevelIndex
{
get
{
return _enforcementLevelIndex;
}
set
{
_enforcementLevelIndex = value;
}
}
internal bool TrySubmit()
{
if (_selectedSymbolSpecificationIndex < 0 || _namingStyleIndex < 0)
{
SendFailureNotification(ServicesVSResources.Choose_a_Symbol_Specification_and_a_Naming_Style);
return false;
}
if (string.IsNullOrWhiteSpace(Title))
{
SendFailureNotification(ServicesVSResources.Enter_a_title_for_this_Naming_Rule);
return false;
}
return true;
}
private void SendFailureNotification(string message)
{
_notificationService.SendNotification(message, severity: NotificationSeverity.Information);
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using Microsoft.Internal.VisualStudio.PlatformUI;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences
{
partial class NamingRuleTreeItemViewModel : IDragDropSourcePattern
{
public IDragDropSourceController DragDropSourceController => NamingRuleTreeItemDragDropSourceController.Instance;
private class NamingRuleTreeItemDragDropSourceController : IDragDropSourceController
{
private static NamingRuleTreeItemDragDropSourceController s_instance;
public static NamingRuleTreeItemDragDropSourceController Instance
{
get { return s_instance ?? (s_instance = new NamingRuleTreeItemDragDropSourceController()); }
}
public bool DoDragDrop(IEnumerable<object> selectedNamingRules)
{
// Only support drag/drop on a single item for simplicity
if (selectedNamingRules.Count() != 1)
{
return false;
}
DependencyObject dragSource = (Keyboard.FocusedElement as DependencyObject) ?? Application.Current.MainWindow;
DragDrop.DoDragDrop(dragSource, selectedNamingRules.Single(), DragDropEffects.All);
return true;
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Windows;
using Microsoft.Internal.VisualStudio.PlatformUI;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences
{
partial class NamingRuleTreeItemViewModel : IDragDropTargetPattern
{
public DirectionalDropArea SupportedAreas
{
get { return DirectionalDropArea.Above | DirectionalDropArea.Below | DirectionalDropArea.On; }
}
public void OnDragEnter(DirectionalDropArea dropArea, DragEventArgs e)
{
UpdateAllowedEffects(dropArea, e);
}
private void UpdateAllowedEffects(DirectionalDropArea dropArea, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(NamingRuleTreeItemViewModel)))
{
NamingRuleTreeItemViewModel namingRule = e.Data.GetData(typeof(NamingRuleTreeItemViewModel)) as NamingRuleTreeItemViewModel;
if (namingRule != null && IsDropAllowed(dropArea, target: this, source: namingRule))
{
e.Effects = DragDropEffects.All;
}
}
}
public void OnDragLeave(DirectionalDropArea dropArea, DragEventArgs e)
{
}
public void OnDragOver(DirectionalDropArea dropArea, DragEventArgs e)
{
UpdateAllowedEffects(dropArea, e);
}
public void OnDrop(DirectionalDropArea dropArea, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(NamingRuleTreeItemViewModel)))
{
NamingRuleTreeItemViewModel namingRule = e.Data.GetData(typeof(NamingRuleTreeItemViewModel)) as NamingRuleTreeItemViewModel;
if (!namingRule.IsAncestorOfMe(this))
{
switch (dropArea)
{
case DirectionalDropArea.On:
namingRule.Parent.Children.Remove(namingRule);
this.Children.Add(namingRule);
break;
case DirectionalDropArea.Above:
namingRule.Parent.Children.Remove(namingRule);
this.Parent.Children.Insert(this.Parent.Children.IndexOf(this), namingRule);
break;
case DirectionalDropArea.Below:
namingRule.Parent.Children.Remove(namingRule);
this.Parent.Children.Insert(this.Parent.Children.IndexOf(this) + 1, namingRule);
break;
}
}
}
}
private static bool IsDropAllowed(DirectionalDropArea dropArea, NamingRuleTreeItemViewModel target, NamingRuleTreeItemViewModel source)
{
switch (dropArea)
{
case DirectionalDropArea.On:
// Naming Rules can't be dropped on themselves or on any of their descendants.
if (source == target || source.IsAncestorOfMe(target))
{
return false;
}
else
{
return true;
}
case DirectionalDropArea.Above:
case DirectionalDropArea.Below:
// Naming Rules can't be dropped on themselves, or on any of their descendants.
if (source == target || source.IsAncestorOfMe(target))
{
return false;
}
// There must always be a single root Naming Rule
if (target.Parent == null)
{
return false;
}
// Insertions that would lead to the same order don't make sense
int direction = dropArea == DirectionalDropArea.Above ? -1 : 1;
return source.Parent != target.Parent || source.Parent.Children.IndexOf(source) != target.Parent.Children.IndexOf(target) + direction;
default:
return false;
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Linq;
using Microsoft.Internal.VisualStudio.PlatformUI;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences
{
partial class NamingRuleTreeItemViewModel : IInvocationPattern
{
public bool CanPreview => false;
public IInvocationController InvocationController => NamingRuleInvocationController.Instance;
private class NamingRuleInvocationController : IInvocationController
{
private static NamingRuleInvocationController s_instance;
public static NamingRuleInvocationController Instance
{
get { return s_instance ?? (s_instance = new NamingRuleInvocationController()); }
}
public bool Invoke(IEnumerable<object> items, InputSource inputSource, bool preview)
{
NamingRuleTreeItemViewModel[] selectedRules = items.OfType<NamingRuleTreeItemViewModel>().ToArray();
// When a single Naming Rule is invoked using the mouse, expanding/collapse it in the tree
if (selectedRules.Length == 1)
{
var selectedRule = selectedRules[0];
if (selectedRule.NamingStylesViewModel == null)
{
return false;
}
var viewModel = new NamingRuleDialogViewModel(
selectedRule._title,
selectedRule.symbolSpec,
selectedRule.NamingStylesViewModel.SymbolSpecificationList,
selectedRule.namingStyle,
selectedRule.NamingStylesViewModel.NamingStyleList,
selectedRule.parent,
selectedRule.NamingStylesViewModel.CreateAllowableParentList(selectedRule),
selectedRule.EnforcementLevel,
selectedRule.NamingStylesViewModel.notificationService);
var dialog = new NamingRuleDialog(viewModel, selectedRule.NamingStylesViewModel, selectedRule.NamingStylesViewModel.categories, selectedRule.NamingStylesViewModel.notificationService);
var result = dialog.ShowModal();
if (result == true)
{
selectedRule.namingStyle = viewModel.NamingStyleList.GetItemAt(viewModel.NamingStyleIndex) as NamingStyleViewModel;
selectedRule.symbolSpec = viewModel.SymbolSpecificationList.GetItemAt(viewModel.SelectedSymbolSpecificationIndex) as SymbolSpecificationViewModel;
selectedRule.Title = viewModel.Title;
selectedRule.EnforcementLevel = viewModel.EnforcementLevelsList[viewModel.EnforcementLevelIndex];
selectedRule.NotifyPropertyChanged(nameof(selectedRule.Text));
if (viewModel.ParentRuleIndex == 0)
{
if (selectedRule.Parent != selectedRule.NamingStylesViewModel.rootNamingRule)
{
selectedRule.Parent.Children.Remove(selectedRule);
selectedRule.NamingStylesViewModel.rootNamingRule.Children.Add(selectedRule);
}
}
else
{
var newParent = viewModel.ParentRuleList.GetItemAt(viewModel.ParentRuleIndex) as NamingRuleTreeItemViewModel;
if (newParent != selectedRule.Parent)
{
selectedRule.Parent.Children.Remove(selectedRule);
newParent.Children.Add(selectedRule);
}
}
}
return true;
}
return false;
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.Internal.VisualStudio.PlatformUI;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences
{
partial class NamingRuleTreeItemViewModel : IRenamePattern
{
public bool CanRename
{
get
{
// Don't allow rename on the root node, which is just a container for all the real
// naming rules.
return this.Parent != null;
}
}
public IRenameItemTransaction BeginRename(object container, Func<IRenameItemTransaction, IRenameItemValidationResult> validator)
{
return new RenameTransaction(this, container, validator);
}
private class RenameTransaction : RenameItemTransaction
{
public RenameTransaction(NamingRuleTreeItemViewModel namingRule, object container, Func<IRenameItemTransaction, IRenameItemValidationResult> validator)
: base(namingRule, container, validator)
{
this.RenameLabel = namingRule.Title;
this.Completed += (s, e) =>
{
namingRule.Title = this.RenameLabel;
};
}
public override void Commit(RenameItemCompletionFocusBehavior completionFocusBehavior)
{
base.Commit(completionFocusBehavior);
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Windows;
using Microsoft.Internal.VisualStudio.PlatformUI;
using Microsoft.VisualStudio.Imaging;
using Microsoft.VisualStudio.Imaging.Interop;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences
{
partial class NamingRuleTreeItemViewModel : ITreeDisplayItemWithImages
{
public ImageMoniker ExpandedIconMoniker => GetMoniker();
public FontStyle FontStyle => FontStyles.Normal;
public FontWeight FontWeight => FontWeights.Normal;
public ImageMoniker IconMoniker => GetMoniker();
public bool IsCut => false;
public ImageMoniker OverlayIconMoniker => default(ImageMoniker);
public ImageMoniker StateIconMoniker => default(ImageMoniker);
public string StateToolTipText => null;
public string Text => Title;
public object ToolTipContent => null;
public string ToolTipText => null;
private ImageMoniker GetMoniker()
{
if (EnforcementLevel == null)
{
return KnownMonikers.FolderOpened;
}
switch (EnforcementLevel.Value)
{
case CodeAnalysis.DiagnosticSeverity.Hidden:
return KnownMonikers.None;
case CodeAnalysis.DiagnosticSeverity.Info:
return KnownMonikers.StatusInformation;
case CodeAnalysis.DiagnosticSeverity.Warning:
return KnownMonikers.StatusWarning;
case CodeAnalysis.DiagnosticSeverity.Error:
return KnownMonikers.StatusError;
default:
break;
}
return KnownMonikers.Rule;
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using Microsoft.Internal.VisualStudio.PlatformUI;
using Microsoft.VisualStudio.PlatformUI;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences
{
public partial class NamingRuleTreeItemViewModel : ObservableObject
{
internal NamingRuleTreeItemViewModel(string name)
{
// TODO: remove this constructor if possible
this._title = name;
this.children = new ChildRuleCollection(this);
this.children.CollectionChanged += OnChildrenCollectionChanged;
}
internal NamingRuleTreeItemViewModel(
string name,
SymbolSpecificationViewModel symbolSpec,
NamingStyleViewModel namingStyle,
EnforcementLevel enforcementLevel,
NamingStylesOptionPageControlViewModel vm)
{
this.EnforcementLevel = enforcementLevel;
this._title = name;
this.symbolSpec = symbolSpec;
this.namingStyle = namingStyle;
this._namingStylesViewModel = vm;
this.children = new ChildRuleCollection(this);
this.children.CollectionChanged += OnChildrenCollectionChanged;
}
private NamingRuleTreeItemViewModel parent;
private readonly ChildRuleCollection children;
private bool hasChildren;
internal SymbolSpecificationViewModel symbolSpec;
internal NamingStyleViewModel namingStyle;
private string _title;
public string Title
{
get
{
return this._title;
}
set
{
this.SetProperty(ref this._title, value, () => NotifyPropertyChanged(nameof(ITreeDisplayItem.Text)));
}
}
public NamingRuleTreeItemViewModel Parent
{
get
{
return this.parent;
}
private set
{
this.SetProperty(ref this.parent, value);
}
}
public IList<NamingRuleTreeItemViewModel> Children
{
get { return this.children; }
}
public bool HasChildren
{
get
{
return this.children.Count > 0;
}
private set
{
this.SetProperty(ref this.hasChildren, value);
}
}
internal bool TrySubmit()
{
return true;
}
private NamingStylesOptionPageControlViewModel _namingStylesViewModel;
internal NamingStylesOptionPageControlViewModel NamingStylesViewModel
{
get
{
return _namingStylesViewModel;
}
}
private EnforcementLevel _enforcementLevel;
internal EnforcementLevel EnforcementLevel
{
get
{
return _enforcementLevel;
}
set
{
if (SetProperty(ref _enforcementLevel, value))
{
NotifyPropertyChanged(nameof(IconMoniker));
NotifyPropertyChanged(nameof(ExpandedIconMoniker));
}
}
}
private void OnChildrenCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
this.HasChildren = this.children.Count > 0;
}
public bool IsAncestorOfMe(NamingRuleTreeItemViewModel rule)
{
NamingRuleTreeItemViewModel potentialAncestor = rule.Parent;
while (potentialAncestor != null)
{
if (potentialAncestor == this)
{
return true;
}
potentialAncestor = potentialAncestor.Parent;
}
return false;
}
private class ChildRuleCollection : ObservableCollection<NamingRuleTreeItemViewModel>
{
private readonly NamingRuleTreeItemViewModel _parent;
public ChildRuleCollection() : this(null)
{
}
public ChildRuleCollection(NamingRuleTreeItemViewModel parent)
{
_parent = parent;
}
protected override void InsertItem(int index, NamingRuleTreeItemViewModel child)
{
base.InsertItem(index, child);
TakeOwnership(child);
}
protected override void RemoveItem(int index)
{
NamingRuleTreeItemViewModel child = this[index];
base.RemoveItem(index);
LoseOwnership(child);
}
protected override void SetItem(int index, NamingRuleTreeItemViewModel newChild)
{
NamingRuleTreeItemViewModel oldChild = this[index];
base.SetItem(index, newChild);
LoseOwnership(oldChild);
TakeOwnership(newChild);
}
protected override void ClearItems()
{
List<NamingRuleTreeItemViewModel> children = new List<NamingRuleTreeItemViewModel>(this);
base.ClearItems();
foreach (NamingRuleTreeItemViewModel child in children)
{
LoseOwnership(child);
}
}
private void TakeOwnership(NamingRuleTreeItemViewModel child)
{
child.Parent = _parent;
}
private void LoseOwnership(NamingRuleTreeItemViewModel child)
{
child.Parent = null;
}
}
}
}
<local:AbstractOptionPageControl
x:Class="Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingStyleOptionPageControl"
x:ClassModifier="internal"
xmlns:local="clr-namespace:Microsoft.VisualStudio.LanguageServices.Implementation.Options"
xmlns:style="clr-namespace:Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style"
xmlns:converters="clr-namespace:Microsoft.VisualStudio.LanguageServices.Implementation.Options.Converters"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:options="clr-namespace:Microsoft.VisualStudio.LanguageServices.Implementation.Options"
xmlns:imaging="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.Imaging"
xmlns:vs="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.14.0"
xmlns:imagingPlatformUI="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Imaging"
xmlns:imagecatalog="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.ImageCatalog"
mc:Ignorable="d"
d:DesignHeight="279"
d:DesignWidth="514">
<Grid>
<Grid.Resources>
<Style x:Key="DataGridStyle" TargetType="DataGrid">
<Setter Property="CellStyle">
<Setter.Value>
<Style TargetType="DataGridCell">
<Setter Property="BorderThickness" Value="1" />
</Style>
</Setter.Value>
</Setter>
</Style>
<Thickness x:Key="cellPadding">8 0 8 0</Thickness>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
<RoutedUICommand x:Key="MoveUp" />
<RoutedUICommand x:Key="MoveDown" />
<vs:NegateBooleanConverter x:Key="NegateBooleanConverter"/>
</Grid.Resources>
<Grid.CommandBindings>
<CommandBinding Command="{StaticResource MoveUp}" Executed="MoveUp_Click" />
<CommandBinding Command="{StaticResource MoveDown}" Executed="MoveDown_Click" />
</Grid.CommandBindings>
<Grid.InputBindings>
<KeyBinding Key="Up" Modifiers="Alt" Command="{StaticResource MoveUp}" />
<KeyBinding Key="Down" Modifiers="Alt" Command="{StaticResource MoveDown}" />
</Grid.InputBindings>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<DataGrid
Grid.Row="0"
x:Uid="CodeStyleContent"
x:Name="CodeStyleMembers"
Margin="0,5,0,0"
ItemsSource="{Binding CodeStyleItems, Mode=OneWay}"
AutoGenerateColumns="False"
CanUserReorderColumns="False"
CanUserSortColumns="False"
CanUserAddRows="False"
CanUserDeleteRows="False"
CanUserResizeRows="False"
CanUserResizeColumns="False"
IsReadOnly="True"
BorderThickness="1"
BorderBrush="Gray"
RowHeaderWidth="0"
GridLinesVisibility="None"
VerticalAlignment="Stretch"
SelectionMode="Single"
SelectionUnit="FullRow"
HorizontalAlignment="Stretch"
SelectionChanged="CodeStyleMembers_SelectionChanged"
Style="{StaticResource ResourceKey=DataGridStyle}">
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="MinHeight" Value="26"/>
<Setter Property="Background" Value="Transparent"/>
</Style>
</DataGrid.RowStyle>
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="IsTabStop" Value="False"/>
</Style>
</DataGrid.CellStyle>
<DataGrid.Resources>
<Style x:Key="GroupHeaderStyle" TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<StackPanel>
<TextBlock Margin="5" Text="{Binding Name}"/>
<ItemsPresenter/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="DataGridCellStyle" TargetType="{x:Type DataGridCell}">
<Setter Property="IsTabStop" Value="False"/>
</Style>
</DataGrid.Resources>
<DataGrid.GroupStyle>
<GroupStyle ContainerStyle="{StaticResource GroupHeaderStyle}">
<GroupStyle.Panel>
<ItemsPanelTemplate>
<DataGridRowsPresenter/>
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
</DataGrid.GroupStyle>
<DataGrid.Columns>
<DataGridTemplateColumn
x:Name="selectable"
Header="Reorder"
Width="Auto">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Button Name="UpButton"
AutomationProperties.Name="{Binding MoveUpAutomationText}"
Height="24" Width="24"
IsEnabled="{Binding CanMoveUp, Mode=OneWay}"
Margin="5 0 0 0"
Command="{StaticResource MoveUp}">
<imaging:CrispImage Name="UpArrowImage"
Height="16"
Width="16"
Moniker="{x:Static imagecatalog:KnownMonikers.MoveUp}"
Grayscale="{Binding IsEnabled, ElementName=UpButton, Converter={StaticResource NegateBooleanConverter}}"/>
</Button>
<Button Name="DownButton"
AutomationProperties.Name="{Binding MoveDownAutomationText}"
IsEnabled="{Binding CanMoveDown, Mode=OneWay}"
AutomationProperties.AutomationId="Down"
Height="24" Width="24"
Margin="5 0 5 0"
Command="{StaticResource MoveDown}">
<imaging:CrispImage Name="DownArrowImage"
Height="16"
Width="16"
Moniker="{x:Static imagecatalog:KnownMonikers.MoveDown}"
Grayscale="{Binding IsEnabled, ElementName=DownButton, Converter={StaticResource NegateBooleanConverter}}"/>
</Button>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn
x:Name="symbolSpec"
Header="Specification"
Width="3*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox
Height="22"
ItemsSource="{Binding Specifications}"
DisplayMemberPath="Name"
SelectedItem="{Binding SelectedSpecification, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
VerticalContentAlignment="Center"
HorizontalContentAlignment="Left"
ToolTip="{Binding Path=SelectedItem.Name, RelativeSource={RelativeSource Self}}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn
x:Name="style"
Header="Style"
Width="3*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox
Height="22"
ItemsSource="{Binding NamingStyles}"
DisplayMemberPath="Name"
SelectedItem="{Binding SelectedStyle, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
VerticalContentAlignment="Center"
HorizontalContentAlignment="Left"
ToolTip="{Binding Path=SelectedItem.Name, RelativeSource={RelativeSource Self}}">
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn
x:Name="severity"
Header="Severity"
Width="2.5*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox
Height="22"
ItemsSource="{Binding NotificationPreferences}"
SelectedItem="{Binding SelectedNotificationPreference,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Visibility="{Binding NotificationsAvailable, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}"
VerticalContentAlignment="Center"
HorizontalContentAlignment="Left"
ToolTip="{Binding Path=SelectedItem.Name, RelativeSource={RelativeSource Self}}">
<ComboBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<imaging:CrispImage Height="16"
Width="16"
Moniker="{Binding Moniker}"
Grid.Column="0"/>
<TextBlock Margin="5, 0, 0, 0"
Text="{Binding Name}"
Grid.Column="1"/>
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn x:Name="Delete"
Width="30">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Click="RemoveButton_Click"
Height="16"
Width="16"
Margin="5, 0, 0, 0"
VerticalContentAlignment="Center"
HorizontalContentAlignment="Center"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<imaging:CrispImage Moniker="{x:Static imagecatalog:KnownMonikers.DeleteListItem}" />
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
<Border Grid.Row="1">
<StackPanel Orientation="Horizontal"
Margin="7">
<Button Name="AddButton"
Click="AddButton_Click"
AutomationProperties.Name="{Binding AddRuleAutomationText}"
AutomationProperties.AutomationId="Add"
Height="24" Width="24"
Margin="0 0 0 0">
<imaging:CrispImage Name="AddButtonImage"
Height="16"
Width="16"
Moniker="{x:Static imagecatalog:KnownMonikers.Add}" />
</Button>
<vs:DialogButton Margin="7 0 0 0" Content="{Binding Path=ManageSpecificationsButtonText}" Click="ManageSpecificationsButton_Click"/>
<vs:DialogButton Margin="7 0 0 0" Content="{Binding Path=ManageStylesButtonText}" Click="ManageStylesButton_Click" />
</StackPanel>
</Border>
</Grid>
</local:AbstractOptionPageControl>
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Xml.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Simplification;
using Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences;
using Microsoft.VisualStudio.PlatformUI;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style
{
internal partial class NamingStyleOptionPageControl : AbstractOptionPageControl
{
private NamingStyleOptionPageViewModel _viewModel;
private readonly string _languageName;
private readonly INotificationService _notificationService;
private readonly ImmutableArray<EnforcementLevel> _notifications = ImmutableArray.Create(
new EnforcementLevel(DiagnosticSeverity.Hidden),
new EnforcementLevel(DiagnosticSeverity.Info),
new EnforcementLevel(DiagnosticSeverity.Warning),
new EnforcementLevel(DiagnosticSeverity.Error));
internal NamingStyleOptionPageControl(IServiceProvider serviceProvider, INotificationService notificationService, string languageName)
: base(serviceProvider)
{
_languageName = languageName;
_notificationService = notificationService;
InitializeComponent();
LoadSettings();
}
private NamingStyleOptionPageViewModel.NamingRuleViewModel CreateItemWithNoSelections()
{
return new NamingStyleOptionPageViewModel.NamingRuleViewModel()
{
Specifications = new ObservableCollection<SymbolSpecification>(_viewModel.Specifications),
NamingStyles = new ObservableCollection<NamingStyle>(_viewModel.NamingStyles),
NotificationPreferences = _notifications
};
}
private void AddButton_Click(object sender, RoutedEventArgs e)
{
_viewModel.AddItem(CreateItemWithNoSelections());
}
private void ManageSpecificationsButton_Click(object sender, RoutedEventArgs e)
{
var viewModel = new ManageSymbolSpecificationsDialogViewModel(_viewModel.Specifications, _viewModel.CodeStyleItems.ToList(), _languageName, _notificationService);
var dialog = new ManageNamingStylesInfoDialog(viewModel);
if (dialog.ShowDialog().Value == true)
{
_viewModel.UpdateSpecificationList(viewModel);
}
}
private void ManageStylesButton_Click(object sender, RoutedEventArgs e)
{
var viewModel = new ManageNamingStylesDialogViewModel(_viewModel.NamingStyles, _viewModel.CodeStyleItems.ToList(), _notificationService);
var dialog = new ManageNamingStylesInfoDialog(viewModel);
if (dialog.ShowDialog().Value == true)
{
_viewModel.UpdateStyleList(viewModel);
}
}
private void MoveUp_Click(object sender, EventArgs e)
{
int oldSelectedIndex = CodeStyleMembers.SelectedIndex;
if (oldSelectedIndex > 0)
{
_viewModel.MoveItem(oldSelectedIndex, oldSelectedIndex - 1);
CodeStyleMembers.SelectedIndex = oldSelectedIndex - 1;
SetFocusToSelectedRow();
}
}
private void MoveDown_Click(object sender, EventArgs e)
{
int oldSelectedIndex = CodeStyleMembers.SelectedIndex;
if (oldSelectedIndex < CodeStyleMembers.Items.Count - 1)
{
_viewModel.MoveItem(oldSelectedIndex, oldSelectedIndex + 1);
CodeStyleMembers.SelectedIndex = oldSelectedIndex + 1;
SetFocusToSelectedRow();
}
}
private void RemoveButton_Click(object sender, System.Windows.RoutedEventArgs e)
{
var button = (Button)sender;
var context = button.DataContext as NamingStyleOptionPageViewModel.NamingRuleViewModel;
_viewModel.RemoveItem(context);
}
private void SetFocusToSelectedRow()
{
if (CodeStyleMembers.SelectedIndex >= 0)
{
DataGridRow row = CodeStyleMembers.ItemContainerGenerator.ContainerFromIndex(CodeStyleMembers.SelectedIndex) as DataGridRow;
if (row == null)
{
CodeStyleMembers.ScrollIntoView(CodeStyleMembers.SelectedItem);
row = CodeStyleMembers.ItemContainerGenerator.ContainerFromIndex(CodeStyleMembers.SelectedIndex) as DataGridRow;
}
if (row != null)
{
DataGridCell cell = row.FindDescendant<DataGridCell>();
if (cell != null)
{
cell.Focus();
}
}
}
}
internal override void SaveSettings()
{
var info = new SerializableNamingStylePreferencesInfo();
foreach (var item in _viewModel.CodeStyleItems)
{
if (!item.IsComplete())
{
continue;
}
var rule = new SerializableNamingRule()
{
EnforcementLevel = item.SelectedNotificationPreference.Value,
NamingStyleID = item.SelectedStyle.ID,
SymbolSpecificationID = item.SelectedSpecification.ID
};
info.NamingRules.Add(rule);
}
foreach (var item in _viewModel.Specifications)
{
info.SymbolSpecifications.Add(item);
}
foreach (var item in _viewModel.NamingStyles)
{
info.NamingStyles.Add(item);
}
var oldOptions = OptionService.GetOptions();
var newOptions = oldOptions.WithChangedOption(SimplificationOptions.NamingPreferences, _languageName, info.CreateXElement().ToString());
OptionService.SetOptions(newOptions);
OptionLogger.Log(oldOptions, newOptions);
}
internal override void LoadSettings()
{
base.LoadSettings();
var options = OptionService.GetOption(SimplificationOptions.NamingPreferences, _languageName);
if (string.IsNullOrEmpty(options))
{
return;
}
var namingPreferencesXml = this.OptionService.GetOption(SimplificationOptions.NamingPreferences, _languageName);
var preferencesInfo = SerializableNamingStylePreferencesInfo.FromXElement(XElement.Parse(namingPreferencesXml));
_viewModel = new NamingStyleOptionPageViewModel(preferencesInfo);
this.DataContext = _viewModel;
}
internal bool ContainsErrors()
{
return _viewModel.CodeStyleItems.Any(i => !i.IsComplete());
}
private void CodeStyleMembers_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
_viewModel.SelectedIndex = CodeStyleMembers.SelectedIndex;
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles;
using Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences;
using Microsoft.VisualStudio.LanguageServices.Implementation.Utilities;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style
{
internal class NamingStyleOptionPageViewModel : AbstractNotifyPropertyChanged
{
public string ManageSpecificationsButtonText => ServicesVSResources.Manage_specifications;
public string ManageStylesButtonText => ServicesVSResources.Manage_styles;
private readonly EnforcementLevel[] _notifications = new[]
{
new EnforcementLevel(DiagnosticSeverity.Hidden),
new EnforcementLevel(DiagnosticSeverity.Info),
new EnforcementLevel(DiagnosticSeverity.Warning),
new EnforcementLevel(DiagnosticSeverity.Error),
};
public ObservableCollection<NamingRuleViewModel> CodeStyleItems { get; set; }
public ObservableCollection<SymbolSpecification> Specifications { get; set; }
public ObservableCollection<NamingStyle> NamingStyles { get; set; }
public NamingStyleOptionPageViewModel(SerializableNamingStylePreferencesInfo info)
{
var viewModels = new List<NamingRuleViewModel>();
foreach (var namingRule in info.NamingRules)
{
var viewModel = new NamingRuleViewModel();
viewModel.NamingStyles = new ObservableCollection<NamingStyle>(info.NamingStyles);
viewModel.Specifications = new ObservableCollection<SymbolSpecification>(info.SymbolSpecifications);
viewModel.NotificationPreferences = new List<EnforcementLevel>(_notifications);
viewModel.SelectedSpecification = viewModel.Specifications.Single(s => s.ID == namingRule.SymbolSpecificationID);
viewModel.SelectedStyle= viewModel.NamingStyles.Single(s => s.ID == namingRule.NamingStyleID);
viewModel.SelectedNotificationPreference = viewModel.NotificationPreferences.Single(n => n.Name == new EnforcementLevel(namingRule.EnforcementLevel).Name);
viewModels.Add(viewModel);
}
CodeStyleItems = new ObservableCollection<NamingRuleViewModel>(viewModels);
Specifications = new ObservableCollection<SymbolSpecification>(info.SymbolSpecifications);
NamingStyles = new ObservableCollection<NamingStyle>(info.NamingStyles);
SetMoveArrowStatuses();
}
private int _selectedIndex;
public int SelectedIndex
{
get
{
return _selectedIndex;
}
set
{
if (value == _selectedIndex)
{
return;
}
_selectedIndex = value;
}
}
internal void AddItem(NamingRuleViewModel namingRuleViewModel)
{
CodeStyleItems.Add(namingRuleViewModel);
SetMoveArrowStatuses();
}
internal void RemoveItem(NamingRuleViewModel namingRuleViewModel)
{
CodeStyleItems.Remove(namingRuleViewModel);
SetMoveArrowStatuses();
}
internal void UpdateSpecificationList(ManageSymbolSpecificationsDialogViewModel viewModel)
{
var symbolSpecifications = viewModel.Items.Cast<SymbolSpecificationViewModel>().Select(n => new SymbolSpecification(
n.ID,
n.ItemName,
n.SymbolKindList.Where(s => s.IsChecked).Select(k => k.CreateSymbolKindOrTypeKind()).ToList(),
n.AccessibilityList.Where(s => s.IsChecked).Select(a => new SymbolSpecification.AccessibilityKind(a._accessibility)).ToList(),
n.ModifierList.Where(s => s.IsChecked).Select(m => new SymbolSpecification.ModifierKind(m._modifier)).ToList()));
Specifications.Clear();
foreach (var specification in symbolSpecifications)
{
Specifications.Add(specification);
}
// The existing rules have had their Specifications pulled out from underneath them, so
// this goes through and resets them.
foreach (var rule in CodeStyleItems)
{
var selectedSpecification = rule.SelectedSpecification;
rule.Specifications.Clear();
foreach (var specification in symbolSpecifications)
{
rule.Specifications.Add(specification);
}
// Set the SelectedSpecification to null and then back to the actual selected
// specification to trigger the INotifyPropertyChanged event.
rule.SelectedSpecification = null;
if (selectedSpecification != null)
{
rule.SelectedSpecification = rule.Specifications.Single(s => s.ID == selectedSpecification.ID);
}
}
}
internal void MoveItem(int oldSelectedIndex, int newSelectedIndex)
{
CodeStyleItems.Move(oldSelectedIndex, newSelectedIndex);
SetMoveArrowStatuses();
}
private void SetMoveArrowStatuses()
{
for (int i = 0; i < CodeStyleItems.Count; i++)
{
CodeStyleItems[i].CanMoveUp = true;
CodeStyleItems[i].CanMoveDown = true;
if (i == 0)
{
CodeStyleItems[i].CanMoveUp = false;
}
if (i == CodeStyleItems.Count - 1)
{
CodeStyleItems[i].CanMoveDown = false;
}
}
}
internal void UpdateStyleList(ManageNamingStylesDialogViewModel viewModel)
{
var namingStyles = viewModel.Items.Cast<NamingStyleViewModel>().Select(n => new NamingStyle
{
ID = n.ID,
Name = n.ItemName,
Prefix = n.RequiredPrefix,
Suffix = n.RequiredSuffix,
WordSeparator = n.WordSeparator,
CapitalizationScheme = n.CapitalizationSchemes[n.CapitalizationSchemeIndex].Capitalization
});
NamingStyles.Clear();
foreach (var style in namingStyles)
{
NamingStyles.Add(style);
}
// The existing rules have had their Styles pulled out from underneath them, so
// this goes through and resets them.
foreach (var rule in CodeStyleItems)
{
var selectedStyle = rule.SelectedStyle;
rule.NamingStyles.Clear();
foreach (var style in namingStyles)
{
rule.NamingStyles.Add(style);
}
// Set the SelectedStyle to null and then back to the actual selected
// style to trigger the INotifyPropertyChanged event.
rule.SelectedStyle = null;
if (selectedStyle != null)
{
rule.SelectedStyle = rule.NamingStyles.Single(n => n.ID == selectedStyle.ID);
}
}
}
internal class NamingRuleViewModel : AbstractNotifyPropertyChanged
{
public NamingRuleViewModel()
{
Specifications = new ObservableCollection<SymbolSpecification>();
NamingStyles = new ObservableCollection<NamingStyle>();
NotificationPreferences = new List<EnforcementLevel>();
}
private SymbolSpecification _selectedSpecification;
private NamingStyle _selectedNamingStyle;
private EnforcementLevel _selectedNotification;
public ObservableCollection<SymbolSpecification> Specifications { get; set; }
public ObservableCollection<NamingStyle> NamingStyles { get; set; }
public IEnumerable<EnforcementLevel> NotificationPreferences { get; set; }
public SymbolSpecification SelectedSpecification
{
get
{
return _selectedSpecification;
}
set
{
SetProperty(ref _selectedSpecification, value);
}
}
public NamingStyle SelectedStyle
{
get
{
return _selectedNamingStyle;
}
set
{
SetProperty(ref _selectedNamingStyle, value);
}
}
public EnforcementLevel SelectedNotificationPreference
{
get
{
return _selectedNotification;
}
set
{
SetProperty(ref _selectedNotification, value);
}
}
private bool _canMoveUp;
public bool CanMoveUp
{
get
{
return _canMoveUp;
}
set
{
SetProperty(ref _canMoveUp, value);
}
}
private bool _canMoveDown;
public bool CanMoveDown
{
get
{
return _canMoveDown;
}
set
{
SetProperty(ref _canMoveDown, value);
}
}
public bool IsComplete()
{
return SelectedSpecification != null && SelectedStyle != null && SelectedNotificationPreference != null;
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.VisualStudio.LanguageServices.Implementation.Utilities;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences
{
internal class ManageNamingStylesDialogViewModel : AbstractNotifyPropertyChanged, IManageNamingStylesInfoDialogViewModel
{
private readonly INotificationService _notificationService;
public ObservableCollection<INamingStylesInfoDialogViewModel> Items { get; set; }
public string DialogTitle => "Manage Naming Styles";
public ManageNamingStylesDialogViewModel(
ObservableCollection<NamingStyle> namingStyles,
List<NamingStyleOptionPageViewModel.NamingRuleViewModel> namingRules,
INotificationService notificationService)
{
_notificationService = notificationService;
Items = new ObservableCollection<INamingStylesInfoDialogViewModel>(namingStyles.Select(style => new NamingStyleViewModel(
style.Clone(),
!namingRules.Any(rule => rule.SelectedStyle?.ID == style.ID),
notificationService)));
}
internal void RemoveNamingStyle(NamingStyleViewModel namingStyle)
{
Items.Remove(namingStyle);
}
public void AddItem()
{
var style = new NamingStyle();
var viewModel = new NamingStyleViewModel(style, canBeDeleted: true, notificationService: _notificationService);
var dialog = new NamingStyleDialog(viewModel);
if (dialog.ShowDialog().Value == true)
{
Items.Add(viewModel);
}
}
public void RemoveItem(INamingStylesInfoDialogViewModel item)
{
Items.Remove(item);
}
public void EditItem(INamingStylesInfoDialogViewModel item)
{
var context = (NamingStyleViewModel)item;
var style = context.GetNamingStyle();
var viewModel = new NamingStyleViewModel(style, context.CanBeDeleted, notificationService: _notificationService);
var dialog = new NamingStyleDialog(viewModel);
if (dialog.ShowDialog().Value == true)
{
context.ItemName = viewModel.ItemName;
context.RequiredPrefix = viewModel.RequiredPrefix;
context.RequiredSuffix = viewModel.RequiredSuffix;
context.WordSeparator = viewModel.WordSeparator;
context.CapitalizationSchemeIndex = viewModel.CapitalizationSchemeIndex;
}
}
}
}
......@@ -47,7 +47,7 @@
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Content="{Binding ElementName=dialog, Path=NamingStyleTitleLabelText}"/>
<TextBox Grid.Row="0" Grid.Column="1" MinWidth="300" Text="{Binding NamingConventionName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalContentAlignment="Center"/>
<TextBox Grid.Row="0" Grid.Column="1" MinWidth="300" Text="{Binding ItemName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalContentAlignment="Center"/>
<Label Grid.Row="1" Grid.Column="0" Margin="0 5 0 0" Content="{Binding ElementName=dialog, Path=RequiredPrefixLabelText}"/>
<TextBox Grid.Row="1" Grid.Column="1" Margin="0 5 0 0" Width="100" HorizontalAlignment="Left" VerticalContentAlignment="Center" Text="{Binding RequiredPrefix, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
......
......@@ -9,11 +9,12 @@
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences
{
internal class NamingStyleViewModel : AbstractNotifyPropertyChanged
internal class NamingStyleViewModel : AbstractNotifyPropertyChanged, INamingStylesInfoDialogViewModel
{
private NamingStyle _style;
private readonly INotificationService _notificationService;
public NamingStyleViewModel(NamingStyle style, INotificationService notificationService)
public NamingStyleViewModel(NamingStyle style, bool canBeDeleted, INotificationService notificationService)
{
_notificationService = notificationService;
_style = style;
......@@ -21,8 +22,8 @@ public NamingStyleViewModel(NamingStyle style, INotificationService notification
this.RequiredPrefix = style.Prefix;
this.RequiredSuffix = style.Suffix;
this.WordSeparator = style.WordSeparator;
this.FirstWordGroupCapitalization = (int)style.CapitalizationScheme;
this.NamingConventionName = style.Name;
this.ItemName = style.Name;
this.CanBeDeleted = canBeDeleted;
CapitalizationSchemes = new List<CapitalizationDisplay>
{
......@@ -57,11 +58,11 @@ public int CapitalizationSchemeIndex
public Guid ID { get; internal set; }
private string _namingConventionName;
public string NamingConventionName
private string _itemName;
public string ItemName
{
get { return _namingConventionName; }
set { SetProperty(ref _namingConventionName, value); }
get { return _itemName; }
set { SetProperty(ref _itemName, value); }
}
public string CurrentConfiguration
......@@ -127,29 +128,12 @@ public string WordSeparator
}
}
}
private int _firstWordGroupCapitalization;
internal readonly INotificationService _notificationService;
public int FirstWordGroupCapitalization
{
get
{
return _firstWordGroupCapitalization;
}
set
{
_style.CapitalizationScheme = (Capitalization)value;
if (SetProperty(ref _firstWordGroupCapitalization, value))
{
NotifyPropertyChanged(nameof(CurrentConfiguration));
}
}
}
public bool CanBeDeleted { get; set; }
internal bool TrySubmit()
{
if (string.IsNullOrWhiteSpace(NamingConventionName))
if (string.IsNullOrWhiteSpace(ItemName))
{
_notificationService.SendNotification(ServicesVSResources.Enter_a_title_for_this_Naming_Style);
return false;
......@@ -160,7 +144,7 @@ internal bool TrySubmit()
internal NamingStyle GetNamingStyle()
{
_style.Name = NamingConventionName;
_style.Name = ItemName;
_style.ID = ID;
return _style;
}
......
<options:AbstractOptionPageControl
x:Class="Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences.NamingStylesOptionPageControl"
x:ClassModifier="internal"
xmlns:options="clr-namespace:Microsoft.VisualStudio.LanguageServices.Implementation.Options"
xmlns:imaging="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.Imaging"
xmlns:imagecatalog="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.ImageCatalog"
xmlns:vs="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.14.0"
xmlns:vsi="clr-namespace:Microsoft.Internal.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.14.0"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:s="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.14.0"
xmlns:naming="clr-namespace:Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences"
mc:Ignorable="d"
d:DesignHeight="500" d:DesignWidth="800">
<Control.Resources>
<Style TargetType="ListBoxItem">
<Setter Property="IsTabStop"
Value="False" />
</Style>
<Thickness x:Key="labelPadding">0, 5, 0, 2</Thickness>
<Thickness x:Key="okCancelButtonPadding">9,2,9,2</Thickness>
<Thickness x:Key="selectDeselectButtonPadding">9,2,9,2</Thickness>
<Thickness x:Key="textboxPadding">2</Thickness>
</Control.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical" Grid.Row="0">
<TextBlock Margin="9 5 5 5" TextWrapping="Wrap" Grid.Row="0" HorizontalAlignment="Left" Text="{Binding NamingStylesExplanationPart1}"/>
<TextBlock Margin="9 0 5 5" TextWrapping="Wrap" Grid.Row="0" HorizontalAlignment="Left" Text="{Binding NamingStylesExplanationPart2}"/>
</StackPanel>
<Separator Grid.Row="1" Margin="0 5 0 0" Visibility="Collapsed"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Grid.Row="2" Margin="9 8 0 0">
<Button Click="AddRule_Click" Height="24" Width="24">
<imaging:CrispImage Height="16"
Width="16"
Moniker="{x:Static imagecatalog:KnownMonikers.Add}"/>
</Button>
<Button Click="DeleteRule_Click" Margin="6 0 0 0" Height="24" Width="24">
<imaging:CrispImage Height="16"
Width="16"
Moniker="{x:Static imagecatalog:KnownMonikers.DeleteListItem}"/>
</Button>
</StackPanel>
<Border Margin="9"
Grid.Row="3"
BorderThickness="1" BorderBrush="Gray">
<vsi:PivotTreeView x:Name="RootTreeView" >
<vsi:PivotTreeView.Resources>
<Style TargetType="vsi:HighlightTextBlock">
<Setter Property="Margin" Value="0, 2"/>
</Style>
<Style TargetType="vsi:EditableItemTextBox">
<Setter Property="Margin" Value="0, 2"/>
</Style>
</vsi:PivotTreeView.Resources>
</vsi:PivotTreeView>
</Border>
</Grid>
</options:AbstractOptionPageControl>
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using System.Xml.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Simplification;
using Microsoft.CodeAnalysis.SymbolCategorization;
using Microsoft.Internal.VisualStudio.PlatformUI;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Shell;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences
{
/// <summary>
/// Interaction logic for NamingStylesOptionPageControl.xaml
/// </summary>
internal partial class NamingStylesOptionPageControl : AbstractOptionPageControl
{
private NamingStylesOptionPageControlViewModel _viewModel;
private string _languageName;
private readonly INotificationService _notificationService;
private readonly ImmutableArray<string> _categories;
internal NamingStylesOptionPageControl(IServiceProvider serviceProvider, string languageName)
: base(serviceProvider)
{
_languageName = languageName;
var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));
var workspace = componentModel.GetService<VisualStudioWorkspace>() as VisualStudioWorkspace;
var notificationService = workspace.Services.GetService<INotificationService>();
var categorizers = componentModel.GetExtensions<ISymbolCategorizer>();
this._categories = categorizers.SelectMany(c => c.SupportedCategories).ToImmutableArray();
this._notificationService = notificationService;
InitializeComponent();
this.AddHandler(UIElementDialogPage.DialogKeyPendingEvent, (RoutedEventHandler)OnDialogKeyPending);
LoadSettings();
}
private void OnDialogKeyPending(object sender, RoutedEventArgs e)
{
// Don't let Escape or Enter close the Options page while we're renaming.
if (this.RootTreeView.IsInRenameMode)
{
e.Handled = true;
}
}
private IEnumerable<object> GetParent(object item)
{
NamingRuleTreeItemViewModel viewModel = item as NamingRuleTreeItemViewModel;
if (viewModel != null && viewModel.Parent != null)
{
yield return viewModel.Parent;
}
}
private void EnsureAncestorsExpanded(NamingRuleTreeItemViewModel item)
{
Stack<NamingRuleTreeItemViewModel> models = new Stack<NamingRuleTreeItemViewModel>();
NamingRuleTreeItemViewModel iter = item.Parent;
while (iter != null)
{
models.Push(iter);
iter = iter.Parent;
}
while (models.Count > 0)
{
NamingRuleTreeItemViewModel manager = models.Pop();
IVirtualizingTreeNode managerNode = this.RootTreeView.GetFirstTreeNode(manager);
managerNode.IsExpanded = true;
}
}
private void AddRule_Click(object sender, RoutedEventArgs e)
{
var viewModel = new NamingRuleDialogViewModel(
string.Empty,
null,
_viewModel.SymbolSpecificationList,
null,
_viewModel.NamingStyleList,
null,
_viewModel.CreateAllowableParentList(_viewModel.rootNamingRule),
new EnforcementLevel(DiagnosticSeverity.Hidden),
_notificationService);
var dialog = new NamingRuleDialog(viewModel, _viewModel, _categories, _notificationService);
var result = dialog.ShowModal();
if (result == true)
{
_viewModel.AddNamingRule(viewModel);
}
}
private void DeleteRule_Click(object sender, RoutedEventArgs e)
{
var index = RootTreeView.SelectedIndex;
if (index > 0)
{
_viewModel.DeleteRuleAtIndex(index);
}
}
private void NamingConventionList_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
var item = ((FrameworkElement)e.OriginalSource).DataContext as NamingStyleViewModel;
if (item != null)
{
var style = item.GetNamingStyle();
var styleClone = style.Clone();
var itemClone = new NamingStyleViewModel(styleClone, item._notificationService);
var dialog = new NamingStyleDialog(itemClone);
var result = dialog.ShowModal();
if (result == true)
{
item.NamingConventionName = itemClone.NamingConventionName;
item.RequiredPrefix = itemClone.RequiredPrefix;
item.RequiredSuffix = itemClone.RequiredSuffix;
item.WordSeparator = itemClone.WordSeparator;
item.FirstWordGroupCapitalization = itemClone.FirstWordGroupCapitalization;
}
}
}
private void SymbolSpecificationList_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
var item = ((FrameworkElement)e.OriginalSource).DataContext as SymbolSpecificationViewModel;
if (item != null)
{
var itemClone = new SymbolSpecificationViewModel(_viewModel.LanguageName, _categories, item.GetSymbolSpecification(), _notificationService);
var dialog = new SymbolSpecificationDialog(itemClone);
var result = dialog.ShowModal();
if (result == true)
{
item.ModifierList = itemClone.ModifierList;
item.SymbolKindList = itemClone.SymbolKindList;
item.AccessibilityList = itemClone.AccessibilityList;
item.SymbolSpecName = itemClone.SymbolSpecName;
item.CustomTagList = itemClone.CustomTagList;
}
}
}
internal override void SaveSettings()
{
base.SaveSettings();
var namingPreferencesXml = _viewModel.GetInfo().CreateXElement().ToString();
var oldOptions = OptionService.GetOptions();
var newOptions = oldOptions.WithChangedOption(SimplificationOptions.NamingPreferences, _languageName, namingPreferencesXml);
OptionService.SetOptions(newOptions);
OptionLogger.Log(oldOptions, newOptions);
}
internal override void LoadSettings()
{
base.LoadSettings();
var namingPreferencesXml = this.OptionService.GetOption(SimplificationOptions.NamingPreferences, _languageName);
SerializableNamingStylePreferencesInfo preferencesInfo;
if (string.IsNullOrEmpty(namingPreferencesXml))
{
preferencesInfo = new SerializableNamingStylePreferencesInfo();
}
else
{
preferencesInfo = SerializableNamingStylePreferencesInfo.FromXElement(XElement.Parse(namingPreferencesXml));
}
_viewModel = new NamingStylesOptionPageControlViewModel(preferencesInfo, _languageName, _categories, _notificationService);
this.DataContext = _viewModel;
this.RootTreeView.ItemsPath = nameof(NamingRuleTreeItemViewModel.Children);
this.RootTreeView.IsExpandablePath = nameof(NamingRuleTreeItemViewModel.HasChildren);
this.RootTreeView.FilterParentEvaluator = GetParent;
this.RootTreeView.RootItemsSource = new ObservableCollection<NamingRuleTreeItemViewModel>() { _viewModel.rootNamingRule };
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Input;
using Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.VisualStudio.Imaging;
using Microsoft.VisualStudio.LanguageServices.Implementation.Utilities;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences
{
internal partial class NamingStylesOptionPageControlViewModel : AbstractNotifyPropertyChanged
{
internal readonly INotificationService notificationService;
internal readonly NamingRuleTreeItemViewModel rootNamingRule;
internal readonly ImmutableArray<string> categories;
public string NamingStylesExplanationPart1 => ServicesVSResources.Naming_Rules_allow_you_to_define_how_particular_sets_of_symbols_should_be_named_and_how_incorrectly_named_symbols_should_be_handled;
public string NamingStylesExplanationPart2 => ServicesVSResources.The_first_matching_top_level_Naming_Rule_is_used_by_default_when_naming_a_symbol_while_any_special_cases_are_handled_by_a_matching_child_rule;
private readonly string _languageName;
internal string LanguageName
{
get { return _languageName; }
}
public ObservableCollection<SymbolSpecificationViewModel> SymbolSpecificationList { get; set; }
public ObservableCollection<NamingStyleViewModel> NamingStyleList { get; set; }
internal NamingStylesOptionPageControlViewModel(SerializableNamingStylePreferencesInfo info, string languageName, ImmutableArray<string> categories, INotificationService notificationService)
{
this._languageName = languageName;
this.categories = categories;
this.notificationService = notificationService;
this.SymbolSpecificationList = new ObservableCollection<SymbolSpecificationViewModel>(info.SymbolSpecifications.Select(s => new SymbolSpecificationViewModel(languageName, categories, s, notificationService)));
this.NamingStyleList = new ObservableCollection<NamingStyleViewModel>(info.NamingStyles.Select(s => new NamingStyleViewModel(s, this.notificationService)));
this.rootNamingRule = CreateRoot(info);
}
internal void AddSymbolSpecification(SymbolSpecificationViewModel viewModel)
{
SymbolSpecificationList.Add(viewModel);
}
internal void AddNamingStyle(NamingStyleViewModel viewModel)
{
NamingStyleList.Add(viewModel);
}
internal void AddNamingRule(NamingRuleDialogViewModel viewModel)
{
var newNode = new NamingRuleTreeItemViewModel(
viewModel.Title,
viewModel.SymbolSpecificationList.GetItemAt(viewModel.SelectedSymbolSpecificationIndex) as SymbolSpecificationViewModel,
viewModel.NamingStyleList.GetItemAt(viewModel.NamingStyleIndex) as NamingStyleViewModel,
viewModel.EnforcementLevelsList[viewModel.EnforcementLevelIndex],
this);
if (viewModel.ParentRuleIndex == 0)
{
rootNamingRule.Children.Add(newNode);
}
else
{
var parent = viewModel.ParentRuleList.GetItemAt(viewModel.ParentRuleIndex) as NamingRuleTreeItemViewModel;
parent.Children.Add(newNode);
}
}
private NamingRuleTreeItemViewModel CreateRoot(SerializableNamingStylePreferencesInfo info)
{
var root = new NamingRuleTreeItemViewModel("Naming Rules:");
CreateRootHelper(root, info.NamingRules);
return root;
}
private void CreateRootHelper(NamingRuleTreeItemViewModel rule, List<SerializableNamingRule> children)
{
foreach (var child in children)
{
var newRule = new NamingRuleTreeItemViewModel(
child.Title,
SymbolSpecificationList.SingleOrDefault(s => s.ID == child.SymbolSpecificationID),
NamingStyleList.SingleOrDefault(s => s.ID == child.NamingStyleID),
new EnforcementLevel(child.EnforcementLevel),
this);
CreateRootHelper(newRule, child.Children);
rule.Children.Add(newRule);
}
}
public SerializableNamingStylePreferencesInfo GetInfo()
{
// TODO!
var info = new SerializableNamingStylePreferencesInfo();
info.SymbolSpecifications = SymbolSpecificationList.Select(s => s.GetSymbolSpecification()).ToList();
info.NamingStyles = NamingStyleList.Select(s => s.GetNamingStyle()).ToList();
info.NamingRules = CreateNamingRuleTree();
return info;
}
private List<SerializableNamingRule> CreateNamingRuleTree()
{
var result = new List<SerializableNamingRule>();
CreateNamingRuleTreeHelper(result, rootNamingRule.Children);
return result;
}
private void CreateNamingRuleTreeHelper(List<SerializableNamingRule> result, IList<NamingRuleTreeItemViewModel> children)
{
foreach (var child in children)
{
var childTree = new SerializableNamingRule
{
Title = child.Title,
Children = new List<SerializableNamingRule>(),
SymbolSpecificationID = child.symbolSpec?.ID ?? Guid.Empty,
NamingStyleID = child.namingStyle?.ID ?? Guid.Empty,
EnforcementLevel = child.EnforcementLevel.Value
};
CreateNamingRuleTreeHelper(childTree.Children, child.Children);
result.Add(childTree);
}
}
internal bool TrySubmit()
{
return true;
}
internal List<NamingRuleTreeItemViewModel> CreateAllowableParentList(NamingRuleTreeItemViewModel excludedSubtree = null)
{
var ruleList = new List<NamingRuleTreeItemViewModel>();
foreach (var child in rootNamingRule.Children)
{
CreateAllowableParentListHelper(child, ruleList, excludedSubtree);
}
return ruleList;
}
public void KeyCommand(object sender, KeyEventArgs e)
{
}
private void CreateAllowableParentListHelper(NamingRuleTreeItemViewModel ruleToProcess, List<NamingRuleTreeItemViewModel> ruleList, NamingRuleTreeItemViewModel excludedSubtree)
{
if (ruleToProcess == excludedSubtree)
{
return;
}
ruleList.Add(ruleToProcess);
foreach (var child in ruleToProcess.Children)
{
CreateAllowableParentListHelper(child, ruleList, excludedSubtree);
}
}
internal void DeleteSymbolSpec(SymbolSpecificationViewModel a)
{
if (!SymbolSpecUsedInTree(a))
{
SymbolSpecificationList.Remove(a);
}
}
internal void DeleteNamingStyle(NamingStyleViewModel a)
{
if (!NamingStyleUsedInTree(a))
{
NamingStyleList.Remove(a);
}
}
internal void DeleteRuleAtIndex(int a)
{
var rule = GetRuleAtPosition(a);
if (rule != null)
{
DeleteRule(rule);
}
}
private NamingRuleTreeItemViewModel GetRuleAtPosition(int a)
{
Queue<NamingRuleTreeItemViewModel> q = new Queue<NamingRuleTreeItemViewModel>();
q.Enqueue(rootNamingRule);
for (int i = 0; i <= a; i++)
{
var elementAtIndex = q.Dequeue();
if (i == a)
{
return elementAtIndex;
}
if (elementAtIndex.HasChildren)
{
foreach (var child in elementAtIndex.Children)
{
q.Enqueue(child);
}
}
}
return null;
}
internal void DeleteRule(NamingRuleTreeItemViewModel a)
{
if (!a.HasChildren && a.Parent != null)
{
a.Parent.Children.Remove(a);
}
}
private bool SymbolSpecUsedInTree(SymbolSpecificationViewModel a)
{
return rootNamingRule.Children.Any(c => c.symbolSpec == a || SymbolSpecUsedInTree(a, c));
}
private bool SymbolSpecUsedInTree(SymbolSpecificationViewModel a, NamingRuleTreeItemViewModel c)
{
return c.Children.Any(child => child.symbolSpec == a || SymbolSpecUsedInTree(a, child));
}
private bool NamingStyleUsedInTree(NamingStyleViewModel a)
{
return rootNamingRule.Children.Any(c => c.namingStyle == a || NamingStyleUsedInTree(a, c));
}
private bool NamingStyleUsedInTree(NamingStyleViewModel a, NamingRuleTreeItemViewModel c)
{
return c.Children.Any(child => child.namingStyle == a || NamingStyleUsedInTree(a, child));
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.VisualStudio.LanguageServices.Implementation.Utilities;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences
{
internal class ManageSymbolSpecificationsDialogViewModel : AbstractNotifyPropertyChanged, IManageNamingStylesInfoDialogViewModel
{
private readonly INotificationService _notificationService;
public ObservableCollection<INamingStylesInfoDialogViewModel> Items { get; set; }
public string LanguageName { get; private set; }
public string DialogTitle => "Manage Specifications";
public ManageSymbolSpecificationsDialogViewModel(
ObservableCollection<SymbolSpecification> specifications,
List<NamingStyleOptionPageViewModel.NamingRuleViewModel> namingRules,
string languageName,
INotificationService notificationService)
{
LanguageName = languageName;
_notificationService = notificationService;
Items = new ObservableCollection<INamingStylesInfoDialogViewModel>(specifications.Select(specification => new SymbolSpecificationViewModel(
languageName,
specification,
!namingRules.Any(rule => rule.SelectedSpecification?.ID == specification.ID),
notificationService)));
}
internal void AddSymbolSpecification(INamingStylesInfoDialogViewModel symbolSpecification)
{
}
internal void RemoveSymbolSpecification(INamingStylesInfoDialogViewModel symbolSpecification)
{
Items.Remove(symbolSpecification);
}
public void AddItem()
{
var viewModel = new SymbolSpecificationViewModel(LanguageName, canBeDeleted: true, notificationService: _notificationService);
var dialog = new SymbolSpecificationDialog(viewModel);
if (dialog.ShowDialog().Value == true)
{
Items.Add(viewModel);
}
}
public void RemoveItem(INamingStylesInfoDialogViewModel item)
{
Items.Remove(item);
}
public void EditItem(INamingStylesInfoDialogViewModel item)
{
var symbolSpecificationViewModel = (SymbolSpecificationViewModel)item;
var symbolSpecification = ((SymbolSpecificationViewModel)item).GetSymbolSpecification();
var viewModel = new SymbolSpecificationViewModel(LanguageName, symbolSpecification, symbolSpecificationViewModel.CanBeDeleted, _notificationService);
var dialog = new SymbolSpecificationDialog(viewModel);
if (dialog.ShowDialog().Value == true)
{
symbolSpecificationViewModel.ItemName = viewModel.ItemName;
symbolSpecificationViewModel.AccessibilityList = viewModel.AccessibilityList;
symbolSpecificationViewModel.ModifierList = viewModel.ModifierList;
symbolSpecificationViewModel.SymbolKindList = viewModel.SymbolKindList;
}
}
}
}
<vs:DialogWindow x:Uid="NamingPreferences"
x:Class="Microsoft.VisualStudio.LanguageServices.Implementation.Options.SymbolSpecificationDialog"
x:Class="Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences.SymbolSpecificationDialog"
x:ClassModifier="internal"
x:Name="dialog"
xmlns:vs="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.14.0"
......@@ -36,7 +36,7 @@
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Grid.Row="0" Margin="0 5 0 0">
<Label Content="{Binding ElementName=dialog, Path=SymbolSpecificationTitleLabelText}"/>
<TextBox Width="300" Text="{Binding SymbolSpecName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalContentAlignment="Center"></TextBox>
<TextBox Width="300" Text="{Binding ItemName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalContentAlignment="Center"></TextBox>
</StackPanel>
<Grid Grid.Row="1" Margin="0 5 0 0">
<Grid.ColumnDefinitions>
......@@ -144,32 +144,6 @@
<RowDefinition Height="*"/>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Content="{Binding ElementName=dialog, Path=CustomTagsLabelText}"/>
<ListView Grid.Row="1" x:Uid="MemberSelectionList2zz"
x:Name="CustomTags"
Margin="8 4 8 7"
SelectionMode="Extended"
MinWidth="130"
ItemsSource="{Binding CustomTagList, Mode=TwoWay}">
<ListView.ItemTemplate x:Uid="SelectableMemberListItemzz">
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox x:Uid="SelectableMemberCheckBox"
IsChecked="{Binding IsChecked, Mode=TwoWay}"
Width="Auto"
Focusable="False"
AutomationProperties.AutomationId="{Binding MemberName}">
</CheckBox>
<TextBlock x:Uid="SelectableMemberName" Margin="4 0 0 0"
Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Left">
<vs:DialogButton Margin="8 0 0 0" Content="{Binding ElementName=dialog, Path=SelectAllButtonText}" Click="SelectAllCustomTags"/>
<vs:DialogButton Margin="7 0 0 0" Content="{Binding ElementName=dialog, Path=DeselectAllButtonText}" Click="DeselectAllCustomTags"/>
</StackPanel>
</Grid>
</Grid>
......
......@@ -6,7 +6,7 @@
using System.Windows.Input;
using Microsoft.VisualStudio.PlatformUI;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences
{
internal partial class SymbolSpecificationDialog : DialogWindow
{
......@@ -16,7 +16,6 @@ internal partial class SymbolSpecificationDialog : DialogWindow
public string SymbolSpecificationTitleLabelText => ServicesVSResources.Symbol_Specification_Title_colon;
public string SymbolKindsLabelText => ServicesVSResources.Symbol_Kinds_can_match_any;
public string AccessibilitiesLabelText => ServicesVSResources.Accessibilities_can_match_any;
public string CustomTagsLabelText => ServicesVSResources.Custom_Tags_must_match_all;
public string ModifiersLabelText => ServicesVSResources.Modifiers_must_match_all;
public string SelectAllButtonText => ServicesVSResources.Select_All;
public string DeselectAllButtonText => ServicesVSResources.Deselect_All;
......@@ -111,22 +110,6 @@ private void DeselectAllModifiers(object sender, RoutedEventArgs e)
}
}
private void SelectAllCustomTags(object sender, RoutedEventArgs e)
{
foreach (var item in CustomTags.Items.OfType<SymbolSpecificationViewModel.CustomTagViewModel>())
{
item.IsChecked = true;
}
}
private void DeselectAllCustomTags(object sender, RoutedEventArgs e)
{
foreach (var item in CustomTags.Items.OfType<SymbolSpecificationViewModel.CustomTagViewModel>())
{
item.IsChecked = false;
}
}
private void OK_Click(object sender, RoutedEventArgs e)
{
if (_viewModel.TrySubmit())
......
......@@ -2,47 +2,43 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles;
using Microsoft.CodeAnalysis.Editing;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.VisualStudio.LanguageServices.Implementation.Utilities;
using static Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles.SymbolSpecification;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences
{
internal class SymbolSpecificationViewModel : AbstractNotifyPropertyChanged
internal class SymbolSpecificationViewModel : AbstractNotifyPropertyChanged, INamingStylesInfoDialogViewModel
{
public Guid ID { get; set; }
public List<SymbolKindViewModel> SymbolKindList { get; set; }
public List<AccessibilityViewModel> AccessibilityList { get; set; }
public List<ModifierViewModel> ModifierList { get; set; }
public List<CustomTagViewModel> CustomTagList { get; set; }
private string _symbolSpecName;
public string SymbolSpecName
{
get { return _symbolSpecName; }
set { SetProperty(ref _symbolSpecName, value); }
}
public bool CanBeDeleted { get; set; }
private readonly INotificationService _notificationService;
public SymbolSpecificationViewModel(string languageName, ImmutableArray<string> categories, INotificationService notificationService) : this(languageName, categories, new SymbolSpecification(), notificationService) { }
public SymbolSpecificationViewModel(
string languageName,
bool canBeDeleted,
INotificationService notificationService) : this(languageName, new SymbolSpecification(), canBeDeleted, notificationService) { }
public SymbolSpecificationViewModel(string languageName, ImmutableArray<string> categories, SymbolSpecification specification, INotificationService notificationService)
public SymbolSpecificationViewModel(string languageName, SymbolSpecification specification, bool canBeDeleted, INotificationService notificationService)
{
CanBeDeleted = canBeDeleted;
_notificationService = notificationService;
SymbolSpecName = specification.Name;
ItemName = specification.Name;
ID = specification.ID;
CustomTagList = new List<CustomTagViewModel>();
foreach (var category in categories)
{
CustomTagList.Add(new CustomTagViewModel(category, specification));
}
// The list of supported SymbolKinds is limited due to https://github.com/dotnet/roslyn/issues/8753.
if (languageName == LanguageNames.CSharp)
{
......@@ -56,9 +52,7 @@ public SymbolSpecificationViewModel(string languageName, ImmutableArray<string>
new SymbolKindViewModel(SymbolKind.Method, "method", specification),
new SymbolKindViewModel(SymbolKind.Field, "field", specification),
new SymbolKindViewModel(SymbolKind.Event, "event", specification),
new SymbolKindViewModel(SymbolKind.Namespace, "namespace", specification),
new SymbolKindViewModel(TypeKind.Delegate, "delegate", specification),
new SymbolKindViewModel(TypeKind.TypeParameter, "type parameter", specification),
};
AccessibilityList = new List<AccessibilityViewModel>
......@@ -92,9 +86,7 @@ public SymbolSpecificationViewModel(string languageName, ImmutableArray<string>
new SymbolKindViewModel(SymbolKind.Method, "Method", specification),
new SymbolKindViewModel(SymbolKind.Field, "Field", specification),
new SymbolKindViewModel(SymbolKind.Event, "Event", specification),
new SymbolKindViewModel(SymbolKind.Namespace, "Namespace", specification),
new SymbolKindViewModel(TypeKind.Delegate, "Delegate", specification),
new SymbolKindViewModel(TypeKind.TypeParameter, "Type Parameter", specification),
};
AccessibilityList = new List<AccessibilityViewModel>
......@@ -121,15 +113,31 @@ public SymbolSpecificationViewModel(string languageName, ImmutableArray<string>
}
}
public string ItemName
{
get { return _symbolSpecName; }
set { SetProperty(ref _symbolSpecName, value); }
}
internal SymbolSpecification GetSymbolSpecification()
{
return new SymbolSpecification(
ID,
SymbolSpecName,
ItemName,
SymbolKindList.Where(s => s.IsChecked).Select(s => s.CreateSymbolKindOrTypeKind()).ToList(),
AccessibilityList.Where(a => a.IsChecked).Select(a => new SymbolSpecification.AccessibilityKind(a._accessibility)).ToList(),
ModifierList.Where(m => m.IsChecked).Select(m => new SymbolSpecification.ModifierKind(m._modifier)).ToList(),
CustomTagList.Where(t => t.IsChecked).Select(t => t.Name).ToList());
ModifierList.Where(m => m.IsChecked).Select(m => new ModifierKind(m._modifier)).ToList());
}
internal bool TrySubmit()
{
if (string.IsNullOrWhiteSpace(ItemName))
{
_notificationService.SendNotification(ServicesVSResources.Enter_a_title_for_this_Naming_Style);
return false;
}
return true;
}
internal interface ISymbolSpecificationViewModelPart
......@@ -165,20 +173,20 @@ public SymbolKindViewModel(TypeKind typeKind, string name, SymbolSpecification s
IsChecked = specification.ApplicableSymbolKindList.Any(k => k.TypeKind == typeKind);
}
internal SymbolSpecification.SymbolKindOrTypeKind CreateSymbolKindOrTypeKind()
internal SymbolKindOrTypeKind CreateSymbolKindOrTypeKind()
{
if (_symbolKind.HasValue)
{
return new SymbolSpecification.SymbolKindOrTypeKind(_symbolKind.Value);
return new SymbolKindOrTypeKind(_symbolKind.Value);
}
else
{
return new SymbolSpecification.SymbolKindOrTypeKind(_typeKind.Value);
return new SymbolKindOrTypeKind(_typeKind.Value);
}
}
}
public class AccessibilityViewModel: AbstractNotifyPropertyChanged, ISymbolSpecificationViewModelPart
public class AccessibilityViewModel : AbstractNotifyPropertyChanged, ISymbolSpecificationViewModelPart
{
internal readonly Accessibility _accessibility;
......@@ -200,7 +208,7 @@ public AccessibilityViewModel(Accessibility accessibility, string name, SymbolSp
}
}
public class ModifierViewModel: AbstractNotifyPropertyChanged, ISymbolSpecificationViewModelPart
public class ModifierViewModel : AbstractNotifyPropertyChanged, ISymbolSpecificationViewModelPart
{
public string Name { get; set; }
......@@ -215,39 +223,11 @@ public bool IsChecked
public ModifierViewModel(DeclarationModifiers modifier, string name, SymbolSpecification specification)
{
this._modifier = modifier;
Name = name;
IsChecked = specification.RequiredModifierList.Any(m => m.Modifier == modifier);
}
}
public class CustomTagViewModel : AbstractNotifyPropertyChanged, ISymbolSpecificationViewModelPart
{
public string Name { get; set; }
private bool _isChecked;
public bool IsChecked
{
get { return _isChecked; }
set { SetProperty(ref _isChecked, value); }
}
public CustomTagViewModel(string name, SymbolSpecification specification)
{
_modifier = modifier;
Name = name;
IsChecked = specification.RequiredCustomTagList.Contains(name);
}
}
internal bool TrySubmit()
{
if (string.IsNullOrWhiteSpace(SymbolSpecName))
{
_notificationService.SendNotification(ServicesVSResources.Enter_a_title_for_this_Symbol_Specification);
return false;
IsChecked = specification.RequiredModifierList.Any(m => m.Modifier == modifier);
}
return true;
}
}
}
......@@ -85,6 +85,7 @@
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Design" />
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.Serialization" />
......@@ -241,30 +242,26 @@
<Compile Include="Options\OptionBinding.cs" />
<Compile Include="Options\PerLanguageOptionBinding.cs" />
<Compile Include="Options\RadioButtonViewModel.cs" />
<Compile Include="Options\Style\NamingPreferences\EnforcementLevel.cs" />
<Compile Include="Options\Style\NamingPreferences\NamingStylesOptionPageControl.xaml.cs">
<DependentUpon>NamingStylesOptionPageControl.xaml</DependentUpon>
</Compile>
<Compile Include="Options\Style\NamingPreferences\NamingStylesOptionPageControlViewModel.cs" />
<Compile Include="Options\Style\NamingPreferences\NamingRuleDialogViewModel.cs" />
<Compile Include="Options\Style\NamingPreferences\NamingRuleTreeItemViewModel.cs" />
<Compile Include="Options\Style\NamingPreferences\NamingRuleTreeItemViewModel.DragDropSourcePattern.cs" />
<Compile Include="Options\Style\NamingPreferences\NamingRuleTreeItemViewModel.DragDropTargetPattern.cs" />
<Compile Include="Options\Style\NamingPreferences\NamingRuleTreeItemViewModel.InteractionPatternProvider.cs" />
<Compile Include="Options\Style\NamingPreferences\NamingRuleTreeItemViewModel.InvocationPattern.cs" />
<Compile Include="Options\Style\NamingPreferences\NamingRuleTreeItemViewModel.RenamePattern.cs" />
<Compile Include="Options\Style\NamingPreferences\NamingRuleTreeItemViewModel.TreeDisplayItem.cs" />
<Compile Include="Options\Style\NamingPreferences\NamingRuleDialog.xaml.cs">
<DependentUpon>NamingRuleDialog.xaml</DependentUpon>
<Compile Include="Options\Style\NamingPreferences\IManageNamingStylesInfoDialogViewModel.cs" />
<Compile Include="Options\Style\NamingPreferences\INamingStylesInfoDialogViewModel.cs" />
<Compile Include="Options\Style\NamingPreferences\ManageNamingStylesInfoDialog.xaml.cs">
<DependentUpon>ManageNamingStylesInfoDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Options\Style\NamingPreferences\NamingStyleViewModel.cs" />
<Compile Include="Options\Style\NamingPreferences\NamingStyleDialog.xaml.cs">
<Compile Include="Options\Style\NamingPreferences\SymbolSpecification\ManageSymbolSpecificationsDialogViewModel.cs" />
<Compile Include="Options\Style\NamingPreferences\NamingStyles\NamingStyleDialog.xaml.cs">
<DependentUpon>NamingStyleDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Options\SymbolSpecification\SymbolSpecificationDialog.xaml.cs">
<Compile Include="Options\Style\NamingPreferences\NamingStyles\ManageNamingStylesDialogViewModel.cs" />
<Compile Include="Options\Style\NamingPreferences\NamingStyles\NamingStyleViewModel.cs" />
<Compile Include="Options\Style\NamingPreferences\NamingStyleOptionPageControl.xaml.cs">
<DependentUpon>NamingStyleOptionPageControl.xaml</DependentUpon>
</Compile>
<Compile Include="Options\Style\NamingPreferences\EnforcementLevel.cs" />
<Compile Include="Options\Style\NamingPreferences\NamingStyleOptionPageViewModel.cs" />
<Compile Include="Options\Style\NamingPreferences\SymbolSpecification\SymbolSpecificationDialog.xaml.cs">
<DependentUpon>SymbolSpecificationDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Options\SymbolSpecification\SymbolSpecificationViewModel.cs" />
<Compile Include="Options\Style\NamingPreferences\SymbolSpecification\SymbolSpecificationViewModel.cs" />
<Compile Include="ProjectSystem\CPS\CPSProject.cs" />
<Compile Include="ProjectSystem\CPS\CPSCodeModelFactory.cs" />
<Compile Include="ProjectSystem\CPS\CPSProjectFactory.cs" />
......@@ -282,23 +279,23 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Options\Style\NamingPreferences\NamingStylesOptionPageControl.xaml">
<Page Include="Options\Style\NamingPreferences\ManageNamingStylesInfoDialog.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Options\Style\NamingPreferences\NamingRuleDialog.xaml">
<Page Include="Options\Style\NamingPreferences\NamingStyles\NamingStyleDialog.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Options\Style\NamingPreferences\NamingStyleDialog.xaml">
<Page Include="Options\Style\NamingPreferences\NamingStyleOptionPageControl.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Options\SymbolSpecification\SymbolSpecificationDialog.xaml">
<Page Include="Options\Style\NamingPreferences\SymbolSpecification\SymbolSpecificationDialog.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup />
<Import Project="..\..\..\..\build\Targets\VSL.Imports.targets" />
</Project>
</Project>
\ No newline at end of file
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports Microsoft.CodeAnalysis
Imports Microsoft.CodeAnalysis.Editor.UnitTests
Imports Microsoft.VisualStudio.Composition
Imports Microsoft.VisualStudio.LanguageServices.Implementation.Options
Imports Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences
Imports Roslyn.Test.Utilities
Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Options.Style.NamingPreferences
Public Class NamingRuleDialogViewModelTests
Private _exportProvider As ExportProvider = MinimalTestExportProvider.CreateExportProvider(
TestExportProvider.MinimumCatalogWithCSharpAndVisualBasic.WithPart(GetType(StubVsEditorAdaptersFactoryService)))
<WpfFact>
Public Sub TestTODO()
Dim viewModel = New NamingRuleDialogViewModel(
"Title",
Nothing,
New List(Of SymbolSpecificationViewModel),
Nothing,
New List(Of NamingStyleViewModel),
Nothing,
New List(Of NamingRuleTreeItemViewModel),
New EnforcementLevel(DiagnosticSeverity.Error),
Nothing)
End Sub
End Class
End Namespace
......@@ -288,7 +288,6 @@
<Compile Include="LanguageBlockTests.vb" />
<Compile Include="MockComponentModel.vb" />
<Compile Include="SymbolSearch\SymbolSearchUpdateEngineTests.vb" />
<Compile Include="Options\Style\NamingPreferences\NamingRuleDialogViewModelTests.vb" />
<Compile Include="Telemetry\VSTelemetryLoggerTest.vb" />
<Compile Include="Utilities\VsNavInfoHelpers.vb" />
<Compile Include="VsNavInfo\VsNavInfoTests.vb" />
......
Imports System.Runtime.InteropServices
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Runtime.InteropServices
Imports System.Windows
Imports Microsoft.CodeAnalysis
Imports Microsoft.CodeAnalysis.Notification
Imports Microsoft.VisualStudio.ComponentModelHost
Imports Microsoft.VisualStudio.LanguageServices.Implementation.Options
Imports Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences
Imports Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style
Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options
<Guid(Guids.VisualBasicOptionPageNamingStyleIdString)>
Friend Class NamingStylesOptionPage
Inherits AbstractOptionPage
Private _grid As NamingStyleOptionPageControl
Private _notificationService As INotificationService
Protected Overrides Function CreateOptionPage(serviceProvider As IServiceProvider) As AbstractOptionPageControl
Return New NamingStylesOptionPageControl(serviceProvider, LanguageNames.VisualBasic)
Dim componentModel = DirectCast(serviceProvider.GetService(GetType(SComponentModel)), IComponentModel)
Dim workspace = componentModel.GetService(Of VisualStudioWorkspace)
_notificationService = workspace.Services.GetService(Of INotificationService)
_grid = New NamingStyleOptionPageControl(serviceProvider, _notificationService, LanguageNames.VisualBasic)
Return _grid
End Function
Protected Overrides Sub OnApply(e As PageApplyEventArgs)
If _grid.ContainsErrors() Then
_notificationService.SendNotification(ServicesVSResources.Some_naming_rules_are_incomplete_Please_complete_or_remove_them)
e.ApplyBehavior = ApplyKind.Cancel
Return
End If
MyBase.OnApply(e)
End Sub
End Class
End Namespace
......@@ -95,11 +95,261 @@ public static class SimplificationOptions
[Obsolete]
public static PerLanguageOption<bool> PreferIntrinsicPredefinedTypeKeywordInMemberAccess { get; } = new PerLanguageOption<bool>(nameof(SimplificationOptions), nameof(PreferIntrinsicPredefinedTypeKeywordInMemberAccess), defaultValue: true);
private static string _defaultNamingPreferences = $@"
<NamingPreferencesInfo SerializationVersion=""3"">
<SymbolSpecifications>
<SymbolSpecification ID=""5c545a62-b14d-460a-88d8-e936c0a39316"" Name=""{WorkspacesResources.Class}"">
<ApplicableSymbolKindList>
<TypeKind>Class</TypeKind>
</ApplicableSymbolKindList>
<ApplicableAccessibilityList>
<AccessibilityKind>Public</AccessibilityKind>
<AccessibilityKind>Internal</AccessibilityKind>
<AccessibilityKind>Private</AccessibilityKind>
<AccessibilityKind>Protected</AccessibilityKind>
<AccessibilityKind>ProtectedOrInternal</AccessibilityKind>
</ApplicableAccessibilityList>
<RequiredModifierList />
</SymbolSpecification>
<SymbolSpecification ID=""23d856b4-5089-4405-83ce-749aada99153"" Name=""{WorkspacesResources.Interface}"">
<ApplicableSymbolKindList>
<TypeKind>Interface</TypeKind>
</ApplicableSymbolKindList>
<ApplicableAccessibilityList>
<AccessibilityKind>Public</AccessibilityKind>
<AccessibilityKind>Internal</AccessibilityKind>
<AccessibilityKind>Private</AccessibilityKind>
<AccessibilityKind>Protected</AccessibilityKind>
<AccessibilityKind>ProtectedOrInternal</AccessibilityKind>
</ApplicableAccessibilityList>
<RequiredModifierList />
</SymbolSpecification>
<SymbolSpecification ID=""d1796e78-ff66-463f-8576-eb46416060c0"" Name=""{WorkspacesResources.Struct}"">
<ApplicableSymbolKindList>
<TypeKind>Struct</TypeKind>
</ApplicableSymbolKindList>
<ApplicableAccessibilityList>
<AccessibilityKind>Public</AccessibilityKind>
<AccessibilityKind>Internal</AccessibilityKind>
<AccessibilityKind>Private</AccessibilityKind>
<AccessibilityKind>Protected</AccessibilityKind>
<AccessibilityKind>ProtectedOrInternal</AccessibilityKind>
</ApplicableAccessibilityList>
<RequiredModifierList />
</SymbolSpecification>
<SymbolSpecification ID=""d8af8dc6-1ade-441d-9947-8946922e198a"" Name=""{WorkspacesResources.Enum}"">
<ApplicableSymbolKindList>
<TypeKind>Enum</TypeKind>
</ApplicableSymbolKindList>
<ApplicableAccessibilityList>
<AccessibilityKind>Public</AccessibilityKind>
<AccessibilityKind>Internal</AccessibilityKind>
<AccessibilityKind>Private</AccessibilityKind>
<AccessibilityKind>Protected</AccessibilityKind>
<AccessibilityKind>ProtectedOrInternal</AccessibilityKind>
</ApplicableAccessibilityList>
<RequiredModifierList />
</SymbolSpecification>
<SymbolSpecification ID=""408a3347-b908-4b54-a954-1355e64c1de3"" Name=""{WorkspacesResources.Delegate}"">
<ApplicableSymbolKindList>
<TypeKind>Delegate</TypeKind>
</ApplicableSymbolKindList>
<ApplicableAccessibilityList>
<AccessibilityKind>Public</AccessibilityKind>
<AccessibilityKind>Internal</AccessibilityKind>
<AccessibilityKind>Private</AccessibilityKind>
<AccessibilityKind>Protected</AccessibilityKind>
<AccessibilityKind>ProtectedOrInternal</AccessibilityKind>
</ApplicableAccessibilityList>
<RequiredModifierList />
</SymbolSpecification>
<SymbolSpecification ID=""830657f6-e7e5-4830-b328-f109d3b6c165"" Name=""{WorkspacesResources.Event}"">
<ApplicableSymbolKindList>
<SymbolKind>Event</SymbolKind>
</ApplicableSymbolKindList>
<ApplicableAccessibilityList>
<AccessibilityKind>Public</AccessibilityKind>
<AccessibilityKind>Internal</AccessibilityKind>
<AccessibilityKind>Private</AccessibilityKind>
<AccessibilityKind>Protected</AccessibilityKind>
<AccessibilityKind>ProtectedOrInternal</AccessibilityKind>
</ApplicableAccessibilityList>
<RequiredModifierList />
</SymbolSpecification>
<SymbolSpecification ID=""390caed4-f0a9-42bb-adbb-b44c4a302a22"" Name=""{WorkspacesResources.Method}"">
<ApplicableSymbolKindList>
<SymbolKind>Method</SymbolKind>
</ApplicableSymbolKindList>
<ApplicableAccessibilityList>
<AccessibilityKind>Public</AccessibilityKind>
</ApplicableAccessibilityList>
<RequiredModifierList />
</SymbolSpecification>
<SymbolSpecification ID=""af410767-f189-47c6-b140-aeccf1ff242e"" Name=""{WorkspacesResources.Private_Method}"">
<ApplicableSymbolKindList>
<SymbolKind>Method</SymbolKind>
</ApplicableSymbolKindList>
<ApplicableAccessibilityList>
<AccessibilityKind>Private</AccessibilityKind>
</ApplicableAccessibilityList>
<RequiredModifierList />
</SymbolSpecification>
<SymbolSpecification ID=""8076757e-6a4a-47f1-9b4b-ae8a3284e987"" Name=""{WorkspacesResources.Abstract_Method}"">
<ApplicableSymbolKindList>
<SymbolKind>Method</SymbolKind>
</ApplicableSymbolKindList>
<ApplicableAccessibilityList>
<AccessibilityKind>Public</AccessibilityKind>
<AccessibilityKind>Internal</AccessibilityKind>
<AccessibilityKind>Private</AccessibilityKind>
<AccessibilityKind>Protected</AccessibilityKind>
<AccessibilityKind>ProtectedOrInternal</AccessibilityKind>
</ApplicableAccessibilityList>
<RequiredModifierList>
<ModifierKind>IsAbstract</ModifierKind>
</RequiredModifierList>
</SymbolSpecification>
<SymbolSpecification ID=""16133061-a8e7-4392-92c3-1d93cd54c218"" Name=""{WorkspacesResources.Static_Method}"">
<ApplicableSymbolKindList>
<SymbolKind>Method</SymbolKind>
</ApplicableSymbolKindList>
<ApplicableAccessibilityList>
<AccessibilityKind>Public</AccessibilityKind>
<AccessibilityKind>Internal</AccessibilityKind>
<AccessibilityKind>Private</AccessibilityKind>
<AccessibilityKind>Protected</AccessibilityKind>
<AccessibilityKind>ProtectedOrInternal</AccessibilityKind>
</ApplicableAccessibilityList>
<RequiredModifierList>
<ModifierKind>IsStatic</ModifierKind>
</RequiredModifierList>
</SymbolSpecification>
<SymbolSpecification ID=""03a274df-b686-4a76-9138-96aecb9bd33b"" Name=""{WorkspacesResources.Async_Method}"">
<ApplicableSymbolKindList>
<SymbolKind>Method</SymbolKind>
</ApplicableSymbolKindList>
<ApplicableAccessibilityList>
<AccessibilityKind>Public</AccessibilityKind>
<AccessibilityKind>Internal</AccessibilityKind>
<AccessibilityKind>Private</AccessibilityKind>
<AccessibilityKind>Protected</AccessibilityKind>
<AccessibilityKind>ProtectedOrInternal</AccessibilityKind>
</ApplicableAccessibilityList>
<RequiredModifierList>
<ModifierKind>IsAsync</ModifierKind>
</RequiredModifierList>
</SymbolSpecification>
<SymbolSpecification ID=""da6a2919-5aa6-4ad1-a24d-576776ed3974"" Name=""{WorkspacesResources.Property}"">
<ApplicableSymbolKindList>
<SymbolKind>Property</SymbolKind>
</ApplicableSymbolKindList>
<ApplicableAccessibilityList>
<AccessibilityKind>Public</AccessibilityKind>
<AccessibilityKind>Internal</AccessibilityKind>
<AccessibilityKind>Private</AccessibilityKind>
<AccessibilityKind>Protected</AccessibilityKind>
<AccessibilityKind>ProtectedOrInternal</AccessibilityKind>
</ApplicableAccessibilityList>
<RequiredModifierList />
</SymbolSpecification>
<SymbolSpecification ID=""b24a91ce-3501-4799-b6df-baf044156c83"" Name=""{WorkspacesResources.Public_or_Protected_Field}"">
<ApplicableSymbolKindList>
<SymbolKind>Field</SymbolKind>
</ApplicableSymbolKindList>
<ApplicableAccessibilityList>
<AccessibilityKind>Public</AccessibilityKind>
<AccessibilityKind>Protected</AccessibilityKind>
</ApplicableAccessibilityList>
<RequiredModifierList />
</SymbolSpecification>
<SymbolSpecification ID=""70af42cb-1741-4027-969c-9edc4877d965"" Name=""{WorkspacesResources.Static_Field}"">
<ApplicableSymbolKindList>
<SymbolKind>Field</SymbolKind>
</ApplicableSymbolKindList>
<ApplicableAccessibilityList>
<AccessibilityKind>Public</AccessibilityKind>
<AccessibilityKind>Internal</AccessibilityKind>
<AccessibilityKind>Private</AccessibilityKind>
<AccessibilityKind>Protected</AccessibilityKind>
<AccessibilityKind>ProtectedOrInternal</AccessibilityKind>
</ApplicableAccessibilityList>
<RequiredModifierList>
<ModifierKind>IsStatic</ModifierKind>
</RequiredModifierList>
</SymbolSpecification>
<SymbolSpecification ID=""10790aa6-0a0b-432d-a52d-d252ca92302b"" Name=""{WorkspacesResources.Private_or_Internal_Field}"">
<ApplicableSymbolKindList>
<SymbolKind>Field</SymbolKind>
</ApplicableSymbolKindList>
<ApplicableAccessibilityList>
<AccessibilityKind>Internal</AccessibilityKind>
<AccessibilityKind>Private</AccessibilityKind>
</ApplicableAccessibilityList>
<RequiredModifierList />
</SymbolSpecification>
<SymbolSpecification ID=""ac995be4-88de-4771-9dcc-a456a7c02d89"" Name=""{WorkspacesResources.Private_or_Internal_Static_Field}"">
<ApplicableSymbolKindList>
<SymbolKind>Field</SymbolKind>
</ApplicableSymbolKindList>
<ApplicableAccessibilityList>
<AccessibilityKind>Internal</AccessibilityKind>
<AccessibilityKind>Private</AccessibilityKind>
</ApplicableAccessibilityList>
<RequiredModifierList>
<ModifierKind>IsStatic</ModifierKind>
</RequiredModifierList>
</SymbolSpecification>
<SymbolSpecification ID=""2c07f5bf-bc81-4c2b-82b4-ae9b3ffd0ba4"" Name=""{WorkspacesResources.Types}"">
<ApplicableSymbolKindList>
<TypeKind>Class</TypeKind>
<TypeKind>Struct</TypeKind>
<TypeKind>Interface</TypeKind>
<TypeKind>Enum</TypeKind>
</ApplicableSymbolKindList>
<ApplicableAccessibilityList>
<AccessibilityKind>Public</AccessibilityKind>
<AccessibilityKind>Internal</AccessibilityKind>
<AccessibilityKind>Private</AccessibilityKind>
<AccessibilityKind>Protected</AccessibilityKind>
<AccessibilityKind>ProtectedOrInternal</AccessibilityKind>
</ApplicableAccessibilityList>
<RequiredModifierList />
</SymbolSpecification>
<SymbolSpecification ID=""5f3ddba1-279f-486c-801e-5c097c36dd85"" Name=""{WorkspacesResources.Non_Field_Members}"">
<ApplicableSymbolKindList>
<SymbolKind>Property</SymbolKind>
<SymbolKind>Method</SymbolKind>
<SymbolKind>Event</SymbolKind>
</ApplicableSymbolKindList>
<ApplicableAccessibilityList>
<AccessibilityKind>Public</AccessibilityKind>
<AccessibilityKind>Internal</AccessibilityKind>
<AccessibilityKind>Private</AccessibilityKind>
<AccessibilityKind>Protected</AccessibilityKind>
<AccessibilityKind>ProtectedOrInternal</AccessibilityKind>
</ApplicableAccessibilityList>
<RequiredModifierList />
</SymbolSpecification>
</SymbolSpecifications>
<NamingStyles>
<NamingStyle ID=""87e7c501-9948-4b53-b1eb-a6cbe918feee"" Name=""{WorkspacesResources.Pascal_Case}"" Prefix="""" Suffix="""" WordSeparator="""" CapitalizationScheme=""PascalCase"" />
<NamingStyle ID=""308152f2-a334-48b3-8bec-ddee40785feb"" Name=""{WorkspacesResources.Ends_with_Async}"" Prefix="""" Suffix=""Async"" WordSeparator="""" CapitalizationScheme=""PascalCase"" />
<NamingStyle ID=""1ecc5eb6-b5fc-49a5-a9f1-a980f3e48c92"" Name=""{WorkspacesResources.Begins_with_I}"" Prefix=""I"" Suffix="""" WordSeparator="""" CapitalizationScheme=""PascalCase"" />
</NamingStyles>
<NamingRules>
<SerializableNamingRule SymbolSpecificationID=""23d856b4-5089-4405-83ce-749aada99153"" NamingStyleID=""1ecc5eb6-b5fc-49a5-a9f1-a980f3e48c92"" EnforcementLevel=""Info"" />
<SerializableNamingRule SymbolSpecificationID=""2c07f5bf-bc81-4c2b-82b4-ae9b3ffd0ba4"" NamingStyleID=""87e7c501-9948-4b53-b1eb-a6cbe918feee"" EnforcementLevel=""Info"" />
<SerializableNamingRule SymbolSpecificationID=""03a274df-b686-4a76-9138-96aecb9bd33b"" NamingStyleID=""308152f2-a334-48b3-8bec-ddee40785feb"" EnforcementLevel=""Info"" />
<SerializableNamingRule SymbolSpecificationID=""5f3ddba1-279f-486c-801e-5c097c36dd85"" NamingStyleID=""87e7c501-9948-4b53-b1eb-a6cbe918feee"" EnforcementLevel=""Info"" />
</NamingRules>
</NamingPreferencesInfo>
";
/// <summary>
/// This option describes the naming rules that should be applied to specified categories of symbols,
/// and the level to which those rules should be enforced.
/// </summary>
public static PerLanguageOption<string> NamingPreferences { get; } = new PerLanguageOption<string>(nameof(SimplificationOptions), nameof(NamingPreferences), defaultValue: "",
public static PerLanguageOption<string> NamingPreferences { get; } = new PerLanguageOption<string>(nameof(SimplificationOptions), nameof(NamingPreferences), defaultValue: _defaultNamingPreferences,
storageLocations: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.NamingPreferences"));
}
}
......@@ -196,6 +196,15 @@ internal class WorkspacesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Abstract Method.
/// </summary>
internal static string Abstract_Method {
get {
return ResourceManager.GetString("Abstract_Method", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Add braces to &apos;{0}&apos; statement..
/// </summary>
......@@ -313,6 +322,15 @@ internal class WorkspacesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Async Method.
/// </summary>
internal static string Async_Method {
get {
return ResourceManager.GetString("Async_Method", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to At least one diagnostic must be supplied..
/// </summary>
......@@ -331,6 +349,15 @@ internal class WorkspacesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Begins with I.
/// </summary>
internal static string Begins_with_I {
get {
return ResourceManager.GetString("Begins_with_I", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Can&apos;t resolve analyzer reference: &apos;{0}&apos;..
/// </summary>
......@@ -449,6 +476,15 @@ internal class WorkspacesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Class.
/// </summary>
internal static string Class {
get {
return ResourceManager.GetString("Class", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Could not find location to generation symbol into..
/// </summary>
......@@ -467,6 +503,15 @@ internal class WorkspacesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Delegate.
/// </summary>
internal static string Delegate {
get {
return ResourceManager.GetString("Delegate", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Destination location was from a different tree..
/// </summary>
......@@ -557,6 +602,33 @@ internal class WorkspacesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Ends with Async.
/// </summary>
internal static string Ends_with_Async {
get {
return ResourceManager.GetString("Ends_with_Async", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Enum.
/// </summary>
internal static string Enum {
get {
return ResourceManager.GetString("Enum", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Event.
/// </summary>
internal static string Event {
get {
return ResourceManager.GetString("Event", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Exceptions:.
/// </summary>
......@@ -647,6 +719,15 @@ internal class WorkspacesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Interface.
/// </summary>
internal static string Interface {
get {
return ResourceManager.GetString("Interface", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Invalid CodePage value: {0}.
/// </summary>
......@@ -773,6 +854,15 @@ internal class WorkspacesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Method.
/// </summary>
internal static string Method {
get {
return ResourceManager.GetString("Method", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Name can be simplified..
/// </summary>
......@@ -818,6 +908,15 @@ internal class WorkspacesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Non-Field Members.
/// </summary>
internal static string Non_Field_Members {
get {
return ResourceManager.GetString("Non_Field_Members", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Options did not come from Workspace.
/// </summary>
......@@ -827,6 +926,15 @@ internal class WorkspacesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Pascal Case.
/// </summary>
internal static string Pascal_Case {
get {
return ResourceManager.GetString("Pascal_Case", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Populate switch.
/// </summary>
......@@ -836,6 +944,33 @@ internal class WorkspacesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Private Method.
/// </summary>
internal static string Private_Method {
get {
return ResourceManager.GetString("Private_Method", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Private or Internal Field.
/// </summary>
internal static string Private_or_Internal_Field {
get {
return ResourceManager.GetString("Private_or_Internal_Field", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Private or Internal Static Field.
/// </summary>
internal static string Private_or_Internal_Static_Field {
get {
return ResourceManager.GetString("Private_or_Internal_Static_Field", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Project file not found: &apos;{0}&apos;.
/// </summary>
......@@ -845,6 +980,24 @@ internal class WorkspacesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Property.
/// </summary>
internal static string Property {
get {
return ResourceManager.GetString("Property", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Public or Protected Field.
/// </summary>
internal static string Public_or_Protected_Field {
get {
return ResourceManager.GetString("Public_or_Protected_Field", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Removed:.
/// </summary>
......@@ -945,6 +1098,24 @@ internal class WorkspacesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Static Field.
/// </summary>
internal static string Static_Field {
get {
return ResourceManager.GetString("Static_Field", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Static Method.
/// </summary>
internal static string Static_Method {
get {
return ResourceManager.GetString("Static_Method", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Stream is too long..
/// </summary>
......@@ -954,6 +1125,15 @@ internal class WorkspacesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Struct.
/// </summary>
internal static string Struct {
get {
return ResourceManager.GetString("Struct", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Supplied diagnostic cannot be null..
/// </summary>
......@@ -1116,6 +1296,15 @@ internal class WorkspacesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Types.
/// </summary>
internal static string Types {
get {
return ResourceManager.GetString("Types", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Unknown identifier..
/// </summary>
......
......@@ -489,4 +489,87 @@
<data name="Stream_is_too_long" xml:space="preserve">
<value>Stream is too long.</value>
</data>
<data name="Pascal_Case" xml:space="preserve">
<value>Pascal Case</value>
</data>
<data name="Abstract_Method" xml:space="preserve">
<value>Abstract Method</value>
<comment>{locked: abstract}{locked: method} These are keywords (unless the order of words or capitalization should be handled differently)</comment>
</data>
<data name="Async_Method" xml:space="preserve">
<value>Async Method</value>
<comment>{locked: async}{locked: method} These are keywords (unless the order of words or capitalization should be handled differently)</comment>
</data>
<data name="Begins_with_I" xml:space="preserve">
<value>Begins with I</value>
<comment>{locked:I}</comment>
</data>
<data name="Class" xml:space="preserve">
<value>Class</value>
<comment>{locked} unless the capitalization should be handled differently</comment>
</data>
<data name="Delegate" xml:space="preserve">
<value>Delegate</value>
<comment>{locked} unless the capitalization should be handled differently</comment>
</data>
<data name="Ends_with_Async" xml:space="preserve">
<value>Ends with Async</value>
<comment>{locked:async}</comment>
</data>
<data name="Enum" xml:space="preserve">
<value>Enum</value>
<comment>{locked} unless the capitalization should be handled differently</comment>
</data>
<data name="Event" xml:space="preserve">
<value>Event</value>
<comment>{locked} unless the capitalization should be handled differently</comment>
</data>
<data name="Interface" xml:space="preserve">
<value>Interface</value>
<comment>{locked} unless the capitalization should be handled differently</comment>
</data>
<data name="Non_Field_Members" xml:space="preserve">
<value>Non-Field Members</value>
<comment>{locked:field}</comment>
</data>
<data name="Private_Method" xml:space="preserve">
<value>Private Method</value>
<comment>{locked: private}{locked: method} These are keywords (unless the order of words or capitalization should be handled differently)</comment>
</data>
<data name="Private_or_Internal_Field" xml:space="preserve">
<value>Private or Internal Field</value>
<comment>{locked: private}{locked: internal}{locked:field}</comment>
</data>
<data name="Private_or_Internal_Static_Field" xml:space="preserve">
<value>Private or Internal Static Field</value>
<comment>{locked: private}{locked: internal}{locked:static}{locked:field}</comment>
</data>
<data name="Property" xml:space="preserve">
<value>Property</value>
<comment>{locked} unless the capitalization should be handled differently</comment>
</data>
<data name="Public_or_Protected_Field" xml:space="preserve">
<value>Public or Protected Field</value>
<comment>{locked: public}{locked: protected}{locked:field}</comment>
</data>
<data name="Static_Field" xml:space="preserve">
<value>Static Field</value>
<comment>{locked:static}{locked:field} (unless the capitalization should be handled differently)</comment>
</data>
<data name="Static_Method" xml:space="preserve">
<value>Static Method</value>
<comment>{locked: static}{locked: method} These are keywords (unless the order of words or capitalization should be handled differently)</comment>
</data>
<data name="Struct" xml:space="preserve">
<value>Struct</value>
<comment>{locked} unless the capitalization should be handled differently</comment>
</data>
<data name="Types" xml:space="preserve">
<value>Types</value>
<comment>{locked:types} unless the capitalization should be handled differently</comment>
</data>
<data name="Method" xml:space="preserve">
<value>Method</value>
<comment>{locked:method} unless the capitalization should be handled differently</comment>
</data>
</root>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册