mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[TUI] Refactor window view models to use ManagedWindow instead of Window
This commit is contained in:
@@ -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<HexViewLine> _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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -42,15 +42,6 @@
|
||||
Foreground="SlateBlue"
|
||||
Text="Shows this help" />
|
||||
</Grid>
|
||||
<Grid ColumnDefinitions="Auto,*"
|
||||
ColumnSpacing="2">
|
||||
<TextBlock Grid.Column="0"
|
||||
Foreground="Aqua"
|
||||
Text="F2 " />
|
||||
<TextBlock Grid.Column="1"
|
||||
Foreground="SlateBlue"
|
||||
Text="Sector viewer" />
|
||||
</Grid>
|
||||
<Grid ColumnDefinitions="Auto,*"
|
||||
ColumnSpacing="2">
|
||||
<TextBlock Grid.Column="0"
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:console="https://github.com/jinek/consolonia"
|
||||
xmlns:windows="clr-namespace:Aaru.Tui.ViewModels.Windows"
|
||||
x:Class="Aaru.Tui.Views.Windows.HexViewWindow"
|
||||
RequestedThemeVariant="Dark">
|
||||
<windowManager:ManagedWindow xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:console="https://github.com/jinek/consolonia"
|
||||
xmlns:windows="clr-namespace:Aaru.Tui.ViewModels.Windows"
|
||||
xmlns:windowManager="clr-namespace:Iciclecreek.Avalonia.WindowManager;assembly=Iciclecreek.Avalonia.WindowManager"
|
||||
x:Class="Aaru.Tui.Views.Windows.HexViewWindow"
|
||||
WindowState="FullScreen"
|
||||
CanResize="False">
|
||||
<Design.DataContext>
|
||||
<windows:HexViewWindowViewModel />
|
||||
</Design.DataContext>
|
||||
@@ -98,4 +100,4 @@
|
||||
</Grid>
|
||||
</Border>
|
||||
</DockPanel>
|
||||
</Window>
|
||||
</windowManager:ManagedWindow>
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
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"
|
||||
xmlns:windows="clr-namespace:Aaru.Tui.ViewModels.Windows"
|
||||
xmlns:brushes="https://github.com/jinek/consolonia"
|
||||
mc:Ignorable="d"
|
||||
d:DesignWidth="800"
|
||||
d:DesignHeight="450"
|
||||
RequestedThemeVariant="Dark"
|
||||
x:Class="Aaru.Tui.Views.Windows.ImageWindow"
|
||||
Title="ImageWindow">
|
||||
<windowManager:ManagedWindow xmlns="https://github.com/avaloniaui"
|
||||
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"
|
||||
xmlns:windows="clr-namespace:Aaru.Tui.ViewModels.Windows"
|
||||
xmlns:brushes="https://github.com/jinek/consolonia"
|
||||
xmlns:windowManager="clr-namespace:Iciclecreek.Avalonia.WindowManager;assembly=Iciclecreek.Avalonia.WindowManager"
|
||||
mc:Ignorable="d"
|
||||
d:DesignWidth="800"
|
||||
d:DesignHeight="450"
|
||||
WindowState="FullScreen"
|
||||
CanResize="False"
|
||||
x:Class="Aaru.Tui.Views.Windows.ImageWindow">
|
||||
<Design.DataContext>
|
||||
<windows:ImageWindowViewModel />
|
||||
</Design.DataContext>
|
||||
@@ -21,9 +22,7 @@
|
||||
<MenuItem Header="F1 Help"
|
||||
Command="{Binding HelpCommand, Mode=OneWay}"
|
||||
HotKey="F1" />
|
||||
<MenuItem Header="F2 ScVw"
|
||||
Command="{Binding SectorViewCommand, Mode=OneWay}"
|
||||
HotKey="F2" />
|
||||
<MenuItem Header="F2 " />
|
||||
<MenuItem Header="F10 Exit"
|
||||
Command="{Binding ExitCommand, Mode=OneWay}"
|
||||
HotKey="F10" />
|
||||
@@ -165,4 +164,4 @@
|
||||
</Grid>
|
||||
</Border>
|
||||
</DockPanel>
|
||||
</Window>
|
||||
</windowManager:ManagedWindow>
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user