提交 510b6e05 编写于 作者: D David Poeschl 提交者: GitHub

Merge pull request #14974 from dpoeschl/LocalizeErrorWarningEtcInCodeStyleOptionPages

Localize "Error"/"Warning" etc. in the code style UIs
// 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;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences
{
public class EnforcementLevel
{
public EnforcementLevel(DiagnosticSeverity severity)
{
Value = severity;
switch (severity)
{
case DiagnosticSeverity.Hidden:
Name = "None";
Moniker = KnownMonikers.None;
return;
case DiagnosticSeverity.Info:
Name = "Suggestion";
Moniker = KnownMonikers.StatusInformation;
return;
case DiagnosticSeverity.Warning:
Name = "Warning";
Moniker = KnownMonikers.StatusWarning;
return;
case DiagnosticSeverity.Error:
Name = "Error";
Moniker = KnownMonikers.StatusError;
return;
default:
throw new ArgumentException("Unexpected DiagnosticSeverity", nameof(severity));
}
}
public EnforcementLevel(string name, DiagnosticSeverity value, ImageMoniker moniker)
{
Name = name;
Value = value;
Moniker = moniker;
}
public ImageMoniker Moniker { get; private set; }
public string Name { get; private set; }
public DiagnosticSeverity Value { get; private set; }
}
}
......@@ -8,9 +8,11 @@
using System.Windows.Controls;
using System.Xml.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Simplification;
using Microsoft.VisualStudio.Imaging;
using Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences;
using Microsoft.VisualStudio.PlatformUI;
......@@ -22,11 +24,13 @@ internal partial class NamingStyleOptionPageControl : AbstractOptionPageControl
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));
private readonly NotificationOptionViewModel[] _notifications = new[]
{
new NotificationOptionViewModel(NotificationOption.None, KnownMonikers.None),
new NotificationOptionViewModel(NotificationOption.Suggestion, KnownMonikers.StatusInformation),
new NotificationOptionViewModel(NotificationOption.Warning, KnownMonikers.StatusWarning),
new NotificationOptionViewModel(NotificationOption.Error, KnownMonikers.StatusError)
};
internal NamingStyleOptionPageControl(IServiceProvider serviceProvider, INotificationService notificationService, string languageName)
: base(serviceProvider)
......@@ -137,7 +141,7 @@ internal override void SaveSettings()
var rule = new SerializableNamingRule()
{
EnforcementLevel = item.SelectedNotificationPreference.Value,
EnforcementLevel = item.SelectedNotificationPreference.Notification.Value,
NamingStyleID = item.SelectedStyle.ID,
SymbolSpecificationID = item.SelectedSpecification.ID
};
......
......@@ -3,7 +3,9 @@
using System.Collections.ObjectModel;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles;
using Microsoft.VisualStudio.Imaging;
using Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences;
using Microsoft.VisualStudio.LanguageServices.Implementation.Utilities;
......@@ -14,12 +16,12 @@ internal class NamingStyleOptionPageViewModel : AbstractNotifyPropertyChanged
public string ManageSpecificationsButtonText => ServicesVSResources.Manage_specifications;
public string ManageStylesButtonText => ServicesVSResources.Manage_styles;
private readonly EnforcementLevel[] _notifications = new[]
private readonly NotificationOptionViewModel[] _notifications = new[]
{
new EnforcementLevel(DiagnosticSeverity.Hidden),
new EnforcementLevel(DiagnosticSeverity.Info),
new EnforcementLevel(DiagnosticSeverity.Warning),
new EnforcementLevel(DiagnosticSeverity.Error),
new NotificationOptionViewModel(NotificationOption.None, KnownMonikers.None),
new NotificationOptionViewModel(NotificationOption.Suggestion, KnownMonikers.StatusInformation),
new NotificationOptionViewModel(NotificationOption.Warning, KnownMonikers.StatusWarning),
new NotificationOptionViewModel(NotificationOption.Error, KnownMonikers.StatusError)
};
public ObservableCollection<NamingRuleViewModel> CodeStyleItems { get; set; }
......@@ -35,11 +37,11 @@ public NamingStyleOptionPageViewModel(SerializableNamingStylePreferencesInfo inf
viewModel.NamingStyles = new ObservableCollection<NamingStyle>(info.NamingStyles);
viewModel.Specifications = new ObservableCollection<SymbolSpecification>(info.SymbolSpecifications);
viewModel.NotificationPreferences = new List<EnforcementLevel>(_notifications);
viewModel.NotificationPreferences = new List<NotificationOptionViewModel>(_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);
viewModel.SelectedNotificationPreference = viewModel.NotificationPreferences.Single(n => n.Notification.Value == namingRule.EnforcementLevel);
viewModels.Add(viewModel);
}
......@@ -196,16 +198,16 @@ public NamingRuleViewModel()
{
Specifications = new ObservableCollection<SymbolSpecification>();
NamingStyles = new ObservableCollection<NamingStyle>();
NotificationPreferences = new List<EnforcementLevel>();
NotificationPreferences = new List<NotificationOptionViewModel>();
}
private SymbolSpecification _selectedSpecification;
private NamingStyle _selectedNamingStyle;
private EnforcementLevel _selectedNotification;
private NotificationOptionViewModel _selectedNotification;
public ObservableCollection<SymbolSpecification> Specifications { get; set; }
public ObservableCollection<NamingStyle> NamingStyles { get; set; }
public IEnumerable<EnforcementLevel> NotificationPreferences { get; set; }
public IEnumerable<NotificationOptionViewModel> NotificationPreferences { get; set; }
public SymbolSpecification SelectedSpecification
{
......@@ -230,7 +232,7 @@ public NamingStyle SelectedStyle
SetProperty(ref _selectedNamingStyle, value);
}
}
public EnforcementLevel SelectedNotificationPreference
public NotificationOptionViewModel SelectedNotificationPreference
{
get
{
......
......@@ -256,7 +256,6 @@
<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>
......
......@@ -16,10 +16,10 @@ public class NotificationOption
public DiagnosticSeverity Value { get; set; }
public static readonly NotificationOption None = new NotificationOption(nameof(None), DiagnosticSeverity.Hidden);
public static readonly NotificationOption Suggestion = new NotificationOption(nameof(Suggestion), DiagnosticSeverity.Info);
public static readonly NotificationOption Warning = new NotificationOption(nameof(Warning), DiagnosticSeverity.Warning);
public static readonly NotificationOption Error = new NotificationOption(nameof(Error), DiagnosticSeverity.Error);
public static readonly NotificationOption None = new NotificationOption(WorkspacesResources.None, DiagnosticSeverity.Hidden);
public static readonly NotificationOption Suggestion = new NotificationOption(WorkspacesResources.Suggestion, DiagnosticSeverity.Info);
public static readonly NotificationOption Warning = new NotificationOption(WorkspacesResources.Warning, DiagnosticSeverity.Warning);
public static readonly NotificationOption Error = new NotificationOption(WorkspacesResources.Error, DiagnosticSeverity.Error);
private NotificationOption(string name, DiagnosticSeverity severity)
{
......
......@@ -620,6 +620,15 @@ internal class WorkspacesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Error.
/// </summary>
internal static string Error {
get {
return ResourceManager.GetString("Error", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Event.
/// </summary>
......@@ -909,21 +918,30 @@ internal class WorkspacesResources {
}
/// <summary>
/// Looks up a localized string similar to Option &apos;{0}&apos; has an unsupported type to use with {1}. You should specify a parsing function..
/// Looks up a localized string similar to Non-Field Members.
/// </summary>
internal static string Option_0_has_an_unsupported_type_to_use_with_1_You_should_specify_a_parsing_function {
internal static string Non_Field_Members {
get {
return ResourceManager.GetString("Option_0_has_an_unsupported_type_to_use_with_1_You_should_specify_a_parsing_funct" +
"ion", resourceCulture);
return ResourceManager.GetString("Non_Field_Members", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Non-Field Members.
/// Looks up a localized string similar to None.
/// </summary>
internal static string Non_Field_Members {
internal static string None {
get {
return ResourceManager.GetString("Non_Field_Members", resourceCulture);
return ResourceManager.GetString("None", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Option &apos;{0}&apos; has an unsupported type to use with {1}. You should specify a parsing function..
/// </summary>
internal static string Option_0_has_an_unsupported_type_to_use_with_1_You_should_specify_a_parsing_function {
get {
return ResourceManager.GetString("Option_0_has_an_unsupported_type_to_use_with_1_You_should_specify_a_parsing_funct" +
"ion", resourceCulture);
}
}
......@@ -1144,6 +1162,15 @@ internal class WorkspacesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Suggestion.
/// </summary>
internal static string Suggestion {
get {
return ResourceManager.GetString("Suggestion", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Supplied diagnostic cannot be null..
/// </summary>
......
......@@ -575,4 +575,13 @@
<value>Method</value>
<comment>{locked:method} unless the capitalization should be handled differently</comment>
</data>
<data name="Error" xml:space="preserve">
<value>Error</value>
</data>
<data name="None" xml:space="preserve">
<value>None</value>
</data>
<data name="Suggestion" xml:space="preserve">
<value>Suggestion</value>
</data>
</root>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册