feat(editor): settings both sides changed on the server ask before anything is overwritten

BRIEF §14.5 asks for an explicit conflict prompt when both sides changed. A save
of a server sequence that meets settings someone changed to other values on the
server now stops (the change stays pending) and the editor asks: Keep mine saves
the editor's values over the server's, Take server (the safe default) shows the
server's values as one undoable step, so Ctrl+Z brings the editor's back. Both
first take in what only the server changed. Settings changed on one side only
still merge silently; a reload after an analysis never merges over a conflicting
pending change. The Export "Sync" box moves under Save to so neither is cut in
longer languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-06 08:02:30 +00:00
1 parent 31c1a2d9c6
commit bda8e1fec2
13 files changed
+311 -32

No files matched your search

+31 -1
View File
@@ -1,5 +1,6 @@
using System.Text.Json.Nodes;
using Titano.Core.Project;
using Titano.Data.Sync;
namespace Titano.App.Editor;
@@ -7,7 +8,8 @@ namespace Titano.App.Editor;
/// Three-way merge of projects: the editor's edit (<c>ours</c>) and a change stored meanwhile by someone else
/// (<c>theirs</c>: an analysis filling Auto values, another client through the server), both made from <c>basis</c>.
/// Values are compared member by member down the JSON tree; a member only one side changed takes that side's value, a
/// member both changed takes the editor's (the user is looking at it).
/// member both changed takes the editor's (the user is looking at it). <see cref="Conflicts"/> lists those members for
/// a source that asks the user instead (a server sequence, BRIEF §14.5).
/// </summary>
public static class ProjectMerge
{
@@ -19,6 +21,20 @@ public static class ProjectMerge
return new Rebase(basis, theirs).Apply(ours);
}
/// <summary>
/// The members both sides changed to different values, in document order: the path below the project
/// ("exposure.deflickerWindow.manual"), the editor's value and theirs as JSON (null when absent).
/// </summary>
public static IReadOnlyList<SettingsDifference> Conflicts(ProjectSettings basis, ProjectSettings ours, ProjectSettings theirs)
{
ArgumentNullException.ThrowIfNull(basis);
ArgumentNullException.ThrowIfNull(ours);
ArgumentNullException.ThrowIfNull(theirs);
var conflicts = new List<SettingsDifference>();
Collect(JsonNode.Parse(basis.ToJson()), JsonNode.Parse(ours.ToJson()), JsonNode.Parse(theirs.ToJson()), string.Empty, conflicts);
return conflicts;
}
/// <summary>True when both projects store the same values.</summary>
public static bool SameValues(ProjectSettings a, ProjectSettings b) => a.ToJson() == b.ToJson();
@@ -37,6 +53,20 @@ public static class ProjectMerge
return merged;
}
/// <summary>The members <see cref="Merge(JsonNode?, JsonNode?, JsonNode?)"/> settles for the editor although both sides changed them.</summary>
private static void Collect(JsonNode? basis, JsonNode? ours, JsonNode? theirs, string path, List<SettingsDifference> conflicts)
{
if (JsonNode.DeepEquals(ours, basis) || JsonNode.DeepEquals(theirs, basis) || JsonNode.DeepEquals(theirs, ours)) return;
if (ours is JsonObject mine && theirs is JsonObject other)
{
var common = basis as JsonObject;
foreach (var name in mine.Select(p => p.Key).Union(other.Select(p => p.Key)))
Collect(common?[name], mine[name], other[name], path.Length == 0 ? name : path + "." + name, conflicts);
return;
}
conflicts.Add(new SettingsDifference(path.Length == 0 ? "settings" : path, ours?.ToJsonString(), theirs?.ToJsonString()));
}
/// <summary>One outside change (<paramref name="basis"/> → <paramref name="theirs"/>) applied to any number of projects made from the basis.</summary>
public sealed class Rebase(ProjectSettings basis, ProjectSettings theirs)
{