Restore the auto-save as the single owner of policy persistence

This commit is contained in:
Thorsten Sommer committed 2026-09-16 11:57:18 +02:00
1 parent 23da69e0af
commit 37d38df597
1 file changed
+29 -15
@@ -256,12 +256,12 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
private async Task AutoSave(bool force = false) private async Task AutoSave(bool force = false)
{ {
// //
// A pending name store is a property of the settings, not of the selected policy: the name // A pending store is a property of the settings, not of the selected policy: the value has
// is written into its policy the very moment it is typed, so what is still outstanding is // been written into its policy already, so what is still outstanding is the store itself.
// the store itself. It therefore outlives a form reset and a switch to another policy, and // It therefore outlives a form reset and a switch to another policy, and only a completed
// only a completed store clears it. // store clears it.
// //
var hasChanges = this.policyNameStorePending; var hasChanges = this.policyStorePending;
if(this.selectedPolicy is { } policy) if(this.selectedPolicy is { } policy)
hasChanges |= this.ApplyFormToPolicy(policy, force); hasChanges |= this.ApplyFormToPolicy(policy, force);
@@ -269,7 +269,7 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
return; return;
await this.SettingsManager.StoreSettings(); await this.SettingsManager.StoreSettings();
this.policyNameStorePending = false; this.policyStorePending = false;
} }
/// <summary> /// <summary>
@@ -333,15 +333,19 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
private string policyName = string.Empty; private string policyName = string.Empty;
/// <summary> /// <summary>
/// Whether a typed policy name still waits to be written to the settings file. /// Whether an edit already applied to a policy still waits to be written to the settings file.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// Typing a name applies it to its policy at once, so that the policy list shows the new name /// Some handlers apply their value to the selected policy at once, because the rest of the
/// right away -- which leaves nothing for the auto-save to compare the form against. This flag /// assistant reads it back from there right away: the policy list has to show a new name while
/// is what tells it that a store is nevertheless due. It belongs to no particular policy: the /// it is being typed, and the provider preselection is recomputed from the policy, not from the
/// name has long arrived where it belongs, only the file has not caught up yet. /// form. Doing so leaves the auto-save nothing to compare the form against -- form and policy
/// already agree -- so every such handler has to announce the store itself. That is what this
/// flag is for. It belongs to no particular policy: the value has long arrived where it
/// belongs, only the file has not caught up yet, which is why a form reset or a switch to
/// another policy does not clear it. Only a completed store does.
/// </remarks> /// </remarks>
private bool policyNameStorePending; private bool policyStorePending;
private string policyDescription = string.Empty; private string policyDescription = string.Empty;
private string policyAnalysisRules = string.Empty; private string policyAnalysisRules = string.Empty;
private string policyOutputRules = string.Empty; private string policyOutputRules = string.Empty;
@@ -521,7 +525,7 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
return; return;
this.selectedPolicy.PolicyName = this.policyName; this.selectedPolicy.PolicyName = this.policyName;
this.policyNameStorePending = true; this.policyStorePending = true;
} }
private async Task PolicyProtectionWasChanged(bool state) private async Task PolicyProtectionWasChanged(bool state)
@@ -626,15 +630,21 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
private void PolicyAllowedToolsWasChanged(HashSet<string> allowedToolIds) private void PolicyAllowedToolsWasChanged(HashSet<string> allowedToolIds)
{ {
this.policyAllowedToolIds = allowedToolIds; this.policyAllowedToolIds = allowedToolIds;
if (this.selectedPolicy is not null) if (this.selectedPolicy is null)
this.selectedPolicy.AllowedToolIds = [..allowedToolIds]; return;
this.selectedPolicy.AllowedToolIds = [..allowedToolIds];
this.policyStorePending = true;
} }
private void PolicyMinimumConfidenceWasChanged(ConfidenceLevel level) private void PolicyMinimumConfidenceWasChanged(ConfidenceLevel level)
{ {
this.policyMinimumProviderConfidence = level; this.policyMinimumProviderConfidence = level;
if (this.selectedPolicy is not null) if (this.selectedPolicy is not null)
{
this.selectedPolicy.MinimumProviderConfidence = level; this.selectedPolicy.MinimumProviderConfidence = level;
this.policyStorePending = true;
}
this.ApplyPolicyPreselection(); this.ApplyPolicyPreselection();
} }
@@ -646,6 +656,7 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
this.policyPreselectedProviderId = providerId; this.policyPreselectedProviderId = providerId;
this.selectedPolicy.PreselectedProvider = providerId; this.selectedPolicy.PreselectedProvider = providerId;
this.policyStorePending = true;
this.ProviderSettings = Settings.Provider.NONE; this.ProviderSettings = Settings.Provider.NONE;
this.ApplyPolicyPreselection(); this.ApplyPolicyPreselection();
} }
@@ -654,7 +665,10 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
{ {
this.policyPreselectedProfile = selection; this.policyPreselectedProfile = selection;
if (this.selectedPolicy is not null) if (this.selectedPolicy is not null)
{
this.selectedPolicy.PreselectedProfile = this.policyPreselectedProfile; this.selectedPolicy.PreselectedProfile = this.policyPreselectedProfile;
this.policyStorePending = true;
}
this.CurrentProfile = this.ResolveProfileSelection(); this.CurrentProfile = this.ResolveProfileSelection();
} }