diff --git a/app/MindWork AI Studio/Settings/ConfigMeta.cs b/app/MindWork AI Studio/Settings/ConfigMeta.cs
index cbb4d6b9..712e43d6 100644
--- a/app/MindWork AI Studio/Settings/ConfigMeta.cs
+++ b/app/MindWork AI Studio/Settings/ConfigMeta.cs
@@ -11,11 +11,10 @@ namespace AIStudio.Settings;
/// The type of the configuration property value.
public record ConfigMeta : ConfigMetaBase
{
- public ConfigMeta(Expression> configSelection, Expression> propertyExpression)
+ public ConfigMeta(Expression> configSelection, Expression> propertyExpression) : base(SettingsManager.ToSettingName(propertyExpression))
{
this.ConfigSelection = configSelection;
this.PropertyExpression = propertyExpression;
- this.SettingName = SettingsManager.ToSettingName(propertyExpression);
}
///
@@ -28,132 +27,16 @@ public record ConfigMeta : ConfigMetaBase
///
private Expression> PropertyExpression { get; }
- ///
- /// The persisted name of the configuration setting.
- ///
- public string SettingName { get; }
-
- ///
- /// Indicates whether the configuration is locked by a configuration plugin.
- ///
- public bool IsLocked { get; private set; }
-
- ///
- /// The ID of the plugin that locked this configuration.
- ///
- public Guid LockedByConfigPluginId { get; private set; }
-
- ///
- /// How this setting is managed by a configuration plugin, if at all.
- ///
- public ManagedConfigurationMode? ManagedMode { get; private set; }
-
- ///
- /// The ID of the plugin that currently provides an editable default value.
- ///
- public Guid EditableDefaultByConfigPluginId { get; private set; }
-
///
/// The default value for the configuration property. This is used when resetting the property to its default state.
///
public required TValue Default { get; init; }
- ///
- /// Indicates whether a plugin contribution is available.
- ///
- public bool HasPluginContribution { get; private set; }
-
///
/// The additive value contribution provided by a configuration plugin.
///
public TValue PluginContribution { get; private set; } = default!;
- ///
- /// The ID of the plugin that provided the additive value contribution.
- ///
- public Guid PluginContributionByConfigPluginId { get; private set; }
-
- ///
- /// Locks the configuration state, indicating that it is controlled by a specific plugin.
- ///
- /// The ID of the plugin that is locking this configuration.
- public void LockConfiguration(Guid pluginId)
- {
- this.IsLocked = true;
- this.LockedByConfigPluginId = pluginId;
- this.ManagedMode = ManagedConfigurationMode.LOCKED;
- this.EditableDefaultByConfigPluginId = Guid.Empty;
- SettingsManagerAccess.ConfigurationData.ManagedLockedConfigurations[this.SettingName] = pluginId;
- }
-
- ///
- /// Restores persisted locked configuration metadata after settings were loaded.
- ///
- public void RestoreLockedConfiguration()
- {
- if (this.IsLocked || this.ManagedMode is not null)
- return;
-
- if (!SettingsManagerAccess.ConfigurationData.ManagedLockedConfigurations.TryGetValue(this.SettingName, out var pluginId)
- || pluginId == Guid.Empty)
- return;
-
- this.IsLocked = true;
- this.LockedByConfigPluginId = pluginId;
- this.ManagedMode = ManagedConfigurationMode.LOCKED;
- this.EditableDefaultByConfigPluginId = Guid.Empty;
- }
-
- ///
- /// Resets the locked state of the configuration, allowing it to be modified again.
- /// This will also reset the property to its default value.
- ///
- public void ResetLockedConfiguration()
- {
- SettingsManagerAccess.ConfigurationData.ManagedLockedConfigurations.Remove(this.SettingName);
- this.IsLocked = false;
- this.LockedByConfigPluginId = Guid.Empty;
- if (this.ManagedMode is ManagedConfigurationMode.LOCKED)
- this.ManagedMode = null;
-
- this.Reset();
- }
-
- ///
- /// Unlocks the configuration state without changing the current value.
- ///
- public void UnlockConfiguration()
- {
- SettingsManagerAccess.ConfigurationData.ManagedLockedConfigurations.Remove(this.SettingName);
- this.IsLocked = false;
- this.LockedByConfigPluginId = Guid.Empty;
- if (this.ManagedMode is ManagedConfigurationMode.LOCKED)
- this.ManagedMode = null;
- }
-
- ///
- /// Marks the setting as having an editable default provided by a configuration plugin.
- ///
- public void SetEditableDefaultConfiguration(Guid pluginId)
- {
- SettingsManagerAccess.ConfigurationData.ManagedLockedConfigurations.Remove(this.SettingName);
- this.IsLocked = false;
- this.LockedByConfigPluginId = Guid.Empty;
- this.ManagedMode = ManagedConfigurationMode.EDITABLE_DEFAULT;
- this.EditableDefaultByConfigPluginId = pluginId;
- }
-
- ///
- /// Clears the editable-default state without changing the current value.
- ///
- public void ClearEditableDefaultConfiguration()
- {
- if (this.ManagedMode is ManagedConfigurationMode.EDITABLE_DEFAULT)
- this.ManagedMode = null;
-
- this.EditableDefaultByConfigPluginId = Guid.Empty;
- }
-
///
/// Stores an additive plugin contribution.
///
@@ -164,20 +47,15 @@ public record ConfigMeta : ConfigMetaBase
this.HasPluginContribution = true;
}
- ///
- /// Clears the additive plugin contribution without changing the current value.
- ///
- public void ClearPluginContribution()
+ ///
+ public override void ClearPluginContribution()
{
this.PluginContribution = default!;
- this.PluginContributionByConfigPluginId = Guid.Empty;
- this.HasPluginContribution = false;
+ base.ClearPluginContribution();
}
-
- ///
- /// Resets the configuration property to its default value.
- ///
- private void Reset()
+
+ ///
+ protected override void Reset()
{
var configInstance = this.ConfigSelection.Compile().Invoke(SettingsManagerAccess.ConfigurationData);
var memberExpression = this.PropertyExpression.GetMemberExpression();
diff --git a/app/MindWork AI Studio/Settings/ConfigMetaBase.cs b/app/MindWork AI Studio/Settings/ConfigMetaBase.cs
index d077a701..5c34dee5 100644
--- a/app/MindWork AI Studio/Settings/ConfigMetaBase.cs
+++ b/app/MindWork AI Studio/Settings/ConfigMetaBase.cs
@@ -1,6 +1,148 @@
namespace AIStudio.Settings;
-public abstract record ConfigMetaBase : IConfig
+///
+/// The type-independent part of the configuration metadata: which configuration plugin manages
+/// the setting, and in which way.
+///
+///
+/// The managed state lives here so that it can be processed without knowing the setting's type,
+/// e.g. when cleaning up settings whose configuration plugin was removed.
+///
+public abstract record ConfigMetaBase(string SettingName) : IConfig
{
protected static SettingsManager SettingsManagerAccess => Program.SERVICE_PROVIDER.GetRequiredService();
+
+ ///
+ /// The persisted name of the configuration setting.
+ ///
+ public string SettingName { get; } = SettingName;
+
+ ///
+ /// Indicates whether the configuration is locked by a configuration plugin.
+ ///
+ public bool IsLocked { get; private set; }
+
+ ///
+ /// The ID of the plugin that locked this configuration.
+ ///
+ public Guid LockedByConfigPluginId { get; private set; }
+
+ ///
+ /// How this setting is managed by a configuration plugin, if at all.
+ ///
+ public ManagedConfigurationMode? ManagedMode { get; private set; }
+
+ ///
+ /// The ID of the plugin that currently provides an editable default value.
+ ///
+ public Guid EditableDefaultByConfigPluginId { get; private set; }
+
+ ///
+ /// Indicates whether a plugin contribution is available.
+ ///
+ public bool HasPluginContribution { get; protected set; }
+
+ ///
+ /// The ID of the plugin that provided the additive value contribution.
+ ///
+ public Guid PluginContributionByConfigPluginId { get; protected set; }
+
+ ///
+ /// Locks the configuration state, indicating that it is controlled by a specific plugin.
+ ///
+ /// The ID of the plugin that is locking this configuration.
+ public void LockConfiguration(Guid pluginId)
+ {
+ this.IsLocked = true;
+ this.LockedByConfigPluginId = pluginId;
+ this.ManagedMode = ManagedConfigurationMode.LOCKED;
+ this.EditableDefaultByConfigPluginId = Guid.Empty;
+ SettingsManagerAccess.ConfigurationData.ManagedLockedConfigurations[this.SettingName] = pluginId;
+ }
+
+ ///
+ /// Restores persisted locked configuration metadata after settings were loaded.
+ ///
+ public void RestoreLockedConfiguration()
+ {
+ if (this.IsLocked || this.ManagedMode is not null)
+ return;
+
+ if (!SettingsManagerAccess.ConfigurationData.ManagedLockedConfigurations.TryGetValue(this.SettingName, out var pluginId) || pluginId == Guid.Empty)
+ return;
+
+ this.IsLocked = true;
+ this.LockedByConfigPluginId = pluginId;
+ this.ManagedMode = ManagedConfigurationMode.LOCKED;
+ this.EditableDefaultByConfigPluginId = Guid.Empty;
+ }
+
+ ///
+ /// Resets the locked state of the configuration, allowing it to be modified again.
+ /// This will also reset the property to its default value.
+ ///
+ public void ResetLockedConfiguration()
+ {
+ SettingsManagerAccess.ConfigurationData.ManagedLockedConfigurations.Remove(this.SettingName);
+
+ this.IsLocked = false;
+ this.LockedByConfigPluginId = Guid.Empty;
+
+ if (this.ManagedMode is ManagedConfigurationMode.LOCKED)
+ this.ManagedMode = null;
+
+ this.Reset();
+ }
+
+ ///
+ /// Unlocks the configuration state without changing the current value.
+ ///
+ public void UnlockConfiguration()
+ {
+ SettingsManagerAccess.ConfigurationData.ManagedLockedConfigurations.Remove(this.SettingName);
+
+ this.IsLocked = false;
+ this.LockedByConfigPluginId = Guid.Empty;
+
+ if (this.ManagedMode is ManagedConfigurationMode.LOCKED)
+ this.ManagedMode = null;
+ }
+
+ ///
+ /// Marks the setting as having an editable default provided by a configuration plugin.
+ ///
+ public void SetEditableDefaultConfiguration(Guid pluginId)
+ {
+ SettingsManagerAccess.ConfigurationData.ManagedLockedConfigurations.Remove(this.SettingName);
+
+ this.IsLocked = false;
+ this.LockedByConfigPluginId = Guid.Empty;
+ this.ManagedMode = ManagedConfigurationMode.EDITABLE_DEFAULT;
+ this.EditableDefaultByConfigPluginId = pluginId;
+ }
+
+ ///
+ /// Clears the editable-default state without changing the current value.
+ ///
+ public void ClearEditableDefaultConfiguration()
+ {
+ if (this.ManagedMode is ManagedConfigurationMode.EDITABLE_DEFAULT)
+ this.ManagedMode = null;
+
+ this.EditableDefaultByConfigPluginId = Guid.Empty;
+ }
+
+ ///
+ /// Clears the additive plugin contribution without changing the current value.
+ ///
+ public virtual void ClearPluginContribution()
+ {
+ this.PluginContributionByConfigPluginId = Guid.Empty;
+ this.HasPluginContribution = false;
+ }
+
+ ///
+ /// Resets the configuration property to its default value.
+ ///
+ protected abstract void Reset();
}
\ No newline at end of file