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,10 +32,10 @@ using Aaru.CommonTypes.Interfaces;
|
|||||||
using Aaru.Tui.ViewModels.Dialogs;
|
using Aaru.Tui.ViewModels.Dialogs;
|
||||||
using Aaru.Tui.Views.Dialogs;
|
using Aaru.Tui.Views.Dialogs;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
|
||||||
using Avalonia.Controls.ApplicationLifetimes;
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
using Iciclecreek.Avalonia.WindowManager;
|
||||||
using GoToSectorDialog = Aaru.Tui.Views.Dialogs.GoToSectorDialog;
|
using GoToSectorDialog = Aaru.Tui.Views.Dialogs.GoToSectorDialog;
|
||||||
|
|
||||||
namespace Aaru.Tui.ViewModels.Windows;
|
namespace Aaru.Tui.ViewModels.Windows;
|
||||||
@@ -44,8 +44,7 @@ public sealed partial class HexViewWindowViewModel : ViewModelBase
|
|||||||
{
|
{
|
||||||
private const int BYTES_PER_LINE = 16;
|
private const int BYTES_PER_LINE = 16;
|
||||||
readonly IMediaImage _imageFormat;
|
readonly IMediaImage _imageFormat;
|
||||||
readonly Window _parent;
|
readonly ManagedWindow _view;
|
||||||
readonly Window _view;
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
ulong _currentSector;
|
ulong _currentSector;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
@@ -56,7 +55,7 @@ public sealed partial class HexViewWindowViewModel : ViewModelBase
|
|||||||
ObservableCollection<HexViewLine> _lines = [];
|
ObservableCollection<HexViewLine> _lines = [];
|
||||||
bool _longMode;
|
bool _longMode;
|
||||||
|
|
||||||
internal HexViewWindowViewModel(Window parent, Window view, IMediaImage imageFormat, string filePath,
|
internal HexViewWindowViewModel(ManagedWindow view, IMediaImage imageFormat, string filePath,
|
||||||
ulong currentSector = 0)
|
ulong currentSector = 0)
|
||||||
{
|
{
|
||||||
ExitCommand = new RelayCommand(Exit);
|
ExitCommand = new RelayCommand(Exit);
|
||||||
@@ -67,7 +66,6 @@ public sealed partial class HexViewWindowViewModel : ViewModelBase
|
|||||||
HelpCommand = new AsyncRelayCommand(HelpAsync);
|
HelpCommand = new AsyncRelayCommand(HelpAsync);
|
||||||
ToggleLongCommand = new RelayCommand(ToggleLong);
|
ToggleLongCommand = new RelayCommand(ToggleLong);
|
||||||
|
|
||||||
_parent = parent;
|
|
||||||
_view = view;
|
_view = view;
|
||||||
_imageFormat = imageFormat;
|
_imageFormat = imageFormat;
|
||||||
_currentSector = currentSector;
|
_currentSector = currentSector;
|
||||||
@@ -152,7 +150,6 @@ public sealed partial class HexViewWindowViewModel : ViewModelBase
|
|||||||
|
|
||||||
void Back()
|
void Back()
|
||||||
{
|
{
|
||||||
_parent.Show();
|
|
||||||
_view.Close();
|
_view.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,14 +33,13 @@ using Aaru.CommonTypes.Interfaces;
|
|||||||
using Aaru.Tui.Models;
|
using Aaru.Tui.Models;
|
||||||
using Aaru.Tui.ViewModels.Dialogs;
|
using Aaru.Tui.ViewModels.Dialogs;
|
||||||
using Aaru.Tui.Views.Dialogs;
|
using Aaru.Tui.Views.Dialogs;
|
||||||
using Aaru.Tui.Views.Windows;
|
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
|
||||||
using Avalonia.Controls.ApplicationLifetimes;
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
using Humanizer;
|
using Humanizer;
|
||||||
using Humanizer.Bytes;
|
using Humanizer.Bytes;
|
||||||
|
using Iciclecreek.Avalonia.WindowManager;
|
||||||
using Partition = Aaru.CommonTypes.Partition;
|
using Partition = Aaru.CommonTypes.Partition;
|
||||||
|
|
||||||
namespace Aaru.Tui.ViewModels.Windows;
|
namespace Aaru.Tui.ViewModels.Windows;
|
||||||
@@ -48,8 +47,7 @@ namespace Aaru.Tui.ViewModels.Windows;
|
|||||||
public sealed partial class ImageWindowViewModel : ViewModelBase
|
public sealed partial class ImageWindowViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
readonly IMediaImage _imageFormat;
|
readonly IMediaImage _imageFormat;
|
||||||
readonly Window _parent;
|
readonly ManagedWindow _view;
|
||||||
readonly Window _view;
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
public string _filePath;
|
public string _filePath;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
@@ -84,17 +82,15 @@ public sealed partial class ImageWindowViewModel : ViewModelBase
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
string? _status;
|
string? _status;
|
||||||
|
|
||||||
public ImageWindowViewModel(Window parent, Window view, IMediaImage imageFormat, string filePath)
|
public ImageWindowViewModel(ManagedWindow view, IMediaImage imageFormat, string filePath)
|
||||||
{
|
{
|
||||||
_imageFormat = imageFormat;
|
_imageFormat = imageFormat;
|
||||||
FilePath = filePath;
|
FilePath = filePath;
|
||||||
_view = view;
|
_view = view;
|
||||||
_parent = parent;
|
|
||||||
|
|
||||||
ExitCommand = new RelayCommand(Exit);
|
ExitCommand = new RelayCommand(Exit);
|
||||||
BackCommand = new RelayCommand(Back);
|
BackCommand = new RelayCommand(Back);
|
||||||
HelpCommand = new AsyncRelayCommand(HelpAsync);
|
HelpCommand = new AsyncRelayCommand(HelpAsync);
|
||||||
SectorViewCommand = new RelayCommand(SectorView);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileSystemModelNode? SelectedNode
|
public FileSystemModelNode? SelectedNode
|
||||||
@@ -151,23 +147,9 @@ public sealed partial class ImageWindowViewModel : ViewModelBase
|
|||||||
public ICommand BackCommand { get; }
|
public ICommand BackCommand { get; }
|
||||||
public ICommand HelpCommand { get; }
|
public ICommand HelpCommand { get; }
|
||||||
public ICommand ExitCommand { 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Back()
|
void Back()
|
||||||
{
|
{
|
||||||
_parent.Show();
|
|
||||||
_view.Close();
|
_view.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -163,10 +163,9 @@ public sealed partial class MainWindowViewModel : ViewModelBase
|
|||||||
|
|
||||||
var view = new HexViewWindow();
|
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.DataContext = vm;
|
||||||
view.Show();
|
view.Show();
|
||||||
_view.Hide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Exit()
|
void Exit()
|
||||||
@@ -397,11 +396,10 @@ public sealed partial class MainWindowViewModel : ViewModelBase
|
|||||||
|
|
||||||
var imageWindow = new ImageWindow();
|
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.DataContext = imageViewModel;
|
||||||
imageWindow.Show();
|
imageWindow.Show();
|
||||||
_view.Hide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CanOpenSelectedFile() => SelectedFile != null;
|
bool CanOpenSelectedFile() => SelectedFile != null;
|
||||||
|
|||||||
@@ -42,15 +42,6 @@
|
|||||||
Foreground="SlateBlue"
|
Foreground="SlateBlue"
|
||||||
Text="Shows this help" />
|
Text="Shows this help" />
|
||||||
</Grid>
|
</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,*"
|
<Grid ColumnDefinitions="Auto,*"
|
||||||
ColumnSpacing="2">
|
ColumnSpacing="2">
|
||||||
<TextBlock Grid.Column="0"
|
<TextBlock Grid.Column="0"
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
<Window xmlns="https://github.com/avaloniaui"
|
<windowManager:ManagedWindow xmlns="https://github.com/avaloniaui"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:console="https://github.com/jinek/consolonia"
|
xmlns:console="https://github.com/jinek/consolonia"
|
||||||
xmlns:windows="clr-namespace:Aaru.Tui.ViewModels.Windows"
|
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"
|
x:Class="Aaru.Tui.Views.Windows.HexViewWindow"
|
||||||
RequestedThemeVariant="Dark">
|
WindowState="FullScreen"
|
||||||
|
CanResize="False">
|
||||||
<Design.DataContext>
|
<Design.DataContext>
|
||||||
<windows:HexViewWindowViewModel />
|
<windows:HexViewWindowViewModel />
|
||||||
</Design.DataContext>
|
</Design.DataContext>
|
||||||
@@ -98,4 +100,4 @@
|
|||||||
</Grid>
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
</Window>
|
</windowManager:ManagedWindow>
|
||||||
@@ -26,12 +26,12 @@
|
|||||||
// ****************************************************************************/
|
// ****************************************************************************/
|
||||||
|
|
||||||
using Aaru.Tui.ViewModels.Windows;
|
using Aaru.Tui.ViewModels.Windows;
|
||||||
using Avalonia.Controls;
|
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
|
using Iciclecreek.Avalonia.WindowManager;
|
||||||
|
|
||||||
namespace Aaru.Tui.Views.Windows;
|
namespace Aaru.Tui.Views.Windows;
|
||||||
|
|
||||||
public partial class HexViewWindow : Window
|
public partial class HexViewWindow : ManagedWindow
|
||||||
{
|
{
|
||||||
public HexViewWindow()
|
public HexViewWindow()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
<Window xmlns="https://github.com/avaloniaui"
|
<windowManager:ManagedWindow xmlns="https://github.com/avaloniaui"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:windows="clr-namespace:Aaru.Tui.ViewModels.Windows"
|
xmlns:windows="clr-namespace:Aaru.Tui.ViewModels.Windows"
|
||||||
xmlns:brushes="https://github.com/jinek/consolonia"
|
xmlns:brushes="https://github.com/jinek/consolonia"
|
||||||
|
xmlns:windowManager="clr-namespace:Iciclecreek.Avalonia.WindowManager;assembly=Iciclecreek.Avalonia.WindowManager"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
d:DesignWidth="800"
|
d:DesignWidth="800"
|
||||||
d:DesignHeight="450"
|
d:DesignHeight="450"
|
||||||
RequestedThemeVariant="Dark"
|
WindowState="FullScreen"
|
||||||
x:Class="Aaru.Tui.Views.Windows.ImageWindow"
|
CanResize="False"
|
||||||
Title="ImageWindow">
|
x:Class="Aaru.Tui.Views.Windows.ImageWindow">
|
||||||
<Design.DataContext>
|
<Design.DataContext>
|
||||||
<windows:ImageWindowViewModel />
|
<windows:ImageWindowViewModel />
|
||||||
</Design.DataContext>
|
</Design.DataContext>
|
||||||
@@ -21,9 +22,7 @@
|
|||||||
<MenuItem Header="F1 Help"
|
<MenuItem Header="F1 Help"
|
||||||
Command="{Binding HelpCommand, Mode=OneWay}"
|
Command="{Binding HelpCommand, Mode=OneWay}"
|
||||||
HotKey="F1" />
|
HotKey="F1" />
|
||||||
<MenuItem Header="F2 ScVw"
|
<MenuItem Header="F2 " />
|
||||||
Command="{Binding SectorViewCommand, Mode=OneWay}"
|
|
||||||
HotKey="F2" />
|
|
||||||
<MenuItem Header="F10 Exit"
|
<MenuItem Header="F10 Exit"
|
||||||
Command="{Binding ExitCommand, Mode=OneWay}"
|
Command="{Binding ExitCommand, Mode=OneWay}"
|
||||||
HotKey="F10" />
|
HotKey="F10" />
|
||||||
@@ -165,4 +164,4 @@
|
|||||||
</Grid>
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
</Window>
|
</windowManager:ManagedWindow>
|
||||||
@@ -26,12 +26,12 @@
|
|||||||
// ****************************************************************************/
|
// ****************************************************************************/
|
||||||
|
|
||||||
using Aaru.Tui.ViewModels.Windows;
|
using Aaru.Tui.ViewModels.Windows;
|
||||||
using Avalonia.Controls;
|
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
|
using Iciclecreek.Avalonia.WindowManager;
|
||||||
|
|
||||||
namespace Aaru.Tui.Views.Windows;
|
namespace Aaru.Tui.Views.Windows;
|
||||||
|
|
||||||
public partial class ImageWindow : Window
|
public partial class ImageWindow : ManagedWindow
|
||||||
{
|
{
|
||||||
public ImageWindow()
|
public ImageWindow()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user