Convert some static methods in ToolHelpers to extension methods
This commit is contained in:
parent
b0b057ef2c
commit
ce4ce0bacc
|
@ -498,6 +498,7 @@
|
|||
<Compile Include="DisplayManager\SwappableDisplaySurfaceSet.cs" />
|
||||
<Compile Include="DisplayManager\TextureFrugalizer.cs" />
|
||||
<Compile Include="Extensions\ControlExtensions.cs" />
|
||||
<Compile Include="Extensions\ToolExtensions.cs" />
|
||||
<Compile Include="GlobalWin.cs" />
|
||||
<Compile Include="Input\GamePad.cs" Condition=" '$(OS)' == 'Windows_NT' " />
|
||||
<Compile Include="Input\GamePad360.cs" />
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using BizHawk.Client.Common;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk.ToolExtensions
|
||||
{
|
||||
public static class ToolExtensions
|
||||
{
|
||||
public static ToolStripItem[] RecentMenu(this RecentFiles recent, Action<string> loadFileCallback, bool autoload = false)
|
||||
{
|
||||
var items = new List<ToolStripItem>();
|
||||
|
||||
if (recent.Empty)
|
||||
{
|
||||
var none = new ToolStripMenuItem { Enabled = false, Text = "None" };
|
||||
items.Add(none);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var filename in recent)
|
||||
{
|
||||
var temp = filename;
|
||||
var item = new ToolStripMenuItem { Text = temp };
|
||||
item.Click += (o, ev) => loadFileCallback(temp);
|
||||
items.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
items.Add(new ToolStripSeparator());
|
||||
|
||||
var clearitem = new ToolStripMenuItem { Text = "&Clear" };
|
||||
clearitem.Click += (o, ev) => recent.Clear();
|
||||
items.Add(clearitem);
|
||||
|
||||
if (autoload)
|
||||
{
|
||||
var auto = new ToolStripMenuItem { Text = "&Autoload", Checked = recent.AutoLoad };
|
||||
auto.Click += (o, ev) => recent.ToggleAutoLoad();
|
||||
items.Add(auto);
|
||||
}
|
||||
|
||||
return items.ToArray();
|
||||
}
|
||||
|
||||
public static void HandleLoadError(this RecentFiles recent, string path)
|
||||
{
|
||||
GlobalWin.Sound.StopSound();
|
||||
var result = MessageBox.Show("Could not open " + path + "\nRemove from list?", "File not found", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
recent.Remove(path);
|
||||
}
|
||||
|
||||
GlobalWin.Sound.StartSound();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,6 +18,7 @@ using BizHawk.Client.Common;
|
|||
using BizHawk.Client.EmuHawk.config.NES;
|
||||
using BizHawk.Client.EmuHawk.CustomControls;
|
||||
using BizHawk.Client.EmuHawk.WinFormExtensions;
|
||||
using BizHawk.Client.EmuHawk.ToolExtensions;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
|
@ -41,11 +42,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
RecentRomSubMenu.DropDownItems.Clear();
|
||||
RecentRomSubMenu.DropDownItems.AddRange(
|
||||
ToolHelpers.GenerateRecentMenu(Global.Config.RecentRoms, LoadRomFromRecent)
|
||||
);
|
||||
RecentRomSubMenu.DropDownItems.Add(
|
||||
ToolHelpers.GenerateAutoLoadItem(Global.Config.RecentRoms)
|
||||
);
|
||||
Global.Config.RecentRoms.RecentMenu(LoadRomFromRecent, true));
|
||||
}
|
||||
|
||||
private void SaveStateSubMenu_DropDownOpened(object sender, EventArgs e)
|
||||
|
@ -261,11 +258,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
RecentMovieSubMenu.DropDownItems.Clear();
|
||||
RecentMovieSubMenu.DropDownItems.AddRange(
|
||||
ToolHelpers.GenerateRecentMenu(Global.Config.RecentMovies, LoadMoviesFromRecent)
|
||||
);
|
||||
RecentMovieSubMenu.DropDownItems.Add(
|
||||
ToolHelpers.GenerateAutoLoadItem(Global.Config.RecentMovies)
|
||||
);
|
||||
Global.Config.RecentMovies.RecentMenu(LoadMoviesFromRecent, true));
|
||||
}
|
||||
|
||||
private void MovieEndSubMenu_DropDownOpened(object sender, EventArgs e)
|
||||
|
|
|
@ -34,6 +34,7 @@ using BizHawk.Emulation.DiscSystem;
|
|||
using BizHawk.Emulation.Cores.Nintendo.N64;
|
||||
|
||||
using BizHawk.Client.EmuHawk.WinFormExtensions;
|
||||
using BizHawk.Client.EmuHawk.ToolExtensions;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
|
@ -1564,7 +1565,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
else
|
||||
{
|
||||
ToolHelpers.HandleLoadError(Global.Config.RecentMovies, path);
|
||||
Global.Config.RecentMovies.HandleLoadError(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1572,7 +1573,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
if (!LoadRom(rom))
|
||||
{
|
||||
ToolHelpers.HandleLoadError(Global.Config.RecentRoms, rom);
|
||||
Global.Config.RecentRoms.HandleLoadError(rom);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ using System.Windows.Forms;
|
|||
using BizHawk.Client.Common;
|
||||
using BizHawk.Emulation.Cores.Nintendo.SNES;
|
||||
using BizHawk.Emulation.Cores.Sega.Genesis;
|
||||
using BizHawk.Client.EmuHawk.ToolExtensions;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
|
@ -102,7 +103,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
var loadResult = Global.CheatList.Load(path, append: false);
|
||||
if (!loadResult)
|
||||
{
|
||||
ToolHelpers.HandleLoadError(Global.Config.RecentWatches, path);
|
||||
Global.Config.RecentWatches.HandleLoadError(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -467,8 +468,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
RecentSubMenu.DropDownItems.Clear();
|
||||
RecentSubMenu.DropDownItems.AddRange(
|
||||
ToolHelpers.GenerateRecentMenu(Global.Config.RecentCheats, LoadFileFromRecent)
|
||||
);
|
||||
Global.Config.RecentCheats.RecentMenu(LoadFileFromRecent));
|
||||
}
|
||||
|
||||
private void NewMenuItem_Click(object sender, EventArgs e)
|
||||
|
|
|
@ -15,6 +15,7 @@ using BizHawk.Common.IOExtensions;
|
|||
using BizHawk.Emulation.Common;
|
||||
using BizHawk.Client.Common;
|
||||
using BizHawk.Client.EmuHawk.WinFormExtensions;
|
||||
using BizHawk.Client.EmuHawk.ToolExtensions;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
|
@ -1336,7 +1337,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
var result = LoadTable(path);
|
||||
if (!result)
|
||||
{
|
||||
ToolHelpers.HandleLoadError(Global.Config.RecentTables, path);
|
||||
Global.Config.RecentTables.HandleLoadError(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1349,10 +1350,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
RecentTablesSubMenu.DropDownItems.Clear();
|
||||
RecentTablesSubMenu.DropDownItems.AddRange(
|
||||
ToolHelpers.GenerateRecentMenu(Global.Config.RecentTables, LoadFileFromRecent));
|
||||
|
||||
RecentTablesSubMenu.DropDownItems.Add(
|
||||
ToolHelpers.GenerateAutoLoadItem(Global.Config.RecentTables));
|
||||
Global.Config.RecentTables.RecentMenu(LoadFileFromRecent, true));
|
||||
}
|
||||
|
||||
private void ExitMenuItem_Click(object sender, EventArgs e)
|
||||
|
|
|
@ -12,6 +12,7 @@ using LuaInterface;
|
|||
using BizHawk.Client.Common;
|
||||
using BizHawk.Emulation.Common;
|
||||
using BizHawk.Client.EmuHawk.WinFormExtensions;
|
||||
using BizHawk.Client.EmuHawk.ToolExtensions;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
|
@ -510,7 +511,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
if (!_luaList.LoadLuaSession(path))
|
||||
{
|
||||
ToolHelpers.HandleLoadError(Global.Config.RecentLuaSession, path);
|
||||
Global.Config.RecentLuaSession.HandleLoadError(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -584,14 +585,14 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
RecentSessionsSubMenu.DropDownItems.Clear();
|
||||
RecentSessionsSubMenu.DropDownItems.AddRange(
|
||||
ToolHelpers.GenerateRecentMenu(Global.Config.RecentLuaSession, LoadSessionFromRecent));
|
||||
Global.Config.RecentLuaSession.RecentMenu(LoadSessionFromRecent));
|
||||
}
|
||||
|
||||
private void RecentScriptsSubMenu_DropDownOpened(object sender, EventArgs e)
|
||||
{
|
||||
RecentScriptsSubMenu.DropDownItems.Clear();
|
||||
RecentScriptsSubMenu.DropDownItems.AddRange(
|
||||
ToolHelpers.GenerateRecentMenu(Global.Config.RecentLua, LoadLuaFromRecent));
|
||||
Global.Config.RecentLua.RecentMenu(LoadLuaFromRecent));
|
||||
}
|
||||
|
||||
private void NewSessionMenuItem_Click(object sender, EventArgs e)
|
||||
|
|
|
@ -7,6 +7,7 @@ using System.Windows.Forms;
|
|||
using BizHawk.Client.Common;
|
||||
using BizHawk.Emulation.Cores.Components.H6280;
|
||||
using BizHawk.Emulation.Cores.PCEngine;
|
||||
using BizHawk.Client.EmuHawk.ToolExtensions;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
|
@ -175,9 +176,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
RecentSubMenu.DropDownItems.Clear();
|
||||
RecentSubMenu.DropDownItems.AddRange(
|
||||
ToolHelpers.GenerateRecentMenu(Global.Config.RecentPceCdlFiles, LoadFile));
|
||||
RecentSubMenu.DropDownItems.Add(
|
||||
ToolHelpers.GenerateAutoLoadItem(Global.Config.RecentPceCdlFiles));
|
||||
Global.Config.RecentPceCdlFiles.RecentMenu(LoadFile, true));
|
||||
}
|
||||
|
||||
private void NewMenuItem_Click(object sender, EventArgs e)
|
||||
|
|
|
@ -10,6 +10,7 @@ using BizHawk.Client.Common;
|
|||
using BizHawk.Client.Common.MovieConversionExtensions;
|
||||
|
||||
using BizHawk.Client.EmuHawk.WinFormExtensions;
|
||||
using BizHawk.Client.EmuHawk.ToolExtensions;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
|
@ -213,7 +214,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
var file = new FileInfo(path);
|
||||
if (!file.Exists)
|
||||
{
|
||||
ToolHelpers.HandleLoadError(Global.Config.RecentTas, path);
|
||||
Global.Config.RecentTas.HandleLoadError(path);
|
||||
}
|
||||
|
||||
GlobalWin.MainForm.StartNewMovie(movie, record: false);
|
||||
|
@ -505,8 +506,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
RecentSubMenu.DropDownItems.Clear();
|
||||
RecentSubMenu.DropDownItems.AddRange(
|
||||
ToolHelpers.GenerateRecentMenu(Global.Config.RecentTas, LoadProject)
|
||||
);
|
||||
Global.Config.RecentTas.RecentMenu(LoadProject));
|
||||
}
|
||||
|
||||
private void NewTasMenuItem_Click(object sender, EventArgs e)
|
||||
|
|
|
@ -205,54 +205,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
return new FileInfo(sfd.FileName);
|
||||
}
|
||||
|
||||
public static ToolStripMenuItem GenerateAutoLoadItem(RecentFiles recent)
|
||||
{
|
||||
var auto = new ToolStripMenuItem { Text = "&Autoload", Checked = recent.AutoLoad };
|
||||
auto.Click += (o, ev) => recent.ToggleAutoLoad();
|
||||
return auto;
|
||||
}
|
||||
|
||||
public static ToolStripItem[] GenerateRecentMenu(RecentFiles recent, Action<string> loadFileCallback)
|
||||
{
|
||||
var items = new List<ToolStripItem>();
|
||||
|
||||
if (recent.Empty)
|
||||
{
|
||||
var none = new ToolStripMenuItem { Enabled = false, Text = "None" };
|
||||
items.Add(none);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var filename in recent)
|
||||
{
|
||||
var temp = filename;
|
||||
var item = new ToolStripMenuItem { Text = temp };
|
||||
item.Click += (o, ev) => loadFileCallback(temp);
|
||||
items.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
items.Add(new ToolStripSeparator());
|
||||
|
||||
var clearitem = new ToolStripMenuItem { Text = "&Clear" };
|
||||
clearitem.Click += (o, ev) => recent.Clear();
|
||||
items.Add(clearitem);
|
||||
|
||||
return items.ToArray();
|
||||
}
|
||||
|
||||
public static void HandleLoadError(RecentFiles recent, string path)
|
||||
{
|
||||
GlobalWin.Sound.StopSound();
|
||||
var result = MessageBox.Show("Could not open " + path + "\nRemove from list?", "File not found", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
recent.Remove(path);
|
||||
}
|
||||
|
||||
GlobalWin.Sound.StartSound();
|
||||
}
|
||||
|
||||
public static IEnumerable<ToolStripItem> GenerateMemoryDomainMenuItems(Action<string> setCallback, string selectedDomain = "", int? maxSize = null)
|
||||
{
|
||||
var items = new List<ToolStripMenuItem>();
|
||||
|
@ -306,11 +258,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
watches
|
||||
.Where(w => !w.IsSeparator)
|
||||
.Select(w => new Cheat(w, w.Value ?? 0)));
|
||||
|
||||
//foreach (var watch in watches.Where(watch => !watch.IsSeparator))
|
||||
//{
|
||||
// Global.CheatList.Add(new Cheat(watch, watch.Value ?? 0));
|
||||
//}
|
||||
}
|
||||
|
||||
public static void UnfreezeAddress(IEnumerable<Watch> watches)
|
||||
|
|
|
@ -14,6 +14,7 @@ using BizHawk.Common.NumberExtensions;
|
|||
using BizHawk.Client.Common;
|
||||
|
||||
using BizHawk.Client.EmuHawk.WinFormExtensions;
|
||||
using BizHawk.Client.EmuHawk.ToolExtensions;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
|
@ -555,7 +556,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
if (!file.Exists)
|
||||
{
|
||||
ToolHelpers.HandleLoadError(Global.Config.RecentSearches, path);
|
||||
Global.Config.RecentSearches.HandleLoadError(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -962,8 +963,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
RecentSubMenu.DropDownItems.Clear();
|
||||
RecentSubMenu.DropDownItems.AddRange(
|
||||
ToolHelpers.GenerateRecentMenu(Global.Config.RecentSearches, LoadFileFromRecent)
|
||||
);
|
||||
Global.Config.RecentSearches.RecentMenu(LoadFileFromRecent));
|
||||
}
|
||||
|
||||
private void OpenMenuItem_Click(object sender, EventArgs e)
|
||||
|
|
|
@ -9,6 +9,7 @@ using System.Windows.Forms;
|
|||
|
||||
using BizHawk.Client.Common;
|
||||
using BizHawk.Client.EmuHawk.WinFormExtensions;
|
||||
using BizHawk.Client.EmuHawk.ToolExtensions;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
|
@ -145,7 +146,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
var load_result = _watches.Load(path, append: false);
|
||||
if (!load_result)
|
||||
{
|
||||
ToolHelpers.HandleLoadError(Global.Config.RecentWatches, path);
|
||||
Global.Config.RecentWatches.HandleLoadError(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -684,11 +685,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
RecentSubMenu.DropDownItems.Clear();
|
||||
RecentSubMenu.DropDownItems.AddRange(
|
||||
ToolHelpers.GenerateRecentMenu(Global.Config.RecentWatches, LoadFileFromRecent)
|
||||
);
|
||||
RecentSubMenu.DropDownItems.Add(
|
||||
ToolHelpers.GenerateAutoLoadItem(Global.Config.RecentWatches)
|
||||
);
|
||||
Global.Config.RecentWatches.RecentMenu(LoadFileFromRecent, true));
|
||||
}
|
||||
|
||||
private void ExitMenuItem_Click(object sender, EventArgs e)
|
||||
|
|
Loading…
Reference in New Issue