From d58d1f39d127dce8e3120c6a256c894256797e0b Mon Sep 17 00:00:00 2001 From: Sour Date: Tue, 29 Jan 2019 16:09:53 -0500 Subject: [PATCH] Debugger: Add move up/down shortcuts to watch list --- GUI.NET/Config/DebuggerShortcutsConfig.cs | 4 + GUI.NET/Controls/MyListView.cs | 20 ++- .../Debugger/Controls/ctrlWatch.Designer.cs | 47 ++++++- GUI.NET/Debugger/Controls/ctrlWatch.cs | 120 +++++++++++++++--- GUI.NET/Debugger/frmDbgPreferences.cs | 2 + GUI.NET/GUI.NET.csproj | 2 + GUI.NET/Properties/Resources.Designer.cs | 20 +++ GUI.NET/Properties/Resources.resx | 6 + GUI.NET/Resources/MoveDown.png | Bin 0 -> 543 bytes GUI.NET/Resources/MoveUp.png | Bin 0 -> 533 bytes 10 files changed, 197 insertions(+), 24 deletions(-) create mode 100644 GUI.NET/Resources/MoveDown.png create mode 100644 GUI.NET/Resources/MoveUp.png diff --git a/GUI.NET/Config/DebuggerShortcutsConfig.cs b/GUI.NET/Config/DebuggerShortcutsConfig.cs index bc3e3c6e..50726ca8 100644 --- a/GUI.NET/Config/DebuggerShortcutsConfig.cs +++ b/GUI.NET/Config/DebuggerShortcutsConfig.cs @@ -195,6 +195,10 @@ namespace Mesen.GUI.Config [ShortcutName("Watch List: Delete")] public XmlKeys WatchList_Delete = Keys.Delete; + [ShortcutName("Watch List: Move Up")] + public XmlKeys WatchList_MoveUp = Keys.Control | Keys.Up; + [ShortcutName("Watch List: Move Down")] + public XmlKeys WatchList_MoveDown = Keys.Control | Keys.Down; [ShortcutName("Save Rom")] public XmlKeys SaveRom = Keys.Control | Keys.S; diff --git a/GUI.NET/Controls/MyListView.cs b/GUI.NET/Controls/MyListView.cs index 58a6e0bc..c0ebfff3 100644 --- a/GUI.NET/Controls/MyListView.cs +++ b/GUI.NET/Controls/MyListView.cs @@ -44,7 +44,25 @@ namespace Mesen.GUI.Controls base.OnKeyDown(e); } } - + + public class WatchListView : DoubleBufferedListView + { + public delegate void MoveUpDownHandler(Keys keyData, ref bool processed); + public event MoveUpDownHandler OnMoveUpDown; + + protected override bool ProcessCmdKey(ref Message msg, Keys keyData) + { + if(keyData.HasFlag(Keys.Up) || keyData.HasFlag(Keys.Down)) { + bool processed = false; + OnMoveUpDown?.Invoke(keyData, ref processed); + if(processed) { + return true; + } + } + return base.ProcessCmdKey(ref msg, keyData); + } + } + public class DoubleBufferedListView : ListView { public DoubleBufferedListView() diff --git a/GUI.NET/Debugger/Controls/ctrlWatch.Designer.cs b/GUI.NET/Debugger/Controls/ctrlWatch.Designer.cs index 4bc26fb5..4c9803d7 100644 --- a/GUI.NET/Debugger/Controls/ctrlWatch.Designer.cs +++ b/GUI.NET/Debugger/Controls/ctrlWatch.Designer.cs @@ -30,7 +30,7 @@ { this.components = new System.ComponentModel.Container(); System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(""); - this.lstWatch = new Mesen.GUI.Controls.DoubleBufferedListView(); + this.lstWatch = new Mesen.GUI.Controls.WatchListView(); this.colName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.colValue = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.contextMenuWatch = new System.Windows.Forms.ContextMenuStrip(this.components); @@ -38,8 +38,12 @@ this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator(); this.mnuEditInMemoryViewer = new System.Windows.Forms.ToolStripMenuItem(); this.mnuViewInDisassembly = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem4 = new System.Windows.Forms.ToolStripSeparator(); + this.mnuMoveUp = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuMoveDown = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator(); this.mnuHexDisplay = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripSeparator(); this.txtEdit = new System.Windows.Forms.TextBox(); this.contextMenuWatch.SuspendLayout(); this.SuspendLayout(); @@ -62,6 +66,7 @@ this.lstWatch.TabIndex = 6; this.lstWatch.UseCompatibleStateImageBehavior = false; this.lstWatch.View = System.Windows.Forms.View.Details; + this.lstWatch.OnMoveUpDown += new Mesen.GUI.Controls.WatchListView.MoveUpDownHandler(this.lstWatch_OnMoveUpDown); this.lstWatch.SelectedIndexChanged += new System.EventHandler(this.lstWatch_SelectedIndexChanged); this.lstWatch.Click += new System.EventHandler(this.lstWatch_Click); this.lstWatch.DoubleClick += new System.EventHandler(this.lstWatch_DoubleClick); @@ -84,10 +89,14 @@ this.toolStripMenuItem1, this.mnuEditInMemoryViewer, this.mnuViewInDisassembly, + this.toolStripMenuItem4, + this.mnuMoveUp, + this.mnuMoveDown, this.toolStripMenuItem2, - this.mnuHexDisplay}); + this.mnuHexDisplay, + this.toolStripMenuItem3}); this.contextMenuWatch.Name = "contextMenuWatch"; - this.contextMenuWatch.Size = new System.Drawing.Size(194, 104); + this.contextMenuWatch.Size = new System.Drawing.Size(194, 160); this.contextMenuWatch.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenuWatch_Opening); // // mnuRemoveWatch @@ -119,6 +128,27 @@ this.mnuViewInDisassembly.Text = "View in disassembly"; this.mnuViewInDisassembly.Click += new System.EventHandler(this.mnuViewInDisassembly_Click); // + // toolStripMenuItem4 + // + this.toolStripMenuItem4.Name = "toolStripMenuItem4"; + this.toolStripMenuItem4.Size = new System.Drawing.Size(190, 6); + // + // mnuMoveUp + // + this.mnuMoveUp.Image = global::Mesen.GUI.Properties.Resources.MoveUp; + this.mnuMoveUp.Name = "mnuMoveUp"; + this.mnuMoveUp.Size = new System.Drawing.Size(193, 22); + this.mnuMoveUp.Text = "Move up"; + this.mnuMoveUp.Click += new System.EventHandler(this.mnuMoveUp_Click); + // + // mnuMoveDown + // + this.mnuMoveDown.Image = global::Mesen.GUI.Properties.Resources.MoveDown; + this.mnuMoveDown.Name = "mnuMoveDown"; + this.mnuMoveDown.Size = new System.Drawing.Size(193, 22); + this.mnuMoveDown.Text = "Move down"; + this.mnuMoveDown.Click += new System.EventHandler(this.mnuMoveDown_Click); + // // toolStripMenuItem2 // this.toolStripMenuItem2.Name = "toolStripMenuItem2"; @@ -134,6 +164,11 @@ this.mnuHexDisplay.Text = "Hexadecimal Display"; this.mnuHexDisplay.Click += new System.EventHandler(this.mnuHexDisplay_Click); // + // toolStripMenuItem3 + // + this.toolStripMenuItem3.Name = "toolStripMenuItem3"; + this.toolStripMenuItem3.Size = new System.Drawing.Size(190, 6); + // // txtEdit // this.txtEdit.AcceptsReturn = true; @@ -160,7 +195,7 @@ #endregion - private Mesen.GUI.Controls.DoubleBufferedListView lstWatch; + private Mesen.GUI.Controls.WatchListView lstWatch; private System.Windows.Forms.ColumnHeader colName; private System.Windows.Forms.ColumnHeader colValue; private System.Windows.Forms.ContextMenuStrip contextMenuWatch; @@ -171,5 +206,9 @@ private System.Windows.Forms.ToolStripMenuItem mnuViewInDisassembly; private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2; private System.Windows.Forms.TextBox txtEdit; + private System.Windows.Forms.ToolStripSeparator toolStripMenuItem4; + private System.Windows.Forms.ToolStripMenuItem mnuMoveUp; + private System.Windows.Forms.ToolStripMenuItem mnuMoveDown; + private System.Windows.Forms.ToolStripSeparator toolStripMenuItem3; } } diff --git a/GUI.NET/Debugger/Controls/ctrlWatch.cs b/GUI.NET/Debugger/Controls/ctrlWatch.cs index 9e12f596..99c8d95a 100644 --- a/GUI.NET/Debugger/Controls/ctrlWatch.cs +++ b/GUI.NET/Debugger/Controls/ctrlWatch.cs @@ -43,6 +43,8 @@ namespace Mesen.GUI.Debugger mnuRemoveWatch.InitShortcut(this, nameof(DebuggerShortcutsConfig.WatchList_Delete)); mnuEditInMemoryViewer.InitShortcut(this, nameof(DebuggerShortcutsConfig.CodeWindow_EditInMemoryViewer)); mnuViewInDisassembly.InitShortcut(this, nameof(DebuggerShortcutsConfig.MemoryViewer_ViewInDisassembly)); + mnuMoveUp.InitShortcut(this, nameof(DebuggerShortcutsConfig.WatchList_MoveUp)); + mnuMoveDown.InitShortcut(this, nameof(DebuggerShortcutsConfig.WatchList_MoveDown)); } } @@ -51,22 +53,22 @@ namespace Mesen.GUI.Debugger if(lstWatch.SelectedItems.Count > 0) { //Used to prevent a Mono issue where pressing a key will change the selected item before we get a chance to edit it _keyDownItem = lstWatch.SelectedItems[0]; + + if((_isEditing && keyData == Keys.Escape) || keyData == Keys.Enter) { + if(keyData == Keys.Enter) { + if(_isEditing) { + ApplyEdit(); + } else { + StartEdit(lstWatch.SelectedItems[0].Text); + } + } else if(keyData == Keys.Escape) { + CancelEdit(); + } + return true; + } } else { _keyDownItem = null; } - - if((_isEditing && keyData == Keys.Escape) || keyData == Keys.Enter) { - if(keyData == Keys.Enter) { - if(_isEditing) { - ApplyEdit(); - } else { - StartEdit(lstWatch.SelectedItems[0].Text); - } - } else if(keyData == Keys.Escape) { - CancelEdit(); - } - return true; - } UpdateActions(); return base.ProcessCmdKey(ref msg, keyData); @@ -90,7 +92,7 @@ namespace Mesen.GUI.Debugger { List watchContent = WatchManager.GetWatchContent(mnuHexDisplay.Checked); - int currentSelection = lstWatch.SelectedIndices.Count > 0 ? lstWatch.SelectedIndices[0] : -1; + int currentSelection = lstWatch.FocusedItem?.Index ?? -1; bool updating = false; if(watchContent.Count != lstWatch.Items.Count - 1) { @@ -143,8 +145,7 @@ namespace Mesen.GUI.Debugger } if(currentSelection >= 0 && lstWatch.Items.Count > currentSelection) { - lstWatch.FocusedItem = lstWatch.Items[currentSelection]; - lstWatch.Items[currentSelection].Selected = true; + SetSelectedItem(currentSelection); } } @@ -165,6 +166,8 @@ namespace Mesen.GUI.Debugger { mnuEditInMemoryViewer.Enabled = false; mnuViewInDisassembly.Enabled = false; + mnuMoveUp.Enabled = false; + mnuMoveDown.Enabled = false; if(lstWatch.SelectedItems.Count == 1) { Match match = _watchAddressOrLabel.Match(lstWatch.SelectedItems[0].Text); @@ -187,6 +190,9 @@ namespace Mesen.GUI.Debugger } } } + + mnuMoveUp.Enabled = lstWatch.SelectedIndices[0] > 0 && lstWatch.SelectedIndices[0] < lstWatch.Items.Count - 1; + mnuMoveDown.Enabled = lstWatch.SelectedIndices[0] < lstWatch.Items.Count - 2; } } @@ -267,14 +273,18 @@ namespace Mesen.GUI.Debugger private void ApplyEdit() { - lstWatch.SelectedItems[0].Text = txtEdit.Text; - WatchManager.UpdateWatch(lstWatch.SelectedIndices[0], txtEdit.Text); + if(lstWatch.SelectedItems.Count > 0) { + lstWatch.SelectedItems[0].Text = txtEdit.Text; + WatchManager.UpdateWatch(lstWatch.SelectedIndices[0], txtEdit.Text); + } lstWatch.Focus(); } private void CancelEdit() { - txtEdit.Text = lstWatch.SelectedItems[0].Text; + if(lstWatch.SelectedItems.Count > 0) { + txtEdit.Text = lstWatch.SelectedItems[0].Text; + } lstWatch.Focus(); } @@ -294,5 +304,77 @@ namespace Mesen.GUI.Debugger lstWatch.Focus(); ApplyEdit(); } + + private void mnuMoveUp_Click(object sender, EventArgs e) + { + MoveUp(false); + } + + private void mnuMoveDown_Click(object sender, EventArgs e) + { + MoveDown(); + } + + private void SetSelectedItem(int index) + { + if(index < lstWatch.Items.Count) { + lstWatch.FocusedItem = lstWatch.Items[index]; + foreach(ListViewItem item in lstWatch.Items) { + item.Selected = lstWatch.FocusedItem == item; + } + } + } + + private void MoveUp(bool fromUpDownArrow) + { + if(lstWatch.SelectedIndices.Count == 0) { + return; + } + + int index = lstWatch.SelectedIndices[0]; + if(Program.IsMono && fromUpDownArrow) { + //Mono appears to move the selection up before processing this + index++; + } + + if(index > 0 && index < lstWatch.Items.Count - 1) { + string currentEntry = lstWatch.Items[index].SubItems[0].Text; + string entryAbove = lstWatch.Items[index - 1].SubItems[0].Text; + SetSelectedItem(index - 1); + WatchManager.UpdateWatch(index - 1, currentEntry); + WatchManager.UpdateWatch(index, entryAbove); + } else { + SetSelectedItem(index); + } + } + + private void MoveDown() + { + if(lstWatch.SelectedIndices.Count == 0) { + return; + } + + int index = lstWatch.SelectedIndices[0]; + if(index < lstWatch.Items.Count - 2) { + string currentEntry = lstWatch.Items[index].SubItems[0].Text; + string entryBelow = lstWatch.Items[index + 1].SubItems[0].Text; + SetSelectedItem(index + 1); + WatchManager.UpdateWatch(index + 1, currentEntry); + WatchManager.UpdateWatch(index, entryBelow); + } else { + SetSelectedItem(index); + } + } + + private void lstWatch_OnMoveUpDown(Keys keyData, ref bool processed) + { + if(keyData == ConfigManager.Config.DebugInfo.Shortcuts.WatchList_MoveUp) { + MoveUp(true); + processed = true; + } else if(keyData == ConfigManager.Config.DebugInfo.Shortcuts.WatchList_MoveDown) { + MoveDown(); + processed = true; + } + } } } diff --git a/GUI.NET/Debugger/frmDbgPreferences.cs b/GUI.NET/Debugger/frmDbgPreferences.cs index a7ecd0bb..39c6555e 100644 --- a/GUI.NET/Debugger/frmDbgPreferences.cs +++ b/GUI.NET/Debugger/frmDbgPreferences.cs @@ -121,6 +121,8 @@ namespace Mesen.GUI.Debugger GetMember(nameof(DebuggerShortcutsConfig.BreakpointList_GoToLocation)), GetMember(nameof(DebuggerShortcutsConfig.BreakpointList_Delete)), GetMember(nameof(DebuggerShortcutsConfig.WatchList_Delete)), + GetMember(nameof(DebuggerShortcutsConfig.WatchList_MoveUp)), + GetMember(nameof(DebuggerShortcutsConfig.WatchList_MoveDown)), GetMember(nameof(DebuggerShortcutsConfig.SaveRom)), GetMember(nameof(DebuggerShortcutsConfig.SaveRomAs)), GetMember(nameof(DebuggerShortcutsConfig.SaveEditAsIps)), diff --git a/GUI.NET/GUI.NET.csproj b/GUI.NET/GUI.NET.csproj index ba24f96d..8b8387cf 100644 --- a/GUI.NET/GUI.NET.csproj +++ b/GUI.NET/GUI.NET.csproj @@ -1262,6 +1262,8 @@ + + diff --git a/GUI.NET/Properties/Resources.Designer.cs b/GUI.NET/Properties/Resources.Designer.cs index 85fe01ca..97483bf3 100644 --- a/GUI.NET/Properties/Resources.Designer.cs +++ b/GUI.NET/Properties/Resources.Designer.cs @@ -580,6 +580,26 @@ namespace Mesen.GUI.Properties { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap MoveDown { + get { + object obj = ResourceManager.GetObject("MoveDown", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap MoveUp { + get { + object obj = ResourceManager.GetObject("MoveUp", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/GUI.NET/Properties/Resources.resx b/GUI.NET/Properties/Resources.resx index 2e69fe1f..feeae36b 100644 --- a/GUI.NET/Properties/Resources.resx +++ b/GUI.NET/Properties/Resources.resx @@ -454,4 +454,10 @@ ..\Resources\NudUpArrowDarkTheme.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\MoveDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\MoveUp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/GUI.NET/Resources/MoveDown.png b/GUI.NET/Resources/MoveDown.png new file mode 100644 index 0000000000000000000000000000000000000000..39730ac7e558f676304dbb9d80c063f101ef4594 GIT binary patch literal 543 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucLCF%=h?3y^w370~qEv>0#LT=By}Z;C1rt33 zJwwYY*ERtaG4^}9IEGmGC;#~W-`-VXwSp!b`-q5(dmle~d`)Lp-;ddIrhPGH?U)=a zT(7oNrJ*pX=+F6zRMe}69@ z_UHTi`~Rn26}^A>uygU_M~_$@vNdd&I(2GEgv*H|H;dE%u}FS;b(UM?&+qT+|4Wpy%rxPQfs5AIf0R#BfmebSL&Yp~?ui2=H4+s2QE^Y_>O|Mvg$bpQYMwf}zne-6|t z9Q`ho*u~wXZwA5Ig&+N5)~3ylgx6840=K*hyZcL cpZSao>7mOXZJD*C2pE41p00i_>zopr07)tLX#fBK literal 0 HcmV?d00001 diff --git a/GUI.NET/Resources/MoveUp.png b/GUI.NET/Resources/MoveUp.png new file mode 100644 index 0000000000000000000000000000000000000000..75f5913cbafdf4d0bac80ca6c533e296db785c0a GIT binary patch literal 533 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucLCF%=h?3y^w370~qEv>0#LT=By}Z;C1rt33 zJwwYY*ERtaF}8ZTIEGmGC;#~W-`-VXwSp!P^Dr}N3v5oD+?=?kNr8u@X49rkYDPvz zX%1%gW~K@~u>u*J7c5v%mQwQL@QWEAt_KALwK*7;t;sTEk&uvRjL_3iDY!b%c6Z%; zo6<-A5fvZe7R+Gs;B&TZV_;^I;?9{mSQ_$t z)sSIh(+dp^y?x`yjPv*R)&Ktg^Yrrn^X=+^YOkOF->LcWeoxOA+nF^ViS+;_K)A{r~Cf=l|^d@_)L!cgTe~DWM4fgwXBw literal 0 HcmV?d00001