Plugins: Don't force validation on disabled options
This commit is contained in:
@@ -95,6 +95,12 @@ namespace Il2CppInspector.PluginAPI.V100
|
|||||||
public T Value {
|
public T Value {
|
||||||
get => _value;
|
get => _value;
|
||||||
set {
|
set {
|
||||||
|
// Disabled options can be set to invalid values
|
||||||
|
if (!If()) {
|
||||||
|
_value = value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Perform internal validation
|
// Perform internal validation
|
||||||
InternalValidate(value);
|
InternalValidate(value);
|
||||||
|
|
||||||
|
|||||||
@@ -109,7 +109,11 @@ namespace Il2CppInspectorGUI
|
|||||||
// Remove event
|
// Remove event
|
||||||
lstOptions.ItemContainerGenerator.StatusChanged -= OptionsListBoxStatusChanged;
|
lstOptions.ItemContainerGenerator.StatusChanged -= OptionsListBoxStatusChanged;
|
||||||
|
|
||||||
// your items are now generated
|
// Validate all options
|
||||||
|
ValidateAllOptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ValidateAllOptions() {
|
||||||
// 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);
|
||||||
@@ -236,14 +240,18 @@ namespace Il2CppInspectorGUI
|
|||||||
if (lstOptions.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated)
|
if (lstOptions.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (var item in lstOptions.Items) {
|
// Update If binding for all options
|
||||||
|
foreach (IPluginOption item in lstOptions.Items) {
|
||||||
var listBoxItem = lstOptions.ItemContainerGenerator.ContainerFromItem(item);
|
var listBoxItem = lstOptions.ItemContainerGenerator.ContainerFromItem(item);
|
||||||
var presenter = FindVisualChild<ContentPresenter>(listBoxItem);
|
var presenter = FindVisualChild<ContentPresenter>(listBoxItem);
|
||||||
var dataTemplate = presenter.ContentTemplateSelector.SelectTemplate(item, listBoxItem);
|
var dataTemplate = presenter.ContentTemplateSelector.SelectTemplate(item, listBoxItem);
|
||||||
|
|
||||||
if (dataTemplate.FindName("optionPanel", presenter) is FrameworkElement boundControl)
|
if (dataTemplate.FindName("optionPanel", presenter) is FrameworkElement boundControl)
|
||||||
boundControl.IsEnabled = ((IPluginOption) item).If();
|
boundControl.IsEnabled = item.If();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove validation errors for disabled options
|
||||||
|
ValidateAllOptions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user