From 5a0d477dba6a12c78571d9c78073586dbcd406c7 Mon Sep 17 00:00:00 2001 From: "andres.delikat" Date: Fri, 18 Feb 2011 05:52:09 +0000 Subject: [PATCH] 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 --- BizHawk.MultiClient/tools/RamWatch.cs | 29 ++++++++++++++------------ BizHawk.Util/InputValidate.cs | 30 ++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/BizHawk.MultiClient/tools/RamWatch.cs b/BizHawk.MultiClient/tools/RamWatch.cs index 3610ac21b0..c202dae6d8 100644 --- a/BizHawk.MultiClient/tools/RamWatch.cs +++ b/BizHawk.MultiClient/tools/RamWatch.cs @@ -279,25 +279,27 @@ namespace BizHawk.MultiClient MessageLabel.Text = Path.GetFileName(currentWatchFile) + " *"; } - void EditWatch() + void EditWatchObject(int pos) { - ListView.SelectedIndexCollection indexes = WatchListView.SelectedIndices; - RamWatchNewWatch r = new RamWatchNewWatch(); r.location = GetPromptPoint(); - - int x = indexes[0]; - r.SetToEditWatch(watchList[x], "Edit Watch"); + r.SetToEditWatch(watchList[pos], "Edit Watch"); r.ShowDialog(); if (r.userSelected == true) { Changes(); - watchList[x] = r.watch; + watchList[pos] = r.watch; DisplayWatchList(); } } + void EditWatch() + { + ListView.SelectedIndexCollection indexes = WatchListView.SelectedIndices; + EditWatchObject(indexes[0]); + } + void RemoveWatch() { Changes(); @@ -631,17 +633,18 @@ namespace BizHawk.MultiClient { if (e.Label == null) //If no change return; - - char[] temp = e.Label.ToCharArray(); - if (InputValidate.IsValidUnsignedNumber(temp)) //TODO: + string Str = e.Label.ToUpper().Trim(); + int index = e.Item; + + if (InputValidate.IsValidHexNumber(Str)) { - //TODO: Change address to this new value - //TODO: show Edit watch dialog + watchList[e.Item].address = int.Parse(Str, NumberStyles.HexNumber); + EditWatchObject(index); } else { 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 } } diff --git a/BizHawk.Util/InputValidate.cs b/BizHawk.Util/InputValidate.cs index 2eb7583d49..111fd4543b 100644 --- a/BizHawk.Util/InputValidate.cs +++ b/BizHawk.Util/InputValidate.cs @@ -10,8 +10,9 @@ namespace BizHawk /// public static class InputValidate { - public static bool IsValidUnsignedNumber(char[] input) + public static bool IsValidUnsignedNumber(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++) @@ -25,5 +26,32 @@ namespace BizHawk } return true; } + + /// + /// validates is a Hex number 0-9, A-F (must be capital letters) + /// + /// + /// + 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; + } } }