From 490deac178035e42a7e1aa5b3feb4dafc4343eb5 Mon Sep 17 00:00:00 2001 From: Andrei Zhvaleuski Date: Thu, 26 Sep 2024 17:14:28 +0300 Subject: [PATCH 01/16] Use dropdown for active layout selection --- .../ActiveLayout/ActiveLayoutWidget.xaml | 29 +++++------- .../ActiveLayoutWidgetViewModel.cs | 23 +++++++--- .../ActiveLayout/NextLayoutEngineCommand.cs | 38 ---------------- src/Whim.Bar/Workspace/WorkspaceWidget.xaml | 45 ------------------- 4 files changed, 30 insertions(+), 105 deletions(-) delete mode 100644 src/Whim.Bar/ActiveLayout/NextLayoutEngineCommand.cs delete mode 100644 src/Whim.Bar/Workspace/WorkspaceWidget.xaml diff --git a/src/Whim.Bar/ActiveLayout/ActiveLayoutWidget.xaml b/src/Whim.Bar/ActiveLayout/ActiveLayoutWidget.xaml index 64afc1563..270ca31b6 100644 --- a/src/Whim.Bar/ActiveLayout/ActiveLayoutWidget.xaml +++ b/src/Whim.Bar/ActiveLayout/ActiveLayoutWidget.xaml @@ -1,19 +1,14 @@  - + x:Class="Whim.Bar.ActiveLayoutWidget" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + d:DesignHeight="450" + d:DesignWidth="800" + mc:Ignorable="d"> + diff --git a/src/Whim.Bar/ActiveLayout/ActiveLayoutWidgetViewModel.cs b/src/Whim.Bar/ActiveLayout/ActiveLayoutWidgetViewModel.cs index 89e2d45a4..8e4c0fa44 100644 --- a/src/Whim.Bar/ActiveLayout/ActiveLayoutWidgetViewModel.cs +++ b/src/Whim.Bar/ActiveLayout/ActiveLayoutWidgetViewModel.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.ObjectModel; using System.ComponentModel; +using System.Linq; namespace Whim.Bar; @@ -20,13 +22,25 @@ internal class ActiveLayoutWidgetViewModel : INotifyPropertyChanged, IDisposable /// /// The name of the active layout engine. /// - public string ActiveLayoutEngine => - _context.Butler.Pantry.GetWorkspaceForMonitor(Monitor)?.ActiveLayoutEngine.Name ?? ""; + public ObservableCollection LayoutEngines => + new(_context.Butler.Pantry.GetWorkspaceForMonitor(Monitor)?.LayoutEngines.Select(layoutEngine => layoutEngine.Name).ToArray() ?? []); /// - /// Command to switch to the next layout engine. + /// The name of the active layout engine. /// - public System.Windows.Input.ICommand NextLayoutEngineCommand { get; } + public string ActiveLayoutEngine + { + get => _context.Butler.Pantry.GetWorkspaceForMonitor(Monitor)?.ActiveLayoutEngine.Name ?? ""; + set + { + if (_context.Butler.Pantry.GetWorkspaceForMonitor(Monitor) is IWorkspace workspace + && workspace.ActiveLayoutEngine.Name != value + && workspace.TrySetLayoutEngineFromName(value)) + { + OnPropertyChanged(nameof(ActiveLayoutEngine)); + } + } + } /// /// @@ -37,7 +51,6 @@ public ActiveLayoutWidgetViewModel(IContext context, IMonitor monitor) { _context = context; Monitor = monitor; - NextLayoutEngineCommand = new NextLayoutEngineCommand(context, this); _context.WorkspaceManager.ActiveLayoutEngineChanged += WorkspaceManager_ActiveLayoutEngineChanged; _context.Butler.MonitorWorkspaceChanged += Butler_MonitorWorkspaceChanged; diff --git a/src/Whim.Bar/ActiveLayout/NextLayoutEngineCommand.cs b/src/Whim.Bar/ActiveLayout/NextLayoutEngineCommand.cs deleted file mode 100644 index e9bfde7e4..000000000 --- a/src/Whim.Bar/ActiveLayout/NextLayoutEngineCommand.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; - -namespace Whim.Bar; - -/// -/// Command to switch to the next layout engine. -/// -/// -/// Creates a new instance of . -/// -/// -/// -internal class NextLayoutEngineCommand(IContext context, ActiveLayoutWidgetViewModel viewModel) - : System.Windows.Input.ICommand -{ - private readonly IContext _context = context; - private readonly ActiveLayoutWidgetViewModel _viewModel = viewModel; - - /// - public event EventHandler? CanExecuteChanged - { - add { } - remove { } - } - - /// - public bool CanExecute(object? parameter) => true; - - /// - public void Execute(object? parameter) - { - Logger.Debug("Switching to next layout engine"); - if (_context.Butler.Pantry.GetWorkspaceForMonitor(_viewModel.Monitor) is IWorkspace workspace) - { - workspace.CycleLayoutEngine(false); - } - } -} diff --git a/src/Whim.Bar/Workspace/WorkspaceWidget.xaml b/src/Whim.Bar/Workspace/WorkspaceWidget.xaml deleted file mode 100644 index 840e964f9..000000000 --- a/src/Whim.Bar/Workspace/WorkspaceWidget.xaml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - - - - - From 67989088546f86e42c8daf4a77615f3111eb8e90 Mon Sep 17 00:00:00 2001 From: Andrei Zhvaleuski Date: Thu, 26 Sep 2024 17:57:23 +0300 Subject: [PATCH 02/16] Add draft styling --- .../ActiveLayout/ActiveLayoutWidget.xaml | 24 +++++----- .../ActiveLayoutWidgetViewModel.cs | 13 ++++-- src/Whim.Bar/Workspace/WorkspaceWidget.xaml | 45 +++++++++++++++++++ src/Whim/Resources/Defaults.xaml | 9 +++- 4 files changed, 75 insertions(+), 16 deletions(-) create mode 100644 src/Whim.Bar/Workspace/WorkspaceWidget.xaml diff --git a/src/Whim.Bar/ActiveLayout/ActiveLayoutWidget.xaml b/src/Whim.Bar/ActiveLayout/ActiveLayoutWidget.xaml index 270ca31b6..2c21467a1 100644 --- a/src/Whim.Bar/ActiveLayout/ActiveLayoutWidget.xaml +++ b/src/Whim.Bar/ActiveLayout/ActiveLayoutWidget.xaml @@ -1,14 +1,14 @@  - + x:Class="Whim.Bar.ActiveLayoutWidget" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + d:DesignHeight="450" + d:DesignWidth="800" + mc:Ignorable="d"> + diff --git a/src/Whim.Bar/ActiveLayout/ActiveLayoutWidgetViewModel.cs b/src/Whim.Bar/ActiveLayout/ActiveLayoutWidgetViewModel.cs index 8e4c0fa44..9f0417931 100644 --- a/src/Whim.Bar/ActiveLayout/ActiveLayoutWidgetViewModel.cs +++ b/src/Whim.Bar/ActiveLayout/ActiveLayoutWidgetViewModel.cs @@ -23,7 +23,12 @@ internal class ActiveLayoutWidgetViewModel : INotifyPropertyChanged, IDisposable /// The name of the active layout engine. /// public ObservableCollection LayoutEngines => - new(_context.Butler.Pantry.GetWorkspaceForMonitor(Monitor)?.LayoutEngines.Select(layoutEngine => layoutEngine.Name).ToArray() ?? []); + new( + _context + .Butler.Pantry.GetWorkspaceForMonitor(Monitor) + ?.LayoutEngines.Select(layoutEngine => layoutEngine.Name) + .ToArray() ?? [] + ); /// /// The name of the active layout engine. @@ -33,9 +38,11 @@ public string ActiveLayoutEngine get => _context.Butler.Pantry.GetWorkspaceForMonitor(Monitor)?.ActiveLayoutEngine.Name ?? ""; set { - if (_context.Butler.Pantry.GetWorkspaceForMonitor(Monitor) is IWorkspace workspace + if ( + _context.Butler.Pantry.GetWorkspaceForMonitor(Monitor) is IWorkspace workspace && workspace.ActiveLayoutEngine.Name != value - && workspace.TrySetLayoutEngineFromName(value)) + && workspace.TrySetLayoutEngineFromName(value) + ) { OnPropertyChanged(nameof(ActiveLayoutEngine)); } diff --git a/src/Whim.Bar/Workspace/WorkspaceWidget.xaml b/src/Whim.Bar/Workspace/WorkspaceWidget.xaml new file mode 100644 index 000000000..840e964f9 --- /dev/null +++ b/src/Whim.Bar/Workspace/WorkspaceWidget.xaml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + diff --git a/src/Whim/Resources/Defaults.xaml b/src/Whim/Resources/Defaults.xaml index 45b660d03..30b152658 100644 --- a/src/Whim/Resources/Defaults.xaml +++ b/src/Whim/Resources/Defaults.xaml @@ -59,7 +59,14 @@ - + From 0179706ad1c0b5844508e44d09f43d81a29d3b0a Mon Sep 17 00:00:00 2001 From: Andrei Zhvaleuski Date: Thu, 26 Sep 2024 22:19:18 +0300 Subject: [PATCH 03/16] Improve styling --- src/Whim/Resources/Defaults.xaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Whim/Resources/Defaults.xaml b/src/Whim/Resources/Defaults.xaml index 30b152658..ae8b8cfaa 100644 --- a/src/Whim/Resources/Defaults.xaml +++ b/src/Whim/Resources/Defaults.xaml @@ -60,8 +60,9 @@ - +