Debugger: Added back/forward navigation

This commit is contained in:
Souryo 2016-11-27 12:14:32 -05:00
parent 0715ac60c2
commit 76fa3338a9
7 changed files with 152 additions and 15 deletions

View file

@ -38,6 +38,9 @@
this.mnuGoToLocation = new System.Windows.Forms.ToolStripMenuItem(); this.mnuGoToLocation = new System.Windows.Forms.ToolStripMenuItem();
this.mnuAddToWatch = new System.Windows.Forms.ToolStripMenuItem(); this.mnuAddToWatch = new System.Windows.Forms.ToolStripMenuItem();
this.mnuFindOccurrences = new System.Windows.Forms.ToolStripMenuItem(); this.mnuFindOccurrences = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripSeparator();
this.mnuNavigateBackward = new System.Windows.Forms.ToolStripMenuItem();
this.mnuNavigateForward = new System.Windows.Forms.ToolStripMenuItem();
this.toolTip = new System.Windows.Forms.ToolTip(this.components); this.toolTip = new System.Windows.Forms.ToolTip(this.components);
this.ctrlCodeViewer = new Mesen.GUI.Debugger.ctrlScrollableTextbox(); this.ctrlCodeViewer = new Mesen.GUI.Debugger.ctrlScrollableTextbox();
this.contextMenuMargin = new System.Windows.Forms.ContextMenuStrip(this.components); this.contextMenuMargin = new System.Windows.Forms.ContextMenuStrip(this.components);
@ -74,9 +77,12 @@
this.toolStripMenuItem2, this.toolStripMenuItem2,
this.mnuGoToLocation, this.mnuGoToLocation,
this.mnuAddToWatch, this.mnuAddToWatch,
this.mnuFindOccurrences}); this.mnuFindOccurrences,
this.toolStripMenuItem3,
this.mnuNavigateBackward,
this.mnuNavigateForward});
this.contextMenuCode.Name = "contextMenuWatch"; this.contextMenuCode.Name = "contextMenuWatch";
this.contextMenuCode.Size = new System.Drawing.Size(259, 170); this.contextMenuCode.Size = new System.Drawing.Size(259, 220);
this.contextMenuCode.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenuCode_Opening); this.contextMenuCode.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenuCode_Opening);
// //
// mnuShowNextStatement // mnuShowNextStatement
@ -144,6 +150,29 @@
this.mnuFindOccurrences.Text = "Find Occurrences"; this.mnuFindOccurrences.Text = "Find Occurrences";
this.mnuFindOccurrences.Click += new System.EventHandler(this.mnuFindOccurrences_Click); this.mnuFindOccurrences.Click += new System.EventHandler(this.mnuFindOccurrences_Click);
// //
// toolStripMenuItem3
//
this.toolStripMenuItem3.Name = "toolStripMenuItem3";
this.toolStripMenuItem3.Size = new System.Drawing.Size(255, 6);
//
// mnuNavigateBackward
//
this.mnuNavigateBackward.Image = global::Mesen.GUI.Properties.Resources.PreviousArrow;
this.mnuNavigateBackward.Name = "mnuNavigateBackward";
this.mnuNavigateBackward.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.Left)));
this.mnuNavigateBackward.Size = new System.Drawing.Size(258, 22);
this.mnuNavigateBackward.Text = "Navigate Backward";
this.mnuNavigateBackward.Click += new System.EventHandler(this.mnuNavigateBackward_Click);
//
// mnuNavigateForward
//
this.mnuNavigateForward.Image = global::Mesen.GUI.Properties.Resources.NextArrow;
this.mnuNavigateForward.Name = "mnuNavigateForward";
this.mnuNavigateForward.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.Right)));
this.mnuNavigateForward.Size = new System.Drawing.Size(258, 22);
this.mnuNavigateForward.Text = "Navigate Forward";
this.mnuNavigateForward.Click += new System.EventHandler(this.mnuNavigateForward_Click);
//
// ctrlCodeViewer // ctrlCodeViewer
// //
this.ctrlCodeViewer.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.ctrlCodeViewer.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
@ -345,5 +374,8 @@
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2;
private System.Windows.Forms.PictureBox picCloseOccurrenceList; private System.Windows.Forms.PictureBox picCloseOccurrenceList;
private System.Windows.Forms.Label lblSearchResult; private System.Windows.Forms.Label lblSearchResult;
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem3;
private System.Windows.Forms.ToolStripMenuItem mnuNavigateForward;
private System.Windows.Forms.ToolStripMenuItem mnuNavigateBackward;
} }
} }

