[TUI] Add Next Sector command and update hex view for sector navigation

This commit is contained in:
2025-10-16 15:43:16 +01:00
parent 6f29dfa272
commit 35df953491
2 changed files with 44 additions and 11 deletions

View File

@@ -12,11 +12,12 @@ namespace Aaru.Tui.ViewModels.Windows;
public sealed partial class HexViewWindowViewModel : ViewModelBase
{
private const int BYTES_PER_LINE = 16;
readonly ulong _currentSector;
readonly IMediaImage _imageFormat;
readonly Window _parent;
readonly Window _view;
[ObservableProperty]
ulong _currentSector;
[ObservableProperty]
string _filePath;
[ObservableProperty]
long _fileSize;
@@ -26,18 +27,31 @@ public sealed partial class HexViewWindowViewModel : ViewModelBase
internal HexViewWindowViewModel(Window parent, Window view, IMediaImage imageFormat, string filePath,
ulong currentSector = 0)
{
ExitCommand = new RelayCommand(Exit);
BackCommand = new RelayCommand(Back);
ExitCommand = new RelayCommand(Exit);
BackCommand = new RelayCommand(Back);
NextSectorCommand = new RelayCommand(NextSector);
_parent = parent;
_view = view;
_imageFormat = imageFormat;
_currentSector = currentSector;
FilePath = filePath;
LoadSector();
}
public ICommand BackCommand { get; }
public ICommand ExitCommand { get; }
public ICommand NextSectorCommand { get; }
void NextSector()
{
if(CurrentSector >= _imageFormat.Info.Sectors - 1) return;
CurrentSector++;
LoadSector();
}
public ICommand BackCommand { get; }
public ICommand ExitCommand { get; }
void Back()
{
@@ -53,7 +67,9 @@ public sealed partial class HexViewWindowViewModel : ViewModelBase
void LoadSector()
{
_imageFormat.ReadSector(_currentSector, out byte[]? sector);
Lines.Clear();
_imageFormat.ReadSector(CurrentSector, out byte[]? sector);
using var stream = new MemoryStream(sector);
var buffer = new byte[BYTES_PER_LINE];
@@ -78,10 +94,7 @@ public sealed partial class HexViewWindowViewModel : ViewModelBase
}
}
public void LoadComplete()
{
LoadSector();
}
public void LoadComplete() {}
}
public sealed class HexViewLine

View File

@@ -12,6 +12,19 @@
<MenuItem Header="ESC Back"
HotKey="Escape"
Command="{Binding BackCommand, Mode=OneWay}" />
<MenuItem Header="F1 Help" />
<MenuItem Header="F2 Next"
Command="{Binding NextSectorCommand, Mode=OneWay}"
HotKey="F2" />
<MenuItem Header="F3 Prev"
Command="{Binding PreviousSectorCommand, Mode=OneWay}"
HotKey="F3" />
<MenuItem Header="F4 GoTo"
Command="{Binding GoToCommand, Mode=OneWay}"
HotKey="F4" />
<MenuItem Header="F5 Save"
Command="{Binding SaveCommand, Mode=OneWay}"
HotKey="F5" />
<MenuItem Header="F10 Exit"
HotKey="F10"
Command="{Binding ExitCommand, Mode=OneWay}" />
@@ -21,7 +34,7 @@
<console:LineBrush LineStyle="DoubleLine"
Brush="Blue" />
</Border.BorderBrush>
<Grid RowDefinitions="Auto,Auto,*">
<Grid RowDefinitions="Auto,Auto,*,Auto">
<TextBlock Grid.Row="0"
Foreground="Green"
Text="{Binding FilePath, Mode=OneWay}" />
@@ -73,6 +86,13 @@
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<StackPanel Orientation="Horizontal"
Grid.Row="3">
<TextBlock Foreground="SlateBlue"
Text="Current sector: " />
<TextBlock Foreground="Lime"
Text="{Binding CurrentSector, Mode=OneWay}" />
</StackPanel>
</Grid>
</Border>
</DockPanel>