A Swiss Army knife for developers.
C# blazorcross-platformcsharpdesktopdesktop-appdesktop-applicationdeveloper-toolsextensiblefluentfluent-designlinuxmacosmicasyntax-highlightingtypescriptwindowswindows-10windows-11winui
Added compact mode
Etienne Baudoux6d1eeecb1b92
diff --git a/src/app/dev/DevToys.Api/Core/Theme/IThemeListener.cs b/src/app/dev/DevToys.Api/Core/Theme/IThemeListener.csindex 91d6916bf..6ada2d459 100644--- a/src/app/dev/DevToys.Api/Core/Theme/IThemeListener.cs+++ b/src/app/dev/DevToys.Api/Core/Theme/IThemeListener.cs@@ -21,10 +21,15 @@ public interface IThemeListenerApplicationTheme ActualAppTheme { get; }/// <summary>- /// Gets or sets a value indicating whether the current theme is high contrast.+ /// Gets a value indicating whether the current theme is high contrast./// </summary>bool IsHighContrast { get; }+ /// <summary>+ /// Gets a value indicating whether the UI should be in compact mode.+ /// </summary>+ bool IsCompactMode { get; }+/// <summary>/// Raised when the theme has changed./// </summary>diff --git a/src/app/dev/DevToys.Api/Settings/PredefinedSettings.cs b/src/app/dev/DevToys.Api/Settings/PredefinedSettings.csnew file mode 100644index 000000000..b73560056--- /dev/null+++ b/src/app/dev/DevToys.Api/Settings/PredefinedSettings.cs@@ -0,0 +1,12 @@+namespace DevToys.Api;++public static class PredefinedSettings+{+ /// <summary>+ /// Whether the compact mode is enabled or not.+ /// </summary>+ public static readonly SettingDefinition<bool> CompactMode+ = new(+ name: nameof(CompactMode),+ defaultValue: false);+}diff --git a/src/app/dev/DevToys.Core/Tools/GuiToolProvider.cs b/src/app/dev/DevToys.Core/Tools/GuiToolProvider.csindex 1eff78556..ff77d137e 100644--- a/src/app/dev/DevToys.Core/Tools/GuiToolProvider.cs+++ b/src/app/dev/DevToys.Core/Tools/GuiToolProvider.cs@@ -1,9 +1,7 @@using System.Collections.ObjectModel;using System.Reflection;-using System.Xml.Linq;using DevToys.Api;using DevToys.Api.Core;-using DevToys.Core.Settings;using DevToys.Core.Tools.Metadata;using DevToys.Core.Tools.ViewItems;using DevToys.Localization;@@ -12,6 +10,7 @@ using FuzzySharp;using FuzzySharp.PreProcess;using Microsoft.Extensions.Logging;using Uno.Extensions;+using PredefinedSettings = DevToys.Core.Settings.PredefinedSettings;namespace DevToys.Core.Tools;diff --git a/src/app/dev/DevToys.Tools/Settings/SettingsGuiTool.cs b/src/app/dev/DevToys.Tools/Settings/SettingsGuiTool.csindex 4b54baffb..d3e0748ae 100644--- a/src/app/dev/DevToys.Tools/Settings/SettingsGuiTool.cs+++ b/src/app/dev/DevToys.Tools/Settings/SettingsGuiTool.cs@@ -65,9 +65,8 @@ internal sealed class SettingsGuiTool : IGuiToolItem("Dark", AvailableApplicationTheme.Dark)).WithSettings(Setting()- .Title("Title")- .Description("Description")- .Handle(_settingsProvider, DummySetting, OnDummySettingChangedAsync),+ .Title("Compact mode")+ .Handle(_settingsProvider, PredefinedSettings.CompactMode),Setting().Title("Title").Description("Description")@@ -99,8 +98,6 @@ internal sealed class SettingsGuiTool : IGuiToolprivate ValueTask OnDummySettingChangedAsync(bool state){- _clickCount++;- _topLeftButton.Text($"Clicked {_clickCount} time !");return ValueTask.CompletedTask;}diff --git a/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UISettingGroupPresenter.xaml b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UISettingGroupPresenter.xamlindex 208ccc00a..4f48a0c07 100644--- a/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UISettingGroupPresenter.xaml+++ b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UISettingGroupPresenter.xaml@@ -15,7 +15,7 @@<Expander.Header><local:UISettingHeaderControlx:Name="UISettingHeaderControl"- Margin="0,16"/>+ Margin="{ThemeResource UISettingGroupPresenterContentMargin}"/></Expander.Header><StackPaneldiff --git a/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UISettingPresenter.xaml b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UISettingPresenter.xamlindex b33f78812..d1605b589 100644--- a/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UISettingPresenter.xaml+++ b/src/app/dev/DevToys.UI.Framework/Controls/GuiTool/UISettingPresenter.xaml@@ -16,7 +16,7 @@<Setter Property="BorderThickness" Value="{ThemeResource ExpanderHeaderBorderThickness}" /><Setter Property="HorizontalAlignment" Value="Stretch" /><Setter Property="MinHeight" Value="{StaticResource ExpanderMinHeight}" />- <Setter Property="Padding" Value="{StaticResource ExpanderContentPadding}" />+ <Setter Property="Padding" Value="{ThemeResource UISettingPresenterContentPadding}" /></Style></UserControl.Resources>diff --git a/src/app/dev/DevToys.UI/Views/MainWindow.xaml b/src/app/dev/DevToys.UI/Views/MainWindow.xamlindex 98cd01433..95509122c 100644--- a/src/app/dev/DevToys.UI/Views/MainWindow.xaml+++ b/src/app/dev/DevToys.UI/Views/MainWindow.xaml@@ -190,6 +190,7 @@<dts:MainMenuNavigationViewMenuItemSelector.GroupViewItem><DataTemplate x:DataType="tools:GroupViewItem"><NavigationViewItem+ MinHeight="{ThemeResource NavigationViewItemOnLeftMinHeight}"AutomationProperties.Name="{x:Bind AccessibleName}"MenuItemsSource="{x:Bind Children}"IsExpanded="{x:Bind local:MainWindow.UpdateMenuItemShouldBeExpanded(MenuItemShouldBeExpanded), Mode=OneWay}">@@ -218,6 +219,7 @@<dts:MainMenuNavigationViewMenuItemSelector.GuiToolViewItem><DataTemplate x:DataType="tools:GuiToolViewItem"><NavigationViewItem+ MinHeight="{ThemeResource NavigationViewItemOnLeftMinHeight}"AutomationProperties.Name="{x:Bind ToolInstance.AccessibleName}"><NavigationViewItem.Icon><FontIcondiff --git a/src/app/dev/DevToys.UI/Views/ToolGroupPage.xaml b/src/app/dev/DevToys.UI/Views/ToolGroupPage.xamlindex b8f5ab47e..681f0d617 100644--- a/src/app/dev/DevToys.UI/Views/ToolGroupPage.xaml+++ b/src/app/dev/DevToys.UI/Views/ToolGroupPage.xaml@@ -43,7 +43,7 @@<GridViewx:Name="GridView"TabIndex="0"- Padding="56,32,56,56"+ Padding="{ThemeResource PageDefaultPadding}"SelectionMode="None"IsSwipeEnabled="False"IsItemClickEnabled="True"diff --git a/src/app/dev/DevToys.UI/Views/ToolPage.xaml b/src/app/dev/DevToys.UI/Views/ToolPage.xamlindex 6f9eb00c4..6b2ff31a8 100644--- a/src/app/dev/DevToys.UI/Views/ToolPage.xaml+++ b/src/app/dev/DevToys.UI/Views/ToolPage.xaml@@ -21,7 +21,7 @@<ScrollViewerx:Name="RootScrollViewer"- Padding="56,32,56,56">+ Padding="{ThemeResource PageDefaultPadding}"><VisualStateManager.VisualStateGroups><VisualStateGroup><VisualState x:Name="NavigationViewExpanded">diff --git a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Core/Theme/ThemeListener.cs b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Core/Theme/ThemeListener.csindex 741425f3f..c45dc8035 100644--- a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Core/Theme/ThemeListener.cs+++ b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Core/Theme/ThemeListener.cs@@ -32,12 +32,14 @@ internal sealed class ThemeListener : IThemeListenerpublic AvailableApplicationTheme CurrentSystemTheme { get; private set; }- public AvailableApplicationTheme CurrentAppTheme => _settingsProvider.GetSetting(PredefinedSettings.Theme);+ public AvailableApplicationTheme CurrentAppTheme => _settingsProvider.GetSetting(DevToys.Core.Settings.PredefinedSettings.Theme);public ApplicationTheme ActualAppTheme { get; private set; }public bool IsHighContrast { get; private set; }+ public bool IsCompactMode => _settingsProvider.GetSetting(DevToys.Api.PredefinedSettings.CompactMode);+public event EventHandler? ThemeChanged;public void ApplyDesiredColorTheme()@@ -81,11 +83,15 @@ internal sealed class ThemeListener : IThemeListenerprivate void SettingsProvider_SettingChanged(object? sender, SettingChangedEventArgs e){- if (string.Equals(PredefinedSettings.Theme.Name, e.SettingName, StringComparison.Ordinal))+ if (string.Equals(DevToys.Core.Settings.PredefinedSettings.Theme.Name, e.SettingName, StringComparison.Ordinal)){ApplyDesiredColorTheme();ThemeChanged?.Invoke(this, EventArgs.Empty);}+ else if (string.Equals(DevToys.Api.PredefinedSettings.CompactMode.Name, e.SettingName, StringComparison.Ordinal))+ {+ // TODO: Apply the mode.+ }}/// <summary>diff --git a/src/app/dev/platforms/desktop/windows/DevToys.Wasdk/Core/Theme/ThemeListener.cs b/src/app/dev/platforms/desktop/windows/DevToys.Wasdk/Core/Theme/ThemeListener.csindex e4008b8e8..35ab31c95 100644--- a/src/app/dev/platforms/desktop/windows/DevToys.Wasdk/Core/Theme/ThemeListener.cs+++ b/src/app/dev/platforms/desktop/windows/DevToys.Wasdk/Core/Theme/ThemeListener.cs@@ -1,6 +1,5 @@using DevToys.Api;using DevToys.Api.Core.Theme;-using DevToys.Core.Settings;using Microsoft.UI.Xaml;using Windows.UI.ViewManagement;@@ -11,6 +10,7 @@ internal sealed class ThemeListener : IThemeListener{private readonly AccessibilitySettings _accessible = new();private readonly ISettingsProvider _settingsProvider;+ private readonly ResourceDictionary _compactModeResourceDictionary = new();[ImportingConstructor]public ThemeListener(ISettingsProvider settingsProvider)@@ -19,6 +19,8 @@ internal sealed class ThemeListener : IThemeListener_settingsProvider.SettingChanged += SettingsProvider_SettingChanged;+ _compactModeResourceDictionary.Source = new Uri("ms-appx:///DevToys.UI.Framework/Themes/Generic.xaml");+if (Application.Current.RequestedTheme == Microsoft.UI.Xaml.ApplicationTheme.Dark){CurrentSystemTheme = AvailableApplicationTheme.Dark;@@ -33,16 +35,20 @@ internal sealed class ThemeListener : IThemeListenerpublic AvailableApplicationTheme CurrentSystemTheme { get; private set; }- public AvailableApplicationTheme CurrentAppTheme => _settingsProvider.GetSetting(PredefinedSettings.Theme);+ public AvailableApplicationTheme CurrentAppTheme => _settingsProvider.GetSetting(DevToys.Core.Settings.PredefinedSettings.Theme);public Api.Core.Theme.ApplicationTheme ActualAppTheme { get; private set; }public bool IsHighContrast { get; private set; }+ public bool IsCompactMode => _settingsProvider.GetSetting(DevToys.Api.PredefinedSettings.CompactMode);+public event EventHandler? ThemeChanged;public void UpdateThemeIfNeeded(){+ UpdateCompactMode();+AvailableApplicationTheme currentAppTheme;if (Application.Current.RequestedTheme == Microsoft.UI.Xaml.ApplicationTheme.Dark){@@ -81,11 +87,15 @@ internal sealed class ThemeListener : IThemeListenerprivate void SettingsProvider_SettingChanged(object? sender, SettingChangedEventArgs e){- if (string.Equals(PredefinedSettings.Theme.Name, e.SettingName, StringComparison.Ordinal))+ if (string.Equals(DevToys.Core.Settings.PredefinedSettings.Theme.Name, e.SettingName, StringComparison.Ordinal)){ApplyDesiredColorTheme();ThemeChanged?.Invoke(this, EventArgs.Empty);}+ else if (string.Equals(DevToys.Api.PredefinedSettings.CompactMode.Name, e.SettingName, StringComparison.Ordinal))+ {+ UpdateCompactMode();+ }}/// <summary>@@ -120,4 +130,56 @@ internal sealed class ThemeListener : IThemeListenerApplyDesiredColorTheme();ThemeChanged?.Invoke(this, EventArgs.Empty);}++ private void UpdateCompactMode()+ {+ if (IsCompactMode)+ {+ // NavigationView+ UpdateAppResource("NavigationViewItemOnLeftMinHeight", 20);++ // Page+ UpdateAppResource("PageDefaultPadding", new Thickness(16, 32, 16, 32));++ // UISetting+ UpdateAppResource("UISettingPresenterContentPadding", new Thickness(16, 4, 16, 4));+ UpdateAppResource("UISettingGroupPresenterContentMargin", new Thickness(0, 4, 0, 4));++ // ComboBox+ UpdateAppResource("ComboBoxMinHeight", 24);+ UpdateAppResource("ComboBoxPadding", new Thickness(12, 1, 0, 3));+ }+ else+ {+ // NavigationView+ UpdateAppResource("NavigationViewItemOnLeftMinHeight", 32);++ // Page+ UpdateAppResource("PageDefaultPadding", new Thickness(56, 32, 56, 56));++ // UISetting+ UpdateAppResource("UISettingPresenterContentPadding", new Thickness(16));+ UpdateAppResource("UISettingGroupPresenterContentMargin", new Thickness(0, 16, 0, 16));++ // ComboBox+ UpdateAppResource("ComboBoxMinHeight", 32);+ UpdateAppResource("ComboBoxPadding", new Thickness(12, 5, 0, 7));+ }++ // Toggle between the themes to force reload the resource styles.+ Api.Core.Theme.ApplicationTheme backupTheme = ActualAppTheme;+ ActualAppTheme = Api.Core.Theme.ApplicationTheme.Dark;+ ThemeChanged?.Invoke(this, EventArgs.Empty);++ ActualAppTheme = Api.Core.Theme.ApplicationTheme.Light;+ ThemeChanged?.Invoke(this, EventArgs.Empty);++ ActualAppTheme = backupTheme;+ ThemeChanged?.Invoke(this, EventArgs.Empty);+ }++ private static void UpdateAppResource(string resourceName, object value)+ {+ App.Current.Resources[resourceName] = value;+ }}diff --git a/src/app/dev/shared/App.xaml b/src/app/dev/shared/App.xamlindex be0e2e4c5..d76cf4fc1 100644--- a/src/app/dev/shared/App.xaml+++ b/src/app/dev/shared/App.xaml@@ -11,6 +11,7 @@<ResourceDictionary Source="ms-appx:///DevToys.UI.Framework/Themes/Generic.xaml"/><!-- Add resource dictionaries here --></ResourceDictionary.MergedDictionaries>+<!-- Add resources here --></ResourceDictionary></Application.Resources>diff --git a/src/app/dev/shared/App.xaml.cs b/src/app/dev/shared/App.xaml.csindex 12411af70..02ceb0d9f 100644--- a/src/app/dev/shared/App.xaml.cs+++ b/src/app/dev/shared/App.xaml.cs@@ -17,6 +17,7 @@ using Windows.ApplicationModel;using Windows.ApplicationModel.Core;using ILogger = Microsoft.Extensions.Logging.ILogger;using LaunchActivatedEventArgs = Microsoft.UI.Xaml.LaunchActivatedEventArgs;+using PredefinedSettings = DevToys.Core.Settings.PredefinedSettings;using UnhandledExceptionEventArgs = Microsoft.UI.Xaml.UnhandledExceptionEventArgs;namespace DevToys;