GUI: Allow plugins to be reset to default options
This commit is contained in:
@@ -175,7 +175,7 @@
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="50" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="50" />
|
||||
<RowDefinition Height="70" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Title -->
|
||||
@@ -197,8 +197,9 @@
|
||||
</ListBox>
|
||||
|
||||
<!-- Accept button -->
|
||||
<StackPanel Grid.Row="2" VerticalAlignment="Bottom" Margin="10">
|
||||
<Button Name="okButton" Click="okButton_Click" Style="{StaticResource LightBoxButton}" IsDefault="True" Width="150" FontSize="18">OK</Button>
|
||||
</StackPanel>
|
||||
<DockPanel Grid.Row="2" VerticalAlignment="Bottom" Margin="10">
|
||||
<Button Name="resetButton" DockPanel.Dock="Left" Click="resetButton_Click" Style="{StaticResource LightBoxButton}" Width="150" FontSize="18" Padding="5">Defaults</Button>
|
||||
<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>
|
||||
</Window>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user