Lua console - implement saving/loading of column info

This commit is contained in:
adelikat 2019-10-19 10:45:42 -05:00
parent f802f48754
commit 6c22e1c4c6
5 changed files with 35 additions and 1 deletions

View File

@ -123,6 +123,7 @@
<Compile Include="config\ConfigPersistAttribute.cs" />
<Compile Include="config\ConfigService.cs" />
<Compile Include="config\PathEntry.cs" />
<Compile Include="config\RestoreDefaultsAttribute.cs" />
<Compile Include="config\ToolDialogSettings.cs" />
<Compile Include="ControllerBinding.cs" />
<Compile Include="CoreFileProvider.cs" />

View File

@ -0,0 +1,12 @@
using System;
namespace BizHawk.Client.Common
{
/// <summary>
/// Defines a method to be called when a tool dialog's Restore Defaults method is called
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public class RestoreDefaultsAttribute : Attribute
{
}
}

View File

@ -134,7 +134,7 @@ namespace BizHawk.Client.EmuHawk
private void LuaConsole_Load(object sender, EventArgs e)
{
// Hack for previous config settings
if (Settings.Columns.Any(c => string.IsNullOrWhiteSpace(c.Text)))
if (Settings.Columns.Any(c => c.Text == null))
{
Settings = new LuaConsoleSettings();
}
@ -154,6 +154,7 @@ namespace BizHawk.Client.EmuHawk
}
}
LuaListView.AllColumns.Clear();
SetColumns();
}
@ -1468,5 +1469,14 @@ namespace BizHawk.Client.EmuHawk
}
}
}
[RestoreDefaults]
private void RestoreDefaults()
{
Settings = new LuaConsoleSettings();
LuaListView.AllColumns.Clear();
SetColumns();
UpdateDialog();
}
}
}

View File

@ -323,6 +323,11 @@ namespace BizHawk.Client.EmuHawk
settings.RestoreDefaults();
RefreshSettings(form, dest, settings, idx);
form.Size = oldsize;
form.GetType()
.GetMethodsWithAttrib(typeof(RestoreDefaultsAttribute))
.FirstOrDefault()
?.Invoke(form, new object[0]);
};
}

View File

@ -19,6 +19,12 @@ namespace BizHawk.Common.ReflectionExtensions
.Where(p => p.GetCustomAttributes(attributeType, false).Length > 0);
}
public static IEnumerable<MethodInfo> GetMethodsWithAttrib(this Type type, Type attributeType)
{
return type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic)
.Where(p => p.GetCustomAttributes(attributeType, false).Length > 0);
}
/// <summary>
/// Gets the description attribute from an object
/// </summary>