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(); ExternalToolMenuItem.DropDownItems.Clear();
foreach (var item in ExternalToolManager.ToolStripMenu) foreach (var item in ExtToolManager.ToolStripMenu)
{ {
if (item.Tag is ValueTuple<string, string> tuple) if (item.Tag is ValueTuple<string, string> tuple)
{ {

View File

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

View File

@ -11,18 +11,13 @@ using BizHawk.Common;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
/// <summary> public sealed class ExternalToolManager
/// This static class handle all ExternalTools
/// </summary>
public static class ExternalToolManager
{ {
private static readonly FileSystemWatcher DirectoryMonitor; private readonly FileSystemWatcher DirectoryMonitor;
private static readonly List<ToolStripMenuItem> MenuItems = new List<ToolStripMenuItem>();
/// <summary> private readonly List<ToolStripMenuItem> MenuItems = new List<ToolStripMenuItem>();
/// Initialization
/// </summary> public ExternalToolManager()
static ExternalToolManager()
{ {
if(!Directory.Exists(GlobalWin.Config.PathEntries["Global", "External Tools"].Path)) if(!Directory.Exists(GlobalWin.Config.PathEntries["Global", "External Tools"].Path))
{ {
@ -41,10 +36,7 @@ namespace BizHawk.Client.EmuHawk
BuildToolStrip(); BuildToolStrip();
} }
/// <summary> internal void BuildToolStrip()
/// Build the ToolStrip menu
/// </summary>
internal static void BuildToolStrip()
{ {
MenuItems.Clear(); MenuItems.Clear();
if (Directory.Exists(DirectoryMonitor.Path)) 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>; /// 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 /// 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> /// </returns>
private static ToolStripMenuItem GenerateToolTipFromFileName(string fileName) private ToolStripMenuItem GenerateToolTipFromFileName(string fileName)
{ {
if (fileName == null) throw new Exception(); if (fileName == null) throw new Exception();
var item = new ToolStripMenuItem(Path.GetFileName(fileName)) { Enabled = false }; var item = new ToolStripMenuItem(Path.GetFileName(fileName)) { Enabled = false };
@ -144,7 +136,7 @@ namespace BizHawk.Client.EmuHawk
/// </summary> /// </summary>
/// <param name="sender">Object that raised the event</param> /// <param name="sender">Object that raised the event</param>
/// <param name="e">Event arguments</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)); MenuItems.Add(GenerateToolTipFromFileName(e.FullPath));
} }
@ -153,6 +145,6 @@ namespace BizHawk.Client.EmuHawk
/// Gets a prebuild <see cref="ToolStripMenuItem"/> /// Gets a prebuild <see cref="ToolStripMenuItem"/>
/// This list auto-updated by the <see cref="ExternalToolManager"/> itself /// This list auto-updated by the <see cref="ExternalToolManager"/> itself
/// </summary> /// </summary>
public static IEnumerable<ToolStripMenuItem> ToolStripMenu => MenuItems; public IEnumerable<ToolStripMenuItem> ToolStripMenu => MenuItems;
} }
} }