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:
adelikat 2021-04-23 15:41:58 -05:00 committed by GitHub
parent 2ba5fe338a
commit 838f571e0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 37 deletions

View File

@ -40,12 +40,23 @@
/// </summary>
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
bool Focus();
bool ContainsFocus { get; }
void Show();
void Close();
bool IsDisposed { get; }
bool IsHandleCreated { get; }
}
}

View File

@ -27,6 +27,9 @@ namespace BizHawk.Client.EmuHawk
public virtual bool AskSaveChanges() => true;
public virtual bool IsActive => IsHandleCreated && !IsDisposed;
public virtual bool IsLoaded => IsActive;
public virtual void Restart() {}
public virtual void UpdateValues(ToolFormUpdateType type)

View File

@ -111,15 +111,17 @@ namespace BizHawk.Client.EmuHawk
var existingTool = _tools.OfType<T>().FirstOrDefault();
if (existingTool != null)
{
if (!existingTool.IsDisposed)
if (existingTool.IsLoaded)
{
if (focus)
{
existingTool.Show();
existingTool.Focus();
}
return existingTool;
}
_tools.Remove(existingTool);
}
@ -161,7 +163,7 @@ namespace BizHawk.Client.EmuHawk
var existingTool = _tools.OfType<IExternalToolForm>().FirstOrDefault(t => t.GetType().Assembly.Location == toolPath);
if (existingTool != null)
{
if (!existingTool.IsDisposed)
if (existingTool.IsActive)
{
if (focus)
{
@ -170,6 +172,7 @@ namespace BizHawk.Client.EmuHawk
}
return existingTool;
}
_tools.Remove(existingTool);
}
@ -457,7 +460,7 @@ namespace BizHawk.Client.EmuHawk
var existingTool = _tools.FirstOrDefault(t => t is T);
if (existingTool != null)
{
return !existingTool.IsDisposed;
return existingTool.IsActive;
}
return false;
@ -466,12 +469,7 @@ namespace BizHawk.Client.EmuHawk
public bool IsLoaded(Type toolType)
{
var existingTool = _tools.FirstOrDefault(t => t.GetType() == toolType);
if (existingTool != null)
{
return !existingTool.IsDisposed || (existingTool is RamWatch && _config.DisplayRamWatch);
}
return false;
return existingTool != null && existingTool.IsActive;
}
public bool IsOnScreen(Point topLeft)
@ -486,7 +484,7 @@ namespace BizHawk.Client.EmuHawk
/// <typeparam name="T">Type of tool to check</typeparam>
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>
@ -510,13 +508,9 @@ namespace BizHawk.Client.EmuHawk
public void UpdateValues<T>() where T : IToolForm
{
var tool = _tools.FirstOrDefault(t => t is T);
if (tool != null)
if (tool != null && tool.IsActive)
{
if (!tool.IsDisposed ||
(tool is RamWatch && _config.DisplayRamWatch)) // RAM Watch hack, on screen display should run even if RAM Watch is closed
{
tool.UpdateValues(ToolFormUpdateType.General);
}
tool.UpdateValues(ToolFormUpdateType.General);
}
}
@ -541,10 +535,13 @@ namespace BizHawk.Client.EmuHawk
{
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)
{
ApiInjector.UpdateApis(ApiProvider, tool);
}
tool.Restart();
}
}
@ -691,8 +688,7 @@ namespace BizHawk.Client.EmuHawk
{
foreach (var tool in _tools)
{
if (!tool.IsDisposed
|| (tool is RamWatch && _config.DisplayRamWatch)) // RAM Watch hack, on screen display should run even if RAM Watch is closed
if (tool.IsActive)
{
tool.UpdateValues(ToolFormUpdateType.PreFrame);
}
@ -703,8 +699,7 @@ namespace BizHawk.Client.EmuHawk
{
foreach (var tool in _tools)
{
if (!tool.IsDisposed
|| (tool is RamWatch && _config.DisplayRamWatch)) // RAM Watch hack, on screen display should run even if RAM Watch is closed
if (tool.IsActive)
{
tool.UpdateValues(ToolFormUpdateType.PostFrame);
}
@ -715,8 +710,7 @@ namespace BizHawk.Client.EmuHawk
{
foreach (var tool in _tools)
{
if (!tool.IsDisposed
|| (tool is RamWatch && _config.DisplayRamWatch)) // RAM Watch hack, on screen display should run even if RAM Watch is closed
if (tool.IsActive)
{
tool.UpdateValues(ToolFormUpdateType.FastPreFrame);
}
@ -727,8 +721,7 @@ namespace BizHawk.Client.EmuHawk
{
foreach (var tool in _tools)
{
if (!tool.IsDisposed
|| (tool is RamWatch && _config.DisplayRamWatch)) // RAM Watch hack, on screen display should run even if RAM Watch is closed
if (tool.IsActive)
{
tool.UpdateValues(ToolFormUpdateType.FastPostFrame);
}
@ -767,10 +760,11 @@ namespace BizHawk.Client.EmuHawk
T tool = _tools.OfType<T>().FirstOrDefault();
if (tool != null)
{
if (!tool.IsDisposed)
if (tool.IsActive)
{
return tool;
}
_tools.Remove(tool);
}
tool = new T();
@ -794,7 +788,7 @@ namespace BizHawk.Client.EmuHawk
public void LoadRamWatch(bool loadDialog)
{
if (IsLoaded<RamWatch>())
if (IsLoaded<RamWatch>() && !_config.DisplayRamWatch)
{
return;
}

View File

@ -102,6 +102,9 @@ namespace BizHawk.Client.EmuHawk
SetColumns();
}
public override bool IsActive => Config!.DisplayRamWatch || base.IsActive;
public override bool IsLoaded => base.IsActive;
private void SetColumns()
{
WatchListView.AllColumns.AddRange(Settings.Columns);
@ -117,14 +120,14 @@ namespace BizHawk.Client.EmuHawk
{
Columns = new List<RollColumn>
{
new RollColumn { 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 RollColumn { 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 RollColumn { 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 RollColumn { 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 = "Address", Name = WatchList.Address, Visible = true, UnscaledWidth = 60, Type = ColumnType.Text },
new() { Text = "Value", Name = WatchList.Value, Visible = true, UnscaledWidth = 59, Type = ColumnType.Text },
new() { Text = "Prev", Name = WatchList.Prev, Visible = false, UnscaledWidth = 59, Type = ColumnType.Text },
new() { Text = "Changes", Name = WatchList.ChangesCol, Visible = true, UnscaledWidth = 60, Type = ColumnType.Text },
new() { Text = "Diff", Name = WatchList.Diff, Visible = false, UnscaledWidth = 59, Type = ColumnType.Text },
new() { Text = "Type", Name = WatchList.Type, Visible = false, UnscaledWidth = 55, Type = ColumnType.Text },
new() { Text = "Domain", Name = WatchList.Domain, Visible = true, UnscaledWidth = 55, Type = ColumnType.Text },
new() { Text = "Notes", Name = WatchList.Notes, Visible = true, UnscaledWidth = 128, Type = ColumnType.Text }
};
}