Tiny ToolManager.Load cleanup 2 electric boogaloo
see2d6bac879
,7c3ccd664
This commit is contained in:
parent
1f6ead6354
commit
6acf4ae6fb
|
@ -64,10 +64,10 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
throw new ArgumentException($"Type {toolType.Name} does not implement {nameof(IToolForm)}.");
|
throw new ArgumentException($"Type {toolType.Name} does not implement {nameof(IToolForm)}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// The type[] in parameter is used to avoid an ambiguous name exception
|
return (IToolForm) typeof(ToolManager).GetMethod("Load", new[] { typeof(bool), typeof(string) })
|
||||||
MethodInfo method = GetType().GetMethod("Load", new Type[] { typeof(bool) }).MakeGenericMethod(toolType);
|
.MakeGenericMethod(toolType)
|
||||||
return (IToolForm)method.Invoke(this, new object[] { focus });
|
.Invoke(this, new object[] { focus, "" });
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the form inherits ToolFormBase, it will set base properties such as Tools, Config, etc
|
// If the form inherits ToolFormBase, it will set base properties such as Tools, Config, etc
|
||||||
|
@ -87,23 +87,11 @@ namespace BizHawk.Client.EmuHawk
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads the tool dialog T (T must implement <see cref="IToolForm"/>) , if it does not exist it will be created, if it is already open, it will be focused
|
/// Loads the tool dialog T (T must implement <see cref="IToolForm"/>) , if it does not exist it will be created, if it is already open, it will be focused
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">Type of tool you want to load</typeparam>
|
|
||||||
/// <param name="focus">Define if the tool form has to get the focus or not (Default is true)</param>
|
/// <param name="focus">Define if the tool form has to get the focus or not (Default is true)</param>
|
||||||
/// <returns>An instantiated <see cref="IToolForm"/></returns>
|
|
||||||
public T Load<T>(bool focus = true)
|
|
||||||
where T : class, IToolForm
|
|
||||||
{
|
|
||||||
return Load<T>("", focus);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Loads the tool dialog T (T must implement <see cref="IToolForm"/>) , if it does not exist it will be created, if it is already open, it will be focused
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">Type of tool you want to load</typeparam>
|
|
||||||
/// <param name="toolPath">Path to the .dll of the external tool</param>
|
/// <param name="toolPath">Path to the .dll of the external tool</param>
|
||||||
/// <param name="focus">Define if the tool form has to get the focus or not (Default is true)</param>
|
/// <typeparam name="T">Type of tool you want to load</typeparam>
|
||||||
/// <returns>An instantiated <see cref="IToolForm"/></returns>
|
/// <returns>An instantiated <see cref="IToolForm"/></returns>
|
||||||
public T Load<T>(string toolPath, bool focus = true)
|
public T Load<T>(bool focus = true, string toolPath = "")
|
||||||
where T : class, IToolForm
|
where T : class, IToolForm
|
||||||
{
|
{
|
||||||
if (!IsAvailable<T>()) return null;
|
if (!IsAvailable<T>()) return null;
|
||||||
|
@ -123,8 +111,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
_tools.Remove(existingTool);
|
_tools.Remove(existingTool);
|
||||||
}
|
}
|
||||||
|
|
||||||
var newTool = CreateInstance<T>(toolPath);
|
if (!(CreateInstance<T>(toolPath) is T newTool)) return null;
|
||||||
if (newTool == null) return null;
|
|
||||||
|
|
||||||
if (newTool is Form form) form.Owner = _owner;
|
if (newTool is Form form) form.Owner = _owner;
|
||||||
ServiceInjector.UpdateServices(_emulator.ServiceProvider, newTool);
|
ServiceInjector.UpdateServices(_emulator.ServiceProvider, newTool);
|
||||||
|
@ -153,7 +140,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
newTool.Restart();
|
newTool.Restart();
|
||||||
newTool.Show();
|
newTool.Show();
|
||||||
return (T)newTool;
|
return newTool;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Loads the external tool's entry form.</summary>
|
/// <summary>Loads the external tool's entry form.</summary>
|
||||||
|
|
Loading…
Reference in New Issue