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:
parent
a46101d816
commit
5a0d477dba
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,8 +10,9 @@ namespace BizHawk
|
|||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue