[TUI] Display partition information in image window

This commit is contained in:
2025-10-16 12:36:27 +01:00
parent af362cdbf0
commit 8f7ace0e36
2 changed files with 150 additions and 1 deletions

View File

@@ -8,6 +8,8 @@ using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Humanizer;
using Humanizer.Bytes;
namespace Aaru.Tui.ViewModels.Windows;
@@ -19,10 +21,31 @@ public sealed partial class ImageWindowViewModel : ViewModelBase
[ObservableProperty]
public string _filePath;
[ObservableProperty]
bool _isPartitionInformationVisible;
[ObservableProperty]
bool _isStatusVisible;
[ObservableProperty]
ObservableCollection<FileSystemModelNode> _nodes;
[ObservableProperty]
string _partitionDescription;
[ObservableProperty]
string _partitionLength;
[ObservableProperty]
string _partitionName;
[ObservableProperty]
string _partitionOffset;
[ObservableProperty]
string _partitionScheme;
[ObservableProperty]
string _partitionSequence;
[ObservableProperty]
string _partitionSize;
[ObservableProperty]
string _partitionStart;
[ObservableProperty]
string _partitionType;
FileSystemModelNode? _selectedNode;
[ObservableProperty]
string? _status;
public ImageWindowViewModel(Window parent, Window view, IMediaImage imageFormat, string filePath)
@@ -36,6 +59,46 @@ public sealed partial class ImageWindowViewModel : ViewModelBase
BackCommand = new RelayCommand(Back);
}
public FileSystemModelNode? SelectedNode
{
get => _selectedNode;
set
{
SetProperty(ref _selectedNode, value);
if(_selectedNode is null) return;
if(_selectedNode.Partition is not null)
{
IsPartitionInformationVisible = true;
PartitionSequence = _selectedNode.Partition.Value.Sequence.ToString();
PartitionName = _selectedNode.Partition.Value.Name;
PartitionType = _selectedNode.Partition.Value.Type;
PartitionStart = _selectedNode.Partition.Value.Start.ToString();
PartitionOffset = ByteSize.FromBytes(_selectedNode.Partition.Value.Offset).Humanize();
PartitionLength = $"{_selectedNode.Partition.Value.Length} sectors";
PartitionSize = ByteSize.FromBytes(_selectedNode.Partition.Value.Size).Humanize();
PartitionScheme = _selectedNode.Partition.Value.Scheme;
PartitionDescription = _selectedNode.Partition.Value.Description;
OnPropertyChanged(nameof(PartitionSequence));
OnPropertyChanged(nameof(PartitionName));
OnPropertyChanged(nameof(PartitionType));
OnPropertyChanged(nameof(PartitionStart));
OnPropertyChanged(nameof(PartitionOffset));
OnPropertyChanged(nameof(PartitionLength));
OnPropertyChanged(nameof(PartitionSize));
OnPropertyChanged(nameof(PartitionScheme));
OnPropertyChanged(nameof(PartitionDescription));
}
else
IsPartitionInformationVisible = false;
OnPropertyChanged(nameof(IsPartitionInformationVisible));
}
}
public ICommand BackCommand { get; }
public ICommand ExitCommand { get; }

View File

@@ -36,7 +36,8 @@
Grid.Row="1">
<TreeView Grid.Column="0"
ItemsSource="{Binding Nodes, Mode=OneWay}"
BorderThickness="1">
BorderThickness="1"
SelectedItem="{Binding SelectedNode, Mode=TwoWay}">
<TreeView.BorderBrush>
<brushes:LineBrush LineStyle="DoubleLine"
Brush="Blue" />
@@ -47,6 +48,91 @@
</TreeDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
<Border BorderThickness="1"
Grid.Column="1"
IsVisible="{Binding IsPartitionInformationVisible, Mode=OneWay}">
<Border.BorderBrush>
<brushes:LineBrush LineStyle="DoubleLine"
Brush="Blue" />
</Border.BorderBrush>
<StackPanel HorizontalAlignment="Stretch">
<TextBlock Text="Partition information"
Foreground="SlateBlue"
HorizontalAlignment="Center" />
<Grid ColumnDefinitions="Auto,*">
<TextBlock Grid.Column="0"
Foreground="SlateBlue"
Text="Sequence: " />
<TextBlock Grid.Column="1"
Foreground="LawnGreen"
Text="{Binding PartitionSequence, Mode=OneWay}" />
</Grid>
<Grid ColumnDefinitions="Auto,*">
<TextBlock Grid.Column="0"
Foreground="SlateBlue"
Text="Name: " />
<TextBlock Grid.Column="1"
Foreground="DarkGreen"
Text="{Binding PartitionName, Mode=OneWay}" />
</Grid>
<Grid ColumnDefinitions="Auto,*">
<TextBlock Grid.Column="0"
Foreground="SlateBlue"
Text="Type: " />
<TextBlock Grid.Column="1"
Foreground="Olive"
Text="{Binding PartitionType, Mode=OneWay}" />
</Grid>
<Grid ColumnDefinitions="Auto,*">
<TextBlock Grid.Column="0"
Foreground="SlateBlue"
Text="Starting sector: " />
<TextBlock Grid.Column="1"
Foreground="Violet"
Text="{Binding PartitionStart, Mode=OneWay}" />
</Grid>
<Grid ColumnDefinitions="Auto,*">
<TextBlock Grid.Column="0"
Foreground="SlateBlue"
Text="Offset: " />
<TextBlock Grid.Column="1"
Foreground="Lime"
Text="{Binding PartitionOffset, Mode=OneWay}" />
</Grid>
<Grid ColumnDefinitions="Auto,*">
<TextBlock Grid.Column="0"
Foreground="SlateBlue"
Text="Length: " />
<TextBlock Grid.Column="1"
Foreground="Violet"
Text="{Binding PartitionLength, Mode=OneWay}" />
</Grid>
<Grid ColumnDefinitions="Auto,*">
<TextBlock Grid.Column="0"
Foreground="SlateBlue"
Text="Size: " />
<TextBlock Grid.Column="1"
Foreground="Lime"
Text="{Binding PartitionSize, Mode=OneWay}" />
</Grid>
<Grid ColumnDefinitions="Auto,*">
<TextBlock Grid.Column="0"
Foreground="SlateBlue"
Text="Scheme: " />
<TextBlock Grid.Column="1"
Foreground="Purple"
Text="{Binding PartitionScheme, Mode=OneWay}" />
</Grid>
<Grid ColumnDefinitions="Auto,*">
<TextBlock Grid.Column="0"
Foreground="SlateBlue"
Text="Description: " />
<TextBlock Grid.Column="1"
Foreground="Fuchsia"
Text="{Binding PartitionDescription, Mode=OneWay}" />
</Grid>
</StackPanel>
</Border>
</Grid>
<TextBlock Grid.Row="2"
Text="{Binding Status, Mode=OneWay}"