diff --git a/GUI.NET/Config/DebuggerShortcutsConfig.cs b/GUI.NET/Config/DebuggerShortcutsConfig.cs index 6396a117..85358ffb 100644 --- a/GUI.NET/Config/DebuggerShortcutsConfig.cs +++ b/GUI.NET/Config/DebuggerShortcutsConfig.cs @@ -161,6 +161,8 @@ namespace Mesen.GUI.Config public XmlKeys CodeWindow_EditSourceFile = Keys.F4; [ShortcutName("Code Window: Edit Label")] public XmlKeys CodeWindow_EditLabel = Keys.F2; + [ShortcutName("Code Window: Edit Code Comment")] + public XmlKeys CodeWindow_EditCodeComment = Keys.OemSemicolon; [ShortcutName("Code Window: Navigate Back")] public XmlKeys CodeWindow_NavigateBack = Keys.Alt | Keys.Left; [ShortcutName("Code Window: Navigate Forward")] @@ -257,7 +259,29 @@ namespace Mesen.GUI.Config return ""; } else { string keyString = new KeysConverter().ConvertToString(keys); - return keyString.Replace("+None", "").Replace("Oemcomma", ",").Replace("Oemplus", "+").Replace("Oemtilde", "Tilde").Replace("OemMinus", "-").Replace("Cancel", "Break").Replace("Escape", "Esc"); + return keyString.Replace("+None", "") + .Replace("Cancel", "Break") + .Replace("Escape", "Esc") + .Replace("Oem1", ";") + .Replace("OemSemicolon", ";") + .Replace("OemPeriod", ".") + .Replace("Oemcomma", ",") + .Replace("Oemplus", "+") + .Replace("OemMinus", "-") + .Replace("Oem2", "/") + .Replace("OemQuestion", "/") + .Replace("Oem3", "Tilde") + .Replace("Oemtilde", "Tilde") + .Replace("Oem4", "[") + .Replace("OemOpenBrackets", "[") + .Replace("Oem5", "\\") + .Replace("OemPipe", "\\") + .Replace("Oem6", "]") + .Replace("OemCloseBrackets", "]") + .Replace("Oem7", "'") + .Replace("OemQuotes", "'") + .Replace("OemBackslash", "\\") + .Replace("Oem102", "\\"); } } diff --git a/GUI.NET/Debugger/Controls/CodeViewerActions.Designer.cs b/GUI.NET/Debugger/Controls/CodeViewerActions.Designer.cs index f74b78d0..74a772d6 100644 --- a/GUI.NET/Debugger/Controls/CodeViewerActions.Designer.cs +++ b/GUI.NET/Debugger/Controls/CodeViewerActions.Designer.cs @@ -63,6 +63,7 @@ this.mnuHidePrgAddresses = new System.Windows.Forms.ToolStripMenuItem(); this.sepEditLabel = new System.Windows.Forms.ToolStripSeparator(); this.mnuEditLabel = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuEditCodeComment = new System.Windows.Forms.ToolStripMenuItem(); this.mnuEditInMemoryViewer = new System.Windows.Forms.ToolStripMenuItem(); this.mnuToggleBreakpoint = new System.Windows.Forms.ToolStripMenuItem(); this.sepAddToWatch = new System.Windows.Forms.ToolStripSeparator(); @@ -101,6 +102,7 @@ this.sepEditLabel, this.mnuEditLabel, this.mnuEditInMemoryViewer, + this.mnuEditCodeComment, this.mnuToggleBreakpoint, this.sepAddToWatch, this.mnuAddToWatch, @@ -372,6 +374,14 @@ this.mnuEditLabel.Text = "Edit Label"; this.mnuEditLabel.Click += new System.EventHandler(this.mnuEditLabel_Click); // + // mnuEditCodeComment + // + this.mnuEditCodeComment.Image = global::Mesen.GUI.Properties.Resources.EditComment; + this.mnuEditCodeComment.Name = "mnuSetComment"; + this.mnuEditCodeComment.Size = new System.Drawing.Size(253, 22); + this.mnuEditCodeComment.Text = "Edit Code Comment"; + this.mnuEditCodeComment.Click += new System.EventHandler(this.mnuEditCodeComment_Click); + // // mnuEditInMemoryViewer // this.mnuEditInMemoryViewer.Image = global::Mesen.GUI.Properties.Resources.CheatCode; @@ -512,6 +522,7 @@ private System.Windows.Forms.ToolStripMenuItem mnuHidePrgAddresses; private System.Windows.Forms.ToolStripSeparator sepEditLabel; private System.Windows.Forms.ToolStripMenuItem mnuEditLabel; + private System.Windows.Forms.ToolStripMenuItem mnuEditCodeComment; private System.Windows.Forms.ToolStripMenuItem mnuEditInMemoryViewer; private System.Windows.Forms.ToolStripMenuItem mnuToggleBreakpoint; private System.Windows.Forms.ToolStripSeparator sepAddToWatch; diff --git a/GUI.NET/Debugger/Controls/CodeViewerActions.cs b/GUI.NET/Debugger/Controls/CodeViewerActions.cs index 558cabcf..432b106a 100644 --- a/GUI.NET/Debugger/Controls/CodeViewerActions.cs +++ b/GUI.NET/Debugger/Controls/CodeViewerActions.cs @@ -49,6 +49,7 @@ namespace Mesen.GUI.Debugger.Controls Control parent = (Control)Viewer; mnuEditInMemoryViewer.InitShortcut(parent, nameof(DebuggerShortcutsConfig.CodeWindow_EditInMemoryViewer)); mnuEditLabel.InitShortcut(parent, nameof(DebuggerShortcutsConfig.CodeWindow_EditLabel)); + mnuEditCodeComment.InitShortcut(parent, nameof(DebuggerShortcutsConfig.CodeWindow_EditCodeComment)); mnuSetNextStatement.InitShortcut(parent, nameof(DebuggerShortcutsConfig.CodeWindow_SetNextStatement)); mnuShowNextStatement.InitShortcut(parent, nameof(DebuggerShortcutsConfig.GoToProgramCounter)); mnuToggleBreakpoint.InitShortcut(parent, nameof(DebuggerShortcutsConfig.CodeWindow_ToggleBreakpoint)); @@ -263,10 +264,20 @@ namespace Mesen.GUI.Debugger.Controls { if(UpdateContextMenu(_lastLocation)) { if(_lastClickedAddress >= 0) { + //get selected adress of debugger text window + int startAddress, endAddress; + string rangeString; + GetSelectedAddressRange(out startAddress, out endAddress, out rangeString); + AddressTypeInfo info = new AddressTypeInfo(); InteropEmu.DebugGetAbsoluteAddressAndType((UInt32)_lastClickedAddress, info); if(info.Address >= 0) { ctrlLabelList.EditLabel((UInt32)info.Address, info.Type); + //if that is the same as the address we just edited, restore selected line + if (startAddress == info.Address) + { + GoToDestination(new GoToDestination() { AddressInfo = info }); + } } else { ctrlLabelList.EditLabel((UInt32)_lastClickedAddress, AddressType.Register); } @@ -281,6 +292,26 @@ namespace Mesen.GUI.Debugger.Controls } } + private void mnuEditCodeComment_Click(object sender, EventArgs e) + { + int startAddress, endAddress; + string rangeString; + GetSelectedAddressRange(out startAddress, out endAddress, out rangeString); + if (startAddress >= 0) + { + AddressTypeInfo info = new AddressTypeInfo(); + info.Address = startAddress; + info.Type = AddressType.PrgRom; + if (info.Address >= 0) + { + ctrlLabelList.EditComment((UInt32)info.Address, info.Type); + GoToDestination destination = new GoToDestination(); + destination.AddressInfo = info; + GoToDestination(destination); + } + } + } + private void mnuNavigateForward_Click(object sender, EventArgs e) { Viewer.CodeViewer.NavigateForward(); @@ -662,5 +693,6 @@ namespace Mesen.GUI.Debugger.Controls mnuPerfTrackerTextOnly.Checked = mode == PerfTrackerMode.TextOnly; mnuPerfTrackerDisabled.Checked = mode == PerfTrackerMode.Disabled; } + } } diff --git a/GUI.NET/Debugger/Controls/ctrlLabelList.cs b/GUI.NET/Debugger/Controls/ctrlLabelList.cs index b5208e4e..87066f65 100644 --- a/GUI.NET/Debugger/Controls/ctrlLabelList.cs +++ b/GUI.NET/Debugger/Controls/ctrlLabelList.cs @@ -75,6 +75,64 @@ namespace Mesen.GUI.Debugger.Controls } } + public static void EditComment(UInt32 address, AddressType type) + { + string autoName = "C" + address.ToString("X4"); + CodeLabel existingLabel = LabelManager.GetLabel(address, type); + CodeLabel newLabel = new CodeLabel() + { + Address = existingLabel?.Address ?? address, + AddressType = existingLabel?.AddressType ?? type, + Label = existingLabel?.Label, + Comment = existingLabel?.Comment, + Length = existingLabel?.Length ?? 1 + }; + if (existingLabel == null) + { + newLabel.Label = autoName; + } + bool isMultiLine = false; + + if (existingLabel != null && existingLabel.Comment.Contains("\r\n")) + { + isMultiLine = true; + } + + if (isMultiLine) + { + frmEditLabel frm = new frmEditLabel(newLabel, existingLabel, true); + if (frm.ShowDialog() == DialogResult.OK) + { + bool empty = string.IsNullOrWhiteSpace(newLabel.Comment) && newLabel.Label == autoName; + if (existingLabel != null) + { + LabelManager.DeleteLabel(existingLabel, empty); + } + if (!empty) + { + LabelManager.SetLabel(newLabel.Address, newLabel.AddressType, newLabel.Label, newLabel.Comment, true, CodeLabelFlags.None, newLabel.Length); + } + } + } + else + { + frmEditComment frm = new frmEditComment(newLabel, existingLabel); + if (frm.ShowDialog() == DialogResult.OK) + { + bool empty = string.IsNullOrWhiteSpace(newLabel.Comment) && newLabel.Label == autoName; + if (existingLabel != null) + { + LabelManager.DeleteLabel(existingLabel, empty); + } + if (!empty) + { + LabelManager.SetLabel(newLabel.Address, newLabel.AddressType, newLabel.Label, newLabel.Comment, true, CodeLabelFlags.None, newLabel.Length); + } + } + } + } + + public int CompareLabels(ListViewItem x, ListViewItem y) { int result = String.Compare(((ListViewItem)x).SubItems[_sortColumn].Text, ((ListViewItem)y).SubItems[_sortColumn].Text); diff --git a/GUI.NET/Debugger/frmEditComment.Designer.cs b/GUI.NET/Debugger/frmEditComment.Designer.cs new file mode 100644 index 00000000..4bf2c215 --- /dev/null +++ b/GUI.NET/Debugger/frmEditComment.Designer.cs @@ -0,0 +1,82 @@ +namespace Mesen.GUI.Debugger +{ + partial class frmEditComment + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if(disposing && (components != null)) { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.lblComment = new System.Windows.Forms.Label(); + this.txtComment = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // baseConfigPanel + // + this.baseConfigPanel.Location = new System.Drawing.Point(0, 42); + this.baseConfigPanel.Size = new System.Drawing.Size(377, 29); + // + // lblComment + // + this.lblComment.AutoSize = true; + this.lblComment.Location = new System.Drawing.Point(3, 15); + this.lblComment.Name = "lblComment"; + this.lblComment.Size = new System.Drawing.Size(54, 13); + this.lblComment.TabIndex = 4; + this.lblComment.Text = "Comment:"; + // + // txtComment + // + this.txtComment.AcceptsReturn = true; + this.txtComment.Location = new System.Drawing.Point(63, 12); + this.txtComment.Name = "txtComment"; + this.txtComment.ScrollBars = System.Windows.Forms.ScrollBars.Both; + this.txtComment.Size = new System.Drawing.Size(311, 20); + this.txtComment.TabIndex = 5; + // + // frmEditComment + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(377, 71); + this.Controls.Add(this.lblComment); + this.Controls.Add(this.txtComment); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; + this.Name = "frmEditComment"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Edit Comment"; + this.Load += new System.EventHandler(this.frmEditComment_Load); + this.Controls.SetChildIndex(this.baseConfigPanel, 0); + this.Controls.SetChildIndex(this.txtComment, 0); + this.Controls.SetChildIndex(this.lblComment, 0); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label lblComment; + private System.Windows.Forms.TextBox txtComment; + } +} \ No newline at end of file diff --git a/GUI.NET/Debugger/frmEditComment.cs b/GUI.NET/Debugger/frmEditComment.cs new file mode 100644 index 00000000..8d0c99ce --- /dev/null +++ b/GUI.NET/Debugger/frmEditComment.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Windows.Forms; +using Mesen.GUI.Forms; + +namespace Mesen.GUI.Debugger +{ + public partial class frmEditComment : BaseConfigForm + { + private CodeLabel _originalLabel; + + public frmEditComment(CodeLabel label, CodeLabel originalLabel = null) + { + InitializeComponent(); + _originalLabel = originalLabel; + Entity = label; + AddBinding("Comment", txtComment); + } + + protected override void OnShown(EventArgs e) + { + base.OnShown(e); + txtComment.Focus(); + } + + protected override bool ValidateInput() + { + UpdateObject(); + return !txtComment.Text.Contains('\x1'); + } + + protected override void OnFormClosed(FormClosedEventArgs e) + { + base.OnFormClosed(e); + } + + protected override bool ProcessCmdKey(ref Message msg, Keys keyData) + { + if(keyData == (Keys.Control | Keys.Enter)) { + this.DialogResult = DialogResult.OK; + this.Close(); + } + return base.ProcessCmdKey(ref msg, keyData); + } + + private void frmEditComment_Load(object sender, EventArgs e) + { + + } + } +} diff --git a/GUI.NET/Debugger/frmEditComment.resx b/GUI.NET/Debugger/frmEditComment.resx new file mode 100644 index 00000000..8766f298 --- /dev/null +++ b/GUI.NET/Debugger/frmEditComment.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/GUI.NET/Debugger/frmEditLabel.cs b/GUI.NET/Debugger/frmEditLabel.cs index 6cda34fe..615c4c1f 100644 --- a/GUI.NET/Debugger/frmEditLabel.cs +++ b/GUI.NET/Debugger/frmEditLabel.cs @@ -20,9 +20,11 @@ namespace Mesen.GUI.Debugger private int _maxPrgRomAddress = 0; private int _maxWorkRamAddress = 0; private int _maxSaveRamAddress = 0; + private bool focusComment = false; - public frmEditLabel(CodeLabel label, CodeLabel originalLabel = null) + public frmEditLabel(CodeLabel label, CodeLabel originalLabel = null, bool focusComment = false) { + this.focusComment = focusComment; InitializeComponent(); _originalLabel = originalLabel; @@ -44,7 +46,14 @@ namespace Mesen.GUI.Debugger { base.OnShown(e); UpdateByteLabel(); - txtLabel.Focus(); + if (!focusComment) + { + txtLabel.Focus(); + } + else + { + txtComment.Focus(); + } } private int GetMaxAddress(AddressType type) diff --git a/GUI.NET/GUI.NET.csproj b/GUI.NET/GUI.NET.csproj index 42f75ecb..899306fa 100644 --- a/GUI.NET/GUI.NET.csproj +++ b/GUI.NET/GUI.NET.csproj @@ -689,6 +689,12 @@ frmAssembler.cs + + Form + + + frmEditComment.cs + Form @@ -1307,6 +1313,7 @@ + @@ -1437,6 +1444,9 @@ ctrlSourceViewer.cs + + frmEditComment.cs + frmExternalEditorConfig.cs @@ -1920,7 +1930,7 @@ Always Designer - + Always Designer diff --git a/GUI.NET/Properties/Resources.Designer.cs b/GUI.NET/Properties/Resources.Designer.cs index cda9883c..a3351cc3 100644 --- a/GUI.NET/Properties/Resources.Designer.cs +++ b/GUI.NET/Properties/Resources.Designer.cs @@ -350,6 +350,16 @@ namespace Mesen.GUI.Properties { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap EditComment { + get { + object obj = ResourceManager.GetObject("EditComment", 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 fb7a74ae..a91f38f8 100644 --- a/GUI.NET/Properties/Resources.resx +++ b/GUI.NET/Properties/Resources.resx @@ -391,6 +391,9 @@ ..\Resources\EditLabel.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\EditComment.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\Paste.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a diff --git a/GUI.NET/Resources/EditComment.png b/GUI.NET/Resources/EditComment.png new file mode 100644 index 00000000..92c52b55 Binary files /dev/null and b/GUI.NET/Resources/EditComment.png differ