From 28b59e853545579b8b56aa1ca3561f0941102493 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 16 Oct 2025 11:03:35 +0100 Subject: [PATCH] [TUI] Added window for images. --- Aaru.Tui/Models/FileModel.cs | 14 +- .../Windows/ImageWindowViewModel.cs | 39 +++ .../ViewModels/Windows/MainWindowViewModel.cs | 25 +- Aaru.Tui/Views/Windows/ImageWindow.axaml | 39 +++ Aaru.Tui/Views/Windows/ImageWindow.axaml.cs | 11 + Aaru.Tui/Views/Windows/MainWindow.axaml | 276 +++++++++--------- 6 files changed, 257 insertions(+), 147 deletions(-) create mode 100644 Aaru.Tui/ViewModels/Windows/ImageWindowViewModel.cs create mode 100644 Aaru.Tui/Views/Windows/ImageWindow.axaml create mode 100644 Aaru.Tui/Views/Windows/ImageWindow.axaml.cs diff --git a/Aaru.Tui/Models/FileModel.cs b/Aaru.Tui/Models/FileModel.cs index c07b86a90..cea204c2b 100644 --- a/Aaru.Tui/Models/FileModel.cs +++ b/Aaru.Tui/Models/FileModel.cs @@ -1,13 +1,15 @@ +using Aaru.CommonTypes.Interfaces; using Avalonia.Media; namespace Aaru.Tui.Models; public class FileModel { - public string Path { get; set; } - public string Filename { get; set; } - public IBrush ForegroundBrush { get; set; } - public bool IsDirectory { get; set; } - public FileInfo? FileInfo { get; set; } - public string? Information { get; set; } + public string Path { get; set; } + public string Filename { get; set; } + public IBrush ForegroundBrush { get; set; } + public bool IsDirectory { get; set; } + public FileInfo? FileInfo { get; set; } + public string? Information { get; set; } + public IBaseImage? ImageFormat { get; set; } } \ No newline at end of file diff --git a/Aaru.Tui/ViewModels/Windows/ImageWindowViewModel.cs b/Aaru.Tui/ViewModels/Windows/ImageWindowViewModel.cs new file mode 100644 index 000000000..77ebb7eac --- /dev/null +++ b/Aaru.Tui/ViewModels/Windows/ImageWindowViewModel.cs @@ -0,0 +1,39 @@ +using System.Windows.Input; +using Aaru.CommonTypes.Interfaces; +using Avalonia; +using Avalonia.Controls; +using Avalonia.Controls.ApplicationLifetimes; +using CommunityToolkit.Mvvm.Input; + +namespace Aaru.Tui.ViewModels.Windows; + +public sealed partial class ImageWindowViewModel : ViewModelBase +{ + readonly string _filename; + readonly IBaseImage _imageFormat; + readonly Window _view; + + public ImageWindowViewModel(Window view, IBaseImage imageFormat, string filename) + { + _imageFormat = imageFormat; + _filename = filename; + _view = view; + + ExitCommand = new RelayCommand(Exit); + BackCommand = new RelayCommand(Back); + } + + public ICommand BackCommand { get; } + public ICommand ExitCommand { get; } + + void Back() + { + _view.Close(); + } + + void Exit() + { + var lifetime = Application.Current!.ApplicationLifetime as IControlledApplicationLifetime; + lifetime!.Shutdown(); + } +} \ No newline at end of file diff --git a/Aaru.Tui/ViewModels/Windows/MainWindowViewModel.cs b/Aaru.Tui/ViewModels/Windows/MainWindowViewModel.cs index a97531714..9192e159e 100644 --- a/Aaru.Tui/ViewModels/Windows/MainWindowViewModel.cs +++ b/Aaru.Tui/ViewModels/Windows/MainWindowViewModel.cs @@ -8,6 +8,7 @@ using Aaru.CommonTypes.Interfaces; using Aaru.Core; using Aaru.Helpers; using Aaru.Tui.Models; +using Aaru.Tui.Views.Windows; using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Media; @@ -165,7 +166,7 @@ public sealed partial class MainWindowViewModel : ViewModelBase if(imageFormat is null) continue; - var opened = imageFormat.Open(inputFilter); + ErrorNumber opened = imageFormat.Open(inputFilter); if(opened != ErrorNumber.NoError) continue; @@ -214,9 +215,11 @@ public sealed partial class MainWindowViewModel : ViewModelBase sb.AppendLine($"Comments: {imageFormat.Info.Comments}"); if(imageFormat.Info.MediaSequence != 0 && imageFormat.Info.LastMediaSequence != 0) + { sb.AppendLine($"Media is number {imageFormat.Info.MediaSequence}" + - "\n" + + "\n" + $" on a set of {imageFormat.Info.LastMediaSequence} medias"); + } if(!string.IsNullOrWhiteSpace(imageFormat.Info.MediaTitle)) sb.AppendLine($"Media title: {imageFormat.Info.MediaTitle}"); @@ -273,6 +276,8 @@ public sealed partial class MainWindowViewModel : ViewModelBase } file.Information = sb.ToString(); + + file.ImageFormat = imageFormat; } catch(Exception ex) { @@ -286,11 +291,19 @@ public sealed partial class MainWindowViewModel : ViewModelBase void OpenSelectedFile() { - if(SelectedFile?.IsDirectory != true) return; + if(SelectedFile.IsDirectory) + { + CurrentPath = SelectedFile.Path; + Environment.CurrentDirectory = CurrentPath; + LoadFiles(); + } - CurrentPath = SelectedFile.Path; - Environment.CurrentDirectory = CurrentPath; - LoadFiles(); + if(SelectedFile.ImageFormat is null) return; + + var imageWindow = new ImageWindow(); + var imageViewModel = new ImageWindowViewModel(imageWindow, SelectedFile.ImageFormat, SelectedFile.Filename); + imageWindow.DataContext = imageViewModel; + imageWindow.Show(); } bool CanOpenSelectedFile() => SelectedFile != null; diff --git a/Aaru.Tui/Views/Windows/ImageWindow.axaml b/Aaru.Tui/Views/Windows/ImageWindow.axaml new file mode 100644 index 000000000..f21dcee79 --- /dev/null +++ b/Aaru.Tui/Views/Windows/ImageWindow.axaml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Aaru.Tui/Views/Windows/ImageWindow.axaml.cs b/Aaru.Tui/Views/Windows/ImageWindow.axaml.cs new file mode 100644 index 000000000..be705ec2c --- /dev/null +++ b/Aaru.Tui/Views/Windows/ImageWindow.axaml.cs @@ -0,0 +1,11 @@ +using Avalonia.Controls; + +namespace Aaru.Tui.Views.Windows; + +public partial class ImageWindow : Window +{ + public ImageWindow() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/Aaru.Tui/Views/Windows/MainWindow.axaml b/Aaru.Tui/Views/Windows/MainWindow.axaml index bb607ef5f..838b2dd55 100644 --- a/Aaru.Tui/Views/Windows/MainWindow.axaml +++ b/Aaru.Tui/Views/Windows/MainWindow.axaml @@ -11,6 +11,7 @@ + @@ -21,143 +22,148 @@ Brush="Blue" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - + HorizontalAlignment="Center"> + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +