[TUI] Add Toggle Long Mode functionality with F5 shortcut in HexView

This commit is contained in:
2025-10-16 22:16:38 +01:00
parent 3518dbce43
commit 65fd89371c
3 changed files with 44 additions and 2 deletions

View File

@@ -27,6 +27,7 @@
using System.Collections.ObjectModel;
using System.Windows.Input;
using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces;
using Aaru.Tui.ViewModels.Dialogs;
using Aaru.Tui.Views.Dialogs;
@@ -53,6 +54,7 @@ public sealed partial class HexViewWindowViewModel : ViewModelBase
long _fileSize;
[ObservableProperty]
ObservableCollection<HexViewLine> _lines = [];
bool _longMode;
internal HexViewWindowViewModel(Window parent, Window view, IMediaImage imageFormat, string filePath,
ulong currentSector = 0)
@@ -63,6 +65,7 @@ public sealed partial class HexViewWindowViewModel : ViewModelBase
PreviousSectorCommand = new RelayCommand(PreviousSector);
GoToCommand = new AsyncRelayCommand(GoToAsync);
HelpCommand = new AsyncRelayCommand(HelpAsync);
ToggleLongCommand = new RelayCommand(ToggleLong);
_parent = parent;
_view = view;
@@ -78,6 +81,19 @@ public sealed partial class HexViewWindowViewModel : ViewModelBase
public ICommand PreviousSectorCommand { get; }
public ICommand GoToCommand { get; }
public ICommand HelpCommand { get; }
public ICommand ToggleLongCommand { get; }
void ToggleLong()
{
_longMode = !_longMode;
if(_longMode)
FilePath += " (Long Mode)";
else
FilePath = FilePath.Replace(" (Long Mode)", string.Empty);
LoadSector();
}
Task HelpAsync()
{
@@ -150,7 +166,21 @@ public sealed partial class HexViewWindowViewModel : ViewModelBase
{
Lines.Clear();
_imageFormat.ReadSector(CurrentSector, out byte[]? sector);
byte[]? sector;
if(_longMode)
{
ErrorNumber errno = _imageFormat.ReadSectorLong(CurrentSector, out sector);
if(errno != ErrorNumber.NoError)
{
ToggleLong();
return;
}
}
else
_imageFormat.ReadSector(CurrentSector, out sector);
using var stream = new MemoryStream(sector);
var buffer = new byte[BYTES_PER_LINE];

View File

@@ -10,7 +10,7 @@
d:DesignHeight="450"
x:Class="Aaru.Tui.Views.Dialogs.HexViewHelpDialog"
Width="40"
Height="10"
Height="11"
WindowStartupLocation="CenterScreen"
BorderBrush="Blue"
CanResize="False"
@@ -69,6 +69,15 @@
Foreground="SlateBlue"
Text="Go to the specified sector" />
</Grid>
<Grid ColumnDefinitions="Auto,*"
ColumnSpacing="2">
<TextBlock Grid.Column="0"
Foreground="Aqua"
Text="F5 " />
<TextBlock Grid.Column="1"
Foreground="SlateBlue"
Text="Toggle long sector mode" />
</Grid>
<Grid ColumnDefinitions="Auto,*"
ColumnSpacing="2">
<TextBlock Grid.Column="0"

View File

@@ -24,6 +24,9 @@
<MenuItem Header="F4 GoTo"
Command="{Binding GoToCommand, Mode=OneWay}"
HotKey="F4" />
<MenuItem Header="F5 Long"
Command="{Binding ToggleLongCommand, Mode=OneWay}"
HotKey="F5" />
<MenuItem Header="F10 Exit"
HotKey="F10"
Command="{Binding ExitCommand, Mode=OneWay}" />