Move watchlist to common
This commit is contained in:
parent
3ff9dc8f4c
commit
f72303f326
|
@ -107,6 +107,7 @@
|
||||||
<Compile Include="tools\Cheat.cs" />
|
<Compile Include="tools\Cheat.cs" />
|
||||||
<Compile Include="tools\CheatList.cs" />
|
<Compile Include="tools\CheatList.cs" />
|
||||||
<Compile Include="tools\Watch.cs" />
|
<Compile Include="tools\Watch.cs" />
|
||||||
|
<Compile Include="tools\WatchList.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\BizHawk.Emulation\BizHawk.Emulation.csproj">
|
<ProjectReference Include="..\BizHawk.Emulation\BizHawk.Emulation.csproj">
|
||||||
|
|
|
@ -4,16 +4,11 @@ using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
using BizHawk.Client.Common;
|
namespace BizHawk.Client.Common
|
||||||
|
|
||||||
namespace BizHawk.MultiClient
|
|
||||||
{
|
{
|
||||||
public class WatchList : IEnumerable<Watch>
|
public class WatchList : IEnumerable<Watch>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public const string ADDRESS = "AddressColumn";
|
public const string ADDRESS = "AddressColumn";
|
||||||
public const string VALUE = "ValueColumn";
|
public const string VALUE = "ValueColumn";
|
||||||
public const string PREV = "PrevColumn";
|
public const string PREV = "PrevColumn";
|
||||||
|
@ -297,26 +292,6 @@ namespace BizHawk.MultiClient
|
||||||
public string CurrentFileName { get { return _currentFilename; } set { _currentFilename = value; } }
|
public string CurrentFileName { get { return _currentFilename; } set { _currentFilename = value; } }
|
||||||
public bool Changes { get; set; }
|
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)
|
public bool Load(string path, bool append)
|
||||||
{
|
{
|
||||||
bool result = LoadFile(path, append);
|
bool result = LoadFile(path, append);
|
||||||
|
@ -346,7 +321,7 @@ namespace BizHawk.MultiClient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool SaveFile()
|
public bool Save()
|
||||||
{
|
{
|
||||||
if (String.IsNullOrWhiteSpace(CurrentFileName))
|
if (String.IsNullOrWhiteSpace(CurrentFileName))
|
||||||
{
|
{
|
||||||
|
@ -380,13 +355,12 @@ namespace BizHawk.MultiClient
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SaveAs()
|
public bool SaveAs(FileInfo file)
|
||||||
{
|
{
|
||||||
var file = GetSaveFileFromUser(CurrentFileName);
|
|
||||||
if (file != null)
|
if (file != null)
|
||||||
{
|
{
|
||||||
CurrentFileName = file.FullName;
|
CurrentFileName = file.FullName;
|
||||||
return SaveFile();
|
return Save();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -546,53 +520,6 @@ namespace BizHawk.MultiClient
|
||||||
return 0;
|
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
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -741,7 +741,6 @@
|
||||||
<DependentUpon>WatchEditor.cs</DependentUpon>
|
<DependentUpon>WatchEditor.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="tools\Watch\WatchHistory.cs" />
|
<Compile Include="tools\Watch\WatchHistory.cs" />
|
||||||
<Compile Include="tools\Watch\WatchList.cs" />
|
|
||||||
<Compile Include="tools\Watch\WatchValueBox.cs">
|
<Compile Include="tools\Watch\WatchValueBox.cs">
|
||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|
|
@ -11,6 +11,55 @@ namespace BizHawk.MultiClient
|
||||||
{
|
{
|
||||||
class ToolHelpers
|
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)
|
public static FileInfo GetCheatFileFromUser(string currentFile)
|
||||||
{
|
{
|
||||||
var ofd = new OpenFileDialog();
|
var ofd = new OpenFileDialog();
|
||||||
|
|
|
@ -911,7 +911,7 @@ namespace BizHawk.MultiClient
|
||||||
private void OpenMenuItem_Click(object sender, EventArgs e)
|
private void OpenMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
LoadWatchFile(
|
LoadWatchFile(
|
||||||
WatchList.GetFileFromUser(String.Empty),
|
ToolHelpers.GetWatchFileFromUser(String.Empty),
|
||||||
sender == AppendFileMenuItem,
|
sender == AppendFileMenuItem,
|
||||||
sender == TruncateFromFileMenuItem
|
sender == TruncateFromFileMenuItem
|
||||||
);
|
);
|
||||||
|
@ -928,10 +928,22 @@ namespace BizHawk.MultiClient
|
||||||
watches.Add(Searches[i]);
|
watches.Add(Searches[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (watches.Save())
|
if (!String.IsNullOrWhiteSpace(watches.CurrentFileName))
|
||||||
{
|
{
|
||||||
CurrentFileName = watches.CurrentFileName;
|
if (watches.Save())
|
||||||
MessageLabel.Text = Path.GetFileName(CurrentFileName) + " saved";
|
{
|
||||||
|
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]);
|
watches.Add(Searches[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (watches.SaveAs())
|
if (watches.SaveAs(ToolHelpers.GetWatchSaveFileFromUser(watches.CurrentFileName)))
|
||||||
{
|
{
|
||||||
CurrentFileName = watches.CurrentFileName;
|
CurrentFileName = watches.CurrentFileName;
|
||||||
MessageLabel.Text = Path.GetFileName(CurrentFileName) + " saved";
|
MessageLabel.Text = Path.GetFileName(CurrentFileName) + " saved";
|
||||||
|
|
|
@ -737,6 +737,16 @@ namespace BizHawk.MultiClient
|
||||||
WatchListView.Refresh();
|
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
|
#region Winform Events
|
||||||
|
|
||||||
private void NewRamWatch_Load(object sender, EventArgs e)
|
private void NewRamWatch_Load(object sender, EventArgs e)
|
||||||
|
@ -783,25 +793,27 @@ namespace BizHawk.MultiClient
|
||||||
private void openToolStripMenuItem_Click(object sender, EventArgs e)
|
private void openToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
bool append = sender == appendFileToolStripMenuItem;
|
bool append = sender == appendFileToolStripMenuItem;
|
||||||
LoadWatchFile(WatchList.GetFileFromUser(Watches.CurrentFileName), append);
|
LoadWatchFile(ToolHelpers.GetWatchFileFromUser(Watches.CurrentFileName), append);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
|
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)
|
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
bool result = Watches.SaveAs();
|
SaveAs();
|
||||||
if (result)
|
|
||||||
{
|
|
||||||
UpdateMessageLabel(saved: true);
|
|
||||||
Global.Config.RecentWatches.Add(Watches.CurrentFileName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void recentToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
|
private void recentToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
|
||||||
|
|
Loading…
Reference in New Issue