mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[TUI] Added window for images.
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
39
Aaru.Tui/ViewModels/Windows/ImageWindowViewModel.cs
Normal file
39
Aaru.Tui/ViewModels/Windows/ImageWindowViewModel.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
39
Aaru.Tui/Views/Windows/ImageWindow.axaml
Normal file
39
Aaru.Tui/Views/Windows/ImageWindow.axaml
Normal 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>
|
||||
11
Aaru.Tui/Views/Windows/ImageWindow.axaml.cs
Normal file
11
Aaru.Tui/Views/Windows/ImageWindow.axaml.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace Aaru.Tui.Views.Windows;
|
||||
|
||||
public partial class ImageWindow : Window
|
||||
{
|
||||
public ImageWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -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,143 +22,148 @@
|
||||
Brush="Blue" />
|
||||
</Border.BorderBrush>
|
||||
<Grid RowDefinitions="*,Auto">
|
||||
<Grid ColumnDefinitions="*,*" Grid.Row="0">
|
||||
<ListBox Grid.Column="0"
|
||||
ItemsSource="{Binding Files, Mode=OneWay}"
|
||||
BorderThickness="1"
|
||||
Background="Transparent"
|
||||
SelectedItem="{Binding SelectedFile, Mode=TwoWay}"
|
||||
KeyDown="ListBox_OnKeyDown">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate DataType="models:FileModel">
|
||||
<TextBox Text="{Binding Filename, Mode=OneWay}"
|
||||
Foreground="{Binding ForegroundBrush, Mode=OneWay}"
|
||||
Background="Transparent" />
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
<ListBox.BorderBrush>
|
||||
<console:LineBrush LineStyle="DoubleLine"
|
||||
Brush="Blue" />
|
||||
</ListBox.BorderBrush>
|
||||
</ListBox>
|
||||
<Border Grid.Column="1"
|
||||
BorderThickness="1">
|
||||
<Border.BorderBrush>
|
||||
<console:LineBrush LineStyle="DoubleLine"
|
||||
Brush="Blue" />
|
||||
</Border.BorderBrush>
|
||||
<Grid RowDefinitions="Auto,Auto,Auto,*"
|
||||
VerticalAlignment="Top">
|
||||
<Border Grid.Row="0"
|
||||
BorderThickness="1">
|
||||
<Border.BorderBrush>
|
||||
<console:LineBrush LineStyle="DoubleLine"
|
||||
Brush="Blue" />
|
||||
</Border.BorderBrush>
|
||||
<StackPanel VerticalAlignment="Top"
|
||||
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>
|
||||
<Grid ColumnDefinitions="*,*"
|
||||
Grid.Row="0">
|
||||
<ListBox Grid.Column="0"
|
||||
ItemsSource="{Binding Files, Mode=OneWay}"
|
||||
BorderThickness="1"
|
||||
Background="Transparent"
|
||||
SelectedItem="{Binding SelectedFile, Mode=TwoWay}"
|
||||
KeyDown="ListBox_OnKeyDown">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate DataType="models:FileModel">
|
||||
<TextBox Text="{Binding Filename, Mode=OneWay}"
|
||||
Foreground="{Binding ForegroundBrush, Mode=OneWay}"
|
||||
Background="Transparent" />
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
<ListBox.BorderBrush>
|
||||
<console:LineBrush LineStyle="DoubleLine"
|
||||
Brush="Blue" />
|
||||
</ListBox.BorderBrush>
|
||||
</ListBox>
|
||||
<Border Grid.Column="1"
|
||||
BorderThickness="1">
|
||||
<Border.BorderBrush>
|
||||
<console:LineBrush LineStyle="DoubleLine"
|
||||
Brush="Blue" />
|
||||
</Border.BorderBrush>
|
||||
<Grid RowDefinitions="Auto,Auto,Auto,*"
|
||||
VerticalAlignment="Top">
|
||||
<Border Grid.Row="0"
|
||||
BorderThickness="1">
|
||||
<Border.BorderBrush>
|
||||
<console:LineBrush LineStyle="DoubleLine"
|
||||
Brush="Blue" />
|
||||
</Border.BorderBrush>
|
||||
<StackPanel VerticalAlignment="Top"
|
||||
HorizontalAlignment="Stretch">
|
||||
<TextBlock Text="Image information"
|
||||
Foreground="SlateBlue"
|
||||
FontWeight="Bold" HorizontalAlignment="Center" />
|
||||
<TextBlock Text="{Binding SelectedFileInformation, Mode=OneWay}" HorizontalAlignment="Left"/>
|
||||
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>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
<TextBlock Grid.Row="1" Text="{Binding Status, Mode=OneWay}" IsVisible="{Binding IsStatusVisible, Mode=OneWay}"/>
|
||||
</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"
|
||||
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>
|
||||
</Border>
|
||||
</DockPanel>
|
||||
|
||||
Reference in New Issue
Block a user