View file

@ -77,7 +77,7 @@ namespace Mesen.GUI.Debugger
public void SelectActiveAddress(UInt32 address) public void SelectActiveAddress(UInt32 address)
{ {
this.SetActiveAddress(address); this.SetActiveAddress(address);
this.ctrlCodeViewer.ScrollToLineNumber((int)address); this.ctrlCodeViewer.ScrollToLineNumber((int)address, eHistoryType.OnScroll);
} }
public void SetActiveAddress(UInt32 address) public void SetActiveAddress(UInt32 address)
@ -457,6 +457,16 @@ namespace Mesen.GUI.Debugger
UpdateConfig(); UpdateConfig();
} }
private void mnuNavigateForward_Click(object sender, EventArgs e)
{
this.ctrlCodeViewer.NavigateForward();
}
private void mnuNavigateBackward_Click(object sender, EventArgs e)
{
this.ctrlCodeViewer.NavigateBackward();
}
#endregion #endregion
#endregion #endregion

View file

@ -114,7 +114,7 @@ namespace Mesen.GUI.Debugger.Controls
private void lstFunctions_DoubleClick(object sender, EventArgs e) private void lstFunctions_DoubleClick(object sender, EventArgs e)
{ {
if(lstFunctions.SelectedItems.Count > 0) { if(lstFunctions.SelectedItems.Count > 0) {
Int32 relativeAddress = (Int32)lstFunctions.SelectedItems[0].Tag; Int32 relativeAddress = (Int32)lstFunctions.SelectedItems[0].SubItems[1].Tag;
if(relativeAddress >= 0) { if(relativeAddress >= 0) {
OnFunctionSelected?.Invoke(relativeAddress, e); OnFunctionSelected?.Invoke(relativeAddress, e);

View file

@ -131,9 +131,9 @@ namespace Mesen.GUI.Debugger
this.ctrlTextbox.ScrollToLineIndex(lineIndex); this.ctrlTextbox.ScrollToLineIndex(lineIndex);
} }
public void ScrollToLineNumber(int lineNumber) public void ScrollToLineNumber(int lineNumber, eHistoryType historyType = eHistoryType.Always)
{ {
this.ctrlTextbox.ScrollToLineNumber(lineNumber); this.ctrlTextbox.ScrollToLineNumber(lineNumber, historyType);
} }
public int CurrentLine public int CurrentLine
@ -375,5 +375,15 @@ namespace Mesen.GUI.Debugger
{ {
return this.ctrlTextbox.FindAllOccurrences(text); return this.ctrlTextbox.FindAllOccurrences(text);
} }
public void NavigateForward()
{
this.ctrlTextbox.NavigateForward();
}
public void NavigateBackward()
{
this.ctrlTextbox.NavigateBackward();
}
} }
} }

View file

