[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,13 +1,15 @@
using Aaru.CommonTypes.Interfaces;
using Avalonia.Media; using Avalonia.Media;
namespace Aaru.Tui.Models; namespace Aaru.Tui.Models;
public class FileModel public class FileModel
{ {
public string Path { get; set; } public string Path { get; set; }
public string Filename { get; set; } public string Filename { get; set; }
public IBrush ForegroundBrush { get; set; } public IBrush ForegroundBrush { get; set; }
public bool IsDirectory { get; set; } public bool IsDirectory { get; set; }
public FileInfo? FileInfo { get; set; } public FileInfo? FileInfo { get; set; }
public string? Information { 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.Core;
using Aaru.Helpers; using Aaru.Helpers;
using Aaru.Tui.Models; using Aaru.Tui.Models;
using Aaru.Tui.Views.Windows;
using Avalonia; using Avalonia;
using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Media; using Avalonia.Media;
@@ -165,7 +166,7 @@ public sealed partial class MainWindowViewModel : ViewModelBase
if(imageFormat is null) continue; if(imageFormat is null) continue;
var opened = imageFormat.Open(inputFilter); ErrorNumber opened = imageFormat.Open(inputFilter);
if(opened != ErrorNumber.NoError) continue; if(opened != ErrorNumber.NoError) continue;
@@ -214,9 +215,11 @@ public sealed partial class MainWindowViewModel : ViewModelBase
sb.AppendLine($"Comments: {imageFormat.Info.Comments}"); sb.AppendLine($"Comments: {imageFormat.Info.Comments}");
if(imageFormat.Info.MediaSequence != 0 && imageFormat.Info.LastMediaSequence != 0) if(imageFormat.Info.MediaSequence != 0 && imageFormat.Info.LastMediaSequence != 0)
{
sb.AppendLine($"Media is number {imageFormat.Info.MediaSequence}" + sb.AppendLine($"Media is number {imageFormat.Info.MediaSequence}" +
"\n" + "\n" +
$" on a set of {imageFormat.Info.LastMediaSequence} medias"); $" on a set of {imageFormat.Info.LastMediaSequence} medias");
}
if(!string.IsNullOrWhiteSpace(imageFormat.Info.MediaTitle)) if(!string.IsNullOrWhiteSpace(imageFormat.Info.MediaTitle))
sb.AppendLine($"Media title: {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.Information = sb.ToString();
file.ImageFormat = imageFormat;
} }
catch(Exception ex) catch(Exception ex)
{ {
@@ -286,11 +291,19 @@ public sealed partial class MainWindowViewModel : ViewModelBase
void OpenSelectedFile() void OpenSelectedFile()
{ {
if(SelectedFile?.IsDirectory != true) return; if(SelectedFile.IsDirectory)
{
CurrentPath = SelectedFile.Path;
Environment.CurrentDirectory = CurrentPath;
LoadFiles();
}
CurrentPath = SelectedFile.Path; if(SelectedFile.ImageFormat is null) return;
Environment.CurrentDirectory = CurrentPath;
LoadFiles(); var imageWindow = new ImageWindow();
var imageViewModel = new ImageWindowViewModel(imageWindow, SelectedFile.ImageFormat, SelectedFile.Filename);
imageWindow.DataContext = imageViewModel;
imageWindow.Show();
} }
bool CanOpenSelectedFile() => SelectedFile != null; 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> </Design.DataContext>
<DockPanel> <DockPanel>
<Menu DockPanel.Dock="Bottom"> <Menu DockPanel.Dock="Bottom">
<MenuItem Header="ESC " />
<MenuItem Header="F10 Exit" <MenuItem Header="F10 Exit"
Command="{Binding ExitCommand, Mode=OneWay}" Command="{Binding ExitCommand, Mode=OneWay}"
HotKey="F10" /> HotKey="F10" />
@@ -21,143 +22,148 @@
Brush="Blue" /> Brush="Blue" />
</Border.BorderBrush> </Border.BorderBrush>
<Grid RowDefinitions="*,Auto"> <Grid RowDefinitions="*,Auto">
<Grid ColumnDefinitions="*,*" Grid.Row="0"> <Grid ColumnDefinitions="*,*"
<ListBox Grid.Column="0" Grid.Row="0">
ItemsSource="{Binding Files, Mode=OneWay}" <ListBox Grid.Column="0"
BorderThickness="1" ItemsSource="{Binding Files, Mode=OneWay}"
Background="Transparent" BorderThickness="1"
SelectedItem="{Binding SelectedFile, Mode=TwoWay}" Background="Transparent"
KeyDown="ListBox_OnKeyDown"> SelectedItem="{Binding SelectedFile, Mode=TwoWay}"
<ListBox.ItemTemplate> KeyDown="ListBox_OnKeyDown">
<DataTemplate DataType="models:FileModel"> <ListBox.ItemTemplate>
<TextBox Text="{Binding Filename, Mode=OneWay}" <DataTemplate DataType="models:FileModel">
Foreground="{Binding ForegroundBrush, Mode=OneWay}" <TextBox Text="{Binding Filename, Mode=OneWay}"
Background="Transparent" /> Foreground="{Binding ForegroundBrush, Mode=OneWay}"
</DataTemplate> Background="Transparent" />
</ListBox.ItemTemplate> </DataTemplate>
<ListBox.BorderBrush> </ListBox.ItemTemplate>
<console:LineBrush LineStyle="DoubleLine" <ListBox.BorderBrush>
Brush="Blue" /> <console:LineBrush LineStyle="DoubleLine"
</ListBox.BorderBrush> Brush="Blue" />
</ListBox> </ListBox.BorderBrush>
<Border Grid.Column="1" </ListBox>
BorderThickness="1"> <Border Grid.Column="1"
<Border.BorderBrush> BorderThickness="1">
<console:LineBrush LineStyle="DoubleLine" <Border.BorderBrush>
Brush="Blue" /> <console:LineBrush LineStyle="DoubleLine"
</Border.BorderBrush> Brush="Blue" />
<Grid RowDefinitions="Auto,Auto,Auto,*" </Border.BorderBrush>
VerticalAlignment="Top"> <Grid RowDefinitions="Auto,Auto,Auto,*"
<Border Grid.Row="0" VerticalAlignment="Top">
BorderThickness="1"> <Border Grid.Row="0"
<Border.BorderBrush> BorderThickness="1">
<console:LineBrush LineStyle="DoubleLine" <Border.BorderBrush>
Brush="Blue" /> <console:LineBrush LineStyle="DoubleLine"
</Border.BorderBrush> Brush="Blue" />
<StackPanel VerticalAlignment="Top" </Border.BorderBrush>
HorizontalAlignment="Center">
<TextBlock Text="Aaru Data Preservation Suite"
Foreground="Red"
FontWeight="Bold" />
<TextBlock Text="{Binding InformationalVersion, Mode=OneWay}"
Foreground="Green"
FontWeight="Bold" />
<TextBlock Text="{Binding Copyright, Mode=OneWay}"
Foreground="Blue"
FontWeight="Bold" />
</StackPanel>
</Border>
<Border Grid.Row="1"
BorderThickness="1">
<Border.BorderBrush>
<console:LineBrush LineStyle="DoubleLine"
Brush="Blue" />
</Border.BorderBrush>
<Grid ColumnDefinitions="Auto, *">
<TextBlock Grid.Column="0"
Text="Path: "
Foreground="SlateBlue" />
<TextBlock Grid.Column="1"
Text="{Binding CurrentPath, Mode=OneWay}"
Foreground="Green" />
</Grid>
</Border>
<Border Grid.Row="2"
BorderThickness="1"
IsVisible="{Binding IsFileInfoAvailable, Mode=OneWay}">
<Border.BorderBrush>
<console:LineBrush LineStyle="DoubleLine"
Brush="Blue" />
</Border.BorderBrush>
<Grid RowDefinitions="Auto, *, *, *, *, *">
<TextBlock Text="File information"
Grid.Row="0"
HorizontalAlignment="Center"
Foreground="SlateBlue" />
<Grid ColumnDefinitions="Auto, *"
Grid.Row="1"
IsVisible="{Binding SelectedFileIsNotDirectory, Mode=OneWay}">
<TextBlock Grid.Column="0"
Text="Length: " />
<TextBlock Grid.Column="1"
Text="{Binding SelectedFileLength, Mode=OneWay}"
Foreground="Aqua" />
</Grid>
<Grid ColumnDefinitions="Auto, *"
Grid.Row="2">
<TextBlock Grid.Column="0"
Text="Creation time: " />
<TextBlock Grid.Column="1"
Text="{Binding SelectedFileCreationTime, Mode=OneWay}"
Foreground="Aqua" />
</Grid>
<Grid ColumnDefinitions="Auto, *"
Grid.Row="3">
<TextBlock Grid.Column="0"
Text="Last write time: " />
<TextBlock Grid.Column="1"
Text="{Binding SelectedFileLastWriteTime, Mode=OneWay}"
Foreground="Aqua" />
</Grid>
<Grid ColumnDefinitions="Auto, *"
Grid.Row="4">
<TextBlock Grid.Column="0"
Text="Attributes: " />
<TextBlock Grid.Column="1"
Text="{Binding SelectedFileAttributes, Mode=OneWay}"
Foreground="Aqua" />
</Grid>
<Grid ColumnDefinitions="Auto, *"
Grid.Row="5">
<TextBlock Grid.Column="0"
Text="Mode: " />
<TextBlock Grid.Column="1"
Text="{Binding SelectedFileUnixMode, Mode=OneWay}"
Foreground="Aqua" />
</Grid>
</Grid>
</Border>
<Border Grid.Row="3"
IsVisible="{Binding SelectedFileHasInformation, Mode=OneWay}"
BorderThickness="1">
<Border.BorderBrush>
<console:LineBrush LineStyle="DoubleLine"
Brush="Blue" />
</Border.BorderBrush>
<ScrollViewer>
<StackPanel VerticalAlignment="Top" <StackPanel VerticalAlignment="Top"
HorizontalAlignment="Stretch"> HorizontalAlignment="Center">
<TextBlock Text="Image information" <TextBlock Text="Aaru Data Preservation Suite"
Foreground="SlateBlue" Foreground="Red"
FontWeight="Bold" HorizontalAlignment="Center" /> FontWeight="Bold" />
<TextBlock Text="{Binding SelectedFileInformation, Mode=OneWay}" HorizontalAlignment="Left"/> <TextBlock Text="{Binding InformationalVersion, Mode=OneWay}"
Foreground="Green"
FontWeight="Bold" />
<TextBlock Text="{Binding Copyright, Mode=OneWay}"
Foreground="Blue"
FontWeight="Bold" />
</StackPanel> </StackPanel>
</ScrollViewer> </Border>
</Border> <Border Grid.Row="1"
</Grid> BorderThickness="1">
</Border> <Border.BorderBrush>
</Grid> <console:LineBrush LineStyle="DoubleLine"
<TextBlock Grid.Row="1" Text="{Binding Status, Mode=OneWay}" IsVisible="{Binding IsStatusVisible, Mode=OneWay}"/> Brush="Blue" />
</Border.BorderBrush>
<Grid ColumnDefinitions="Auto, *">
<TextBlock Grid.Column="0"
Text="Path: "
Foreground="SlateBlue" />
<TextBlock Grid.Column="1"
Text="{Binding CurrentPath, Mode=OneWay}"
Foreground="Green" />
</Grid>
</Border>
<Border Grid.Row="2"
BorderThickness="1"
IsVisible="{Binding IsFileInfoAvailable, Mode=OneWay}">
<Border.BorderBrush>
<console:LineBrush LineStyle="DoubleLine"
Brush="Blue" />
</Border.BorderBrush>
<Grid RowDefinitions="Auto, *, *, *, *, *">
<TextBlock Text="File information"
Grid.Row="0"
HorizontalAlignment="Center"
Foreground="SlateBlue" />
<Grid ColumnDefinitions="Auto, *"
Grid.Row="1"
IsVisible="{Binding SelectedFileIsNotDirectory, Mode=OneWay}">
<TextBlock Grid.Column="0"
Text="Length: " />
<TextBlock Grid.Column="1"
Text="{Binding SelectedFileLength, Mode=OneWay}"
Foreground="Aqua" />
</Grid>
<Grid ColumnDefinitions="Auto, *"
Grid.Row="2">
<TextBlock Grid.Column="0"
Text="Creation time: " />
<TextBlock Grid.Column="1"
Text="{Binding SelectedFileCreationTime, Mode=OneWay}"
Foreground="Aqua" />
</Grid>
<Grid ColumnDefinitions="Auto, *"
Grid.Row="3">
<TextBlock Grid.Column="0"
Text="Last write time: " />
<TextBlock Grid.Column="1"
Text="{Binding SelectedFileLastWriteTime, Mode=OneWay}"
Foreground="Aqua" />
</Grid>
<Grid ColumnDefinitions="Auto, *"
Grid.Row="4">
<TextBlock Grid.Column="0"
Text="Attributes: " />
<TextBlock Grid.Column="1"
Text="{Binding SelectedFileAttributes, Mode=OneWay}"
Foreground="Aqua" />
</Grid>
<Grid ColumnDefinitions="Auto, *"
Grid.Row="5">
<TextBlock Grid.Column="0"
Text="Mode: " />
<TextBlock Grid.Column="1"
Text="{Binding SelectedFileUnixMode, Mode=OneWay}"
Foreground="Aqua" />
</Grid>
</Grid>
</Border>
<Border Grid.Row="3"
IsVisible="{Binding SelectedFileHasInformation, Mode=OneWay}"
BorderThickness="1">
<Border.BorderBrush>
<console:LineBrush LineStyle="DoubleLine"
Brush="Blue" />
</Border.BorderBrush>
<ScrollViewer>
<StackPanel VerticalAlignment="Top"
HorizontalAlignment="Stretch">
<TextBlock Text="Image information"
Foreground="SlateBlue"
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}" />
</Grid> </Grid>
</Border> </Border>
</DockPanel> </DockPanel>