There is a new Comment editor accessible by pressing ; in the debugger. Allows you to quickly set single line comments.

Add Comment Editor Form, Icon, Menu item, Shortcut Key
Fix Debugger shortcut key display for punctuation keys
Restore cursor on disassembly window after using Label editor
Restore cursor on disassembly window after using Comment editor
Allow label editor to focus the Comment field on spawn instead of the label
This commit is contained in:
Dwedit 2021-04-13 03:20:54 -04:00
parent 0f35fdc97c
commit b200db5d68
12 changed files with 424 additions and 4 deletions

View file

@ -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", "\\");
}
}

View file

@ -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;

View file

@ -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;
}
}
}

View file

@ -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);

View file

@ -0,0 +1,82 @@
namespace Mesen.GUI.Debugger
{
partial class frmEditComment
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if(disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View file

@ -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)
{
}
}
}

View file

@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View file

@ -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,8 +46,15 @@ namespace Mesen.GUI.Debugger
{
base.OnShown(e);
UpdateByteLabel();
if (!focusComment)
{
txtLabel.Focus();
}
else
{
txtComment.Focus();
}
}
private int GetMaxAddress(AddressType type)
{

View file

@ -689,6 +689,12 @@
<Compile Include="Debugger\frmAssembler.Designer.cs">
<DependentUpon>frmAssembler.cs</DependentUpon>
</Compile>
<Compile Include="Debugger\frmEditComment.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Debugger\frmEditComment.Designer.cs">
<DependentUpon>frmEditComment.cs</DependentUpon>
</Compile>
<Compile Include="Debugger\frmExternalEditorConfig.cs">
<SubType>Form</SubType>
</Compile>
@ -1307,6 +1313,7 @@
<Compile Include="RuntimeChecker.cs" />
<Compile Include="SingleInstance.cs" />
<Compile Include="TestRunner.cs" />
<None Include="Resources\EditComment.png" />
<None Include="Resources\MoveDown.png" />
<None Include="Resources\MoveUp.png" />
<None Include="Resources\NudDownArrowDarkTheme.png" />
@ -1437,6 +1444,9 @@
<EmbeddedResource Include="Debugger\Controls\ctrlSourceViewer.resx">
<DependentUpon>ctrlSourceViewer.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Debugger\frmEditComment.resx">
<DependentUpon>frmEditComment.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Debugger\frmExternalEditorConfig.resx">
<DependentUpon>frmExternalEditorConfig.cs</DependentUpon>
</EmbeddedResource>

View file

@ -350,6 +350,16 @@ namespace Mesen.GUI.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap EditComment {
get {
object obj = ResourceManager.GetObject("EditComment", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>

View file

@ -391,6 +391,9 @@
<data name="EditLabel" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\EditLabel.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="EditComment" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\EditComment.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Paste" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Paste.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 B