@ -21,6 +21,13 @@ namespace Mesen.GUI.Debugger
Arrow = 4, Arrow = 4,
} }
public enum eHistoryType
{
Always,
OnScroll,
None
}
public class LineProperties public class LineProperties
{ {
public Color? BgColor; public Color? BgColor;
@ -35,6 +42,8 @@ namespace Mesen.GUI.Debugger
private const float HorizontalScrollFactor = 8; private const float HorizontalScrollFactor = 8;
private TextboxHistory _history = new TextboxHistory();
private string[] _contents = new string[0]; private string[] _contents = new string[0];
private string[] _contentNotes = new string[0]; private string[] _contentNotes = new string[0];
private string[] _compareContents = null; private string[] _compareContents = null;
@ -323,20 +332,31 @@ namespace Mesen.GUI.Debugger
} }
} }
public void ScrollToLineIndex(int lineIndex) public void ScrollToLineIndex(int lineIndex, eHistoryType historyType = eHistoryType.Always)
{ {
if(lineIndex < this.ScrollPosition || lineIndex > this.GetLastVisibleLineIndex()) { if(this.CursorPosition != lineIndex) {
//Line isn't currently visible, scroll it to the middle of the viewport bool scrolled = false;
this.ScrollPosition = lineIndex - this.GetNumberVisibleLines()/2; if(lineIndex < this.ScrollPosition || lineIndex > this.GetLastVisibleLineIndex()) {
//Line isn't currently visible, scroll it to the middle of the viewport
this.ScrollPosition = lineIndex - this.GetNumberVisibleLines()/2;
scrolled = true;
}
if(historyType == eHistoryType.Always || scrolled && historyType == eHistoryType.OnScroll) {
_history.AddHistory(this.CursorPosition);
}
this.CursorPosition = lineIndex;
if(historyType == eHistoryType.Always || scrolled && historyType == eHistoryType.OnScroll) {
_history.AddHistory(this.CursorPosition);
}
} }
this.CursorPosition = lineIndex;
} }
public void ScrollToLineNumber(int lineNumber) public void ScrollToLineNumber(int lineNumber, eHistoryType historyType = eHistoryType.Always)
{ {
int lineIndex = this.GetLineIndex(lineNumber); int lineIndex = this.GetLineIndex(lineNumber);
if(lineIndex >= 0) { if(lineIndex >= 0) {
ScrollToLineIndex(lineIndex); ScrollToLineIndex(lineIndex, historyType);
} }
} }
@ -533,8 +553,25 @@ namespace Mesen.GUI.Debugger
{ {
base.OnMouseDown(e); base.OnMouseDown(e);
this.Focus(); this.Focus();
int clickedLine = this.GetLineAtPosition(e.Y);
this.CursorPosition = this.ScrollPosition + clickedLine; if(e.Button == MouseButtons.XButton1) {
this.NavigateBackward();
} else if(e.Button == MouseButtons.XButton2) {
this.NavigateForward();
} else {
int clickedLine = this.GetLineAtPosition(e.Y);
this.CursorPosition = this.ScrollPosition + clickedLine;
}
}
public void NavigateForward()
{
this.ScrollToLineIndex(_history.GoForward(), eHistoryType.None);
}
public void NavigateBackward()
{
this.ScrollToLineIndex(_history.GoBack(), eHistoryType.None);
} }
private void DrawLine(Graphics g, int currentLine, int marginLeft, int positionY, int lineHeight) private void DrawLine(Graphics g, int currentLine, int marginLeft, int positionY, int lineHeight)

View file

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mesen.GUI.Debugger
{
class TextboxHistory
{
private List<int> _historyList = new List<int>() { 0 };
private int _historyPosition = 0;
private void ClearForwardHistory()
{
_historyList.RemoveRange(_historyPosition + 1, _historyList.Count - _historyPosition - 1);
}
public void AddHistory(int lineIndex)
{
if(_historyList.Count - 1 > _historyPosition) {
ClearForwardHistory();
}
if(_historyList[_historyList.Count-1] != lineIndex) {
_historyList.Add(lineIndex);
_historyPosition++;
}
}
public int GoBack()
{
if(_historyPosition > 0) {
_historyPosition--;
}
return _historyList[_historyPosition];
}
public int GoForward()
{
if(_historyPosition < _historyList.Count - 1) {
_historyPosition++;
}
return _historyList[_historyPosition];
}
}
}

View file

@ -399,6 +399,7 @@
<DependentUpon>frmTraceLogger.cs</DependentUpon> <DependentUpon>frmTraceLogger.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Debugger\LabelManager.cs" /> <Compile Include="Debugger\LabelManager.cs" />
<Compile Include="Debugger\TextboxHistory.cs" />
<Compile Include="Forms\BaseConfigForm.Designer.cs"> <Compile Include="Forms\BaseConfigForm.Designer.cs">
<DependentUpon>BaseConfigForm.cs</DependentUpon> <DependentUpon>BaseConfigForm.cs</DependentUpon>
</Compile> </Compile>