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

View File

@@ -12,6 +12,19 @@
<MenuItem Header="ESC Back" <MenuItem Header="ESC Back"
HotKey="Escape" HotKey="Escape"
Command="{Binding BackCommand, Mode=OneWay}" /> 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" <MenuItem Header="F10 Exit"
HotKey="F10" HotKey="F10"
Command="{Binding ExitCommand, Mode=OneWay}" /> Command="{Binding ExitCommand, Mode=OneWay}" />
@@ -21,7 +34,7 @@
<console:LineBrush LineStyle="DoubleLine" <console:LineBrush LineStyle="DoubleLine"
Brush="Blue" /> Brush="Blue" />
</Border.BorderBrush> </Border.BorderBrush>
<Grid RowDefinitions="Auto,Auto,*"> <Grid RowDefinitions="Auto,Auto,*,Auto">
<TextBlock Grid.Row="0" <TextBlock Grid.Row="0"
Foreground="Green" Foreground="Green"
Text="{Binding FilePath, Mode=OneWay}" /> Text="{Binding FilePath, Mode=OneWay}" />
@@ -73,6 +86,13 @@
</ItemsControl.ItemTemplate> </ItemsControl.ItemTemplate>
</ItemsControl> </ItemsControl>
</ScrollViewer> </ScrollViewer>
<StackPanel Orientation="Horizontal"
Grid.Row="3">
<TextBlock Foreground="SlateBlue"
Text="Current sector: " />
<TextBlock Foreground="Lime"
Text="{Binding CurrentSector, Mode=OneWay}" />
</StackPanel>
</Grid> </Grid>
</Border> </Border>
</DockPanel> </DockPanel>