GUI: Add Cancel button to plugin configuration dialog
This commit is contained in:
@@ -212,9 +212,14 @@
|
|||||||
</ListBox.ItemTemplateSelector>
|
</ListBox.ItemTemplateSelector>
|
||||||
</ListBox>
|
</ListBox>
|
||||||
|
|
||||||
<!-- Accept button -->
|
|
||||||
<DockPanel Grid.Row="2" VerticalAlignment="Bottom" Margin="10">
|
<DockPanel Grid.Row="2" VerticalAlignment="Bottom" Margin="10">
|
||||||
|
<!-- Reset options to defaults -->
|
||||||
<Button Name="resetButton" DockPanel.Dock="Left" Click="resetButton_Click" Style="{StaticResource LightBoxButton}" Width="150" FontSize="18" Padding="5">Defaults</Button>
|
<Button Name="resetButton" DockPanel.Dock="Left" Click="resetButton_Click" Style="{StaticResource LightBoxButton}" Width="150" FontSize="18" Padding="5">Defaults</Button>
|
||||||
|
|
||||||
|
<!-- Cancel button -->
|
||||||
|
<Button Name="cancelButton" DockPanel.Dock="Right" HorizontalAlignment="Right" Click="cancelButton_Click" Style="{StaticResource LightBoxButton}" IsDefault="True" Width="150" FontSize="18" Padding="5" Margin="10,0,0,0">Cancel</Button>
|
||||||
|
|
||||||
|
<!-- Accept 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>
|
<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>
|
</DockPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@@ -71,7 +71,11 @@ namespace Il2CppInspectorGUI
|
|||||||
public partial class PluginConfigurationDialog : Window
|
public partial class PluginConfigurationDialog : Window
|
||||||
{
|
{
|
||||||
// Item to configure
|
// Item to configure
|
||||||
public IPlugin Plugin { get; private set; }
|
private ManagedPlugin ManagedPlugin { get; set; }
|
||||||
|
public IPlugin Plugin => ManagedPlugin.Plugin;
|
||||||
|
|
||||||
|
// Options when window was opened
|
||||||
|
public Dictionary<string, object> OriginalOptions { 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
|
||||||
@@ -135,10 +139,13 @@ namespace Il2CppInspectorGUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize configuration dialog window
|
// Initialize configuration dialog window
|
||||||
public PluginConfigurationDialog(IPlugin plugin) {
|
public PluginConfigurationDialog(ManagedPlugin plugin) {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
DataContext = this;
|
DataContext = this;
|
||||||
Plugin = plugin;
|
ManagedPlugin = plugin;
|
||||||
|
|
||||||
|
// Copy current options
|
||||||
|
OriginalOptions = new Dictionary<string, object>(Plugin.Options.ToDictionary(o => o.Name, o => o.Value));
|
||||||
|
|
||||||
// Validate options once they have loaded
|
// Validate options once they have loaded
|
||||||
lstOptions.ItemContainerGenerator.StatusChanged += OptionsListBoxStatusChanged;
|
lstOptions.ItemContainerGenerator.StatusChanged += OptionsListBoxStatusChanged;
|
||||||
@@ -210,6 +217,11 @@ namespace Il2CppInspectorGUI
|
|||||||
|
|
||||||
// Check options validity before allowing the dialog to close either by clicking OK or the close icon
|
// Check options validity before allowing the dialog to close either by clicking OK or the close icon
|
||||||
private void Window_Closing(object sender, CancelEventArgs e) {
|
private void Window_Closing(object sender, CancelEventArgs e) {
|
||||||
|
|
||||||
|
// Do nothing if user clicked Cancel
|
||||||
|
if (DialogResult == false)
|
||||||
|
return;
|
||||||
|
|
||||||
// Don't allow the window to close if any of the options are invalid
|
// Don't allow the window to close if any of the options are invalid
|
||||||
if (!IsValid(lstOptions)) {
|
if (!IsValid(lstOptions)) {
|
||||||
MessageBox.Show("One or more options are invalid.", "Il2CppInspector Plugin Configuration");
|
MessageBox.Show("One or more options are invalid.", "Il2CppInspector Plugin Configuration");
|
||||||
@@ -224,8 +236,8 @@ namespace Il2CppInspectorGUI
|
|||||||
|
|
||||||
// Reset a plugin's settings
|
// Reset a plugin's settings
|
||||||
private void resetButton_Click(object sender, RoutedEventArgs e) {
|
private void resetButton_Click(object sender, RoutedEventArgs e) {
|
||||||
// Get new context
|
// Get new context (updates ManagedPlugin)
|
||||||
Plugin = PluginManager.Reset(Plugin);
|
PluginManager.Reset(Plugin);
|
||||||
|
|
||||||
// Validate options once they have loaded
|
// Validate options once they have loaded
|
||||||
lstOptions.ItemContainerGenerator.StatusChanged += OptionsListBoxStatusChanged;
|
lstOptions.ItemContainerGenerator.StatusChanged += OptionsListBoxStatusChanged;
|
||||||
@@ -253,5 +265,17 @@ namespace Il2CppInspectorGUI
|
|||||||
// Remove validation errors for disabled options
|
// Remove validation errors for disabled options
|
||||||
ValidateAllOptions();
|
ValidateAllOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void cancelButton_Click(object sender, RoutedEventArgs e) {
|
||||||
|
|
||||||
|
// Revert changes
|
||||||
|
foreach (var option in OriginalOptions)
|
||||||
|
ManagedPlugin[option.Key] = option.Value;
|
||||||
|
|
||||||
|
// Replace options in ListBox
|
||||||
|
lstOptions.ItemsSource = Plugin.Options;
|
||||||
|
|
||||||
|
DialogResult = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ namespace Il2CppInspector.GUI
|
|||||||
private void btnConfig_Click(object sender, RoutedEventArgs e) {
|
private void btnConfig_Click(object sender, RoutedEventArgs e) {
|
||||||
var plugin = (ManagedPlugin) ((Button) sender).DataContext;
|
var plugin = (ManagedPlugin) ((Button) sender).DataContext;
|
||||||
|
|
||||||
var configDlg = new Il2CppInspectorGUI.PluginConfigurationDialog(plugin.Plugin);
|
var configDlg = new Il2CppInspectorGUI.PluginConfigurationDialog(plugin);
|
||||||
configDlg.Owner = this;
|
configDlg.Owner = this;
|
||||||
configDlg.ShowDialog();
|
configDlg.ShowDialog();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user