Move watchlist to common

This commit is contained in:
adelikat 2013-10-25 13:27:20 +00:00
parent 3ff9dc8f4c
commit f72303f326
6 changed files with 92 additions and 92 deletions

View File

@ -107,6 +107,7 @@
<Compile Include="tools\Cheat.cs" />
<Compile Include="tools\CheatList.cs" />
<Compile Include="tools\Watch.cs" />
<Compile Include="tools\WatchList.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BizHawk.Emulation\BizHawk.Emulation.csproj">

View File

@ -4,16 +4,11 @@ using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BizHawk.Client.Common;
namespace BizHawk.MultiClient
namespace BizHawk.Client.Common
{
public class WatchList : IEnumerable<Watch>
{
public const string ADDRESS = "AddressColumn";
public const string VALUE = "ValueColumn";
public const string PREV = "PrevColumn";
@ -297,26 +292,6 @@ namespace BizHawk.MultiClient
public string CurrentFileName { get { return _currentFilename; } set { _currentFilename = value; } }
public bool Changes { get; set; }
public bool Save()
{
bool result;
if (!String.IsNullOrWhiteSpace(CurrentFileName))
{
result = SaveFile();
}
else
{
result = SaveAs();
}
if (result)
{
Changes = false;
}
return result;
}
public bool Load(string path, bool append)
{
bool result = LoadFile(path, append);
@ -346,7 +321,7 @@ namespace BizHawk.MultiClient
}
}
private bool SaveFile()
public bool Save()
{
if (String.IsNullOrWhiteSpace(CurrentFileName))
{
@ -380,13 +355,12 @@ namespace BizHawk.MultiClient
return true;
}
public bool SaveAs()
public bool SaveAs(FileInfo file)
{
var file = GetSaveFileFromUser(CurrentFileName);
if (file != null)
{
CurrentFileName = file.FullName;
return SaveFile();
return Save();
}
else
{
@ -546,53 +520,6 @@ namespace BizHawk.MultiClient
return 0;
}
public static FileInfo GetFileFromUser(string currentFile)
{
var ofd = new OpenFileDialog();
if (currentFile.Length > 0)
ofd.FileName = Path.GetFileNameWithoutExtension(currentFile);
ofd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.WatchPath, null);
ofd.Filter = "Watch Files (*.wch)|*.wch|All Files|*.*";
ofd.RestoreDirectory = true;
GlobalWinF.Sound.StopSound();
var result = ofd.ShowDialog();
GlobalWinF.Sound.StartSound();
if (result != DialogResult.OK)
return null;
var file = new FileInfo(ofd.FileName);
return file;
}
public static FileInfo GetSaveFileFromUser(string currentFile)
{
var sfd = new SaveFileDialog();
if (currentFile.Length > 0)
{
sfd.FileName = Path.GetFileNameWithoutExtension(currentFile);
sfd.InitialDirectory = Path.GetDirectoryName(currentFile);
}
else if (!(Global.Emulator is NullEmulator))
{
sfd.FileName = PathManager.FilesystemSafeName(Global.Game);
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.WatchPath, null);
}
else
{
sfd.FileName = "NULL";
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.WatchPath, null);
}
sfd.Filter = "Watch Files (*.wch)|*.wch|All Files|*.*";
sfd.RestoreDirectory = true;
GlobalWinF.Sound.StopSound();
var result = sfd.ShowDialog();
GlobalWinF.Sound.StartSound();
if (result != DialogResult.OK)
return null;
var file = new FileInfo(sfd.FileName);
return file;
}
#endregion
}
}

View File

@ -741,7 +741,6 @@
<DependentUpon>WatchEditor.cs</DependentUpon>
</Compile>
<Compile Include="tools\Watch\WatchHistory.cs" />
<Compile Include="tools\Watch\WatchList.cs" />
<Compile Include="tools\Watch\WatchValueBox.cs">
<SubType>Component</SubType>
</Compile>

View File

