From 096b2d9c5d9da67491c319880a8819b18d18d2b1 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Mon, 28 Dec 2020 01:23:35 +0100 Subject: [PATCH] GUI: Allow plugins to be reset to default options --- .../Plugins/Internal/PluginManager.cs | 9 +++++++++ .../PluginConfigurationDialog.xaml | 9 +++++---- .../PluginConfigurationDialog.xaml.cs | 17 ++++++++++++++--- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Il2CppInspector.Common/Plugins/Internal/PluginManager.cs b/Il2CppInspector.Common/Plugins/Internal/PluginManager.cs index 9656f02..0656cba 100644 --- a/Il2CppInspector.Common/Plugins/Internal/PluginManager.cs +++ b/Il2CppInspector.Common/Plugins/Internal/PluginManager.cs @@ -249,6 +249,15 @@ namespace Il2CppInspector } } + // Reset a plugin to its default "factory" state + public static IPlugin Reset(IPlugin plugin) { + var managedPlugin = AsInstance.ManagedPlugins.Single(p => p.Plugin == plugin); + + var replacement = (IPlugin) Activator.CreateInstance(plugin.GetType()); + managedPlugin.Plugin = replacement; + return replacement; + } + // Commit options change for the specified plugin public static PluginOptionsChangedEventInfo OptionsChanged(IPlugin plugin) { var eventInfo = new PluginOptionsChangedEventInfo(); diff --git a/Il2CppInspector.GUI/PluginConfigurationDialog.xaml b/Il2CppInspector.GUI/PluginConfigurationDialog.xaml index b5c165a..37e96ce 100644 --- a/Il2CppInspector.GUI/PluginConfigurationDialog.xaml +++ b/Il2CppInspector.GUI/PluginConfigurationDialog.xaml @@ -175,7 +175,7 @@ - + @@ -197,8 +197,9 @@ - - - + + + + diff --git a/Il2CppInspector.GUI/PluginConfigurationDialog.xaml.cs b/Il2CppInspector.GUI/PluginConfigurationDialog.xaml.cs index 78c40ac..bf070e3 100644 --- a/Il2CppInspector.GUI/PluginConfigurationDialog.xaml.cs +++ b/Il2CppInspector.GUI/PluginConfigurationDialog.xaml.cs @@ -55,7 +55,7 @@ namespace Il2CppInspectorGUI public partial class PluginConfigurationDialog : Window { // Item to configure - public IPlugin Plugin { get; } + public IPlugin Plugin { get; private set; } // This helps us find XAML elements withing a DataTemplate // Adapted from https://docs.microsoft.com/en-us/dotnet/desktop/wpf/data/how-to-find-datatemplate-generated-elements?view=netframeworkdesktop-4.8 @@ -85,7 +85,7 @@ namespace Il2CppInspectorGUI // then force WPF to try to update the source property to see if it raises an exception // and cause the DataTriggers to execute. // This relies on a 'valueControl' named element existing. - void OptionsListBoxStatusChanged(object sender, EventArgs e) { + private void OptionsListBoxStatusChanged(object sender, EventArgs e) { // Wait for items to be generated if (lstOptions.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated) return; @@ -94,7 +94,6 @@ namespace Il2CppInspectorGUI lstOptions.ItemContainerGenerator.StatusChanged -= OptionsListBoxStatusChanged; // your items are now generated - // Adapted from https://stackoverflow.com/a/18008545 foreach (var item in lstOptions.Items) { var listBoxItem = lstOptions.ItemContainerGenerator.ContainerFromItem(item); @@ -202,5 +201,17 @@ namespace Il2CppInspectorGUI if (PluginManager.OptionsChanged(Plugin).Error != null) e.Cancel = true; } + + // Reset a plugin's settings + private void resetButton_Click(object sender, RoutedEventArgs e) { + // Get new context + Plugin = PluginManager.Reset(Plugin); + + // Validate options once they have loaded + lstOptions.ItemContainerGenerator.StatusChanged += OptionsListBoxStatusChanged; + + // Replace options in ListBox + lstOptions.ItemsSource = Plugin.Options; + } } }