Ram Search - better implementation of input validation on text boxes. Do preview as user types into the boxes

This commit is contained in:
andres.delikat 2011-02-22 19:49:22 +00:00
parent 776a314eb8
commit 4bc3587ca7
5 changed files with 119 additions and 38 deletions

View File

@ -16,6 +16,7 @@ namespace BizHawk.MultiClient
//If signed/unsigned/hex radios selected, auto-change the value box //If signed/unsigned/hex radios selected, auto-change the value box
//Checked signed/u/h value on RamPoke_Load and set value appopriately //Checked signed/u/h value on RamPoke_Load and set value appopriately
//Memory domain selection //Memory domain selection
//Overhaul input validation of textboxes to be like Ram Search
public Watch watch = new Watch(); public Watch watch = new Watch();
public Point location = new Point(); public Point location = new Point();

View File

@ -68,6 +68,7 @@
this.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.definePreviousValueToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.definePreviousValueToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.sinceLastSearchToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.sinceLastSearchToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.originalValueToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.sinceLastFrameToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.sinceLastFrameToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.restoreOriginalWindowSizeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.restoreOriginalWindowSizeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveWindowPositionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.saveWindowPositionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -113,7 +114,6 @@
this.AutoSearchCheckBox = new System.Windows.Forms.CheckBox(); this.AutoSearchCheckBox = new System.Windows.Forms.CheckBox();
this.MemDomainLabel = new System.Windows.Forms.Label(); this.MemDomainLabel = new System.Windows.Forms.Label();
this.OutputLabel = new System.Windows.Forms.Label(); this.OutputLabel = new System.Windows.Forms.Label();
this.originalValueToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.SearchtoolStrip1.SuspendLayout(); this.SearchtoolStrip1.SuspendLayout();
this.menuStrip1.SuspendLayout(); this.menuStrip1.SuspendLayout();
this.toolStripContainer1.TopToolStripPanel.SuspendLayout(); this.toolStripContainer1.TopToolStripPanel.SuspendLayout();
@ -467,6 +467,13 @@
this.sinceLastSearchToolStripMenuItem.Text = "Since last Search"; this.sinceLastSearchToolStripMenuItem.Text = "Since last Search";
this.sinceLastSearchToolStripMenuItem.Click += new System.EventHandler(this.sinceLastSearchToolStripMenuItem_Click); this.sinceLastSearchToolStripMenuItem.Click += new System.EventHandler(this.sinceLastSearchToolStripMenuItem_Click);
// //
// originalValueToolStripMenuItem
//
this.originalValueToolStripMenuItem.Name = "originalValueToolStripMenuItem";
this.originalValueToolStripMenuItem.Size = new System.Drawing.Size(166, 22);
this.originalValueToolStripMenuItem.Text = "Original value";
this.originalValueToolStripMenuItem.Click += new System.EventHandler(this.originalValueToolStripMenuItem_Click);
//
// sinceLastFrameToolStripMenuItem // sinceLastFrameToolStripMenuItem
// //
this.sinceLastFrameToolStripMenuItem.Name = "sinceLastFrameToolStripMenuItem"; this.sinceLastFrameToolStripMenuItem.Name = "sinceLastFrameToolStripMenuItem";
@ -730,7 +737,9 @@
this.NumberOfChangesBox.Name = "NumberOfChangesBox"; this.NumberOfChangesBox.Name = "NumberOfChangesBox";
this.NumberOfChangesBox.Size = new System.Drawing.Size(65, 20); this.NumberOfChangesBox.Size = new System.Drawing.Size(65, 20);
this.NumberOfChangesBox.TabIndex = 6; this.NumberOfChangesBox.TabIndex = 6;
this.NumberOfChangesBox.TextChanged += new System.EventHandler(this.NumberOfChangesBox_TextChanged);
this.NumberOfChangesBox.Leave += new System.EventHandler(this.NumberOfChangesBox_Leave); this.NumberOfChangesBox.Leave += new System.EventHandler(this.NumberOfChangesBox_Leave);
this.NumberOfChangesBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.NumberOfChangesBox_KeyPress);
// //
// SpecificAddressBox // SpecificAddressBox
// //
@ -741,7 +750,9 @@
this.SpecificAddressBox.Name = "SpecificAddressBox"; this.SpecificAddressBox.Name = "SpecificAddressBox";
this.SpecificAddressBox.Size = new System.Drawing.Size(65, 20); this.SpecificAddressBox.Size = new System.Drawing.Size(65, 20);
this.SpecificAddressBox.TabIndex = 5; this.SpecificAddressBox.TabIndex = 5;
this.SpecificAddressBox.TextChanged += new System.EventHandler(this.SpecificAddressBox_TextChanged);
this.SpecificAddressBox.Leave += new System.EventHandler(this.SpecificAddressBox_Leave); this.SpecificAddressBox.Leave += new System.EventHandler(this.SpecificAddressBox_Leave);
this.SpecificAddressBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.SpecificAddressBox_KeyPress);
// //
// SpecificValueBox // SpecificValueBox
// //
@ -751,7 +762,9 @@
this.SpecificValueBox.Name = "SpecificValueBox"; this.SpecificValueBox.Name = "SpecificValueBox";
this.SpecificValueBox.Size = new System.Drawing.Size(65, 20); this.SpecificValueBox.Size = new System.Drawing.Size(65, 20);
this.SpecificValueBox.TabIndex = 4; this.SpecificValueBox.TabIndex = 4;
this.SpecificValueBox.TextChanged += new System.EventHandler(this.SpecificValueBox_TextChanged);
this.SpecificValueBox.Leave += new System.EventHandler(this.SpecificValueBox_Leave); this.SpecificValueBox.Leave += new System.EventHandler(this.SpecificValueBox_Leave);
this.SpecificValueBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.SpecificValueBox_KeyPress);
// //
// NumberOfChangesRadio // NumberOfChangesRadio
// //
@ -825,7 +838,9 @@
this.DifferentByBox.Name = "DifferentByBox"; this.DifferentByBox.Name = "DifferentByBox";
this.DifferentByBox.Size = new System.Drawing.Size(50, 20); this.DifferentByBox.Size = new System.Drawing.Size(50, 20);
this.DifferentByBox.TabIndex = 9; this.DifferentByBox.TabIndex = 9;
this.DifferentByBox.TextChanged += new System.EventHandler(this.DifferentByBox_TextChanged);
this.DifferentByBox.Leave += new System.EventHandler(this.DifferentByBox_Leave); this.DifferentByBox.Leave += new System.EventHandler(this.DifferentByBox_Leave);
this.DifferentByBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.DifferentByBox_KeyPress);
// //
// DifferentByRadio // DifferentByRadio
// //
@ -937,13 +952,6 @@
this.OutputLabel.TabIndex = 9; this.OutputLabel.TabIndex = 9;
this.OutputLabel.Text = " "; this.OutputLabel.Text = " ";
// //
// originalValueToolStripMenuItem
//
this.originalValueToolStripMenuItem.Name = "originalValueToolStripMenuItem";
this.originalValueToolStripMenuItem.Size = new System.Drawing.Size(166, 22);
this.originalValueToolStripMenuItem.Text = "Original value";
this.originalValueToolStripMenuItem.Click += new System.EventHandler(this.originalValueToolStripMenuItem_Click);
//
// RamSearch // RamSearch
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

