From 76fa3338a9454d3264807ef3764c21d38546b17c Mon Sep 17 00:00:00 2001 From: Souryo Date: Sun, 27 Nov 2016 12:14:32 -0500 Subject: [PATCH] Debugger: Added back/forward navigation --- .../Controls/ctrlDebuggerCode.Designer.cs | 36 +++++++++++- GUI.NET/Debugger/Controls/ctrlDebuggerCode.cs | 12 +++- GUI.NET/Debugger/Controls/ctrlFunctionList.cs | 2 +- .../Controls/ctrlScrollableTextbox.cs | 14 ++++- GUI.NET/Debugger/Controls/ctrlTextbox.cs | 55 ++++++++++++++++--- GUI.NET/Debugger/TextboxHistory.cs | 47 ++++++++++++++++ GUI.NET/GUI.NET.csproj | 1 + 7 files changed, 152 insertions(+), 15 deletions(-) create mode 100644 GUI.NET/Debugger/TextboxHistory.cs diff --git a/GUI.NET/Debugger/Controls/ctrlDebuggerCode.Designer.cs b/GUI.NET/Debugger/Controls/ctrlDebuggerCode.Designer.cs index 47aef218..4e8ccece 100644 --- a/GUI.NET/Debugger/Controls/ctrlDebuggerCode.Designer.cs +++ b/GUI.NET/Debugger/Controls/ctrlDebuggerCode.Designer.cs @@ -38,6 +38,9 @@ this.mnuGoToLocation = new System.Windows.Forms.ToolStripMenuItem(); this.mnuAddToWatch = 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.ctrlCodeViewer = new Mesen.GUI.Debugger.ctrlScrollableTextbox(); this.contextMenuMargin = new System.Windows.Forms.ContextMenuStrip(this.components); @@ -74,9 +77,12 @@ this.toolStripMenuItem2, this.mnuGoToLocation, this.mnuAddToWatch, - this.mnuFindOccurrences}); + this.mnuFindOccurrences, + this.toolStripMenuItem3, + this.mnuNavigateBackward, + this.mnuNavigateForward}); 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); // // mnuShowNextStatement @@ -144,6 +150,29 @@ this.mnuFindOccurrences.Text = "Find Occurrences"; 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 // this.ctrlCodeViewer.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; @@ -345,5 +374,8 @@ private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2; private System.Windows.Forms.PictureBox picCloseOccurrenceList; private System.Windows.Forms.Label lblSearchResult; + private System.Windows.Forms.ToolStripSeparator toolStripMenuItem3; + private System.Windows.Forms.ToolStripMenuItem mnuNavigateForward; + private System.Windows.Forms.ToolStripMenuItem mnuNavigateBackward; } } diff --git a/GUI.NET/Debugger/Controls/ctrlDebuggerCode.cs b/GUI.NET/Debugger/Controls/ctrlDebuggerCode.cs index 670f0f4e..78347652 100644 --- a/GUI.NET/Debugger/Controls/ctrlDebuggerCode.cs +++ b/GUI.NET/Debugger/Controls/ctrlDebuggerCode.cs @@ -77,7 +77,7 @@ namespace Mesen.GUI.Debugger public void SelectActiveAddress(UInt32 address) { this.SetActiveAddress(address); - this.ctrlCodeViewer.ScrollToLineNumber((int)address); + this.ctrlCodeViewer.ScrollToLineNumber((int)address, eHistoryType.OnScroll); } public void SetActiveAddress(UInt32 address) @@ -457,6 +457,16 @@ namespace Mesen.GUI.Debugger 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 diff --git a/GUI.NET/Debugger/Controls/ctrlFunctionList.cs b/GUI.NET/Debugger/Controls/ctrlFunctionList.cs index 821c9354..917a83b9 100644 --- a/GUI.NET/Debugger/Controls/ctrlFunctionList.cs +++ b/GUI.NET/Debugger/Controls/ctrlFunctionList.cs @@ -114,7 +114,7 @@ namespace Mesen.GUI.Debugger.Controls private void lstFunctions_DoubleClick(object sender, EventArgs e) { if(lstFunctions.SelectedItems.Count > 0) { - Int32 relativeAddress = (Int32)lstFunctions.SelectedItems[0].Tag; + Int32 relativeAddress = (Int32)lstFunctions.SelectedItems[0].SubItems[1].Tag; if(relativeAddress >= 0) { OnFunctionSelected?.Invoke(relativeAddress, e); diff --git a/GUI.NET/Debugger/Controls/ctrlScrollableTextbox.cs b/GUI.NET/Debugger/Controls/ctrlScrollableTextbox.cs index 3922eb6f..42d28474 100644 --- a/GUI.NET/Debugger/Controls/ctrlScrollableTextbox.cs +++ b/GUI.NET/Debugger/Controls/ctrlScrollableTextbox.cs @@ -131,9 +131,9 @@ namespace Mesen.GUI.Debugger 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 @@ -375,5 +375,15 @@ namespace Mesen.GUI.Debugger { return this.ctrlTextbox.FindAllOccurrences(text); } + + public void NavigateForward() + { + this.ctrlTextbox.NavigateForward(); + } + + public void NavigateBackward() + { + this.ctrlTextbox.NavigateBackward(); + } } } diff --git a/GUI.NET/Debugger/Controls/ctrlTextbox.cs b/GUI.NET/Debugger/Controls/ctrlTextbox.cs index fb78caa7..30e15d48 100644 --- a/GUI.NET/Debugger/Controls/ctrlTextbox.cs +++ b/GUI.NET/Debugger/Controls/ctrlTextbox.cs @@ -21,6 +21,13 @@ namespace Mesen.GUI.Debugger Arrow = 4, } + public enum eHistoryType + { + Always, + OnScroll, + None + } + public class LineProperties { public Color? BgColor; @@ -35,6 +42,8 @@ namespace Mesen.GUI.Debugger private const float HorizontalScrollFactor = 8; + private TextboxHistory _history = new TextboxHistory(); + private string[] _contents = new string[0]; private string[] _contentNotes = new string[0]; 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()) { - //Line isn't currently visible, scroll it to the middle of the viewport - this.ScrollPosition = lineIndex - this.GetNumberVisibleLines()/2; + if(this.CursorPosition != lineIndex) { + bool scrolled = false; + 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); if(lineIndex >= 0) { - ScrollToLineIndex(lineIndex); + ScrollToLineIndex(lineIndex, historyType); } } @@ -533,8 +553,25 @@ namespace Mesen.GUI.Debugger { base.OnMouseDown(e); 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) diff --git a/GUI.NET/Debugger/TextboxHistory.cs b/GUI.NET/Debugger/TextboxHistory.cs new file mode 100644 index 00000000..141f6a02 --- /dev/null +++ b/GUI.NET/Debugger/TextboxHistory.cs @@ -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 _historyList = new List() { 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]; + } + } +} diff --git a/GUI.NET/GUI.NET.csproj b/GUI.NET/GUI.NET.csproj index 477f4f78..b8c9ceb1 100644 --- a/GUI.NET/GUI.NET.csproj +++ b/GUI.NET/GUI.NET.csproj @@ -399,6 +399,7 @@ frmTraceLogger.cs + BaseConfigForm.cs