GUI: Allow plugins to be reset to default options
This commit is contained in:
@@ -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
|
// Commit options change for the specified plugin
|
||||||
public static PluginOptionsChangedEventInfo OptionsChanged(IPlugin plugin) {
|
public static PluginOptionsChangedEventInfo OptionsChanged(IPlugin plugin) {
|
||||||
var eventInfo = new PluginOptionsChangedEventInfo();
|
var eventInfo = new PluginOptionsChangedEventInfo();
|
||||||
|
|||||||
@@ -175,7 +175,7 @@
|
|||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="50" />
|
<RowDefinition Height="50" />
|
||||||
<RowDefinition Height="*" />
|
<RowDefinition Height="*" />
|
||||||
<RowDefinition Height="50" />
|
<RowDefinition Height="70" />
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
<!-- Title -->
|
<!-- Title -->
|
||||||
@@ -197,8 +197,9 @@
|
|||||||
</ListBox>
|
</ListBox>
|
||||||
|
|
||||||
<!-- Accept button -->
|
<!-- Accept button -->
|
||||||
<StackPanel Grid.Row="2" VerticalAlignment="Bottom" Margin="10">
|
<DockPanel Grid.Row="2" VerticalAlignment="Bottom" Margin="10">
|
||||||
<Button Name="okButton" Click="okButton_Click" Style="{StaticResource LightBoxButton}" IsDefault="True" Width="150" FontSize="18">OK</Button>
|
<Button Name="resetButton" DockPanel.Dock="Left" Click="resetButton_Click" Style="{StaticResource LightBoxButton}" Width="150" FontSize="18" Padding="5">Defaults</Button>
|
||||||
</StackPanel>
|
<Button Name="okButton" DockPanel.Dock="Right" HorizontalAlignment="Right" Click="okButton_Click" Style="{StaticResource LightBoxButton}" IsDefault="True" Width="150" FontSize="18" Padding="5">OK</Button>
|
||||||
|
</DockPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ namespace Il2CppInspectorGUI
|
|||||||
public partial class PluginConfigurationDialog : Window
|
public partial class PluginConfigurationDialog : Window
|
||||||
{
|
{
|
||||||
// Item to configure
|
// Item to configure
|
||||||
public IPlugin Plugin { get; }
|
public IPlugin Plugin { get; private set; }
|
||||||
|
|
||||||
// This helps us find XAML elements withing a DataTemplate
|
// 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
|
// 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
|
// then force WPF to try to update the source property to see if it raises an exception
|
||||||
// and cause the DataTriggers to execute.
|
// and cause the DataTriggers to execute.
|
||||||
// This relies on a 'valueControl' named element existing.
|
// 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
|
// Wait for items to be generated
|
||||||
if (lstOptions.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated)
|
if (lstOptions.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated)
|
||||||
return;
|
return;
|
||||||
@@ -94,7 +94,6 @@ namespace Il2CppInspectorGUI
|
|||||||
lstOptions.ItemContainerGenerator.StatusChanged -= OptionsListBoxStatusChanged;
|
lstOptions.ItemContainerGenerator.StatusChanged -= OptionsListBoxStatusChanged;
|
||||||
|
|
||||||
// your items are now generated
|
// your items are now generated
|
||||||
|
|
||||||
// Adapted from https://stackoverflow.com/a/18008545
|
// Adapted from https://stackoverflow.com/a/18008545
|
||||||
foreach (var item in lstOptions.Items) {
|
foreach (var item in lstOptions.Items) {
|
||||||
var listBoxItem = lstOptions.ItemContainerGenerator.ContainerFromItem(item);
|
var listBoxItem = lstOptions.ItemContainerGenerator.ContainerFromItem(item);
|
||||||
@@ -202,5 +201,17 @@ namespace Il2CppInspectorGUI
|
|||||||
if (PluginManager.OptionsChanged(Plugin).Error != null)
|
if (PluginManager.OptionsChanged(Plugin).Error != null)
|
||||||
e.Cancel = true;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user