Ram Watch - directly editing an address in the list view validates user input, and if a valid hex number, will pull up an edit watch dialog

This commit is contained in:
andres.delikat 2011-02-18 05:52:09 +00:00
parent a46101d816
commit 5a0d477dba
2 changed files with 45 additions and 14 deletions

View File

@ -279,25 +279,27 @@ namespace BizHawk.MultiClient
MessageLabel.Text = Path.GetFileName(currentWatchFile) + " *"; MessageLabel.Text = Path.GetFileName(currentWatchFile) + " *";
} }
void EditWatch() void EditWatchObject(int pos)
{ {
ListView.SelectedIndexCollection indexes = WatchListView.SelectedIndices;
RamWatchNewWatch r = new RamWatchNewWatch(); RamWatchNewWatch r = new RamWatchNewWatch();
r.location = GetPromptPoint(); r.location = GetPromptPoint();
r.SetToEditWatch(watchList[pos], "Edit Watch");
int x = indexes[0];
r.SetToEditWatch(watchList[x], "Edit Watch");
r.ShowDialog(); r.ShowDialog();
if (r.userSelected == true) if (r.userSelected == true)
{ {
Changes(); Changes();
watchList[x] = r.watch; watchList[pos] = r.watch;
DisplayWatchList(); DisplayWatchList();
} }
} }
void EditWatch()
{
ListView.SelectedIndexCollection indexes = WatchListView.SelectedIndices;
EditWatchObject(indexes[0]);
}
void RemoveWatch() void RemoveWatch()
{ {
Changes(); Changes();
@ -631,17 +633,18 @@ namespace BizHawk.MultiClient
{ {
if (e.Label == null) //If no change if (e.Label == null) //If no change
return; return;
string Str = e.Label.ToUpper().Trim();
int index = e.Item;
char[] temp = e.Label.ToCharArray(); if (InputValidate.IsValidHexNumber(Str))
if (InputValidate.IsValidUnsignedNumber(temp)) //TODO:
{ {
//TODO: Change address to this new value watchList[e.Item].address = int.Parse(Str, NumberStyles.HexNumber);
//TODO: show Edit watch dialog EditWatchObject(index);
} }
else else
{ {
MessageBox.Show("Invalid number!"); MessageBox.Show("Invalid number!");
//TODO: Restore original address value WatchListView.Items[index].Text = watchList[index].address.ToString(); //TODO: Why doesn't the list view update to the new value? It won't until something else changes
} }
} }

View File

@ -10,8 +10,9 @@ namespace BizHawk
/// </summary> /// </summary>
public static class InputValidate public static class InputValidate
{ {
public static bool IsValidUnsignedNumber(char[] input) public static bool IsValidUnsignedNumber(string Str)
{ {
char[] input = (Str.ToCharArray());
ASCIIEncoding AE = new ASCIIEncoding(); ASCIIEncoding AE = new ASCIIEncoding();
// Check each character in the new label to determine if it is a number. // Check each character in the new label to determine if it is a number.
for (int x = 0; x < input.Length; x++) for (int x = 0; x < input.Length; x++)
@ -25,5 +26,32 @@ namespace BizHawk
} }
return true; return true;
} }
/// <summary>
/// validates is a Hex number 0-9, A-F (must be capital letters)
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static bool IsValidHexNumber(string Str)
{
char[] input = (Str.ToCharArray());
ASCIIEncoding AE = new ASCIIEncoding();
// Check each character in the new label to determine if it is a number.
for (int x = 0; x < input.Length; x++)
{
// Encode the character from the character array to its ASCII code.
byte[] bc = AE.GetBytes(input[x].ToString());
// Determine if the ASCII code is within the valid range of numerical values.
if (bc[0] < 47)
return false;
if (bc[0] > 58)
{
if (bc[0] < 65 || bc[0] > 70) //A-F capital letters only!
return false;
}
}
return true;
}
} }
} }