2011-01-18 03:36:43 +00:00
using System ;
using System.Collections.Generic ;
using System.ComponentModel ;
using System.Data ;
using System.Drawing ;
using System.Linq ;
using System.Text ;
using System.Windows.Forms ;
2011-01-18 17:17:14 +00:00
using System.IO ;
2011-01-19 02:49:47 +00:00
using System.Globalization ;
2011-01-18 03:36:43 +00:00
namespace BizHawk.MultiClient
{
2011-02-15 02:30:12 +00:00
/// <summary>
/// A winform designed to display ram address values of the user's choice
/// </summary>
2011-01-18 03:36:43 +00:00
public partial class RamWatch : Form
{
2011-01-19 05:46:08 +00:00
//TODO:
2011-02-18 07:02:33 +00:00
//Call AskSave in main client X function
2011-02-18 06:41:58 +00:00
//On Movie UP/Down set highlighted items to be what the user had selected (in their new position)
2011-02-18 07:02:33 +00:00
//DisplayWatches needs to do value display properly like updatevalues, or just run update values
2011-02-19 01:47:45 +00:00
//When Watch object has a changes member, display in watch list with a reset changes function
//Ability to watch in different memory domains
2011-02-17 16:27:39 +00:00
2011-02-19 21:03:31 +00:00
//IDEAS:
2011-02-22 18:54:59 +00:00
//OPtion to show a change count column
//Option to show previous value
//Option to show change from previous value
2011-02-19 21:03:31 +00:00
2011-01-20 02:28:38 +00:00
int defaultWidth ; //For saving the default size of the dialog, so the user can restore if desired
int defaultHeight ;
2011-01-20 00:17:49 +00:00
List < Watch > watchList = new List < Watch > ( ) ;
string currentWatchFile = "" ;
2011-01-21 04:58:07 +00:00
bool changes = false ;
2011-01-20 00:17:49 +00:00
2011-02-20 03:36:31 +00:00
public void DisplayWatchList ( )
{
WatchListView . ItemCount = watchList . Count ;
}
2011-01-21 05:44:24 +00:00
public void UpdateValues ( )
{
for ( int x = 0 ; x < watchList . Count ; x + + )
2011-02-21 14:23:57 +00:00
watchList [ x ] . PeekAddress ( Global . Emulator . MainMemory ) ;
WatchListView . Refresh ( ) ;
2011-01-21 05:44:24 +00:00
}
2011-02-19 13:32:03 +00:00
public void AddWatch ( Watch w )
{
watchList . Add ( w ) ;
DisplayWatchList ( ) ;
}
2011-01-18 03:36:43 +00:00
public RamWatch ( )
{
InitializeComponent ( ) ;
2011-02-20 01:41:58 +00:00
WatchListView . QueryItemText + = new QueryItemTextHandler ( WatchListView_QueryItemText ) ;
2011-02-20 03:50:08 +00:00
WatchListView . QueryItemBkColor + = new QueryItemBkColorHandler ( WatchListView_QueryItemBkColor ) ;
2011-02-20 01:41:58 +00:00
WatchListView . VirtualMode = true ;
}
2011-02-20 03:50:08 +00:00
private void WatchListView_QueryItemBkColor ( int index , int column , ref Color color )
{
if ( watchList [ index ] . type = = atype . SEPARATOR )
color = this . BackColor ;
}
2011-02-20 01:41:58 +00:00
void WatchListView_QueryItemText ( int index , int column , out string text )
{
text = "" ;
2011-02-20 03:36:31 +00:00
if ( column = = 0 )
{
if ( watchList [ index ] . type = = atype . SEPARATOR )
text = "" ;
else
text = String . Format ( "{0:X}" , watchList [ index ] . address ) ;
}
if ( column = = 1 )
{
if ( watchList [ index ] . type = = atype . SEPARATOR )
text = "" ;
else
{
switch ( watchList [ index ] . signed )
{
case asigned . HEX :
switch ( watchList [ index ] . type )
{
case atype . BYTE :
text = String . Format ( "{0:X2}" , watchList [ index ] . value ) ;
break ;
case atype . WORD :
text = String . Format ( "{0:X4}" , watchList [ index ] . value ) ;
break ;
case atype . DWORD :
text = String . Format ( "{0:X8}" , watchList [ index ] . value ) ;
break ;
}
break ;
case asigned . SIGNED :
text = ( ( sbyte ) watchList [ index ] . value ) . ToString ( ) ;
break ;
case asigned . UNSIGNED :
text = watchList [ index ] . value . ToString ( ) ;
break ;
}
}
}
if ( column = = 2 )
{
if ( watchList [ index ] . type = = atype . SEPARATOR )
text = "" ;
else
text = watchList [ index ] . notes ;
}
2011-01-18 03:36:43 +00:00
}
2011-01-21 17:46:02 +00:00
public int HowMany ( string str , char c )
2011-01-18 17:17:14 +00:00
{
int count = 0 ;
for ( int x = 0 ; x < str . Length ; x + + )
{
if ( str [ x ] = = c )
count + + ;
}
return count ;
}
2011-01-21 05:13:47 +00:00
public bool AskSave ( )
{
if ( changes )
{
DialogResult result = MessageBox . Show ( "Save Changes?" , "Ram Watch" , MessageBoxButtons . YesNoCancel , MessageBoxIcon . Question , MessageBoxDefaultButton . Button3 ) ;
if ( result = = DialogResult . Yes )
{
//TOOD: Do quicksave if filename, else save as
if ( string . Compare ( currentWatchFile , "" ) = = 0 )
{
SaveAs ( ) ;
}
else
SaveWatchFile ( currentWatchFile ) ;
return true ;
}
else if ( result = = DialogResult . No )
return true ;
else if ( result = = DialogResult . Cancel )
return false ;
}
return true ;
}
2011-01-19 04:59:19 +00:00
public void LoadWatchFromRecent ( string file )
2011-01-19 04:41:21 +00:00
{
2011-01-21 05:23:44 +00:00
bool z = true ;
if ( changes ) z = AskSave ( ) ;
if ( z )
2011-01-19 04:41:21 +00:00
{
2011-01-21 05:23:44 +00:00
bool r = LoadWatchFile ( file , false ) ;
if ( ! r )
{
DialogResult result = MessageBox . Show ( "Could not open " + file + "\nRemove from list?" , "File not found" , MessageBoxButtons . YesNo , MessageBoxIcon . Error ) ;
if ( result = = DialogResult . Yes )
Global . Config . RecentWatches . Remove ( file ) ;
}
DisplayWatchList ( ) ;
changes = false ;
2011-01-19 04:41:21 +00:00
}
}
2011-01-19 15:23:00 +00:00
private void NewWatchList ( )
{
2011-01-21 05:13:47 +00:00
bool result = true ;
if ( changes ) result = AskSave ( ) ;
2011-01-21 05:23:44 +00:00
if ( result = = true )
2011-01-21 05:13:47 +00:00
{
watchList . Clear ( ) ;
DisplayWatchList ( ) ;
currentWatchFile = "" ;
changes = false ;
2011-01-21 18:03:38 +00:00
MessageLabel . Text = "" ;
2011-01-21 05:13:47 +00:00
}
2011-01-19 15:23:00 +00:00
}
2011-01-19 16:57:23 +00:00
private bool SaveWatchFile ( string path )
{
var file = new FileInfo ( path ) ;
using ( StreamWriter sw = new StreamWriter ( path ) )
{
string str = "" ;
for ( int x = 0 ; x < watchList . Count ; x + + )
{
2011-01-20 03:28:29 +00:00
str + = string . Format ( "{0:X4}" , watchList [ x ] . address ) + "\t" ;
2011-01-19 16:57:23 +00:00
str + = watchList [ x ] . GetTypeByChar ( ) . ToString ( ) + "\t" ;
str + = watchList [ x ] . GetSignedByChar ( ) . ToString ( ) + "\t" ;
if ( watchList [ x ] . bigendian = = true )
str + = "1\t" ;
else
str + = "0\t" ;
str + = watchList [ x ] . notes + "\n" ;
}
sw . WriteLine ( str ) ;
}
2011-01-21 04:58:07 +00:00
changes = false ;
2011-01-19 16:57:23 +00:00
return true ;
}
2011-01-19 15:23:00 +00:00
2011-01-19 15:56:42 +00:00
bool LoadWatchFile ( string path , bool append )
2011-01-18 17:17:14 +00:00
{
2011-01-19 02:49:47 +00:00
int y , z ;
2011-01-18 17:17:14 +00:00
var file = new FileInfo ( path ) ;
if ( file . Exists = = false ) return false ;
using ( StreamReader sr = file . OpenText ( ) )
{
2011-01-21 19:18:25 +00:00
if ( ! append )
currentWatchFile = path ;
2011-01-20 00:17:49 +00:00
2011-01-19 04:05:01 +00:00
int count = 0 ;
2011-01-18 17:17:14 +00:00
string s = "" ;
string temp = "" ;
2011-01-19 15:56:42 +00:00
if ( append = = false )
watchList . Clear ( ) ; //Wipe existing list and read from file
2011-01-18 17:17:14 +00:00
while ( ( s = sr . ReadLine ( ) ) ! = null )
{
//parse each line and add to watchList
//.wch files from other emulators start with a number representing the number of watch, that line can be discarded here
//Any properly formatted line couldn't possibly be this short anyway, this also takes care of any garbage lines that might be in a file
if ( s . Length < 5 ) continue ;
2011-01-19 02:49:47 +00:00
z = HowMany ( s , '\t' ) ;
2011-01-18 17:17:14 +00:00
if ( z = = 5 )
{
//If 5, then this is a .wch file format made from another emulator, the first column (watch position) is not needed here
2011-01-19 02:49:47 +00:00
y = s . IndexOf ( '\t' ) + 1 ;
2011-01-20 00:10:08 +00:00
s = s . Substring ( y , s . Length - y ) ; //5 digit value representing the watch position number
2011-01-18 17:17:14 +00:00
}
else if ( z ! = 4 )
continue ; //If not 4, something is wrong with this line, ignore it
2011-01-19 04:05:01 +00:00
count + + ;
2011-01-18 17:17:14 +00:00
Watch w = new Watch ( ) ;
temp = s . Substring ( 0 , s . IndexOf ( '\t' ) ) ;
2011-01-19 02:49:47 +00:00
w . address = int . Parse ( temp , NumberStyles . HexNumber ) ;
y = s . IndexOf ( '\t' ) + 1 ;
2011-01-20 00:10:08 +00:00
s = s . Substring ( y , s . Length - y ) ; //Type
2011-01-19 02:49:47 +00:00
w . SetTypeByChar ( s [ 0 ] ) ;
y = s . IndexOf ( '\t' ) + 1 ;
2011-01-20 00:10:08 +00:00
s = s . Substring ( y , s . Length - y ) ; //Signed
2011-01-19 02:49:47 +00:00
w . SetSignedByChar ( s [ 0 ] ) ;
y = s . IndexOf ( '\t' ) + 1 ;
2011-01-20 00:10:08 +00:00
s = s . Substring ( y , s . Length - y ) ; //Endian
2011-01-19 02:49:47 +00:00
y = Int16 . Parse ( s [ 0 ] . ToString ( ) ) ;
if ( y = = 0 )
w . bigendian = false ;
else
w . bigendian = true ;
w . notes = s . Substring ( 2 , s . Length - 2 ) ; //User notes
watchList . Add ( w ) ;
2011-01-18 17:17:14 +00:00
}
2011-01-19 04:05:01 +00:00
2011-01-19 04:41:21 +00:00
Global . Config . RecentWatches . Add ( file . FullName ) ;
2011-01-21 04:58:07 +00:00
changes = false ;
2011-01-21 18:03:38 +00:00
MessageLabel . Text = Path . GetFileName ( file . FullName ) ;
2011-01-19 04:05:01 +00:00
//Update the number of watches
WatchCountLabel . Text = count . ToString ( ) + " watches" ;
2011-01-18 17:17:14 +00:00
}
return true ;
}
2011-01-21 17:32:21 +00:00
private Point GetPromptPoint ( )
2011-01-18 03:36:43 +00:00
{
2011-01-21 17:32:21 +00:00
2011-01-21 17:23:13 +00:00
Point p = new Point ( WatchListView . Location . X , WatchListView . Location . Y ) ;
Point q = new Point ( ) ;
q = PointToScreen ( p ) ;
2011-01-21 17:32:21 +00:00
return q ;
}
void AddNewWatch ( )
{
2011-01-21 17:23:13 +00:00
2011-01-20 04:33:16 +00:00
RamWatchNewWatch r = new RamWatchNewWatch ( ) ;
2011-01-21 17:32:21 +00:00
r . location = GetPromptPoint ( ) ;
2011-01-21 17:23:13 +00:00
2011-01-20 04:33:16 +00:00
r . ShowDialog ( ) ;
2011-01-21 03:20:45 +00:00
if ( r . userSelected = = true )
{
watchList . Add ( r . watch ) ;
2011-02-20 01:41:58 +00:00
DisplayWatchList ( ) ; //TODO: Do I need these calls?
2011-01-21 03:20:45 +00:00
}
2011-01-18 03:36:43 +00:00
}
2011-01-21 18:03:38 +00:00
void Changes ( )
{
changes = true ;
MessageLabel . Text = Path . GetFileName ( currentWatchFile ) + " *" ;
}
2011-02-18 05:52:09 +00:00
void EditWatchObject ( int pos )
2011-01-18 03:36:43 +00:00
{
2011-01-21 04:14:30 +00:00
RamWatchNewWatch r = new RamWatchNewWatch ( ) ;
2011-01-21 17:32:21 +00:00
r . location = GetPromptPoint ( ) ;
2011-02-18 05:52:09 +00:00
r . SetToEditWatch ( watchList [ pos ] , "Edit Watch" ) ;
2011-01-21 04:14:30 +00:00
r . ShowDialog ( ) ;
if ( r . userSelected = = true )
{
2011-01-21 18:03:38 +00:00
Changes ( ) ;
2011-02-18 05:52:09 +00:00
watchList [ pos ] = r . watch ;
2011-01-21 04:14:30 +00:00
DisplayWatchList ( ) ;
}
2011-01-18 03:36:43 +00:00
}
2011-02-18 05:52:09 +00:00
void EditWatch ( )
{
ListView . SelectedIndexCollection indexes = WatchListView . SelectedIndices ;
2011-02-18 06:09:36 +00:00
if ( indexes . Count > 0 )
EditWatchObject ( indexes [ 0 ] ) ;
2011-02-18 05:52:09 +00:00
}
2011-01-18 03:36:43 +00:00
void RemoveWatch ( )
{
2011-01-21 18:03:38 +00:00
Changes ( ) ;
2011-01-21 03:59:53 +00:00
ListView . SelectedIndexCollection indexes = WatchListView . SelectedIndices ;
2011-02-18 06:09:36 +00:00
if ( indexes . Count > 0 )
2011-01-21 03:59:53 +00:00
{
2011-02-18 06:09:36 +00:00
foreach ( int index in indexes )
{
2011-02-18 07:20:16 +00:00
watchList . Remove ( watchList [ indexes [ 0 ] ] ) ; //index[0] used since each iteration will make this the correct list index
2011-02-18 06:09:36 +00:00
}
DisplayWatchList ( ) ;
2011-01-21 03:59:53 +00:00
}
2011-01-18 03:36:43 +00:00
}
void DuplicateWatch ( )
{
2011-01-21 04:32:32 +00:00
ListView . SelectedIndexCollection indexes = WatchListView . SelectedIndices ;
2011-02-18 06:09:36 +00:00
if ( indexes . Count > 0 )
2011-01-21 04:32:32 +00:00
{
2011-02-18 06:09:36 +00:00
RamWatchNewWatch r = new RamWatchNewWatch ( ) ;
r . location = GetPromptPoint ( ) ;
int x = indexes [ 0 ] ;
r . SetToEditWatch ( watchList [ x ] , "Duplicate Watch" ) ;
r . ShowDialog ( ) ;
if ( r . userSelected = = true )
{
Changes ( ) ;
2011-02-18 06:32:26 +00:00
watchList . Add ( r . watch ) ;
2011-02-18 06:09:36 +00:00
DisplayWatchList ( ) ;
}
2011-01-21 04:32:32 +00:00
}
2011-01-18 03:36:43 +00:00
}
void MoveUp ( )
{
2011-01-21 04:44:30 +00:00
ListView . SelectedIndexCollection indexes = WatchListView . SelectedIndices ;
Watch temp = new Watch ( ) ;
foreach ( int index in indexes )
{
temp = watchList [ index ] ;
watchList . Remove ( watchList [ index ] ) ;
watchList . Insert ( index - 1 , temp ) ;
2011-01-21 18:03:38 +00:00
//Note: here it will get flagged many times redundantly potentially,
2011-02-18 06:41:58 +00:00
//but this avoids it being flagged falsely when the user did not select an index
2011-01-21 18:03:38 +00:00
Changes ( ) ;
2011-01-21 04:44:30 +00:00
}
DisplayWatchList ( ) ;
2011-01-18 03:36:43 +00:00
}
void MoveDown ( )
{
2011-01-21 04:48:36 +00:00
ListView . SelectedIndexCollection indexes = WatchListView . SelectedIndices ;
Watch temp = new Watch ( ) ;
foreach ( int index in indexes )
{
temp = watchList [ index ] ;
if ( index < watchList . Count - 1 )
{
watchList . Remove ( watchList [ index ] ) ;
watchList . Insert ( index + 1 , temp ) ;
}
2011-01-21 18:03:38 +00:00
//Note: here it will get flagged many times redundantly potnetially,
2011-02-18 06:41:58 +00:00
//but this avoids it being flagged falsely when the user did not select an index
2011-01-21 18:03:38 +00:00
Changes ( ) ;
2011-01-21 04:48:36 +00:00
}
DisplayWatchList ( ) ;
2011-01-18 03:36:43 +00:00
}
private void exitToolStripMenuItem_Click ( object sender , EventArgs e )
{
2011-01-21 20:28:06 +00:00
this . Hide ( ) ;
2011-01-18 03:36:43 +00:00
}
private void newListToolStripMenuItem_Click ( object sender , EventArgs e )
{
2011-01-19 15:23:00 +00:00
NewWatchList ( ) ;
2011-01-18 03:36:43 +00:00
}
2011-01-19 15:56:42 +00:00
private FileInfo GetFileFromUser ( )
2011-01-18 03:36:43 +00:00
{
2011-01-18 17:17:14 +00:00
var ofd = new OpenFileDialog ( ) ;
ofd . InitialDirectory = Global . Config . LastRomPath ;
ofd . Filter = "Watch Files (*.wch)|*.wch|All Files|*.*" ;
ofd . RestoreDirectory = true ;
2011-01-18 03:36:43 +00:00
2011-01-18 17:17:14 +00:00
Global . Sound . StopSound ( ) ;
var result = ofd . ShowDialog ( ) ;
Global . Sound . StartSound ( ) ;
if ( result ! = DialogResult . OK )
2011-01-19 15:56:42 +00:00
return null ;
2011-01-18 17:17:14 +00:00
var file = new FileInfo ( ofd . FileName ) ;
Global . Config . LastRomPath = file . DirectoryName ;
2011-01-19 15:56:42 +00:00
return file ;
}
2011-01-21 16:15:06 +00:00
private void OpenWatchFile ( )
2011-01-19 15:56:42 +00:00
{
var file = GetFileFromUser ( ) ;
if ( file ! = null )
2011-01-21 05:23:44 +00:00
{
bool r = true ;
if ( changes ) r = AskSave ( ) ;
if ( r )
{
LoadWatchFile ( file . FullName , false ) ;
DisplayWatchList ( ) ;
}
}
2011-01-18 03:36:43 +00:00
}
2011-01-21 16:15:06 +00:00
private void openToolStripMenuItem_Click ( object sender , EventArgs e )
{
OpenWatchFile ( ) ;
}
2011-01-18 03:36:43 +00:00
private void saveToolStripMenuItem_Click ( object sender , EventArgs e )
{
2011-01-20 00:17:49 +00:00
if ( string . Compare ( currentWatchFile , "" ) = = 0 ) return ;
2011-01-18 03:36:43 +00:00
2011-01-21 04:58:07 +00:00
if ( changes )
SaveWatchFile ( currentWatchFile ) ;
2011-01-18 03:36:43 +00:00
}
2011-01-19 16:57:23 +00:00
private FileInfo GetSaveFileFromUser ( )
2011-01-18 03:36:43 +00:00
{
2011-01-19 16:57:23 +00:00
var sfd = new SaveFileDialog ( ) ;
sfd . InitialDirectory = Global . Config . LastRomPath ;
sfd . Filter = "Watch Files (*.wch)|*.wch|All Files|*.*" ;
sfd . RestoreDirectory = true ;
Global . Sound . StopSound ( ) ;
var result = sfd . ShowDialog ( ) ;
Global . Sound . StartSound ( ) ;
if ( result ! = DialogResult . OK )
return null ;
var file = new FileInfo ( sfd . FileName ) ;
Global . Config . LastRomPath = file . DirectoryName ;
return file ;
}
2011-01-18 03:36:43 +00:00
2011-01-21 05:13:47 +00:00
private void SaveAs ( )
2011-01-19 16:57:23 +00:00
{
var file = GetSaveFileFromUser ( ) ;
if ( file ! = null )
2011-01-21 19:22:25 +00:00
{
2011-01-19 16:57:23 +00:00
SaveWatchFile ( file . FullName ) ;
2011-01-21 19:22:25 +00:00
currentWatchFile = file . FullName ;
}
2011-01-21 18:03:38 +00:00
MessageLabel . Text = Path . GetFileName ( currentWatchFile ) + " saved." ;
2011-01-18 03:36:43 +00:00
}
2011-01-21 05:13:47 +00:00
private void saveAsToolStripMenuItem_Click ( object sender , EventArgs e )
{
SaveAs ( ) ;
}
2011-01-18 03:36:43 +00:00
private void appendFileToolStripMenuItem_Click ( object sender , EventArgs e )
{
2011-01-19 15:56:42 +00:00
var file = GetFileFromUser ( ) ;
if ( file ! = null )
LoadWatchFile ( file . FullName , true ) ;
DisplayWatchList ( ) ;
2011-01-21 18:03:38 +00:00
Changes ( ) ;
2011-01-18 03:36:43 +00:00
}
private void autoLoadToolStripMenuItem_Click ( object sender , EventArgs e )
{
2011-01-19 04:41:21 +00:00
UpdateAutoLoadRamWatch ( ) ;
2011-01-18 03:36:43 +00:00
}
private void newWatchToolStripMenuItem_Click ( object sender , EventArgs e )
{
AddNewWatch ( ) ;
}
private void editWatchToolStripMenuItem_Click ( object sender , EventArgs e )
{
EditWatch ( ) ;
}
private void removeWatchToolStripMenuItem_Click ( object sender , EventArgs e )
{
RemoveWatch ( ) ;
}
private void duplicateWatchToolStripMenuItem_Click ( object sender , EventArgs e )
{
DuplicateWatch ( ) ;
}
private void moveUpToolStripMenuItem_Click ( object sender , EventArgs e )
{
MoveUp ( ) ;
}
private void moveDownToolStripMenuItem_Click ( object sender , EventArgs e )
{
MoveDown ( ) ;
}
2011-01-18 05:13:00 +00:00
2011-01-19 05:46:08 +00:00
private void RamWatch_Load ( object sender , EventArgs e )
{
2011-01-20 02:28:38 +00:00
defaultWidth = this . Size . Width ; //Save these first so that the user can restore to its original size
defaultHeight = this . Size . Height ;
2011-01-20 00:40:23 +00:00
if ( Global . Config . RamWatchWndx > = 0 & & Global . Config . RamWatchWndy > = 0 )
2011-01-20 01:10:05 +00:00
this . Location = new Point ( Global . Config . RamWatchWndx , Global . Config . RamWatchWndy ) ;
2011-01-20 02:22:15 +00:00
if ( Global . Config . RamWatchWidth > = 0 & & Global . Config . RamWatchHeight > = 0 )
{
this . Size = new System . Drawing . Size ( Global . Config . RamWatchWidth , Global . Config . RamWatchHeight ) ;
}
2011-01-18 05:13:00 +00:00
}
2011-01-19 04:18:33 +00:00
private void filesToolStripMenuItem_DropDownOpened ( object sender , EventArgs e )
{
if ( Global . Config . AutoLoadRamWatch = = true )
autoLoadToolStripMenuItem . Checked = true ;
else
autoLoadToolStripMenuItem . Checked = false ;
2011-01-20 00:17:49 +00:00
2011-01-21 04:58:07 +00:00
if ( string . Compare ( currentWatchFile , "" ) = = 0 | | ! changes )
2011-01-20 00:17:49 +00:00
{
saveToolStripMenuItem . Enabled = false ;
}
else
{
saveToolStripMenuItem . Enabled = true ;
}
2011-01-19 04:18:33 +00:00
}
2011-01-19 04:41:21 +00:00
private void UpdateAutoLoadRamWatch ( )
{
2011-02-21 04:22:54 +00:00
autoLoadToolStripMenuItem . Checked = Global . Config . AutoLoadRamWatch ^ = true ;
2011-01-19 04:41:21 +00:00
}
private void recentToolStripMenuItem_DropDownOpened ( object sender , EventArgs e )
{
//Clear out recent Roms list
//repopulate it with an up to date list
recentToolStripMenuItem . DropDownItems . Clear ( ) ;
if ( Global . Config . RecentWatches . IsEmpty ( ) )
{
recentToolStripMenuItem . DropDownItems . Add ( "None" ) ;
}
else
{
for ( int x = 0 ; x < Global . Config . RecentWatches . Length ( ) ; x + + )
{
string path = Global . Config . RecentWatches . GetRecentFileByPosition ( x ) ;
var item = new ToolStripMenuItem ( ) ;
item . Text = path ;
item . Click + = ( o , ev ) = > LoadWatchFromRecent ( path ) ;
2011-02-18 06:41:58 +00:00
recentToolStripMenuItem . DropDownItems . Add ( item ) ;
2011-01-19 04:41:21 +00:00
}
}
recentToolStripMenuItem . DropDownItems . Add ( "-" ) ;
var clearitem = new ToolStripMenuItem ( ) ;
clearitem . Text = "&Clear" ;
2011-02-21 04:22:54 +00:00
clearitem . Click + = ( o , ev ) = > Global . Config . RecentWatches . Clear ( ) ;
2011-01-19 04:41:21 +00:00
recentToolStripMenuItem . DropDownItems . Add ( clearitem ) ;
var auto = new ToolStripMenuItem ( ) ;
auto . Text = "&Auto-Load" ;
auto . Click + = ( o , ev ) = > UpdateAutoLoadRamWatch ( ) ;
if ( Global . Config . AutoLoadRamWatch = = true )
auto . Checked = true ;
else
auto . Checked = false ;
recentToolStripMenuItem . DropDownItems . Add ( auto ) ;
}
2011-01-19 15:56:42 +00:00
private void WatchListView_AfterLabelEdit ( object sender , LabelEditEventArgs e )
{
2011-02-18 03:48:42 +00:00
if ( e . Label = = null ) //If no change
return ;
2011-02-18 05:52:09 +00:00
string Str = e . Label . ToUpper ( ) . Trim ( ) ;
int index = e . Item ;
if ( InputValidate . IsValidHexNumber ( Str ) )
2011-02-18 03:48:42 +00:00
{
2011-02-18 05:52:09 +00:00
watchList [ e . Item ] . address = int . Parse ( Str , NumberStyles . HexNumber ) ;
EditWatchObject ( index ) ;
2011-02-18 03:48:42 +00:00
}
else
{
2011-02-18 15:36:41 +00:00
MessageBox . Show ( "Invalid number!" ) ; //TODO: More parameters and better message
2011-02-18 05:52:09 +00:00
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
2011-02-18 03:48:42 +00:00
}
2011-01-19 15:56:42 +00:00
}
2011-01-20 00:40:23 +00:00
private void RamWatch_LocationChanged ( object sender , EventArgs e )
{
Global . Config . RamWatchWndx = this . Location . X ;
Global . Config . RamWatchWndy = this . Location . Y ;
}
2011-01-20 02:22:15 +00:00
private void RamWatch_Resize ( object sender , EventArgs e )
{
Global . Config . RamWatchWidth = this . Right - this . Left ;
Global . Config . RamWatchHeight = this . Bottom - this . Top ;
}
2011-01-20 02:28:38 +00:00
private void restoreWindowSizeToolStripMenuItem_Click ( object sender , EventArgs e )
{
this . Size = new System . Drawing . Size ( defaultWidth , defaultHeight ) ;
}
2011-01-20 03:28:29 +00:00
2011-01-21 16:15:06 +00:00
private void newToolStripButton_Click ( object sender , EventArgs e )
{
NewWatchList ( ) ;
}
private void openToolStripButton_Click ( object sender , EventArgs e )
{
OpenWatchFile ( ) ;
}
private void saveToolStripButton_Click ( object sender , EventArgs e )
{
if ( changes )
{
SaveWatchFile ( currentWatchFile ) ;
}
else
{
SaveAs ( ) ;
}
}
2011-01-21 19:00:50 +00:00
private void InsertSeparator ( )
{
Watch w = new Watch ( ) ;
w . type = atype . SEPARATOR ;
ListView . SelectedIndexCollection indexes = WatchListView . SelectedIndices ;
int x ;
if ( indexes . Count > 0 )
{
x = indexes [ 0 ] ;
if ( indexes [ 0 ] > 0 )
watchList . Insert ( indexes [ 0 ] , w ) ;
}
else
watchList . Add ( w ) ;
DisplayWatchList ( ) ;
}
2011-01-21 16:15:06 +00:00
private void cutToolStripButton_Click ( object sender , EventArgs e )
{
RemoveWatch ( ) ;
}
2011-01-21 16:43:19 +00:00
private void NewWatchStripButton1_Click ( object sender , EventArgs e )
{
AddNewWatch ( ) ;
}
private void MoveUpStripButton1_Click ( object sender , EventArgs e )
{
MoveUp ( ) ;
}
private void MoveDownStripButton1_Click ( object sender , EventArgs e )
{
MoveDown ( ) ;
}
private void EditWatchToolStripButton1_Click ( object sender , EventArgs e )
{
EditWatch ( ) ;
}
private void DuplicateWatchToolStripButton_Click ( object sender , EventArgs e )
{
DuplicateWatch ( ) ;
}
2011-01-21 19:00:50 +00:00
private void toolStripButton1_Click ( object sender , EventArgs e )
{
InsertSeparator ( ) ;
}
private void insertSeparatorToolStripMenuItem_Click ( object sender , EventArgs e )
{
InsertSeparator ( ) ;
}
2011-01-23 19:52:04 +00:00
private void PoketoolStripButton2_Click ( object sender , EventArgs e )
{
PokeAddress ( ) ;
}
private void PokeAddress ( )
{
2011-02-16 16:35:51 +00:00
ListView . SelectedIndexCollection indexes = WatchListView . SelectedIndices ;
2011-02-17 16:27:39 +00:00
RamPoke p = new RamPoke ( ) ;
2011-02-18 06:09:36 +00:00
if ( indexes . Count > 0 )
p . SetWatchObject ( watchList [ indexes [ 0 ] ] ) ;
2011-02-17 16:27:39 +00:00
p . location = GetPromptPoint ( ) ;
p . ShowDialog ( ) ;
2011-01-23 19:52:04 +00:00
}
private void pokeAddressToolStripMenuItem_Click ( object sender , EventArgs e )
{
PokeAddress ( ) ;
}
2011-02-18 06:09:36 +00:00
private void watchesToolStripMenuItem_DropDownOpened ( object sender , EventArgs e )
{
ListView . SelectedIndexCollection indexes = WatchListView . SelectedIndices ;
if ( indexes . Count > 0 )
{
editWatchToolStripMenuItem . Enabled = true ;
duplicateWatchToolStripMenuItem . Enabled = true ;
removeWatchToolStripMenuItem . Enabled = true ;
2011-02-18 06:29:22 +00:00
moveUpToolStripMenuItem . Enabled = true ;
moveDownToolStripMenuItem . Enabled = true ;
2011-02-18 06:09:36 +00:00
}
else
{
editWatchToolStripMenuItem . Enabled = false ;
duplicateWatchToolStripMenuItem . Enabled = false ;
removeWatchToolStripMenuItem . Enabled = false ;
2011-02-18 06:29:22 +00:00
moveUpToolStripMenuItem . Enabled = false ;
moveDownToolStripMenuItem . Enabled = false ;
}
}
private void editToolStripMenuItem_Click ( object sender , EventArgs e )
{
EditWatch ( ) ;
}
private void removeToolStripMenuItem_Click ( object sender , EventArgs e )
{
RemoveWatch ( ) ;
}
private void duplicateToolStripMenuItem_Click ( object sender , EventArgs e )
{
DuplicateWatch ( ) ;
}
private void pokeToolStripMenuItem_Click ( object sender , EventArgs e )
{
PokeAddress ( ) ;
}
private void insertSeperatorToolStripMenuItem_Click ( object sender , EventArgs e )
{
InsertSeparator ( ) ;
}
private void moveUpToolStripMenuItem1_Click ( object sender , EventArgs e )
{
MoveUp ( ) ;
}
private void moveDownToolStripMenuItem1_Click ( object sender , EventArgs e )
{
MoveDown ( ) ;
}
private void contextMenuStrip1_Opening ( object sender , CancelEventArgs e )
{
ListView . SelectedIndexCollection indexes = WatchListView . SelectedIndices ;
if ( indexes . Count = = 0 )
{
contextMenuStrip1 . Items [ 0 ] . Visible = false ;
contextMenuStrip1 . Items [ 1 ] . Visible = false ;
contextMenuStrip1 . Items [ 2 ] . Visible = false ;
contextMenuStrip1 . Items [ 3 ] . Visible = false ;
contextMenuStrip1 . Items [ 4 ] . Visible = false ;
contextMenuStrip1 . Items [ 6 ] . Visible = false ;
contextMenuStrip1 . Items [ 7 ] . Visible = false ;
}
else
{
for ( int x = 0 ; x < contextMenuStrip1 . Items . Count ; x + + )
contextMenuStrip1 . Items [ x ] . Visible = true ;
2011-02-18 06:09:36 +00:00
}
}
2011-02-18 06:49:19 +00:00
private void WatchListView_MouseDoubleClick ( object sender , MouseEventArgs e )
{
ListView . SelectedIndexCollection indexes = WatchListView . SelectedIndices ;
if ( indexes . Count > 0 )
{
EditWatch ( ) ;
}
}
2011-02-18 07:02:33 +00:00
private void RamWatch_DragDrop ( object sender , DragEventArgs e )
{
string [ ] filePaths = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
if ( filePaths [ 0 ] . Contains ( ".wch" ) ) //TODO: a less lazy way to check file extension?
{
LoadWatchFile ( filePaths [ 0 ] , false ) ;
DisplayWatchList ( ) ;
}
}
private void RamWatch_DragEnter ( object sender , DragEventArgs e )
{
e . Effect = e . Data . GetDataPresent ( DataFormats . FileDrop ) ? DragDropEffects . Copy : DragDropEffects . None ; string [ ] filePaths = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
}
2011-01-18 03:36:43 +00:00
}
2011-02-21 15:23:30 +00:00
}