From 320a70bc9de4d6507de62fcea51c6693fb064432 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 18 Oct 2025 11:29:36 +0100 Subject: [PATCH] [TUI] Refactor window view models to use ManagedWindow instead of Window --- .../Windows/HexViewWindowViewModel.cs | 15 +++----- .../Windows/ImageWindowViewModel.cs | 38 +++++-------------- .../ViewModels/Windows/MainWindowViewModel.cs | 6 +-- Aaru.Tui/Views/Dialogs/ImageHelpDialog.axaml | 9 ----- Aaru.Tui/Views/Windows/HexViewWindow.axaml | 16 ++++---- Aaru.Tui/Views/Windows/HexViewWindow.axaml.cs | 4 +- Aaru.Tui/Views/Windows/ImageWindow.axaml | 31 ++++++++------- Aaru.Tui/Views/Windows/ImageWindow.axaml.cs | 4 +- 8 files changed, 46 insertions(+), 77 deletions(-) diff --git a/Aaru.Tui/ViewModels/Windows/HexViewWindowViewModel.cs b/Aaru.Tui/ViewModels/Windows/HexViewWindowViewModel.cs index a0b7c30bc..eb0ce0248 100644 --- a/Aaru.Tui/ViewModels/Windows/HexViewWindowViewModel.cs +++ b/Aaru.Tui/ViewModels/Windows/HexViewWindowViewModel.cs @@ -32,20 +32,19 @@ using Aaru.CommonTypes.Interfaces; using Aaru.Tui.ViewModels.Dialogs; using Aaru.Tui.Views.Dialogs; using Avalonia; -using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; +using Iciclecreek.Avalonia.WindowManager; using GoToSectorDialog = Aaru.Tui.Views.Dialogs.GoToSectorDialog; namespace Aaru.Tui.ViewModels.Windows; public sealed partial class HexViewWindowViewModel : ViewModelBase { - private const int BYTES_PER_LINE = 16; - readonly IMediaImage _imageFormat; - readonly Window _parent; - readonly Window _view; + private const int BYTES_PER_LINE = 16; + readonly IMediaImage _imageFormat; + readonly ManagedWindow _view; [ObservableProperty] ulong _currentSector; [ObservableProperty] @@ -56,8 +55,8 @@ public sealed partial class HexViewWindowViewModel : ViewModelBase ObservableCollection _lines = []; bool _longMode; - internal HexViewWindowViewModel(Window parent, Window view, IMediaImage imageFormat, string filePath, - ulong currentSector = 0) + internal HexViewWindowViewModel(ManagedWindow view, IMediaImage imageFormat, string filePath, + ulong currentSector = 0) { ExitCommand = new RelayCommand(Exit); BackCommand = new RelayCommand(Back); @@ -67,7 +66,6 @@ public sealed partial class HexViewWindowViewModel : ViewModelBase HelpCommand = new AsyncRelayCommand(HelpAsync); ToggleLongCommand = new RelayCommand(ToggleLong); - _parent = parent; _view = view; _imageFormat = imageFormat; _currentSector = currentSector; @@ -152,7 +150,6 @@ public sealed partial class HexViewWindowViewModel : ViewModelBase void Back() { - _parent.Show(); _view.Close(); } diff --git a/Aaru.Tui/ViewModels/Windows/ImageWindowViewModel.cs b/Aaru.Tui/ViewModels/Windows/ImageWindowViewModel.cs index 6a0bede6e..e17581ab2 100644 --- a/Aaru.Tui/ViewModels/Windows/ImageWindowViewModel.cs +++ b/Aaru.Tui/ViewModels/Windows/ImageWindowViewModel.cs @@ -33,23 +33,21 @@ using Aaru.CommonTypes.Interfaces; using Aaru.Tui.Models; using Aaru.Tui.ViewModels.Dialogs; using Aaru.Tui.Views.Dialogs; -using Aaru.Tui.Views.Windows; using Avalonia; -using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using Humanizer; using Humanizer.Bytes; +using Iciclecreek.Avalonia.WindowManager; using Partition = Aaru.CommonTypes.Partition; namespace Aaru.Tui.ViewModels.Windows; public sealed partial class ImageWindowViewModel : ViewModelBase { - readonly IMediaImage _imageFormat; - readonly Window _parent; - readonly Window _view; + readonly IMediaImage _imageFormat; + readonly ManagedWindow _view; [ObservableProperty] public string _filePath; [ObservableProperty] @@ -84,17 +82,15 @@ public sealed partial class ImageWindowViewModel : ViewModelBase [ObservableProperty] string? _status; - public ImageWindowViewModel(Window parent, Window view, IMediaImage imageFormat, string filePath) + public ImageWindowViewModel(ManagedWindow view, IMediaImage imageFormat, string filePath) { _imageFormat = imageFormat; FilePath = filePath; _view = view; - _parent = parent; - ExitCommand = new RelayCommand(Exit); - BackCommand = new RelayCommand(Back); - HelpCommand = new AsyncRelayCommand(HelpAsync); - SectorViewCommand = new RelayCommand(SectorView); + ExitCommand = new RelayCommand(Exit); + BackCommand = new RelayCommand(Back); + HelpCommand = new AsyncRelayCommand(HelpAsync); } public FileSystemModelNode? SelectedNode @@ -148,26 +144,12 @@ public sealed partial class ImageWindowViewModel : ViewModelBase } } - public ICommand BackCommand { get; } - public ICommand HelpCommand { get; } - public ICommand ExitCommand { get; } - public ICommand SectorViewCommand { get; } - - void SectorView() - { - if(SelectedNode?.Partition is null) return; - - var view = new HexViewWindow(); - - var vm = new HexViewWindowViewModel(_view, view, _imageFormat, FilePath, SelectedNode.Partition.Value.Start); - view.DataContext = vm; - view.Show(); - _view.Hide(); - } + public ICommand BackCommand { get; } + public ICommand HelpCommand { get; } + public ICommand ExitCommand { get; } void Back() { - _parent.Show(); _view.Close(); } diff --git a/Aaru.Tui/ViewModels/Windows/MainWindowViewModel.cs b/Aaru.Tui/ViewModels/Windows/MainWindowViewModel.cs index 510663d97..354e5ea2a 100644 --- a/Aaru.Tui/ViewModels/Windows/MainWindowViewModel.cs +++ b/Aaru.Tui/ViewModels/Windows/MainWindowViewModel.cs @@ -163,10 +163,9 @@ public sealed partial class MainWindowViewModel : ViewModelBase var view = new HexViewWindow(); - var vm = new HexViewWindowViewModel(_view, view, SelectedFile.ImageFormat, SelectedFile.Path); + var vm = new HexViewWindowViewModel(view, SelectedFile.ImageFormat, SelectedFile.Path); view.DataContext = vm; view.Show(); - _view.Hide(); } void Exit() @@ -397,11 +396,10 @@ public sealed partial class MainWindowViewModel : ViewModelBase var imageWindow = new ImageWindow(); - var imageViewModel = new ImageWindowViewModel(_view, imageWindow, SelectedFile.ImageFormat, SelectedFile.Path); + var imageViewModel = new ImageWindowViewModel(imageWindow, SelectedFile.ImageFormat, SelectedFile.Path); imageWindow.DataContext = imageViewModel; imageWindow.Show(); - _view.Hide(); } bool CanOpenSelectedFile() => SelectedFile != null; diff --git a/Aaru.Tui/Views/Dialogs/ImageHelpDialog.axaml b/Aaru.Tui/Views/Dialogs/ImageHelpDialog.axaml index 721c4b1ab..5a6b17df3 100644 --- a/Aaru.Tui/Views/Dialogs/ImageHelpDialog.axaml +++ b/Aaru.Tui/Views/Dialogs/ImageHelpDialog.axaml @@ -42,15 +42,6 @@ Foreground="SlateBlue" Text="Shows this help" /> - - - - + @@ -98,4 +100,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/Aaru.Tui/Views/Windows/HexViewWindow.axaml.cs b/Aaru.Tui/Views/Windows/HexViewWindow.axaml.cs index 7d356ee8a..68b9b66d7 100644 --- a/Aaru.Tui/Views/Windows/HexViewWindow.axaml.cs +++ b/Aaru.Tui/Views/Windows/HexViewWindow.axaml.cs @@ -26,12 +26,12 @@ // ****************************************************************************/ using Aaru.Tui.ViewModels.Windows; -using Avalonia.Controls; using Avalonia.Interactivity; +using Iciclecreek.Avalonia.WindowManager; namespace Aaru.Tui.Views.Windows; -public partial class HexViewWindow : Window +public partial class HexViewWindow : ManagedWindow { public HexViewWindow() { diff --git a/Aaru.Tui/Views/Windows/ImageWindow.axaml b/Aaru.Tui/Views/Windows/ImageWindow.axaml index 465fd5d4b..932a38334 100644 --- a/Aaru.Tui/Views/Windows/ImageWindow.axaml +++ b/Aaru.Tui/Views/Windows/ImageWindow.axaml @@ -1,15 +1,16 @@ - + @@ -21,9 +22,7 @@ - + @@ -165,4 +164,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/Aaru.Tui/Views/Windows/ImageWindow.axaml.cs b/Aaru.Tui/Views/Windows/ImageWindow.axaml.cs index 0f7fc90d7..173a06bfa 100644 --- a/Aaru.Tui/Views/Windows/ImageWindow.axaml.cs +++ b/Aaru.Tui/Views/Windows/ImageWindow.axaml.cs @@ -26,12 +26,12 @@ // ****************************************************************************/ using Aaru.Tui.ViewModels.Windows; -using Avalonia.Controls; using Avalonia.Interactivity; +using Iciclecreek.Avalonia.WindowManager; namespace Aaru.Tui.Views.Windows; -public partial class ImageWindow : Window +public partial class ImageWindow : ManagedWindow { public ImageWindow() {