mirror of
https://github.com/haven1433/HexManiacAdvance.git
synced 2026-06-01 04:53:29 -05:00
add right-click menu for controlling base-16/base-10 for length box
This commit is contained in:
parent
b704fb2f50
commit
8545fa95cb
|
|
@ -334,6 +334,13 @@ namespace HavenSoft.HexManiac.Core.ViewModels {
|
|||
get => selectedLength;
|
||||
set => Set(ref selectedLength, value, SelectedLengthChanged);
|
||||
}
|
||||
|
||||
private bool base10SelectionLength;
|
||||
public bool Base10SelectionLength {
|
||||
get => base10SelectionLength;
|
||||
set => Set(ref base10SelectionLength, value, arg => UpdateSelectedAddress());
|
||||
}
|
||||
|
||||
public string SelectedElementName => selectedElementName;
|
||||
|
||||
private void UpdateSelectedAddress() {
|
||||
|
|
@ -346,7 +353,8 @@ namespace HavenSoft.HexManiac.Core.ViewModels {
|
|||
Set(ref selectedElementName, elementName ?? string.Empty, nameof(SelectedElementName));
|
||||
|
||||
int length = Math.Abs(dataIndex1 - dataIndex2) + 1;
|
||||
Set(ref selectedLength, length.ToString("X1"), nameof(SelectedLength));
|
||||
var lengthText = base10SelectionLength ? length.ToString() : length.ToString("X1");
|
||||
Set(ref selectedLength, lengthText, nameof(SelectedLength));
|
||||
}
|
||||
|
||||
private void SelectedAddressChanged(string old) {
|
||||
|
|
@ -355,7 +363,12 @@ namespace HavenSoft.HexManiac.Core.ViewModels {
|
|||
}
|
||||
|
||||
private void SelectedLengthChanged(string old) {
|
||||
if (!selectedLength.TryParseHex(out int length)) return;
|
||||
int length;
|
||||
if (base10SelectionLength) {
|
||||
if (!int.TryParse(selectedLength, out length)) return;
|
||||
} else {
|
||||
if (!selectedLength.TryParseHex(out length)) return;
|
||||
}
|
||||
var left = Math.Min(ConvertViewPointToAddress(SelectionStart), ConvertViewPointToAddress(SelectionEnd));
|
||||
SelectionStart = ConvertAddressToViewPoint(left);
|
||||
SelectionEnd = ConvertAddressToViewPoint(left + length - 1);
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ namespace HavenSoft.HexManiac.WPF.Controls {
|
|||
public partial class AngleTextBox {
|
||||
|
||||
private static readonly Thickness TextContentThickness = new(0, 1, 0, 1);
|
||||
private ContextMenu menu;
|
||||
|
||||
private bool keepTextBoxForContextMenu;
|
||||
public TextBox GetTextBox() {
|
||||
|
|
@ -146,6 +147,12 @@ namespace HavenSoft.HexManiac.WPF.Controls {
|
|||
BorderThickness = TextContentThickness,
|
||||
VerticalAlignment = VerticalAlignment.Stretch,
|
||||
};
|
||||
if (ContextMenu != null) {
|
||||
menu = ContextMenu;
|
||||
ContextMenu = null;
|
||||
}
|
||||
if (menu != null) textBox.ContextMenu = menu;
|
||||
|
||||
if (DataContext is FieldArrayElementViewModel) textBox.InputBindings.Add(
|
||||
new KeyBinding {
|
||||
Key = Key.Enter,
|
||||
|
|
|
|||
|
|
@ -44,7 +44,14 @@
|
|||
<hsg3hv:AngleBorder DockPanel.Dock="Left" Direction="Left" Margin="5,0,0,0">
|
||||
<TextBlock Text="Length:" />
|
||||
</hsg3hv:AngleBorder>
|
||||
<hsg3hv:AngleTextBox DockPanel.Dock="Left" Width="40" Direction="Out" TextBinding="{Binding SelectedLength, UpdateSourceTrigger=PropertyChanged}" Margin="0"/>
|
||||
<hsg3hv:AngleTextBox DockPanel.Dock="Left" Width="40" Direction="Out" Margin="0"
|
||||
TextBinding="{Binding SelectedLength, UpdateSourceTrigger=PropertyChanged}">
|
||||
<hsg3hv:AngleTextBox.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem IsCheckable="True" IsChecked="{Binding Base10SelectionLength}" Header="Display Length in Base 10"/>
|
||||
</ContextMenu>
|
||||
</hsg3hv:AngleTextBox.ContextMenu>
|
||||
</hsg3hv:AngleTextBox>
|
||||
<TextBlock DockPanel.Dock="Left" Text="{Binding SelectedElementName}" Margin="5,0,0,0"/>
|
||||
<Grid HorizontalAlignment="Right" DockPanel.Dock="Right">
|
||||
<TextBlock Margin="5,0,0,0" Text="{Binding SelectedBytes}" MouseRightButtonUp="BytesShowMenu"/>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user