mirror of
https://github.com/fadden/6502bench.git
synced 2024-12-31 21:30:59 +00:00
Implement "go to" feature
This commit is contained in:
parent
779566c236
commit
1685e37c02
@ -1506,6 +1506,14 @@ namespace SourceGenWPF {
|
||||
mMainWin.CodeListView_Focus();
|
||||
}
|
||||
|
||||
public void Goto() {
|
||||
GotoBox dlg = new GotoBox(mMainWin, mProject, mOutputFormatter);
|
||||
if (dlg.ShowDialog() == true) {
|
||||
GoToOffset(dlg.TargetOffset, false, true);
|
||||
mMainWin.CodeListView_Focus();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the view and selection to the specified offset. We want to select stuff
|
||||
/// differently if we're jumping to a note vs. jumping to an instruction.
|
||||
|
@ -99,6 +99,9 @@
|
||||
<Compile Include="WpfGui\FontPicker.xaml.cs">
|
||||
<DependentUpon>FontPicker.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="WpfGui\GotoBox.xaml.cs">
|
||||
<DependentUpon>GotoBox.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="WpfGui\WorkProgress.xaml.cs">
|
||||
<DependentUpon>WorkProgress.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@ -222,6 +225,10 @@
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="WpfGui\GotoBox.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="WpfGui\WorkProgress.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
68
SourceGenWPF/WpfGui/GotoBox.xaml
Normal file
68
SourceGenWPF/WpfGui/GotoBox.xaml
Normal file
@ -0,0 +1,68 @@
|
||||
<!--
|
||||
Copyright 2019 faddenSoft
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<Window x:Class="SourceGenWPF.WpfGui.GotoBox"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:SourceGenWPF.WpfGui"
|
||||
mc:Ignorable="d"
|
||||
Title="Go To..."
|
||||
SizeToContent="WidthAndHeight" ResizeMode="NoResize"
|
||||
ShowInTaskbar="False" WindowStartupLocation="CenterOwner"
|
||||
Loaded="Window_Loaded"
|
||||
PreviewKeyDown="Window_KeyEventHandler">
|
||||
<StackPanel Margin="8">
|
||||
<TextBlock Text="Enter target location as one of:"/>
|
||||
<TextBlock Text=" • Hex file offset (with '+', e.g. +5AB)"/>
|
||||
<TextBlock Text=" • Hex address (e.g. 1000, $1000, 00/1000)"/>
|
||||
<TextBlock Text=" • Label (case-sensitive)"/>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="0,12,0,0">
|
||||
<TextBox Name="targetTextBox" Width="200" TextChanged="TargetTextBox_TextChanged"/>
|
||||
<Button Content="Go" Width="70" Margin="8,0,0,0" IsDefault="True"
|
||||
IsEnabled="{Binding IsValid}" Click="GoButton_Click"/>
|
||||
</StackPanel>
|
||||
|
||||
<Grid Margin="0,12,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Column="0" Grid.Row="0" Text="Offset:"/>
|
||||
<TextBlock Grid.Column="1" Grid.Row="0"
|
||||
Margin="0,2,0,0" FontFamily="{StaticResource GeneralMonoFont}"
|
||||
Text="{Binding OffsetValueStr, FallbackValue=+1234}"/>
|
||||
|
||||
<TextBlock Grid.Column="0" Grid.Row="1" Text="Address:" Margin="0,0,8,0"/>
|
||||
<TextBlock Grid.Column="1" Grid.Row="1"
|
||||
Margin="0,2,0,0" FontFamily="{StaticResource GeneralMonoFont}"
|
||||
Text="{Binding AddressValueStr, FallbackValue=01/2345}"/>
|
||||
|
||||
<TextBlock Grid.Column="0" Grid.Row="2" Text="Label:"/>
|
||||
<TextBlock Grid.Column="1" Grid.Row="2"
|
||||
Margin="0,2,0,0" FontFamily="{StaticResource GeneralMonoFont}"
|
||||
Text="{Binding LabelValueStr, FallbackValue=FUBAR}"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Window>
|
173
SourceGenWPF/WpfGui/GotoBox.xaml.cs
Normal file
173
SourceGenWPF/WpfGui/GotoBox.xaml.cs
Normal file
@ -0,0 +1,173 @@
|
||||
/*
|
||||
* Copyright 2019 faddenSoft
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
||||
using Asm65;
|
||||
|
||||
namespace SourceGenWPF.WpfGui {
|
||||
/// <summary>
|
||||
/// Go to line dialog.
|
||||
/// </summary>
|
||||
public partial class GotoBox : Window, INotifyPropertyChanged {
|
||||
/// <summary>
|
||||
/// On success, this will hold the target offset.
|
||||
/// </summary>
|
||||
public int TargetOffset { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Reference to project.
|
||||
/// </summary>
|
||||
private DisasmProject mProject;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to formatter. This determines how values are displayed.
|
||||
/// </summary>
|
||||
private Formatter mFormatter;
|
||||
|
||||
/// <summary>
|
||||
/// Set to true when input is valid. Controls whether the "Go" button is enabled.
|
||||
/// </summary>
|
||||
public bool IsValid {
|
||||
get { return mIsValid; }
|
||||
set {
|
||||
mIsValid = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
private bool mIsValid;
|
||||
|
||||
public string OffsetValueStr {
|
||||
get { return mOffsetValueStr; }
|
||||
set {
|
||||
mOffsetValueStr = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
private string mOffsetValueStr;
|
||||
|
||||
public string AddressValueStr {
|
||||
get { return mAddressValueStr; }
|
||||
set {
|
||||
mAddressValueStr = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
private string mAddressValueStr;
|
||||
|
||||
public string LabelValueStr {
|
||||
get { return mLabelValueStr; }
|
||||
set {
|
||||
mLabelValueStr = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
private string mLabelValueStr;
|
||||
|
||||
// INotifyPropertyChanged implementation
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
private void OnPropertyChanged([CallerMemberName] string propertyName = "") {
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
|
||||
public GotoBox(Window owner, DisasmProject proj, Formatter formatter) {
|
||||
InitializeComponent();
|
||||
Owner = owner;
|
||||
DataContext = this;
|
||||
|
||||
mProject = proj;
|
||||
mFormatter = formatter;
|
||||
TargetOffset = -1;
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e) {
|
||||
UpdateDisplay();
|
||||
targetTextBox.Focus();
|
||||
}
|
||||
|
||||
// Catch ESC key.
|
||||
private void Window_KeyEventHandler(object sender, KeyEventArgs e) {
|
||||
if (e.Key == Key.Escape) {
|
||||
DialogResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void GoButton_Click(object sender, RoutedEventArgs e) {
|
||||
DialogResult = true;
|
||||
}
|
||||
|
||||
private void TargetTextBox_TextChanged(object sender, TextChangedEventArgs e) {
|
||||
ProcessInput();
|
||||
UpdateDisplay();
|
||||
IsValid = (TargetOffset >= 0);
|
||||
}
|
||||
|
||||
private void ProcessInput() {
|
||||
TargetOffset = -1;
|
||||
|
||||
string input = targetTextBox.Text.Trim();
|
||||
if (string.IsNullOrEmpty(input)) {
|
||||
return;
|
||||
}
|
||||
if (input[0] == '+') {
|
||||
// this can only be an offset; convert as hexadecimal number
|
||||
try {
|
||||
TargetOffset = Convert.ToInt32(input.Substring(1), 16);
|
||||
} catch (Exception) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Try it as a label. If they give the label a hex name (e.g. "A001") they
|
||||
// can prefix it with '$' to disambiguate the address.
|
||||
int labelOffset = mProject.FindLabelOffsetByName(input);
|
||||
if (labelOffset >= 0) {
|
||||
TargetOffset = labelOffset;
|
||||
} else if (Address.ParseAddress(input, 1 << 24, out int addr)) {
|
||||
// could be a valid address; check against address map
|
||||
int offset = mProject.AddrMap.AddressToOffset(0, addr);
|
||||
if (offset >= 0) {
|
||||
TargetOffset = offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateDisplay() {
|
||||
string offsetStr = string.Empty;
|
||||
string addressStr = string.Empty;
|
||||
string labelStr = string.Empty;
|
||||
|
||||
if (TargetOffset >= 0) {
|
||||
offsetStr = mFormatter.FormatOffset24(TargetOffset);
|
||||
int addr = mProject.GetAnattrib(TargetOffset).Address;
|
||||
addressStr = mFormatter.FormatAddress(addr, addr > 0xffff);
|
||||
Symbol sym = mProject.GetAnattrib(TargetOffset).Symbol;
|
||||
if (sym != null) {
|
||||
labelStr = sym.Label;
|
||||
}
|
||||
}
|
||||
|
||||
OffsetValueStr = offsetStr;
|
||||
AddressValueStr = addressStr;
|
||||
LabelValueStr = labelStr;
|
||||
}
|
||||
}
|
||||
}
|
@ -69,6 +69,11 @@ limitations under the License.
|
||||
<KeyGesture>F3</KeyGesture>
|
||||
</RoutedUICommand.InputGestures>
|
||||
</RoutedUICommand>
|
||||
<RoutedUICommand x:Key="GotoCmd" Text="Go To...">
|
||||
<RoutedUICommand.InputGestures>
|
||||
<KeyGesture>Ctrl+G</KeyGesture>
|
||||
</RoutedUICommand.InputGestures>
|
||||
</RoutedUICommand>
|
||||
<RoutedUICommand x:Key="HintAsCodeEntryPointCmd" Text="Hint As Code Entry Point"/>
|
||||
<RoutedUICommand x:Key="HintAsDataStartCmd" Text="Hint As Data Start"/>
|
||||
<RoutedUICommand x:Key="HintAsInlineDataCmd" Text="Hint As Inline Data"/>
|
||||
@ -133,6 +138,8 @@ limitations under the License.
|
||||
CanExecute="IsProjectOpen" Executed="FindCmd_Executed"/>
|
||||
<CommandBinding Command="{StaticResource FindNextCmd}"
|
||||
CanExecute="IsProjectOpen" Executed="FindNextCmd_Executed"/>
|
||||
<CommandBinding Command="{StaticResource GotoCmd}"
|
||||
CanExecute="IsProjectOpen" Executed="GotoCmd_Executed"/>
|
||||
<CommandBinding Command="Help"
|
||||
Executed="HelpCmd_Executed"/>
|
||||
<CommandBinding Command="{StaticResource HintAsCodeEntryPointCmd}"
|
||||
@ -193,9 +200,9 @@ limitations under the License.
|
||||
<MenuItem Command="Copy"/>
|
||||
<Separator/>
|
||||
<MenuItem Command="{StaticResource SelectAllCmd}"/>
|
||||
<MenuItem Command="Find"/> <!-- Ctrl+F -->
|
||||
<MenuItem Header="Find Next"/> <!-- F3 -->
|
||||
<MenuItem Header="Go To..."/> <!-- Ctrl+G -->
|
||||
<MenuItem Command="Find"/>
|
||||
<MenuItem Command="{StaticResource FindNextCmd}"/>
|
||||
<MenuItem Command="{StaticResource GotoCmd}"/>
|
||||
<Separator/>
|
||||
<MenuItem Header="Edit Header Comment..."/>
|
||||
<MenuItem Command="Properties" Header="Project Properties..."/>
|
||||
|
@ -864,6 +864,10 @@ namespace SourceGenWPF.WpfGui {
|
||||
mMainCtrl.FindNext();
|
||||
}
|
||||
|
||||
private void GotoCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
|
||||
mMainCtrl.Goto();
|
||||
}
|
||||
|
||||
private void HelpCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
|
||||
mMainCtrl.ShowHelp();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user