View File

@ -31,6 +31,9 @@ namespace BizHawk.MultiClient
//Add button to set copy current values to prev //Add button to set copy current values to prev
//ON start new search, a preview of equal to prev value would remove all searches, there's an error here //ON start new search, a preview of equal to prev value would remove all searches, there's an error here
//On start new search, don't do preview //On start new search, don't do preview
//On text box leave event, do preview
//After search everything goes pink
//Limit number of digits in specific value based on data type
string systemID = "NULL"; string systemID = "NULL";
@ -556,7 +559,7 @@ namespace BizHawk.MultiClient
SaveUndo(); SaveUndo();
OutputLabel.Text = MakeAddressString(searchList.Count - weededList.Count) + " removed"; OutputLabel.Text = MakeAddressString(searchList.Count - weededList.Count) + " removed";
ReplaceSearchListWithWeedOutList(); ReplaceSearchListWithWeedOutList();
MakePreviousList(); if (Global.Config.RamSearchPreviousAs != 1) MakePreviousList(); //1 = Original value
DisplaySearchList(); DisplaySearchList();
} }
else else
@ -1020,50 +1023,30 @@ namespace BizHawk.MultiClient
private void SpecificValueBox_Leave(object sender, EventArgs e) private void SpecificValueBox_Leave(object sender, EventArgs e)
{ {
SpecificValueBox.Text = SpecificValueBox.Text.Replace(" ", ""); DoPreview();
if (!InputValidate.IsValidSignedNumber(SpecificValueBox.Text))
{
SpecificValueBox.Focus();
SpecificValueBox.SelectAll();
ToolTip t = new ToolTip();
t.Show("Must be a valid decimal value", SpecificValueBox, 5000);
}
} }
private void SpecificAddressBox_Leave(object sender, EventArgs e) private void SpecificAddressBox_Leave(object sender, EventArgs e)
{ {
SpecificAddressBox.Text = SpecificAddressBox.Text.Replace(" ", ""); DoPreview();
if (!InputValidate.IsValidHexNumber(SpecificAddressBox.Text))
{
SpecificAddressBox.Focus();
SpecificAddressBox.SelectAll();
ToolTip t = new ToolTip();
t.Show("Must be a valid hexadecimal value", SpecificAddressBox, 5000);
}
} }
private void NumberOfChangesBox_Leave(object sender, EventArgs e) private void NumberOfChangesBox_Leave(object sender, EventArgs e)
{ {
NumberOfChangesBox.Text = NumberOfChangesBox.Text.Replace(" ", ""); DoPreview();
if (!InputValidate.IsValidUnsignedNumber(NumberOfChangesBox.Text))
{
NumberOfChangesBox.Focus();
NumberOfChangesBox.SelectAll();
ToolTip t = new ToolTip();
t.Show("Must be a valid unsigned decimal value", NumberOfChangesBox, 5000);
}
} }
private void DifferentByBox_Leave(object sender, EventArgs e) private void DifferentByBox_Leave(object sender, EventArgs e)
{ {
DifferentByBox.Text = DifferentByBox.Text.Replace(" ", ""); if (!InputValidate.IsValidUnsignedNumber(DifferentByBox.Text)) //Actually the only way this could happen is from putting dashes after the first character
if (!InputValidate.IsValidUnsignedNumber(DifferentByBox.Text))
{ {
DifferentByBox.Focus(); DifferentByBox.Focus();
DifferentByBox.SelectAll(); DifferentByBox.SelectAll();
ToolTip t = new ToolTip(); ToolTip t = new ToolTip();
t.Show("Must be a valid unsigned decimal value", DifferentByBox, 5000); t.Show("Must be a valid unsigned decimal value", DifferentByBox, 5000);
return;
} }
DoPreview();
} }
private bool SaveSearchFile(string path) private bool SaveSearchFile(string path)
@ -1415,6 +1398,58 @@ namespace BizHawk.MultiClient
Global.Config.RamSearchPreviewMode ^= true; Global.Config.RamSearchPreviewMode ^= true;
} }
private void SpecificValueBox_TextChanged(object sender, EventArgs e)
{
DoPreview();
}
private void SpecificValueBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\b') return;
if (!InputValidate.IsValidUnsignedNumber(e.KeyChar))
e.Handled = true;
}
private void SpecificAddressBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\b') return;
if (!InputValidate.IsValidHexNumber(e.KeyChar))
e.Handled = true;
}
private void NumberOfChangesBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\b') return;
if (!InputValidate.IsValidUnsignedNumber(e.KeyChar))
e.Handled = true;
}
private void DifferentByBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\b') return;
if (!InputValidate.IsValidUnsignedNumber(e.KeyChar))
e.Handled = true;
}
private void SpecificAddressBox_TextChanged(object sender, EventArgs e)
{
DoPreview();
}
private void NumberOfChangesBox_TextChanged(object sender, EventArgs e)
{
DoPreview();
}
private void DifferentByBox_TextChanged(object sender, EventArgs e)
{
DoPreview();
}
} }

