1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-06-11 17:29:29 +00:00

Add "Go to Last Change" feature

Jumps to the first offset associated with the change at the top of
the Undo stack.  We generally jump to the code/data offset, not the
specific line affected.  It's possible to do better (and we do, for
Notes), but probably not worthwhile.
This commit is contained in:
Andy McFadden 2019-11-01 18:44:22 -07:00
parent 2ddd3b400d
commit b4213de4c0
7 changed files with 95 additions and 6 deletions

View File

@ -1830,6 +1830,20 @@ namespace SourceGen {
}
}
/// <summary>
/// Returns the change at the top of the list, i.e. the one that would be popped off
/// if we hit "undo".
/// </summary>
/// <returns>The change set. The caller must not modify it.</returns>
public ChangeSet GetTopChange() {
Debug.Assert(mUndoList.Count > 0);
Debug.Assert(mUndoTop > 0);
return mUndoList[mUndoTop - 1];
}
/// <summary>
/// Generate undo/redo history, for the debug window.
/// </summary>
public string DebugGetUndoRedoHistory() {
StringBuilder sb = new StringBuilder();
sb.Append("Bracketed change will be overwritten by next action\r\n\r\n");

View File

@ -2570,6 +2570,58 @@ namespace SourceGen {
return new NavStack.Location(offset, lineDelta, isNote);
}
public void GotoLastChange() {
ChangeSet cs = mProject.GetTopChange();
Debug.Assert(cs.Count > 0);
// Get the offset from the first change in the set. Ignore the rest.
UndoableChange uc = cs[0];
int offset;
bool isNote = false;
if (uc.HasOffset) {
offset = uc.Offset;
// If we altered a Note, and didn't remove it, jump to the note instead of
// the nearby code/data.
//
// TODO(someday): we can do similar things for comment edits, e.g. if it's
// SetLongComment we can find the line on which the comment starts and
// pass that as a line delta.
if (uc.Type == UndoableChange.ChangeType.SetNote &&
uc.NewValue != null) {
isNote = true;
}
} else if (uc.Type == UndoableChange.ChangeType.SetProjectProperties) {
// some chance it modified the EQU statements... jump there
offset = 0;
} else if (uc.Type == UndoableChange.ChangeType.SetTypeHint) {
TypedRangeSet newSet = (TypedRangeSet)uc.NewValue;
if (newSet.Count == 0) {
// unexpected
Debug.Assert(false);
return;
}
// Get the offset of the first entry.
IEnumerator<TypedRangeSet.Tuple> iter =
(IEnumerator<TypedRangeSet.Tuple>)newSet.GetEnumerator();
iter.MoveNext();
TypedRangeSet.Tuple firstOffset = iter.Current;
offset = firstOffset.Value;
} else {
Debug.Assert(false);
return;
}
if (isNote) {
GoToLocation(new NavStack.Location(offset, 0, true),
GoToMode.JumpToNote, true);
} else {
GoToLocation(new NavStack.Location(offset, 0, false),
GoToMode.JumpToCodeData, true);
}
}
public bool CanNavigateBackward() {
return mNavStack.HasBackward;
}

View File

@ -18,7 +18,9 @@
school in the late 1980s, I read Don Lancaster's
<i>Enhancing Your Apple II, Vol. 1</i> (available for download
<a href="https://www.tinaja.com/ebksamp1.shtml">here</a>). This
included a very detailed methodology for disassembling 6502 software.
included a very detailed methodology for disassembling 6502 software
(nicely reformatted
<a href="https://www.tinaja.com/ebooks/tearing_rework.pdf">here</a>).
I wanted to give it a try, so I generated a monitor listing of an
operating system (called "RDOS") that SSI used on their games, and
printed it out on my Epson RX-80 -- tractor feed paper was helpful for

View File

@ -372,11 +372,23 @@ with a '+'. If you have a label that is also a valid hexadecimal
address, like "FEED", the label takes precedence. To jump to the address
write "$FEED" instead.</p>
<p>When you jump around, by double-clicking on an opcode or an entry
in one of the side windows, the currently-selected line is added to
a navigation stack. You can use the arrows on the toolbar to navigate
forward or backward, or Navigate &gt; Nav Forward and
Navigate &gt; Nav Backward. (You can use Alt+Left/Right Arrow, or
<p>When you edit something, lines throughout the listing can change. This
is different from a source code editor, where editing a line just changes
that line. To allow you to watch the effects changes have, the undo/redo
commands try to keep the listing in the same position.
If you want to go to the place where the last change (i.e. the change
that will be undone by the next Undo operation) was made,
Navigate &gt; Go to Last Change will jump to the first offset
associated with the most recent change.
If the last change was to the project properties, it will jump to the
first offset in the file.</p>
<p>When you jump around, e.g. by double-clicking on an opcode or an entry
in one of the side windows, the previously-selected line is added to
a navigation stack. You can use Navigate &gt; Nav Forward and
Navigate &gt; Nav Backward to move forward and backward through the
stack. (The curly arrows on the left side of the toolbar may be more
convenient. You can use Alt+Left/Right Arrow, or
Ctrl+- / Ctrl+Shift+-, as keyboard shortcuts.)</p>

View File

@ -206,6 +206,7 @@ namespace SourceGen {
/// <returns>Change record.</returns>
public static UndoableChange CreateTypeHintChange(TypedRangeSet undoSet,
TypedRangeSet newSet) {
Debug.Assert(undoSet != null && newSet != null);
if (newSet.Count == 0) {
Debug.WriteLine("Empty hint change?");
}

View File

@ -124,6 +124,7 @@ limitations under the License.
<KeyGesture>Ctrl+G</KeyGesture>
</RoutedUICommand.InputGestures>
</RoutedUICommand>
<RoutedUICommand x:Key="GotoLastChangeCmd" Text="Go to Last Change"/>
<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"/>
@ -239,6 +240,8 @@ limitations under the License.
CanExecute="CanFormatAddressTable" Executed="FormatAddressTableCmd_Executed"/>
<CommandBinding Command="{StaticResource GotoCmd}"
CanExecute="IsProjectOpen" Executed="GotoCmd_Executed"/>
<CommandBinding Command="{StaticResource GotoLastChangeCmd}"
CanExecute="CanUndo" Executed="GotoLastChangeCmd_Executed"/>
<CommandBinding Command="Help"
Executed="HelpCmd_Executed"/>
<CommandBinding Command="{StaticResource HintAsCodeEntryPointCmd}"
@ -345,6 +348,7 @@ limitations under the License.
<MenuItem Command="{StaticResource NavigateForwardCmd}"/>
<MenuItem Command="{StaticResource NavigateBackwardCmd}"/>
<MenuItem Command="{StaticResource GotoCmd}"/>
<MenuItem Command="{StaticResource GotoLastChangeCmd}"/>
<Separator/>
<MenuItem Command="Find"/>
<MenuItem Command="{StaticResource FindNextCmd}"/>

View File

@ -1211,6 +1211,10 @@ namespace SourceGen.WpfGui {
mMainCtrl.Goto();
}
private void GotoLastChangeCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
mMainCtrl.GotoLastChange();
}
private void HelpCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
mMainCtrl.ShowHelp();
}