Make ExternalToolManager not static

This commit is contained in:
YoshiRulz 2020-11-29 17:30:19 +10:00
parent d2c514bc51
commit bed5142ddc
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
3 changed files with 15 additions and 20 deletions

View File

@ -1194,7 +1194,7 @@ namespace BizHawk.Client.EmuHawk
{
ExternalToolMenuItem.DropDownItems.Clear();
foreach (var item in ExternalToolManager.ToolStripMenu)
foreach (var item in ExtToolManager.ToolStripMenu)
{
if (item.Tag is ValueTuple<string, string> tuple)
{

View File

@ -135,7 +135,7 @@ namespace BizHawk.Client.EmuHawk
var requestedExtToolDll = _argParser.openExtToolDll;
if (requestedExtToolDll != null)
{
var enabled = ExternalToolManager.ToolStripMenu.Where(item => item.Enabled)
var enabled = ExtToolManager.ToolStripMenu.Where(item => item.Enabled)
.Select(item => ((string, string)) item.Tag)
.ToList();
try
@ -344,6 +344,7 @@ namespace BizHawk.Client.EmuHawk
Controls.SetChildIndex(_presentationPanel, 0);
Tools = new ToolManager(this, Config, DisplayManager, InputManager, Emulator, MovieSession, Game);
ExtToolManager = new ExternalToolManager();
// TODO GL - move these event handlers somewhere less obnoxious line in the On* overrides
Load += (o, e) =>
@ -865,6 +866,8 @@ namespace BizHawk.Client.EmuHawk
private readonly IGL GL;
private readonly ExternalToolManager ExtToolManager;
public readonly ToolManager Tools;
private DisplayManager DisplayManager;
@ -3789,7 +3792,7 @@ namespace BizHawk.Client.EmuHawk
}
}
ExternalToolManager.BuildToolStrip();
ExtToolManager.BuildToolStrip();
EmuClient.OnRomLoaded(Emulator);
return true;

View File

@ -11,18 +11,13 @@ using BizHawk.Common;
namespace BizHawk.Client.EmuHawk
{
/// <summary>
/// This static class handle all ExternalTools
/// </summary>
public static class ExternalToolManager
public sealed class ExternalToolManager
{
private static readonly FileSystemWatcher DirectoryMonitor;
private static readonly List<ToolStripMenuItem> MenuItems = new List<ToolStripMenuItem>();
private readonly FileSystemWatcher DirectoryMonitor;
/// <summary>
/// Initialization
/// </summary>
static ExternalToolManager()
private readonly List<ToolStripMenuItem> MenuItems = new List<ToolStripMenuItem>();
public ExternalToolManager()
{
if(!Directory.Exists(GlobalWin.Config.PathEntries["Global", "External Tools"].Path))
{
@ -41,10 +36,7 @@ namespace BizHawk.Client.EmuHawk
BuildToolStrip();
}
/// <summary>
/// Build the ToolStrip menu
/// </summary>
internal static void BuildToolStrip()
internal void BuildToolStrip()
{
MenuItems.Clear();
if (Directory.Exists(DirectoryMonitor.Path))
@ -63,7 +55,7 @@ namespace BizHawk.Client.EmuHawk
/// a <see cref="ToolStripMenuItem"/> with its <see cref="ToolStripItem.Tag"/> containing a <c>(string, string)</c>;
/// the first is the assembly path (<paramref name="fileName"/>) and the second is the <see cref="Type.FullName"/> of the entry point form's type
/// </returns>
private static ToolStripMenuItem GenerateToolTipFromFileName(string fileName)
private ToolStripMenuItem GenerateToolTipFromFileName(string fileName)
{
if (fileName == null) throw new Exception();
var item = new ToolStripMenuItem(Path.GetFileName(fileName)) { Enabled = false };
@ -144,7 +136,7 @@ namespace BizHawk.Client.EmuHawk
/// </summary>
/// <param name="sender">Object that raised the event</param>
/// <param name="e">Event arguments</param>
private static void DirectoryMonitor_Created(object sender, FileSystemEventArgs e)
private void DirectoryMonitor_Created(object sender, FileSystemEventArgs e)
{
MenuItems.Add(GenerateToolTipFromFileName(e.FullPath));
}
@ -153,6 +145,6 @@ namespace BizHawk.Client.EmuHawk
/// Gets a prebuild <see cref="ToolStripMenuItem"/>
/// This list auto-updated by the <see cref="ExternalToolManager"/> itself
/// </summary>
public static IEnumerable<ToolStripMenuItem> ToolStripMenu => MenuItems;
public IEnumerable<ToolStripMenuItem> ToolStripMenu => MenuItems;
}
}