replace some winforms specific values and ram watch chacks with IToolForm properties. Removes hacks, and some winforms dependencies in tools, and allows for easier implementation of closeable tools (#2719)
This commit is contained in:
parent
2ba5fe338a
commit
838f571e0b
|
@ -40,12 +40,23 @@
|
||||||
/// </summary>
|
/// </summary>
|
||||||
bool AskSaveChanges();
|
bool AskSaveChanges();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a value indicating whether or not the current tool is active and running
|
||||||
|
/// </summary>
|
||||||
|
bool IsActive { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether a tool is actually open.
|
||||||
|
/// This value should be the same as <see cref="IsActive"/>
|
||||||
|
/// except for tools that can be closed/hidden,
|
||||||
|
/// where the tool can be active but not loaded
|
||||||
|
/// </summary>
|
||||||
|
bool IsLoaded { get; }
|
||||||
|
|
||||||
// Necessary winform calls
|
// Necessary winform calls
|
||||||
bool Focus();
|
bool Focus();
|
||||||
bool ContainsFocus { get; }
|
bool ContainsFocus { get; }
|
||||||
void Show();
|
void Show();
|
||||||
void Close();
|
void Close();
|
||||||
bool IsDisposed { get; }
|
|
||||||
bool IsHandleCreated { get; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,9 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
public virtual bool AskSaveChanges() => true;
|
public virtual bool AskSaveChanges() => true;
|
||||||
|
|
||||||
|
public virtual bool IsActive => IsHandleCreated && !IsDisposed;
|
||||||
|
public virtual bool IsLoaded => IsActive;
|
||||||
|
|
||||||
public virtual void Restart() {}
|
public virtual void Restart() {}
|
||||||
|
|
||||||
public virtual void UpdateValues(ToolFormUpdateType type)
|
public virtual void UpdateValues(ToolFormUpdateType type)
|
||||||
|
|
|
@ -111,15 +111,17 @@ namespace BizHawk.Client.EmuHawk
|
||||||
var existingTool = _tools.OfType<T>().FirstOrDefault();
|
var existingTool = _tools.OfType<T>().FirstOrDefault();
|
||||||
if (existingTool != null)
|
if (existingTool != null)
|
||||||
{
|
{
|
||||||
if (!existingTool.IsDisposed)
|
if (existingTool.IsLoaded)
|
||||||
{
|
{
|
||||||
if (focus)
|
if (focus)
|
||||||
{
|
{
|
||||||
existingTool.Show();
|
existingTool.Show();
|
||||||
existingTool.Focus();
|
existingTool.Focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
return existingTool;
|
return existingTool;
|
||||||
}
|
}
|
||||||
|
|
||||||
_tools.Remove(existingTool);
|
_tools.Remove(existingTool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +163,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
var existingTool = _tools.OfType<IExternalToolForm>().FirstOrDefault(t => t.GetType().Assembly.Location == toolPath);
|
var existingTool = _tools.OfType<IExternalToolForm>().FirstOrDefault(t => t.GetType().Assembly.Location == toolPath);
|
||||||
if (existingTool != null)
|
if (existingTool != null)
|
||||||
{
|
{
|
||||||
if (!existingTool.IsDisposed)
|
if (existingTool.IsActive)
|
||||||
{
|
{
|
||||||
if (focus)
|
if (focus)
|
||||||
{
|
{
|
||||||
|
@ -170,6 +172,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
return existingTool;
|
return existingTool;
|
||||||
}
|
}
|
||||||
|
|
||||||
_tools.Remove(existingTool);
|
_tools.Remove(existingTool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -457,7 +460,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
var existingTool = _tools.FirstOrDefault(t => t is T);
|
var existingTool = _tools.FirstOrDefault(t => t is T);
|
||||||
if (existingTool != null)
|
if (existingTool != null)
|
||||||
{
|
{
|
||||||
return !existingTool.IsDisposed;
|
return existingTool.IsActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -466,12 +469,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
public bool IsLoaded(Type toolType)
|
public bool IsLoaded(Type toolType)
|
||||||
{
|
{
|
||||||
var existingTool = _tools.FirstOrDefault(t => t.GetType() == toolType);
|
var existingTool = _tools.FirstOrDefault(t => t.GetType() == toolType);
|
||||||
if (existingTool != null)
|
return existingTool != null && existingTool.IsActive;
|
||||||
{
|
|
||||||
return !existingTool.IsDisposed || (existingTool is RamWatch && _config.DisplayRamWatch);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsOnScreen(Point topLeft)
|
public bool IsOnScreen(Point topLeft)
|
||||||
|
@ -486,7 +484,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
/// <typeparam name="T">Type of tool to check</typeparam>
|
/// <typeparam name="T">Type of tool to check</typeparam>
|
||||||
public bool Has<T>() where T : IToolForm
|
public bool Has<T>() where T : IToolForm
|
||||||
{
|
{
|
||||||
return _tools.Any(t => t is T && !t.IsDisposed);
|
return _tools.Any(t => t is T && t.IsActive);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -510,13 +508,9 @@ namespace BizHawk.Client.EmuHawk
|
||||||
public void UpdateValues<T>() where T : IToolForm
|
public void UpdateValues<T>() where T : IToolForm
|
||||||
{
|
{
|
||||||
var tool = _tools.FirstOrDefault(t => t is T);
|
var tool = _tools.FirstOrDefault(t => t is T);
|
||||||
if (tool != null)
|
if (tool != null && tool.IsActive)
|
||||||
{
|
{
|
||||||
if (!tool.IsDisposed ||
|
tool.UpdateValues(ToolFormUpdateType.General);
|
||||||
(tool is RamWatch && _config.DisplayRamWatch)) // RAM Watch hack, on screen display should run even if RAM Watch is closed
|
|
||||||
{
|
|
||||||
tool.UpdateValues(ToolFormUpdateType.General);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -541,10 +535,13 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
ServiceInjector.UpdateServices(_emulator.ServiceProvider, tool);
|
ServiceInjector.UpdateServices(_emulator.ServiceProvider, tool);
|
||||||
|
|
||||||
if ((tool.IsHandleCreated && !tool.IsDisposed) || tool is RamWatch) // Hack for RAM Watch - in display watches mode it wants to keep running even closed, it will handle disposed logic
|
if (tool.IsActive)
|
||||||
{
|
{
|
||||||
if (tool is IExternalToolForm)
|
if (tool is IExternalToolForm)
|
||||||
|
{
|
||||||
ApiInjector.UpdateApis(ApiProvider, tool);
|
ApiInjector.UpdateApis(ApiProvider, tool);
|
||||||
|
}
|
||||||
|
|
||||||
tool.Restart();
|
tool.Restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -691,8 +688,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
foreach (var tool in _tools)
|
foreach (var tool in _tools)
|
||||||
{
|
{
|
||||||
if (!tool.IsDisposed
|
if (tool.IsActive)
|
||||||
|| (tool is RamWatch && _config.DisplayRamWatch)) // RAM Watch hack, on screen display should run even if RAM Watch is closed
|
|
||||||
{
|
{
|
||||||
tool.UpdateValues(ToolFormUpdateType.PreFrame);
|
tool.UpdateValues(ToolFormUpdateType.PreFrame);
|
||||||
}
|
}
|
||||||
|
@ -703,8 +699,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
foreach (var tool in _tools)
|
foreach (var tool in _tools)
|
||||||
{
|
{
|
||||||
if (!tool.IsDisposed
|
if (tool.IsActive)
|
||||||
|| (tool is RamWatch && _config.DisplayRamWatch)) // RAM Watch hack, on screen display should run even if RAM Watch is closed
|
|
||||||
{
|
{
|
||||||
tool.UpdateValues(ToolFormUpdateType.PostFrame);
|
tool.UpdateValues(ToolFormUpdateType.PostFrame);
|
||||||
}
|
}
|
||||||
|
@ -715,8 +710,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
foreach (var tool in _tools)
|
foreach (var tool in _tools)
|
||||||
{
|
{
|
||||||
if (!tool.IsDisposed
|
if (tool.IsActive)
|
||||||
|| (tool is RamWatch && _config.DisplayRamWatch)) // RAM Watch hack, on screen display should run even if RAM Watch is closed
|
|
||||||
{
|
{
|
||||||
tool.UpdateValues(ToolFormUpdateType.FastPreFrame);
|
tool.UpdateValues(ToolFormUpdateType.FastPreFrame);
|
||||||
}
|
}
|
||||||
|
@ -727,8 +721,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
foreach (var tool in _tools)
|
foreach (var tool in _tools)
|
||||||
{
|
{
|
||||||
if (!tool.IsDisposed
|
if (tool.IsActive)
|
||||||
|| (tool is RamWatch && _config.DisplayRamWatch)) // RAM Watch hack, on screen display should run even if RAM Watch is closed
|
|
||||||
{
|
{
|
||||||
tool.UpdateValues(ToolFormUpdateType.FastPostFrame);
|
tool.UpdateValues(ToolFormUpdateType.FastPostFrame);
|
||||||
}
|
}
|
||||||
|
@ -767,10 +760,11 @@ namespace BizHawk.Client.EmuHawk
|
||||||
T tool = _tools.OfType<T>().FirstOrDefault();
|
T tool = _tools.OfType<T>().FirstOrDefault();
|
||||||
if (tool != null)
|
if (tool != null)
|
||||||
{
|
{
|
||||||
if (!tool.IsDisposed)
|
if (tool.IsActive)
|
||||||
{
|
{
|
||||||
return tool;
|
return tool;
|
||||||
}
|
}
|
||||||
|
|
||||||
_tools.Remove(tool);
|
_tools.Remove(tool);
|
||||||
}
|
}
|
||||||
tool = new T();
|
tool = new T();
|
||||||
|
@ -794,7 +788,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
public void LoadRamWatch(bool loadDialog)
|
public void LoadRamWatch(bool loadDialog)
|
||||||
{
|
{
|
||||||
if (IsLoaded<RamWatch>())
|
if (IsLoaded<RamWatch>() && !_config.DisplayRamWatch)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,6 +102,9 @@ namespace BizHawk.Client.EmuHawk
|
||||||
SetColumns();
|
SetColumns();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool IsActive => Config!.DisplayRamWatch || base.IsActive;
|
||||||
|
public override bool IsLoaded => base.IsActive;
|
||||||
|
|
||||||
private void SetColumns()
|
private void SetColumns()
|
||||||
{
|
{
|
||||||
WatchListView.AllColumns.AddRange(Settings.Columns);
|
WatchListView.AllColumns.AddRange(Settings.Columns);
|
||||||
|
@ -117,14 +120,14 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
Columns = new List<RollColumn>
|
Columns = new List<RollColumn>
|
||||||
{
|
{
|
||||||
new RollColumn { Text = "Address", Name = WatchList.Address, Visible = true, UnscaledWidth = 60, Type = ColumnType.Text },
|
new() { Text = "Address", Name = WatchList.Address, Visible = true, UnscaledWidth = 60, Type = ColumnType.Text },
|
||||||
new RollColumn { Text = "Value", Name = WatchList.Value, Visible = true, UnscaledWidth = 59, Type = ColumnType.Text },
|
new() { Text = "Value", Name = WatchList.Value, Visible = true, UnscaledWidth = 59, Type = ColumnType.Text },
|
||||||
new RollColumn { Text = "Prev", Name = WatchList.Prev, Visible = false, UnscaledWidth = 59, Type = ColumnType.Text },
|
new() { Text = "Prev", Name = WatchList.Prev, Visible = false, UnscaledWidth = 59, Type = ColumnType.Text },
|
||||||
new RollColumn { Text = "Changes", Name = WatchList.ChangesCol, Visible = true, UnscaledWidth = 60, Type = ColumnType.Text },
|
new() { Text = "Changes", Name = WatchList.ChangesCol, Visible = true, UnscaledWidth = 60, Type = ColumnType.Text },
|
||||||
new RollColumn { Text = "Diff", Name = WatchList.Diff, Visible = false, UnscaledWidth = 59, Type = ColumnType.Text },
|
new() { Text = "Diff", Name = WatchList.Diff, Visible = false, UnscaledWidth = 59, Type = ColumnType.Text },
|
||||||
new RollColumn { Text = "Type", Name = WatchList.Type, Visible = false, UnscaledWidth = 55, Type = ColumnType.Text },
|
new() { Text = "Type", Name = WatchList.Type, Visible = false, UnscaledWidth = 55, Type = ColumnType.Text },
|
||||||
new RollColumn { Text = "Domain", Name = WatchList.Domain, Visible = true, UnscaledWidth = 55, Type = ColumnType.Text },
|
new() { Text = "Domain", Name = WatchList.Domain, Visible = true, UnscaledWidth = 55, Type = ColumnType.Text },
|
||||||
new RollColumn { Text = "Notes", Name = WatchList.Notes, Visible = true, UnscaledWidth = 128, Type = ColumnType.Text }
|
new() { Text = "Notes", Name = WatchList.Notes, Visible = true, UnscaledWidth = 128, Type = ColumnType.Text }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue