diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/Common/ColumnDefinitions.cs b/src/VisualStudio/Core/Def/EditorConfigSettings/Common/ColumnDefinitions.cs index d2dd4a8abebb7..4393341a995c6 100644 --- a/src/VisualStudio/Core/Def/EditorConfigSettings/Common/ColumnDefinitions.cs +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/Common/ColumnDefinitions.cs @@ -31,6 +31,15 @@ internal static class CodeStyle public const string Location = Prefix + CodeStylePrefix + "location"; } + internal static class NamingStyle + { + private const string NamingStylePrefix = "namingstyle."; + public const string Type = Prefix + NamingStylePrefix + "type"; + public const string Style = Prefix + NamingStylePrefix + "style"; + public const string Severity = Prefix + NamingStylePrefix + "severityname"; + public const string Location = Prefix + NamingStylePrefix + "location"; + } + internal static class Whitespace { private const string FormattingPrefix = "whitespace."; diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnDefinitions/NamingStylesLocationColumnDefinition.cs b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnDefinitions/NamingStylesLocationColumnDefinition.cs new file mode 100644 index 0000000000000..8b483b56f4a9c --- /dev/null +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnDefinitions/NamingStylesLocationColumnDefinition.cs @@ -0,0 +1,53 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.ComponentModel.Composition; +using System.Windows; +using Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Data; +using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.ViewModel; +using Microsoft.VisualStudio.Shell.TableControl; +using Microsoft.VisualStudio.Shell.TableManager; +using Microsoft.VisualStudio.Utilities; + +namespace Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.View.ColumnDefinitions +{ + using static Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.Common.ColumnDefinitions.NamingStyle; + + [Export(typeof(ITableColumnDefinition))] + [Name(Location)] + internal class NamingStylesLocationColumnDefinition : TableColumnDefinitionBase + { + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public NamingStylesLocationColumnDefinition() + { + } + + public override string Name => Location; + public override string DisplayName => ServicesVSResources.Location; + public override double MinWidth => 350; + public override bool DefaultVisible => true; + public override bool IsFilterable => true; + public override bool IsSortable => true; + + public override bool TryCreateColumnContent( + ITableEntryHandle entry, + bool singleColumnView, + out FrameworkElement? content) + { + if (!entry.TryGetValue(Location, out NamingStyleSetting setting)) + { + content = null; + return false; + } + + var viewModel = new NamingStylesLocationViewModel(setting); + var control = new NamingStylesLocationControl(viewModel); + content = control; + return true; + } + } +} diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnDefinitions/NamingStylesSeverityColumnDefinition.cs b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnDefinitions/NamingStylesSeverityColumnDefinition.cs new file mode 100644 index 0000000000000..d0f6b13849bac --- /dev/null +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnDefinitions/NamingStylesSeverityColumnDefinition.cs @@ -0,0 +1,49 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.ComponentModel.Composition; +using System.Windows; +using Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Data; +using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.ViewModel; +using Microsoft.VisualStudio.Shell.TableControl; +using Microsoft.VisualStudio.Shell.TableManager; +using Microsoft.VisualStudio.Utilities; + +namespace Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.View.ColumnDefinitions +{ + using static Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.Common.ColumnDefinitions.NamingStyle; + + [Export(typeof(ITableColumnDefinition))] + [Name(Severity)] + internal class NamingStylesSeverityColumnDefinition : TableColumnDefinitionBase + { + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public NamingStylesSeverityColumnDefinition() + { + } + + public override string Name => Severity; + public override string DisplayName => ServicesVSResources.Severity; + public override bool IsFilterable => false; + public override bool IsSortable => false; + public override double MinWidth => 120; + + public override bool TryCreateColumnContent(ITableEntryHandle entry, bool singleColumnView, out FrameworkElement? content) + { + if (!entry.TryGetValue(Severity, out NamingStyleSetting setting)) + { + content = null; + return false; + } + + var viewModel = new NamingStylesSeverityViewModel(setting); + var control = new NamingStylesSeverityControl(viewModel); + content = control; + return true; + } + } +} diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnDefinitions/NamingStylesStyleColumnDefinition.cs b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnDefinitions/NamingStylesStyleColumnDefinition.cs new file mode 100644 index 0000000000000..3745df3a9a8a1 --- /dev/null +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnDefinitions/NamingStylesStyleColumnDefinition.cs @@ -0,0 +1,49 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.ComponentModel.Composition; +using System.Windows; +using Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Data; +using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.ViewModel; +using Microsoft.VisualStudio.Shell.TableControl; +using Microsoft.VisualStudio.Shell.TableManager; +using Microsoft.VisualStudio.Utilities; + +namespace Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.View.ColumnDefinitions +{ + using static Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.Common.ColumnDefinitions.NamingStyle; + + [Export(typeof(ITableColumnDefinition))] + [Name(Style)] + internal class NamingStylesStyleColumnDefinition : TableColumnDefinitionBase + { + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public NamingStylesStyleColumnDefinition() + { + } + + public override string Name => Style; + public override string DisplayName => ServicesVSResources.Naming_Style; + public override bool IsFilterable => true; + public override bool IsSortable => true; + public override double MinWidth => 350; + + public override bool TryCreateColumnContent(ITableEntryHandle entry, bool singleColumnView, out FrameworkElement? content) + { + if (!entry.TryGetValue(Style, out NamingStyleSetting setting)) + { + content = null; + return false; + } + + var viewModel = new NamingStylesStyleViewModel(setting); + var control = new NamingStylesStyleControl(viewModel); + content = control; + return true; + } + } +} diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnDefinitions/NamingStylesTypeColumnDefinition.cs b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnDefinitions/NamingStylesTypeColumnDefinition.cs new file mode 100644 index 0000000000000..6405ffa206ad8 --- /dev/null +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnDefinitions/NamingStylesTypeColumnDefinition.cs @@ -0,0 +1,52 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.ComponentModel.Composition; +using System.Windows; +using Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Data; +using Microsoft.CodeAnalysis.Host.Mef; +using Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.ViewModel; +using Microsoft.VisualStudio.Shell.TableControl; +using Microsoft.VisualStudio.Shell.TableManager; +using Microsoft.VisualStudio.Utilities; + +namespace Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.View.ColumnDefinitions +{ + using static Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.Common.ColumnDefinitions.NamingStyle; + + [Export(typeof(ITableColumnDefinition))] + [Name(Type)] + internal class NamingStylesTypeColumnDefinition : TableColumnDefinitionBase + { + [ImportingConstructor] + [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] + public NamingStylesTypeColumnDefinition() + { + } + + public override string Name => Type; + public override string DisplayName => ServicesVSResources.Type; + public override bool IsFilterable => true; + public override bool IsSortable => true; + public override double MinWidth => 350; + + public override bool TryCreateColumnContent( + ITableEntryHandle entry, + bool singleColumnView, + out FrameworkElement? content) + { + if (!entry.TryGetValue(Type, out NamingStyleSetting setting)) + { + content = null; + return false; + } + + var viewModel = new NamingStylesTypeViewModel(setting); + var control = new NamingStylesTypeControl(viewModel); + content = control; + return true; + } + } +} diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnViews/NamingStylesLocationControl.xaml b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnViews/NamingStylesLocationControl.xaml new file mode 100644 index 0000000000000..68fc7581c0e14 --- /dev/null +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnViews/NamingStylesLocationControl.xaml @@ -0,0 +1,16 @@ + + + + diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnViews/NamingStylesLocationControl.xaml.cs b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnViews/NamingStylesLocationControl.xaml.cs new file mode 100644 index 0000000000000..9fac76db9e440 --- /dev/null +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnViews/NamingStylesLocationControl.xaml.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Windows.Controls; +using Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.ViewModel; + +namespace Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.View +{ + /// + /// Interaction logic for NamingStylesLocationControl.xaml + /// + internal partial class NamingStylesLocationControl : UserControl + { + public NamingStylesLocationControl(NamingStylesLocationViewModel viewModel) + { + InitializeComponent(); + DataContext = viewModel; + } + } +} diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnViews/NamingStylesSeverityControl.xaml b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnViews/NamingStylesSeverityControl.xaml new file mode 100644 index 0000000000000..b2a2959a3b73c --- /dev/null +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnViews/NamingStylesSeverityControl.xaml @@ -0,0 +1,18 @@ + + + + + diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnViews/NamingStylesSeverityControl.xaml.cs b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnViews/NamingStylesSeverityControl.xaml.cs new file mode 100644 index 0000000000000..22904c7cff8e0 --- /dev/null +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnViews/NamingStylesSeverityControl.xaml.cs @@ -0,0 +1,27 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Windows.Controls; +using Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.ViewModel; + +namespace Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.View +{ + /// + /// Interaction logic for NamingStylesSeverityControl.xaml + /// + internal partial class NamingStylesSeverityControl : UserControl + { + private readonly NamingStylesSeverityViewModel _viewModel; + + public NamingStylesSeverityControl(NamingStylesSeverityViewModel viewModel) + { + InitializeComponent(); + _viewModel = viewModel; + DataContext = viewModel; + } + + private void SeverityComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) + => _viewModel.SelectionChanged(SeverityComboBox.SelectedIndex); + } +} diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnViews/NamingStylesStyleControl.xaml b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnViews/NamingStylesStyleControl.xaml new file mode 100644 index 0000000000000..1e49a85fa847d --- /dev/null +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnViews/NamingStylesStyleControl.xaml @@ -0,0 +1,18 @@ + + + + + diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnViews/NamingStylesStyleControl.xaml.cs b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnViews/NamingStylesStyleControl.xaml.cs new file mode 100644 index 0000000000000..89a1c997b1260 --- /dev/null +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnViews/NamingStylesStyleControl.xaml.cs @@ -0,0 +1,27 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Windows.Controls; +using Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.ViewModel; + +namespace Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.View +{ + /// + /// Interaction logic for NamingStylesStyleControl.xaml + /// + internal partial class NamingStylesStyleControl : UserControl + { + private readonly NamingStylesStyleViewModel _viewModel; + + public NamingStylesStyleControl(NamingStylesStyleViewModel viewModel) + { + InitializeComponent(); + _viewModel = viewModel; + DataContext = viewModel; + } + + private void StyleComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) + => _viewModel.SelectionChanged(StyleComboBox.SelectedIndex); + } +} diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnViews/NamingStylesTypeControl.xaml b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnViews/NamingStylesTypeControl.xaml new file mode 100644 index 0000000000000..a0bb3535fc695 --- /dev/null +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnViews/NamingStylesTypeControl.xaml @@ -0,0 +1,16 @@ + + + + diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnViews/NamingStylesTypeControl.xaml.cs b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnViews/NamingStylesTypeControl.xaml.cs new file mode 100644 index 0000000000000..dc7a0caa27388 --- /dev/null +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/ColumnViews/NamingStylesTypeControl.xaml.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Windows.Controls; +using Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.ViewModel; + +namespace Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.View +{ + /// + /// Interaction logic for NamingStylesTypeControl.xaml + /// + internal partial class NamingStylesTypeControl : UserControl + { + public NamingStylesTypeControl(NamingStylesTypeViewModel viewModel) + { + InitializeComponent(); + DataContext = viewModel; + } + } +} diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/NamingStyleSettingsView.xaml b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/NamingStyleSettingsView.xaml new file mode 100644 index 0000000000000..b3a9317069b94 --- /dev/null +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/NamingStyleSettingsView.xaml @@ -0,0 +1,15 @@ + + + diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/NamingStyleSettingsView.xaml.cs b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/NamingStyleSettingsView.xaml.cs new file mode 100644 index 0000000000000..51832e0b90350 --- /dev/null +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/View/NamingStyleSettingsView.xaml.cs @@ -0,0 +1,33 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Threading.Tasks; +using System.Windows.Controls; +using Microsoft.CodeAnalysis.Text; +using Microsoft.VisualStudio.Shell.TableControl; + +namespace Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.View +{ + /// + /// Interaction logic for NamingStyleSettingsView.xaml + /// + internal partial class NamingStyleSettingsView : UserControl, ISettingsEditorView + { + private readonly IWpfSettingsEditorViewModel _viewModel; + + public NamingStyleSettingsView(IWpfSettingsEditorViewModel viewModel) + { + InitializeComponent(); + _viewModel = viewModel; + TableControl = _viewModel.GetTableControl(); + NamingStyleTable.Content = TableControl.Control; + DataContext = viewModel; + } + + public UserControl SettingControl => this; + public IWpfTableControl TableControl { get; } + public Task UpdateEditorConfigAsync(SourceText sourceText) => _viewModel.UpdateEditorConfigAsync(sourceText); + public void OnClose() => _viewModel.ShutDown(); + } +} diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/ViewModel/ColumnViewModels/NamingStylesLocationViewModel.cs b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/ViewModel/ColumnViewModels/NamingStylesLocationViewModel.cs new file mode 100644 index 0000000000000..0ee45ba44b431 --- /dev/null +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/ViewModel/ColumnViewModels/NamingStylesLocationViewModel.cs @@ -0,0 +1,49 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.ComponentModel; +using Microsoft.CodeAnalysis.Editor.EditorConfigSettings; +using Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Data; + +namespace Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.ViewModel +{ + internal class NamingStylesLocationViewModel : NotifyPropertyChangedBase + { + private readonly NamingStyleSetting _setting; + private string _locationValue; + + public NamingStylesLocationViewModel(NamingStyleSetting setting) + { + _setting = setting; + _setting.SettingChanged += OnSettingChanged; + _locationValue = GetLocationString(_setting.Location); + } + + public string LocationValue + { + get => _locationValue; + set + { + if (value is not null && _locationValue != value) + { + _locationValue = value; + OnPropertyChanged(new PropertyChangedEventArgs(nameof(LocationValue))); + } + } + } + + public static string LocationToolTip { get; } = ServicesVSResources.Location; + public static string LocationAutomationName { get; } = ServicesVSResources.Location; + + private void OnSettingChanged(object sender, System.EventArgs e) + => LocationValue = GetLocationString(_setting.Location); + + private static string GetLocationString(SettingLocation? location) + => location?.LocationKind switch + { + LocationKind.EditorConfig or LocationKind.GlobalConfig => location.Path!, + _ => ServicesVSResources.Visual_Studio_Settings, + }; + } +} diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/ViewModel/ColumnViewModels/NamingStylesSeverityViewModel.cs b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/ViewModel/ColumnViewModels/NamingStylesSeverityViewModel.cs new file mode 100644 index 0000000000000..b4497db3c901f --- /dev/null +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/ViewModel/ColumnViewModels/NamingStylesSeverityViewModel.cs @@ -0,0 +1,62 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Data; + +namespace Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.ViewModel +{ + internal class NamingStylesSeverityViewModel + { + private static readonly string[] s_severities = new[] + { + ServicesVSResources.Disabled, + ServicesVSResources.Suggestion, + ServicesVSResources.Warning, + ServicesVSResources.Error + }; + private readonly NamingStyleSetting _setting; + + public NamingStylesSeverityViewModel(NamingStyleSetting setting) + { + _setting = setting; + var selectedSeverityIndex = _setting.Severity switch + { + ReportDiagnostic.Hidden => 0, + ReportDiagnostic.Info => 1, + ReportDiagnostic.Warn => 2, + ReportDiagnostic.Error => 3, + _ => throw new InvalidOperationException(), + }; + + SelectedSeverityValue = Severities[selectedSeverityIndex]; + } + + internal void SelectionChanged(int selectedIndex) + { + var severity = selectedIndex switch + { + 0 => ReportDiagnostic.Hidden, + 1 => ReportDiagnostic.Info, + 2 => ReportDiagnostic.Warn, + 3 => ReportDiagnostic.Error, + _ => throw new InvalidOperationException(), + }; + _setting.ChangeSeverity(severity); + } + + public static string SeverityToolTip => ServicesVSResources.Severity; + + public static string SeverityAutomationName => ServicesVSResources.Severity; + + public string SelectedSeverityValue { get; set; } + + public static string[] Severities { get; } = s_severities; + } +} diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/ViewModel/ColumnViewModels/NamingStylesStyleViewModel.cs b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/ViewModel/ColumnViewModels/NamingStylesStyleViewModel.cs new file mode 100644 index 0000000000000..8cd2b8afef740 --- /dev/null +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/ViewModel/ColumnViewModels/NamingStylesStyleViewModel.cs @@ -0,0 +1,67 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.ComponentModel; +using System.Linq; +using Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Data; + +namespace Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.ViewModel +{ + internal class NamingStylesStyleViewModel : NotifyPropertyChangedBase + { + private readonly NamingStyleSetting _setting; + private string _selectedStyleValue; + private string[] _styleValues; + + public NamingStylesStyleViewModel(NamingStyleSetting setting) + { + _setting = setting; + _setting.SettingChanged += OnSettingChanged; + var selectedStyleIndex = Array.IndexOf(_setting.AllStyles, _setting.StyleName); + _styleValues = _setting.AllStyles; + _selectedStyleValue = _styleValues[selectedStyleIndex]; + } + + public static string StyleToolTip => ServicesVSResources.Naming_Style; + + public static string StyleAutomationName => ServicesVSResources.Naming_Style; + + public string[] StyleValues + { + get => _styleValues; + set + { + if (value is not null && !_styleValues.SequenceEqual(value)) + { + _styleValues = value; + OnPropertyChanged(new PropertyChangedEventArgs(nameof(StyleValues))); + } + } + } + + public string SelectedStyleValue + { + get => _selectedStyleValue; + set + { + if (value is not null && _selectedStyleValue != value) + { + _selectedStyleValue = value; + OnPropertyChanged(new PropertyChangedEventArgs(nameof(SelectedStyleValue))); + } + } + } + + internal void SelectionChanged(int selectedIndex) + => _setting.ChangeStyle(selectedIndex); + + private void OnSettingChanged(object sender, EventArgs e) + { + var selectedStyleIndex = Array.IndexOf(_setting.AllStyles, _setting.StyleName); + StyleValues = _setting.AllStyles; + SelectedStyleValue = StyleValues[selectedStyleIndex]; + } + } +} diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/ViewModel/ColumnViewModels/NamingStylesTypeViewModel.cs b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/ViewModel/ColumnViewModels/NamingStylesTypeViewModel.cs new file mode 100644 index 0000000000000..afe962bc712c0 --- /dev/null +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/ViewModel/ColumnViewModels/NamingStylesTypeViewModel.cs @@ -0,0 +1,41 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.ComponentModel; +using Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Data; + +namespace Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.ViewModel +{ + internal class NamingStylesTypeViewModel : NotifyPropertyChangedBase + { + private readonly NamingStyleSetting _setting; + private string _typeValue; + + public NamingStylesTypeViewModel(NamingStyleSetting setting) + { + _setting = setting; + _setting.SettingChanged += OnSettingChanged; + _typeValue = _setting.TypeName; + } + + public string TypeValue + { + get => _typeValue; + set + { + if (value is not null && _typeValue != value) + { + _typeValue = value; + OnPropertyChanged(new PropertyChangedEventArgs(nameof(TypeValue))); + } + } + } + + public static string TypeToolTip { get; } = ServicesVSResources.Type; + public static string TypeAutomationName { get; } = ServicesVSResources.Type; + + private void OnSettingChanged(object sender, System.EventArgs e) + => TypeValue = _setting.TypeName; + } +} diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/ViewModel/ColumnViewModels/NotifyPropertyChangedBase.cs b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/ViewModel/ColumnViewModels/NotifyPropertyChangedBase.cs new file mode 100644 index 0000000000000..92a1c72862a02 --- /dev/null +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/ViewModel/ColumnViewModels/NotifyPropertyChangedBase.cs @@ -0,0 +1,16 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.ComponentModel; + +namespace Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.ViewModel +{ + internal abstract class NotifyPropertyChangedBase : INotifyPropertyChanged + { + public event PropertyChangedEventHandler? PropertyChanged; + + protected void OnPropertyChanged(PropertyChangedEventArgs args) + => PropertyChanged?.Invoke(this, args); + } +} diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/ViewModel/NamingStyleSettingsViewModel.SettingsEntriesSnapshot.cs b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/ViewModel/NamingStyleSettingsViewModel.SettingsEntriesSnapshot.cs new file mode 100644 index 0000000000000..caddefb646aee --- /dev/null +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/ViewModel/NamingStyleSettingsViewModel.SettingsEntriesSnapshot.cs @@ -0,0 +1,32 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Immutable; +using Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Data; +using Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.Common; + +namespace Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.ViewModel +{ + internal partial class NamingStyleSettingsViewModel + { + internal class SettingsEntriesSnapshot : SettingsEntriesSnapshotBase + { + public SettingsEntriesSnapshot(ImmutableArray data, int currentVersionNumber) : base(data, currentVersionNumber) { } + + protected override bool TryGetValue(NamingStyleSetting result, string keyName, out object? content) + { + content = keyName switch + { + ColumnDefinitions.NamingStyle.Type => result, + ColumnDefinitions.NamingStyle.Style => result, + ColumnDefinitions.NamingStyle.Severity => result, + ColumnDefinitions.NamingStyle.Location => result, + _ => null, + }; + + return content is not null; + } + } + } +} diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/ViewModel/NamingStyleSettingsViewModel.SettingsSnapshotFactory.cs b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/ViewModel/NamingStyleSettingsViewModel.SettingsSnapshotFactory.cs new file mode 100644 index 0000000000000..3ae88e1b0f364 --- /dev/null +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/ViewModel/NamingStyleSettingsViewModel.SettingsSnapshotFactory.cs @@ -0,0 +1,22 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Immutable; +using Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Data; +using Microsoft.CodeAnalysis.Editor.EditorConfigSettings.DataProvider; +using Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.Common; + +namespace Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.ViewModel +{ + internal partial class NamingStyleSettingsViewModel + { + internal sealed class SettingsSnapshotFactory : SettingsSnapshotFactoryBase + { + public SettingsSnapshotFactory(ISettingsProvider data) : base(data) { } + + protected override SettingsEntriesSnapshot CreateSnapshot(ImmutableArray data, int currentVersionNumber) + => new(data, currentVersionNumber); + } + } +} diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/ViewModel/NamingStyleSettingsViewModel.cs b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/ViewModel/NamingStyleSettingsViewModel.cs new file mode 100644 index 0000000000000..ccebaa3dd8726 --- /dev/null +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/NamingStyle/ViewModel/NamingStyleSettingsViewModel.cs @@ -0,0 +1,49 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Data; +using Microsoft.CodeAnalysis.Editor.EditorConfigSettings.DataProvider; +using Microsoft.Internal.VisualStudio.Shell.TableControl; +using Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.Common; +using Microsoft.VisualStudio.Shell.TableControl; +using Microsoft.VisualStudio.Shell.TableManager; + +namespace Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.ViewModel +{ + internal partial class NamingStyleSettingsViewModel : SettingsViewModelBase< + NamingStyleSetting, + NamingStyleSettingsViewModel.SettingsSnapshotFactory, + NamingStyleSettingsViewModel.SettingsEntriesSnapshot> + { + public NamingStyleSettingsViewModel( + ISettingsProvider data, + IWpfTableControlProvider controlProvider, + ITableManagerProvider tableMangerProvider) + : base(data, controlProvider, tableMangerProvider) { } + + public override string Identifier => "NamingStyleSettings"; + + protected override SettingsSnapshotFactory CreateSnapshotFactory(ISettingsProvider data) + => new(data); + + protected override IEnumerable GetInitialColumnStates() + => new[] + { + new ColumnState2(ColumnDefinitions.NamingStyle.Type, isVisible: true, width: 0), + new ColumnState2(ColumnDefinitions.NamingStyle.Style, isVisible: true, width: 0), + new ColumnState2(ColumnDefinitions.NamingStyle.Severity, isVisible: true, width: 0), + new ColumnState2(ColumnDefinitions.NamingStyle.Location, isVisible: true, width: 0) + }; + + protected override string[] GetFixedColumns() + => new[] + { + ColumnDefinitions.NamingStyle.Type, + ColumnDefinitions.NamingStyle.Style, + ColumnDefinitions.NamingStyle.Severity, + ColumnDefinitions.NamingStyle.Location + }; + } +} diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/SettingsEditorControl.xaml b/src/VisualStudio/Core/Def/EditorConfigSettings/SettingsEditorControl.xaml index fde7fa6504046..a36810260d7fc 100644 --- a/src/VisualStudio/Core/Def/EditorConfigSettings/SettingsEditorControl.xaml +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/SettingsEditorControl.xaml @@ -28,13 +28,16 @@ Margin="0,20,0,12" IsSynchronizedWithCurrentItem="False" TabStripPlacement="Top" - SelectionChanged="tabsSettingsEditor_SelectionChanged"> + SelectionChanged="TabsSettingsEditor_SelectionChanged"> + @@ -48,6 +51,7 @@ + diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/SettingsEditorControl.xaml.cs b/src/VisualStudio/Core/Def/EditorConfigSettings/SettingsEditorControl.xaml.cs index df7e357867ecd..176a143efd697 100644 --- a/src/VisualStudio/Core/Def/EditorConfigSettings/SettingsEditorControl.xaml.cs +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/SettingsEditorControl.xaml.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Drawing; using System.Linq; using System.Windows; using System.Windows.Controls; @@ -22,23 +21,25 @@ namespace Microsoft.VisualStudio.LanguageServices.EditorConfigSettings /// internal partial class SettingsEditorControl : UserControl { - private readonly ISettingsEditorView _whitespaceView; - private readonly ISettingsEditorView _codeStyleView; - private readonly ISettingsEditorView _analyzerView; + private readonly ISettingsEditorView[] _views; + private readonly IWpfTableControl[] _tableControls; private readonly Workspace _workspace; private readonly string _filepath; private readonly IThreadingContext _threadingContext; private readonly EditorTextUpdater _textUpdater; public static string WhitespaceTabTitle => ServicesVSResources.Whitespace; - public UserControl WhitespaceControl => _whitespaceView.SettingControl; + public UserControl WhitespaceControl { get; } public static string CodeStyleTabTitle => ServicesVSResources.Code_Style; - public UserControl CodeStyleControl => _codeStyleView.SettingControl; + public UserControl CodeStyleControl { get; } + public static string NamingStyleTabTitle => ServicesVSResources.Naming_Style; + public UserControl NamingStyleControl { get; } public static string AnalyzersTabTitle => ServicesVSResources.Analyzers; - public UserControl AnalyzersControl => _analyzerView.SettingControl; + public UserControl AnalyzersControl { get; } public SettingsEditorControl(ISettingsEditorView whitespaceView, ISettingsEditorView codeStyleView, + ISettingsEditorView namingStyleView, ISettingsEditorView analyzerView, Workspace workspace, string filepath, @@ -51,9 +52,22 @@ public SettingsEditorControl(ISettingsEditorView whitespaceView, _filepath = filepath; _threadingContext = threadingContext; _textUpdater = new EditorTextUpdater(editorAdaptersFactoryService, textLines); - _whitespaceView = whitespaceView; - _codeStyleView = codeStyleView; - _analyzerView = analyzerView; + + WhitespaceControl = whitespaceView.SettingControl; + CodeStyleControl = codeStyleView.SettingControl; + NamingStyleControl = namingStyleView.SettingControl; + AnalyzersControl = analyzerView.SettingControl; + + _views = new[] + { + whitespaceView, + codeStyleView, + namingStyleView, + analyzerView + }; + + _tableControls = _views.SelectAsArray(view => view.TableControl).ToArray(); + InitializeComponent(); } @@ -77,29 +91,27 @@ internal void SynchronizeSettings() _threadingContext.JoinableTaskFactory.Run(async () => { var originalText = await analyzerConfigDocument.GetTextAsync(default).ConfigureAwait(false); - var updatedText = await _whitespaceView.UpdateEditorConfigAsync(originalText).ConfigureAwait(false); - updatedText = await _codeStyleView.UpdateEditorConfigAsync(updatedText).ConfigureAwait(false); - updatedText = await _analyzerView.UpdateEditorConfigAsync(updatedText).ConfigureAwait(false); + var updatedText = originalText; + foreach (var view in _views) + { + updatedText = await view.UpdateEditorConfigAsync(updatedText).ConfigureAwait(false); + } + _textUpdater.UpdateText(updatedText.GetTextChanges(originalText)); }); } - internal IWpfTableControl[] GetTableControls() - => new[] - { - _whitespaceView.TableControl, - _codeStyleView.TableControl, - _analyzerView.TableControl, - }; + internal IWpfTableControl[] GetTableControls() => _tableControls; internal void OnClose() { - _whitespaceView.OnClose(); - _codeStyleView.OnClose(); - _analyzerView.OnClose(); + foreach (var view in _views) + { + view.OnClose(); + } } - private void tabsSettingsEditor_SelectionChanged(object sender, SelectionChangedEventArgs e) + private void TabsSettingsEditor_SelectionChanged(object sender, SelectionChangedEventArgs e) { var previousTabItem = e.RemovedItems.Count > 0 ? e.RemovedItems[0] as TabItem : null; var selectedTabItem = e.AddedItems.Count > 0 ? e.AddedItems[0] as TabItem : null; @@ -129,6 +141,10 @@ ContentPresenter GetTabItem(object tag) { return CodeStyleFrame; } + else if (ReferenceEquals(tag, NamingStyleControl)) + { + return NamingStyleFrame; + } else if (ReferenceEquals(tag, AnalyzersControl)) { return AnalyzersFrame; diff --git a/src/VisualStudio/Core/Def/EditorConfigSettings/SettingsEditorPane.cs b/src/VisualStudio/Core/Def/EditorConfigSettings/SettingsEditorPane.cs index bf7b735527583..8bf575cd68917 100644 --- a/src/VisualStudio/Core/Def/EditorConfigSettings/SettingsEditorPane.cs +++ b/src/VisualStudio/Core/Def/EditorConfigSettings/SettingsEditorPane.cs @@ -4,21 +4,20 @@ using System; using System.ComponentModel.Design; -using System.Linq; using System.Runtime.InteropServices; -using System.Threading; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Editor.EditorConfigSettings; using Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Data; using Microsoft.CodeAnalysis.Editor.EditorConfigSettings.DataProvider; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; -using Microsoft.CodeAnalysis.Host; using Microsoft.Internal.VisualStudio.Shell.TableControl; using Microsoft.VisualStudio.Editor; using Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.Analyzers.View; using Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.Analyzers.ViewModel; using Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.CodeStyle.View; using Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.CodeStyle.ViewModel; +using Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.View; +using Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.NamingStyle.ViewModel; using Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.Whitespace.View; using Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.Whitespace.ViewModel; using Microsoft.VisualStudio.OLE.Interop; @@ -97,11 +96,13 @@ protected override void Initialize() var whitespaceView = GetWhitespaceView(); var codeStyleView = GetCodeStyleView(); + var namingStyleView = GetNamingStyleView(); var analyzerView = GetAnalyzerView(); _control = new SettingsEditorControl( whitespaceView, codeStyleView, + namingStyleView, analyzerView, _workspace, _fileName, @@ -138,6 +139,13 @@ ISettingsEditorView GetCodeStyleView() static viewModel => new CodeStyleSettingsView(viewModel)); } + ISettingsEditorView GetNamingStyleView() + { + return GetView( + static (dataProvider, controlProvider, tableMangerProvider) => new NamingStyleSettingsViewModel(dataProvider, controlProvider, tableMangerProvider), + static viewModel => new NamingStyleSettingsView(viewModel)); + } + ISettingsEditorView GetAnalyzerView() { return GetView(