[TUI] Added window for images.

This commit is contained in:
2025-10-16 11:03:35 +01:00
parent 88f9856301
commit 28b59e8535
6 changed files with 257 additions and 147 deletions

View File

@@ -1,3 +1,4 @@
using Aaru.CommonTypes.Interfaces;
using Avalonia.Media;
namespace Aaru.Tui.Models;
@@ -10,4 +11,5 @@ public class FileModel
public bool IsDirectory { get; set; }
public FileInfo? FileInfo { get; set; }
public string? Information { get; set; }
public IBaseImage? ImageFormat { get; set; }
}

View File

@@ -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();
}
}

View File

@@ -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" +
$" 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,12 +291,20 @@ public sealed partial class MainWindowViewModel : ViewModelBase
void OpenSelectedFile()
{
if(SelectedFile?.IsDirectory != true) return;
if(SelectedFile.IsDirectory)
{
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;
}

View File

@@ -0,0 +1,39 @@
<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">
<Design.DataContext>
<windows:ImageWindowViewModel />
</Design.DataContext>
<DockPanel>
<Menu DockPanel.Dock="Bottom">
<MenuItem Header="ESC Back"
Command="{Binding BackCommand, Mode=OneWay}"
HotKey="Escape" />
<MenuItem Header="F10 Exit"
Command="{Binding ExitCommand, Mode=OneWay}"
HotKey="F10" />
</Menu>
<Border BorderThickness="1">
<Border.BorderBrush>
<brushes:LineBrush LineStyle="DoubleLine"
Brush="Blue" />
</Border.BorderBrush>
<Grid RowDefinitions="*,Auto">
<Grid ColumnDefinitions="*,*"
Grid.Row="0" />
<TextBlock Grid.Row="1"
Text="{Binding Status, Mode=OneWay}"
IsVisible="{Binding IsStatusVisible, Mode=OneWay}" />
</Grid>
</Border>
</DockPanel>
</Window>

View File

@@ -0,0 +1,11 @@
using Avalonia.Controls;
namespace Aaru.Tui.Views.Windows;
public partial class ImageWindow : Window
{
public ImageWindow()
{
InitializeComponent();
}
}

View File

@@ -11,6 +11,7 @@
</Design.DataContext>
<DockPanel>
<Menu DockPanel.Dock="Bottom">
<MenuItem Header="ESC " />
<MenuItem Header="F10 Exit"
Command="{Binding ExitCommand, Mode=OneWay}"
HotKey="F10" />
@@ -21,7 +22,8 @@
Brush="Blue" />
</Border.BorderBrush>
<Grid RowDefinitions="*,Auto">
<Grid ColumnDefinitions="*,*" Grid.Row="0">
<Grid ColumnDefinitions="*,*"
Grid.Row="0">
<ListBox Grid.Column="0"
ItemsSource="{Binding Files, Mode=OneWay}"
BorderThickness="1"
@@ -149,15 +151,19 @@
HorizontalAlignment="Stretch">
<TextBlock Text="Image information"
Foreground="SlateBlue"
FontWeight="Bold" HorizontalAlignment="Center" />
<TextBlock Text="{Binding SelectedFileInformation, Mode=OneWay}" HorizontalAlignment="Left"/>
FontWeight="Bold"
HorizontalAlignment="Center" />
<TextBlock Text="{Binding SelectedFileInformation, Mode=OneWay}"
HorizontalAlignment="Left" />
</StackPanel>
</ScrollViewer>
</Border>
</Grid>
</Border>
</Grid>
<TextBlock Grid.Row="1" Text="{Binding Status, Mode=OneWay}" IsVisible="{Binding IsStatusVisible, Mode=OneWay}"/>
<TextBlock Grid.Row="1"
Text="{Binding Status, Mode=OneWay}"
IsVisible="{Binding IsStatusVisible, Mode=OneWay}" />
</Grid>
</Border>
</DockPanel>