View File

@ -160,9 +160,6 @@
<metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>259, 17</value> <value>259, 17</value>
</metadata> </metadata>
<metadata name="toolStrip2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>358, 17</value>
</metadata>
<data name="toolStripButton1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="toolStripButton1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value> <value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
@ -194,6 +191,9 @@
s1c0gHPmbrPTpHNJKOCo2G1mZs20zcwUJ5yp1AB5+8/zEwgF5GMVDxh4AAAAAElFTkSuQmCC s1c0gHPmbrPTpHNJKOCo2G1mZs20zcwUJ5yp1AB5+8/zEwgF5GMVDxh4AAAAAElFTkSuQmCC
</value> </value>
</data> </data>
<metadata name="toolStrip2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>358, 17</value>
</metadata>
<data name="DataSizetoolStripSplitButton1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="DataSizetoolStripSplitButton1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value> <value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8

View File

@ -27,6 +27,14 @@ namespace BizHawk
return true; return true;
} }
public static bool IsValidUnsignedNumber(char c)
{
if (c < 47 || c > 58)
return false;
return true;
}
/// <summary> /// <summary>
/// Validates all chars are 0-9 or a dash as the first value /// Validates all chars are 0-9 or a dash as the first value
/// </summary> /// </summary>
@ -58,6 +66,17 @@ namespace BizHawk
return true; return true;
} }
public static bool IsValidSignedNumber(char c)
{
if (c == 47) return true;
if (c < 47 || c > 58)
return false;
return true;
}
/// <summary> /// <summary>
/// validates is a Hex number 0-9, A-F (must be capital letters) /// validates is a Hex number 0-9, A-F (must be capital letters)
/// </summary> /// </summary>
@ -84,5 +103,23 @@ namespace BizHawk
} }
return true; return true;
} }
public static bool IsValidHexNumber(char c)
{
if (c < 47) return false; //0
if (c > 58) //9
{
if (c < 65) //A
return false;
if (c > 70) //F
{
if (c < 97 || c > 102) //a-f
return false;
}
}
return true;
}
} }
} }