@ -11,6 +11,55 @@ namespace BizHawk.MultiClient
{
class ToolHelpers
{
public static FileInfo GetWatchFileFromUser(string currentFile)
{
var ofd = new OpenFileDialog();
if (!String.IsNullOrWhiteSpace(currentFile))
{
ofd.FileName = Path.GetFileNameWithoutExtension(currentFile);
}
ofd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.WatchPath, null);
ofd.Filter = "Watch Files (*.wch)|*.wch|All Files|*.*";
ofd.RestoreDirectory = true;
GlobalWinF.Sound.StopSound();
var result = ofd.ShowDialog();
GlobalWinF.Sound.StartSound();
if (result != DialogResult.OK)
return null;
var file = new FileInfo(ofd.FileName);
return file;
}
public static FileInfo GetWatchSaveFileFromUser(string currentFile)
{
var sfd = new SaveFileDialog();
if (!String.IsNullOrWhiteSpace(currentFile))
{
sfd.FileName = Path.GetFileNameWithoutExtension(currentFile);
sfd.InitialDirectory = Path.GetDirectoryName(currentFile);
}
else if (!(Global.Emulator is NullEmulator))
{
sfd.FileName = PathManager.FilesystemSafeName(Global.Game);
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.WatchPath, null);
}
else
{
sfd.FileName = "NULL";
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.WatchPath, null);
}
sfd.Filter = "Watch Files (*.wch)|*.wch|All Files|*.*";
sfd.RestoreDirectory = true;
GlobalWinF.Sound.StopSound();
var result = sfd.ShowDialog();
GlobalWinF.Sound.StartSound();
if (result != DialogResult.OK)
return null;
var file = new FileInfo(sfd.FileName);
return file;
}
public static FileInfo GetCheatFileFromUser(string currentFile)
{
var ofd = new OpenFileDialog();

View File

@ -911,7 +911,7 @@ namespace BizHawk.MultiClient
private void OpenMenuItem_Click(object sender, EventArgs e)
{
LoadWatchFile(
WatchList.GetFileFromUser(String.Empty),
ToolHelpers.GetWatchFileFromUser(String.Empty),
sender == AppendFileMenuItem,
sender == TruncateFromFileMenuItem
);
@ -928,10 +928,22 @@ namespace BizHawk.MultiClient
watches.Add(Searches[i]);
}
if (watches.Save())
if (!String.IsNullOrWhiteSpace(watches.CurrentFileName))
{
CurrentFileName = watches.CurrentFileName;
MessageLabel.Text = Path.GetFileName(CurrentFileName) + " saved";
if (watches.Save())
{
CurrentFileName = watches.CurrentFileName;
MessageLabel.Text = Path.GetFileName(CurrentFileName) + " saved";
}
}
else
{
bool result = watches.SaveAs(ToolHelpers.GetWatchSaveFileFromUser(watches.CurrentFileName));
if (result)
{
MessageLabel.Text = Path.GetFileName(CurrentFileName) + " saved";
Global.Config.RecentWatches.Add(watches.CurrentFileName);
}
}
}
}
@ -945,7 +957,7 @@ namespace BizHawk.MultiClient
watches.Add(Searches[i]);
}
if (watches.SaveAs())
if (watches.SaveAs(ToolHelpers.GetWatchSaveFileFromUser(watches.CurrentFileName)))
{
CurrentFileName = watches.CurrentFileName;
MessageLabel.Text = Path.GetFileName(CurrentFileName) + " saved";

View File

@ -737,6 +737,16 @@ namespace BizHawk.MultiClient
WatchListView.Refresh();
}
private void SaveAs()
{
bool result = Watches.SaveAs(ToolHelpers.GetWatchSaveFileFromUser(Watches.CurrentFileName));
if (result)
{
UpdateMessageLabel(saved: true);
Global.Config.RecentWatches.Add(Watches.CurrentFileName);
}
}
#region Winform Events
private void NewRamWatch_Load(object sender, EventArgs e)
@ -783,25 +793,27 @@ namespace BizHawk.MultiClient
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
bool append = sender == appendFileToolStripMenuItem;
LoadWatchFile(WatchList.GetFileFromUser(Watches.CurrentFileName), append);
LoadWatchFile(ToolHelpers.GetWatchFileFromUser(Watches.CurrentFileName), append);
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (Watches.Save())
if (!String.IsNullOrWhiteSpace(Watches.CurrentFileName))
{
UpdateMessageLabel(saved: true);
if (Watches.Save())
{
UpdateMessageLabel(saved: true);
}
}
else
{
SaveAs();
}
}
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
{
bool result = Watches.SaveAs();
if (result)
{
UpdateMessageLabel(saved: true);
Global.Config.RecentWatches.Add(Watches.CurrentFileName);
}
SaveAs();
}
private void recentToolStripMenuItem_DropDownOpened(object sender, EventArgs e)