A Swiss Army knife for developers.
C# blazorcross-platformcsharpdesktopdesktop-appdesktop-applicationdeveloper-toolsextensiblefluentfluent-designlinuxmacosmicasyntax-highlightingtypescriptwindowswindows-10windows-11winui
Added logic for Settings page
Etienne Baudouxc102fe53b9e5
diff --git a/src/dev/def/DevTools.Core/Settings/PredefinedSettings.cs b/src/dev/def/DevTools.Core/Settings/PredefinedSettings.csindex 1dc949704..5c0e430de 100644--- a/src/dev/def/DevTools.Core/Settings/PredefinedSettings.cs+++ b/src/dev/def/DevTools.Core/Settings/PredefinedSettings.cs@@ -12,5 +12,23 @@ namespace DevTools.Core.Settingsname: nameof(Theme),isRoaming: false,defaultValue: AppTheme.Default);++ /// <summary>+ /// Whether the application should automatically detect the best tool to use based on the clipboard content.+ /// </summary>+ public static readonly SettingDefinition<bool> SmartDetection+ = new(+ name: nameof(SmartDetection),+ isRoaming: true,+ defaultValue: true);++ /// <summary>+ /// The font family name to use in the text editor.+ /// </summary>+ public static readonly SettingDefinition<string> TextEditorFont+ = new(+ name: nameof(TextEditorFont),+ isRoaming: true,+ defaultValue: "CascadiaMono");}}diff --git a/src/dev/def/DevTools.Core/Theme/IThemeListener.cs b/src/dev/def/DevTools.Core/Theme/IThemeListener.csindex 3917c9723..7de3e4520 100644--- a/src/dev/def/DevTools.Core/Theme/IThemeListener.cs+++ b/src/dev/def/DevTools.Core/Theme/IThemeListener.cs@@ -5,9 +5,14 @@ namespace DevTools.Core.Themepublic interface IThemeListener{/// <summary>- /// Gets the current theme.+ /// Gets the current Windows theme./// </summary>- AppTheme CurrentTheme { get; }+ AppTheme CurrentSystemTheme { get; }++ /// <summary>+ /// Gets the current app theme.+ /// </summary>+ AppTheme CurrentAppTheme { get; }/// <summary>/// Gets or sets a value indicating whether the current theme is high contrast.@@ -18,5 +23,10 @@ namespace DevTools.Core.Theme/// Raised when the theme has changed./// </summary>event EventHandler? ThemeChanged;++ /// <summary>+ /// Change the color theme of the app based on <see cref="CurrentSystemTheme"/> and <see cref="CurrentAppTheme"/>.+ /// </summary>+ void ApplyDesiredColorTheme();}}diff --git a/src/dev/impl/DevTools.Common/Assets/CascadiaCode.ttf b/src/dev/impl/DevTools.Common/Assets/CascadiaCode.ttfnew file mode 100644index 000000000..117b8de3eBinary files /dev/null and b/src/dev/impl/DevTools.Common/Assets/CascadiaCode.ttf differdiff --git a/src/dev/impl/DevTools.Common/Assets/CascadiaMono.ttf b/src/dev/impl/DevTools.Common/Assets/CascadiaMono.ttfnew file mode 100644index 000000000..6a66e2b0eBinary files /dev/null and b/src/dev/impl/DevTools.Common/Assets/CascadiaMono.ttf differdiff --git a/src/dev/impl/DevTools.Common/DevTools.Common.csproj b/src/dev/impl/DevTools.Common/DevTools.Common.csprojindex d7650ffec..648a7673b 100644--- a/src/dev/impl/DevTools.Common/DevTools.Common.csproj+++ b/src/dev/impl/DevTools.Common/DevTools.Common.csproj@@ -87,6 +87,7 @@<Compile Include="UI\Controls\ExpandableSettingHeaderControl.xaml.cs"><DependentUpon>ExpandableSettingHeaderControl.xaml</DependentUpon></Compile>+ <Compile Include="UI\Converters\EnumToBooleanConverter.cs" /><Compile Include="UI\Converters\EnumToThicknessConverter.cs" /><Compile Include="UI\Converters\BooleanToVisibilityConverter.cs" /><Compile Include="UI\Converters\DoubleToGridLengthConverter.cs" />@@ -147,6 +148,12 @@<ItemGroup><PRIResource Include="Strings\en\Common.resw" /></ItemGroup>+ <ItemGroup>+ <Content Include="Assets\CascadiaCode.ttf" />+ </ItemGroup>+ <ItemGroup>+ <Content Include="Assets\CascadiaMono.ttf" />+ </ItemGroup><Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" /><!-- To modify your build process, add your task inside one of the targets below and uncomment it.Other similar extension points exist, see Microsoft.Common.targets.diff --git a/src/dev/impl/DevTools.Common/LanguageManager.cs b/src/dev/impl/DevTools.Common/LanguageManager.csindex 0ec877f59..464c6dc9e 100644--- a/src/dev/impl/DevTools.Common/LanguageManager.cs+++ b/src/dev/impl/DevTools.Common/LanguageManager.cs@@ -20,7 +20,7 @@ namespace DevTools.Commonpublic partial class LanguageManager : ObservableObject{private static LanguageManager _languageManager;-+private readonly Base64EncoderDecoderStrings _base64encoderdecoder = new Base64EncoderDecoderStrings();private readonly CommonStrings _common = new CommonStrings();private readonly JsonFormatterStrings _jsonformatter = new JsonFormatterStrings();diff --git a/src/dev/impl/DevTools.Common/LanguageManager.tt b/src/dev/impl/DevTools.Common/LanguageManager.ttindex fdbfbee55..d0e7f7d39 100644--- a/src/dev/impl/DevTools.Common/LanguageManager.tt+++ b/src/dev/impl/DevTools.Common/LanguageManager.tt@@ -43,7 +43,7 @@ namespace DevTools.Commonpublic partial class LanguageManager : ObservableObject{private static LanguageManager _languageManager;-+<#foreach (var file in Directory.GetFiles(stringsFolder, "*.resw")){diff --git a/src/dev/impl/DevTools.Common/Strings/en/Settings.resw b/src/dev/impl/DevTools.Common/Strings/en/Settings.reswindex aa31773d5..7c5d12f0a 100644--- a/src/dev/impl/DevTools.Common/Strings/en/Settings.resw+++ b/src/dev/impl/DevTools.Common/Strings/en/Settings.resw@@ -117,7 +117,43 @@<resheader name="writer"><value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></resheader>+ <data name="About" xml:space="preserve">+ <value>About</value>+ </data>+ <data name="AppTheme" xml:space="preserve">+ <value>App Theme</value>+ </data>+ <data name="AppThemeDescription" xml:space="preserve">+ <value>Select which app theme to display</value>+ </data>+ <data name="Behaviors" xml:space="preserve">+ <value>Behaviors</value>+ </data>+ <data name="Dark" xml:space="preserve">+ <value>Dark</value>+ </data><data name="DisplayName" xml:space="preserve"><value>Settings</value></data>+ <data name="Font" xml:space="preserve">+ <value>Font</value>+ </data>+ <data name="Light" xml:space="preserve">+ <value>Light</value>+ </data>+ <data name="SmartDetection" xml:space="preserve">+ <value>Smart detection</value>+ </data>+ <data name="SmartDetectionDescription" xml:space="preserve">+ <value>Automatically detect the best tool based on the clipboard content</value>+ </data>+ <data name="TextEditor" xml:space="preserve">+ <value>Text editor</value>+ </data>+ <data name="UsefulLinks" xml:space="preserve">+ <value>Useful links</value>+ </data>+ <data name="UseSystemSettings" xml:space="preserve">+ <value>Use system settings</value>+ </data></root>\ No newline at end of filediff --git a/src/dev/impl/DevTools.Common/Themes/Custom.xaml b/src/dev/impl/DevTools.Common/Themes/Custom.xamlindex b197cfc8c..f194c220c 100644--- a/src/dev/impl/DevTools.Common/Themes/Custom.xaml+++ b/src/dev/impl/DevTools.Common/Themes/Custom.xaml@@ -3,6 +3,10 @@xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:localization="using:DevTools.Common"><FontFamily x:Key="FluentSystemIcons">ms-appx:///DevTools.Common/Assets/FluentSystemIcons-Regular.ttf#FluentSystemIcons-Regular</FontFamily>+ <FontFamily x:Key="CascadiaMono">ms-appx:///DevTools.Common/Assets/CascadiaMono.ttf#Cascadia Mono</FontFamily>+ <FontFamily x:Key="CascadiaCode">ms-appx:///DevTools.Common/Assets/CascadiaCode.ttf#Cascadia Code</FontFamily>+ <FontFamily x:Key="SegoeUI">Segoe UI</FontFamily>+ <FontFamily x:Key="Consolas">Consolas</FontFamily><!-- Icons. Most of them are from https://github.com/microsoft/fluentui-system-icons/blob/master/icons.md --><x:String x:Key="EnterCompactOverlayPathIconData">M41.6339 8.13376C42.122 7.64561 42.122 6.85415 41.6339 6.36599C41.1457 5.87784 40.3543 5.87784 39.8661 6.36599L29.5002 16.732V7.25C29.5002 6.55964 28.9405 6 28.2502 6C27.5598 6 27.0002 6.55964 27.0002 7.25V19.75C27.0002 20.4404 27.5598 21 28.2502 21H40.75C41.4404 21 42 20.4404 42 19.75C42 19.0596 41.4404 18.5 40.75 18.5H31.2676L41.6339 8.13376ZM8.5 12.25C8.5 10.1789 10.1789 8.5 12.25 8.5H20.1346C20.825 8.5 21.3846 7.94036 21.3846 7.25C21.3846 6.55964 20.825 6 20.1346 6H12.25C8.79822 6 6 8.79822 6 12.25V35.75C6 39.2018 8.79822 42 12.25 42H35.75C39.2018 42 42 39.2018 42 35.75V27.8654C42 27.175 41.4404 26.6154 40.75 26.6154C40.0596 26.6154 39.5 27.175 39.5 27.8654V35.75C39.5 37.8211 37.8211 39.5 35.75 39.5H24V29.2499C24 26.3504 21.6495 23.9999 18.75 23.9999H8.5V12.25ZM8.5 26.4999H18.75C20.2688 26.4999 21.5 27.7311 21.5 29.2499V39.5H12.25C10.1789 39.5 8.5 37.8211 8.5 35.75V26.4999Z</x:String>diff --git a/src/dev/impl/DevTools.Common/UI/Converters/EnumToBooleanConverter.cs b/src/dev/impl/DevTools.Common/UI/Converters/EnumToBooleanConverter.csnew file mode 100644index 000000000..2d136a46e--- /dev/null+++ b/src/dev/impl/DevTools.Common/UI/Converters/EnumToBooleanConverter.cs@@ -0,0 +1,48 @@+#nullable enable++using System;+using Windows.UI.Xaml;+using Windows.UI.Xaml.Data;++namespace DevTools.Common.UI.Converters+{+ /// <summary>+ /// Convert a <see cref="Enum"/> to a <see cref="bool"/> value.+ /// </summary>+ public sealed class EnumToBooleanConverter : IValueConverter+ {+ public object Convert(object value, Type targetType, object parameter, string language)+ {+ if (value is null || parameter is null || !(value is Enum))+ {+ return false;+ }++ var currentState = value.ToString();+ var stateStrings = parameter.ToString();++ string[] stateStringsSplitted = stateStrings.Split(',');+ for (int i = 0; i < stateStringsSplitted.Length; i++)+ {+ if (string.Equals(currentState, stateStringsSplitted[i].Trim(), StringComparison.Ordinal))+ {+ return true;+ }+ }++ return false;+ }++ public object ConvertBack(object value, Type targetType, object parameter, string language)+ {+ string? parameterString = parameter as string;+ var valueBool = value as bool?;+ if (parameterString is null || valueBool is null)+ {+ return DependencyProperty.UnsetValue;+ }++ return Enum.Parse(targetType, parameterString);+ }+ }+}diff --git a/src/dev/impl/DevTools.Core.Impl/Theme/ThemeListener.cs b/src/dev/impl/DevTools.Core.Impl/Theme/ThemeListener.csindex e95cb2d6b..702d898ad 100644--- a/src/dev/impl/DevTools.Core.Impl/Theme/ThemeListener.cs+++ b/src/dev/impl/DevTools.Core.Impl/Theme/ThemeListener.cs@@ -1,5 +1,6 @@#nullable enable+using DevTools.Core.Settings;using DevTools.Core.Theme;using DevTools.Core.Threading;using System;@@ -16,19 +17,23 @@ namespace DevTools.Core.Impl.Themeprivate readonly AccessibilitySettings _accessible = new();private readonly UISettings _uiSettings = new();private readonly IThread _thread;+ private readonly ISettingsProvider _settingsProvider;- public AppTheme CurrentTheme { get; private set; }+ public AppTheme CurrentSystemTheme { get; private set; }++ public AppTheme CurrentAppTheme => _settingsProvider.GetSetting(PredefinedSettings.Theme);public bool IsHighContrast { get; private set; }public event EventHandler? ThemeChanged;[ImportingConstructor]- public ThemeListener(IThread thread)+ public ThemeListener(IThread thread, ISettingsProvider settingsProvider){_thread = thread;+ _settingsProvider = settingsProvider;- CurrentTheme = Application.Current.RequestedTheme == ApplicationTheme.Dark ? AppTheme.Dark : AppTheme.Light;+ CurrentSystemTheme = Application.Current.RequestedTheme == ApplicationTheme.Dark ? AppTheme.Dark : AppTheme.Light;IsHighContrast = _accessible.HighContrast;_accessible.HighContrastChanged += Accessible_HighContrastChanged;@@ -40,6 +45,22 @@ namespace DevTools.Core.Impl.Theme}}+ public void ApplyDesiredColorTheme()+ {+ AppTheme theme = CurrentAppTheme;++ if (theme == AppTheme.Default)+ {+ theme = CurrentSystemTheme;+ }++ // Set theme for window root.+ if (Window.Current.Content is FrameworkElement frameworkElement)+ {+ frameworkElement.RequestedTheme = theme == AppTheme.Light ? ElementTheme.Light : ElementTheme.Dark;+ }+ }+private void Accessible_HighContrastChanged(AccessibilitySettings sender, object args){_thread.RunOnUIThreadAsync(UpdateProperties).Forget();@@ -53,7 +74,7 @@ namespace DevTools.Core.Impl.Theme{// TODO: This doesn't stop the multiple calls if we're in our faked 'White' HighContrast Mode below.AppTheme currentAppTheme = Application.Current.RequestedTheme == ApplicationTheme.Dark ? AppTheme.Dark : AppTheme.Light;- if (CurrentTheme != currentAppTheme || IsHighContrast != _accessible.HighContrast)+ if (CurrentSystemTheme != currentAppTheme || IsHighContrast != _accessible.HighContrast){UpdateProperties();}@@ -63,7 +84,7 @@ namespace DevTools.Core.Impl.Themeprivate void CoreWindow_Activated(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.WindowActivatedEventArgs args){AppTheme currentAppTheme = Application.Current.RequestedTheme == ApplicationTheme.Dark ? AppTheme.Dark : AppTheme.Light;- if (CurrentTheme != currentAppTheme || IsHighContrast != _accessible.HighContrast)+ if (CurrentSystemTheme != currentAppTheme || IsHighContrast != _accessible.HighContrast){UpdateProperties();}@@ -80,16 +101,17 @@ namespace DevTools.Core.Impl.Themeif (_accessible.HighContrast && _accessible.HighContrastScheme.IndexOf("white", StringComparison.OrdinalIgnoreCase) != -1){IsHighContrast = false;- CurrentTheme = AppTheme.Light;+ CurrentSystemTheme = AppTheme.Light;}else{// Otherwise, we just set to what's in the system as we'd expect.IsHighContrast = _accessible.HighContrast;AppTheme currentAppTheme = Application.Current.RequestedTheme == ApplicationTheme.Dark ? AppTheme.Dark : AppTheme.Light;- CurrentTheme = currentAppTheme;+ CurrentSystemTheme = currentAppTheme;}+ ApplyDesiredColorTheme();ThemeChanged?.Invoke(this, EventArgs.Empty);}}diff --git a/src/dev/impl/DevTools.Core.Impl/TitleBar.cs b/src/dev/impl/DevTools.Core.Impl/TitleBar.csindex 3184305fb..dd7791258 100644--- a/src/dev/impl/DevTools.Core.Impl/TitleBar.cs+++ b/src/dev/impl/DevTools.Core.Impl/TitleBar.cs@@ -80,7 +80,7 @@ namespace DevTools.Core.ImplAppTheme theme = _settingsProvider.GetSetting(PredefinedSettings.Theme);if (theme == AppTheme.Default){- theme = _themeListener.CurrentTheme;+ theme = _themeListener.CurrentSystemTheme;}if (theme == AppTheme.Dark)diff --git a/src/dev/impl/DevTools.Impl/ViewModels/MainPageViewModel.cs b/src/dev/impl/DevTools.Impl/ViewModels/MainPageViewModel.csindex ac8f122e6..7f7b980df 100644--- a/src/dev/impl/DevTools.Impl/ViewModels/MainPageViewModel.cs+++ b/src/dev/impl/DevTools.Impl/ViewModels/MainPageViewModel.cs@@ -23,6 +23,7 @@ using Windows.UI.ViewManagement;using Windows.UI.Xaml.Controls;using Microsoft.Toolkit.Mvvm.Messaging;using Windows.UI.Xaml;+using DevTools.Core.Settings;namespace DevTools.Impl.ViewModels{@@ -33,6 +34,7 @@ namespace DevTools.Impl.ViewModelsprivate readonly IClipboard _clipboard;private readonly IToolProviderFactory _toolProviderFactory;private readonly IUriActivationProtocolService _launchProtocolService;+ private readonly ISettingsProvider _settingsProvider;private readonly List<MatchedToolProviderViewData> _allToolsMenuitems = new();private readonly DisposableSempahore _sempahore = new();private readonly Task _firstUpdateMenuTask;@@ -133,12 +135,14 @@ namespace DevTools.Impl.ViewModelsIClipboard clipboard,ITitleBar titleBar,IToolProviderFactory toolProviderFactory,- IUriActivationProtocolService launchProtocolService)+ IUriActivationProtocolService launchProtocolService,+ ISettingsProvider settingsProvider){_thread = thread;_clipboard = clipboard;_toolProviderFactory = toolProviderFactory;_launchProtocolService = launchProtocolService;+ _settingsProvider = settingsProvider;TitleBar = titleBar;OpenToolInNewWindowCommand = new AsyncRelayCommand<ToolProviderMetadata>(ExecuteOpenToolInNewWindowCommandAsync);@@ -300,7 +304,7 @@ namespace DevTools.Impl.ViewModelsprivate async Task UpdateRecommendedToolsAsync(){- if (IsInCompactOverlayMode)+ if (IsInCompactOverlayMode || !_settingsProvider.GetSetting(PredefinedSettings.SmartDetection)){return;}diff --git a/src/dev/impl/DevTools.Impl/Views/Settings/SettingsToolPage.xaml b/src/dev/impl/DevTools.Impl/Views/Settings/SettingsToolPage.xamlindex 1684ecd9e..2c5c087e4 100644--- a/src/dev/impl/DevTools.Impl/Views/Settings/SettingsToolPage.xaml+++ b/src/dev/impl/DevTools.Impl/Views/Settings/SettingsToolPage.xaml@@ -2,17 +2,15 @@x:Class="DevTools.Impl.Views.Settings.SettingsToolPage"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"- xmlns:local="using:DevTools.Impl.Views.Settings"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:controls="using:DevTools.Common.UI.Controls" xmlns:muxc="using:Microsoft.UI.Xaml.Controls"+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"+ xmlns:muxc="using:Microsoft.UI.Xaml.Controls"+ xmlns:controls="using:DevTools.Common.UI.Controls"+ xmlns:converters="using:DevTools.Common.UI.Converters"mc:Ignorable="d"NavigationCacheMode="Required"><Page.Resources>- <Style x:Key="SubTitleTextBlock" TargetType="TextBlock">- <Setter Property="FontSize" Value="14" />- <Setter Property="FontWeight" Value="Medium" />- <Setter Property="Margin" Value="0,12,0,0" />- </Style>+ <converters:EnumToBooleanConverter x:Key="EnumToBooleanConverter"/></Page.Resources><StackPanel Spacing="4">@@ -23,52 +21,56 @@</StackPanel.ChildrenTransitions><controls:ExpandableSettingControl- Title="App Theme"- Description="Select which app theme to display">+ Title="{x:Bind ViewModel.Strings.AppTheme}"+ Description="{x:Bind ViewModel.Strings.AppThemeDescription}"><controls:ExpandableSettingControl.Icon><FontIcon Glyph="" /></controls:ExpandableSettingControl.Icon><controls:ExpandableSettingControl.ExpandableContent><StackPanel Spacing="4"><RadioButton- Content="Light"/>+ Content="{x:Bind ViewModel.Strings.Light}"+ IsChecked="{x:Bind ViewModel.Theme, Mode=TwoWay, ConverterParameter='Light', Converter={StaticResource EnumToBooleanConverter}}"/><RadioButton- Content="Dark"/>+ Content="{x:Bind ViewModel.Strings.Dark}"+ IsChecked="{x:Bind ViewModel.Theme, Mode=TwoWay, ConverterParameter='Dark', Converter={StaticResource EnumToBooleanConverter}}"/><RadioButton- Content="Use system settings"- IsChecked="True"/>+ Content="{x:Bind ViewModel.Strings.UseSystemSettings}"+ IsChecked="{x:Bind ViewModel.Theme, Mode=TwoWay, ConverterParameter='Default', Converter={StaticResource EnumToBooleanConverter}}"/></StackPanel></controls:ExpandableSettingControl.ExpandableContent></controls:ExpandableSettingControl>- <TextBlock Style="{StaticResource SubTitleTextBlock}" Text="Behaviors" />+ <TextBlock Style="{StaticResource SubTitleTextBlock}" Text="{x:Bind ViewModel.Strings.Behaviors}" /><controls:ExpandableSettingControl- Title="Smart detection"- Description="Automatically detect the best tool based on the clipboard content">+ Title="{x:Bind ViewModel.Strings.SmartDetection}"+ Description="{x:Bind ViewModel.Strings.SmartDetectionDescription}"><controls:ExpandableSettingControl.Icon><FontIcon Glyph="" /></controls:ExpandableSettingControl.Icon>- <ToggleSwitch Style="{StaticResource RightAlignedToggleSwitchStyle}" IsOn="True"/>+ <ToggleSwitch Style="{StaticResource RightAlignedToggleSwitchStyle}" IsOn="{x:Bind ViewModel.SmartDetection, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/><!-- TODO: Put a demo/tutorial in ExpandableContent property --></controls:ExpandableSettingControl>- <TextBlock Style="{StaticResource SubTitleTextBlock}" Text="Text editor" />+ <TextBlock Style="{StaticResource SubTitleTextBlock}" Text="{x:Bind ViewModel.Strings.TextEditor}" /><controls:ExpandableSettingControl- Title="Font">+ Title="{x:Bind ViewModel.Strings.Font}"><controls:ExpandableSettingControl.Icon><FontIcon Glyph="" /></controls:ExpandableSettingControl.Icon>- <ComboBox>- <ComboBoxItem Content="Cascadia Code"/>- <ComboBoxItem Content="Cascadia Mono" IsSelected="True"/>- <ComboBoxItem Content="Consolas"/>- <ComboBoxItem Content="Segoe UI"/>+ <ComboBox+ SelectedValuePath="Tag"+ SelectedValue="{x:Bind ViewModel.TextEditorFont, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">+ <ComboBoxItem Tag="CascadiaCode" Content="Cascadia Code"/>+ <ComboBoxItem Tag="CascadiaMono" Content="Cascadia Mono"/>+ <ComboBoxItem Tag="Consolas" Content="Consolas"/>+ <ComboBoxItem Tag="SegoeUI" Content="Segoe UI"/></ComboBox></controls:ExpandableSettingControl>- <TextBlock Style="{StaticResource SubTitleTextBlock}" Text="About" />+ <TextBlock Style="{StaticResource SubTitleTextBlock}" Text="{x:Bind ViewModel.Strings.About}" /><controls:ExpandableSettingControlTitle="DevTools"@@ -79,7 +81,7 @@</controls:ExpandableSettingControl><controls:ExpandableSettingControl- Title="Useful links">+ Title="{x:Bind ViewModel.Strings.UsefulLinks}"><controls:ExpandableSettingControl.Icon><FontIcon Glyph="" /></controls:ExpandableSettingControl.Icon>diff --git a/src/dev/impl/DevTools.Impl/Views/Settings/SettingsToolViewModel.cs b/src/dev/impl/DevTools.Impl/Views/Settings/SettingsToolViewModel.csindex f08e0054c..76c6d5f9e 100644--- a/src/dev/impl/DevTools.Impl/Views/Settings/SettingsToolViewModel.cs+++ b/src/dev/impl/DevTools.Impl/Views/Settings/SettingsToolViewModel.cs@@ -1,5 +1,8 @@#nullable enable+using DevTools.Common;+using DevTools.Core.Settings;+using DevTools.Core.Theme;using DevTools.Providers;using Microsoft.Toolkit.Mvvm.ComponentModel;using System;@@ -10,6 +13,42 @@ namespace DevTools.Impl.Views.Settings[Export(typeof(SettingsToolViewModel))]public sealed class SettingsToolViewModel : ObservableRecipient, IToolViewModel{+ private readonly IThemeListener _themeListener;+ private readonly ISettingsProvider _settingsProvider;+public Type View { get; } = typeof(SettingsToolPage);++ internal SettingsStrings Strings => LanguageManager.Instance.Settings;++ internal AppTheme Theme+ {+ get => _settingsProvider.GetSetting(PredefinedSettings.Theme);+ set+ {+ _settingsProvider.SetSetting(PredefinedSettings.Theme, value);+ _themeListener.ApplyDesiredColorTheme();+ }+ }++ internal bool SmartDetection+ {+ get => _settingsProvider.GetSetting(PredefinedSettings.SmartDetection);+ set => _settingsProvider.SetSetting(PredefinedSettings.SmartDetection, value);+ }++ internal string TextEditorFont+ {+ get => _settingsProvider.GetSetting(PredefinedSettings.TextEditorFont);+ set => _settingsProvider.SetSetting(PredefinedSettings.TextEditorFont, value);+ }++ [ImportingConstructor]+ public SettingsToolViewModel(+ IThemeListener themeListener,+ ISettingsProvider settingsProvider)+ {+ _themeListener = themeListener;+ _settingsProvider = settingsProvider;+ }}}diff --git a/src/dev/startup/DevTools/App.xaml.cs b/src/dev/startup/DevTools/App.xaml.csindex 183ae6997..e3d3b749c 100644--- a/src/dev/startup/DevTools/App.xaml.cs+++ b/src/dev/startup/DevTools/App.xaml.cs@@ -1,14 +1,13 @@#nullable enable+using DevTools.Common;using DevTools.Core;using DevTools.Core.Impl.Injection;using DevTools.Core.Injection;using DevTools.Core.Navigation;-using DevTools.Core.Settings;using DevTools.Core.Theme;using DevTools.Core.Threading;using DevTools.Impl.Views;-using DevTools.Common;using DevTools.Providers;using System;using System.Globalization;@@ -28,7 +27,6 @@ namespace DevToolssealed partial class App : Application, IDisposable{private readonly MefComposer _mefComposer;- private readonly ISettingsProvider _settingsProvider;private readonly Lazy<IThemeListener> _themeListener;private bool _isDisposed;@@ -50,7 +48,7 @@ namespace DevToolstypeof(Providers.Impl.Dummy).Assembly,typeof(Impl.Dummy).Assembly);- _settingsProvider = _mefComposer.ExportProvider.GetExport<ISettingsProvider>();+ // Importing it in a Lazy because we can't import it before a Window is created._themeListener = new Lazy<IThemeListener>(() => _mefComposer.ExportProvider.GetExport<IThemeListener>());InitializeComponent();@@ -182,31 +180,9 @@ namespace DevToolsWindow.Current.Content = rootFrame;}- _themeListener.Value.ThemeChanged += ThemeListener_ThemeChanged;- UpdateColorTheme();+ _themeListener.Value.ApplyDesiredColorTheme();return rootFrame;}-- private void ThemeListener_ThemeChanged(object sender, EventArgs e)- {- UpdateColorTheme();- }-- private void UpdateColorTheme()- {- AppTheme theme = _settingsProvider.GetSetting(PredefinedSettings.Theme);-- if (theme == AppTheme.Default)- {- theme = _themeListener.Value.CurrentTheme;- }-- // Set theme for window root.- if (Window.Current.Content is FrameworkElement frameworkElement)- {- frameworkElement.RequestedTheme = theme == AppTheme.Light ? ElementTheme.Light : ElementTheme.Dark;- }- }}}\ No newline at end of filediff --git a/src/tests/DevTools.Tests/UI/ConvertersTests.cs b/src/tests/DevTools.Tests/UI/ConvertersTests.csindex b83096ad4..5182cd33a 100644--- a/src/tests/DevTools.Tests/UI/ConvertersTests.cs+++ b/src/tests/DevTools.Tests/UI/ConvertersTests.cs@@ -64,5 +64,20 @@ namespace DevTools.Tests.UIAssert.AreEqual(converter.ThicknessOnEnumDetected, converter.Convert(AppBarClosedDisplayMode.Compact, null, "Compact", null));Assert.AreEqual(converter.ThicknessOnEnumNotDetected, converter.Convert(AppBarClosedDisplayMode.Compact, null, "Test", null));}++ [TestMethod]+ public void EnumToBooleanConverterTest()+ {+ var converter = new EnumToBooleanConverter();++ Assert.IsFalse((bool)converter.Convert(null, null, "foo", null));+ Assert.IsFalse((bool)converter.Convert(AppBarClosedDisplayMode.Compact, null, null, null));+ Assert.IsFalse((bool)converter.Convert("foo", null, "foo", null));++ Assert.IsTrue((bool)converter.Convert(AppBarClosedDisplayMode.Compact, null, "Compact", null));+ Assert.IsFalse((bool)converter.Convert(AppBarClosedDisplayMode.Compact, null, "Test", null));++ Assert.AreEqual(AppBarClosedDisplayMode.Compact, converter.ConvertBack(true, typeof(AppBarClosedDisplayMode), "Compact", null));+ }}}