Ram Watch - support copy and paste (generates and receives the same text as would be in a .wch file)
This commit is contained in:
parent
e195004433
commit
bb2cd1b476
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Common.NumberExtensions;
|
||||
|
@ -16,6 +17,60 @@ namespace BizHawk.Client.Common
|
|||
public enum DisplayType { Separator, Signed, Unsigned, Hex, Binary, FixedPoint_12_4, FixedPoint_20_12, FixedPoint_16_16, Float }
|
||||
public enum PreviousType { Original = 0, LastSearch = 1, LastFrame = 2, LastChange = 3 }
|
||||
|
||||
public static Watch FromString(string line, IMemoryDomains domains)
|
||||
{
|
||||
try
|
||||
{
|
||||
var parts = line.Split(new[] { '\t' }, 6);
|
||||
|
||||
if (parts.Length < 6)
|
||||
{
|
||||
if (parts.Length >= 3 && parts[2] == "_")
|
||||
{
|
||||
return SeparatorWatch.Instance;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
var address = long.Parse(parts[0], NumberStyles.HexNumber);
|
||||
var size = Watch.SizeFromChar(parts[1][0]);
|
||||
var type = Watch.DisplayTypeFromChar(parts[2][0]);
|
||||
var bigEndian = parts[3] == "0" ? false : true;
|
||||
var domain = domains[parts[4]];
|
||||
var notes = parts[5];
|
||||
|
||||
return Watch.GenerateWatch(
|
||||
domain,
|
||||
address,
|
||||
size,
|
||||
type,
|
||||
notes,
|
||||
bigEndian
|
||||
);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static string ToString(Watch watch, int numdigits)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
sb
|
||||
.Append((watch.Address ?? 0).ToHexString(numdigits)).Append('\t')
|
||||
.Append(watch.SizeAsChar).Append('\t')
|
||||
.Append(watch.TypeAsChar).Append('\t')
|
||||
.Append(watch.BigEndian ? '1' : '0').Append('\t')
|
||||
.Append(watch.DomainName).Append('\t')
|
||||
.Append(watch.Notes)
|
||||
.AppendLine();
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static string DisplayTypeToString(DisplayType type)
|
||||
{
|
||||
switch (type)
|
||||
|
@ -365,7 +420,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public static bool operator !=(Watch a, Watch b)
|
||||
{
|
||||
return !(a == b);
|
||||
return !a.Equals(b);
|
||||
}
|
||||
|
||||
public static bool operator ==(Watch a, Cheat b)
|
||||
|
|
|
@ -461,7 +461,7 @@
|
|||
this.pauseToolStripButton.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.Pause;
|
||||
this.pauseToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
|
||||
this.pauseToolStripButton.Name = "pauseToolStripButton";
|
||||
this.pauseToolStripButton.Size = new System.Drawing.Size(23, 20);
|
||||
this.pauseToolStripButton.Size = new System.Drawing.Size(23, 22);
|
||||
this.pauseToolStripButton.Text = "Pause";
|
||||
this.pauseToolStripButton.Click += new System.EventHandler(this.PauseMenuItem_Click);
|
||||
//
|
||||
|
@ -914,6 +914,7 @@
|
|||
this.DragDrop += new System.Windows.Forms.DragEventHandler(this.NewRamWatch_DragDrop);
|
||||
this.DragEnter += new System.Windows.Forms.DragEventHandler(this.NewRamWatch_DragEnter);
|
||||
this.Enter += new System.EventHandler(this.NewRamWatch_Enter);
|
||||
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.WatchListView_KeyDown);
|
||||
this.ListViewContextMenu.ResumeLayout(false);
|
||||
this.statusStrip1.ResumeLayout(false);
|
||||
this.statusStrip1.PerformLayout();
|
||||
|
|
|
@ -366,6 +366,35 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
private void PasteWatchesToClipBoard()
|
||||
{
|
||||
var data = Clipboard.GetDataObject();
|
||||
|
||||
if (data != null && data.GetDataPresent(DataFormats.Text))
|
||||
{
|
||||
var clipboardRows = ((string)data.GetData(DataFormats.Text)).Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
foreach (var row in clipboardRows)
|
||||
{
|
||||
var watch = Watch.FromString(row, _memoryDomains);
|
||||
if ((object)watch != null)
|
||||
{
|
||||
_watches.Add(watch);
|
||||
}
|
||||
}
|
||||
|
||||
FullyUpdateWatchList();
|
||||
}
|
||||
}
|
||||
|
||||
private void FullyUpdateWatchList()
|
||||
{
|
||||
WatchListView.ItemCount = _watches.ItemCount;
|
||||
UpdateWatchCount();
|
||||
UpdateStatusBar();
|
||||
UpdateValues();
|
||||
}
|
||||
|
||||
private void EditWatch(bool duplicate = false)
|
||||
{
|
||||
var indexes = SelectedIndices.ToList();
|
||||
|
@ -1078,10 +1107,14 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
RemoveWatchMenuItem_Click(sender, e);
|
||||
}
|
||||
else if (e.KeyCode == Keys.C && e.Control && !e.Alt && !e.Shift) // Copy
|
||||
else if (e.KeyCode == Keys.C && e.Control && !e.Alt && !e.Shift) // Ctrl+C
|
||||
{
|
||||
CopyWatchesToClipBoard();
|
||||
}
|
||||
else if (e.KeyCode == Keys.V && e.Control && !e.Alt && !e.Shift) // Ctrl+V
|
||||
{
|
||||
PasteWatchesToClipBoard();
|
||||
}
|
||||
else if (e.KeyCode == Keys.Enter && !e.Control && !e.Alt && !e.Shift) // Enter
|
||||
{
|
||||
EditWatch();
|
||||
|
|
Loading…
Reference in New Issue