refactor(ui): single IDialogService replaces scattered Show* dialog seams

Collapses the ~10 per-modal Show*Modal Func callbacks (wired separately on the shell and the lists island) into one IDialogService + WindowDialogService impl. Removes the RepoImport/WorktreesOverview dialog construction duplicated across MainWindow and ListsIslandView, plus the Confirm/Error dialogs duplicated in both code-behinds. Shell/lists Open* commands now route through an injected Dialogs handle (propagated shell->lists); the per-list worktrees overview also wires conflict resolution now, matching the global one. No VM ctor changes (Dialogs is a settable seam), so no test-fake impact.
This commit is contained in:
Mika Kuns
2026-06-22 16:52:50 +02:00
parent 1fb2e34f85
commit d598a539bc
6 changed files with 234 additions and 291 deletions

View File

@@ -42,65 +42,7 @@ public partial class MainWindow : Window
{
if (DataContext is IslandsShellViewModel vm)
{
vm.ShowAboutModal = async (aboutVm) =>
{
var dlg = new AboutModalView { DataContext = aboutVm };
var tcs = new TaskCompletionSource<bool>();
aboutVm.CloseAction = () => { dlg.Close(); tcs.TrySetResult(true); };
await dlg.ShowDialog(this);
};
vm.ShowWeeklyReportModal = async (modal) =>
{
var dlg = new WeeklyReportModalView { DataContext = modal };
modal.CloseAction = () => dlg.Close();
await dlg.ShowDialog(this);
};
vm.ShowWorktreesOverviewModal = async (modal) =>
{
var dlg = new WorktreesOverviewModalView { DataContext = modal };
modal.CloseAction = () => dlg.Close();
modal.JumpToTaskAction = (listId, taskId) =>
{
if (DataContext is IslandsShellViewModel s)
_ = JumpToTaskAsync(s, listId, taskId);
};
modal.ShowDiffAction = diffVm =>
{
var diffDlg = new WorktreeModalView { DataContext = diffVm };
diffVm.CloseAction = () => diffDlg.Close();
_ = diffVm.LoadAsync();
_ = diffDlg.ShowDialog(this);
};
modal.ConfirmAction = ShowConfirmAsync;
modal.ResolveMergeVm = vm.ResolveMergeVm;
modal.ShowMergeAction = async mergeVm =>
{
var mergeDlg = new MergeModalView { DataContext = mergeVm };
await mergeDlg.ShowDialog(this);
};
modal.RequestConflictResolution = (taskId, target) =>
DataContext is IslandsShellViewModel s
? s.RequestConflictResolutionAsync(taskId, target)
: System.Threading.Tasks.Task.CompletedTask;
await dlg.ShowDialog(this);
};
vm.ShowRepoImportModal = async (modal) =>
{
var dlg = new RepoImportModalView { DataContext = modal };
modal.CloseAction = () => dlg.Close();
await dlg.ShowDialog(this);
};
vm.ShowWorkerConnectionModal = async (connVm) =>
{
var dlg = new WorkerConnectionModalView { DataContext = connVm };
connVm.CloseAction = () => dlg.Close();
await dlg.ShowDialog(this);
};
vm.ShowConflictResolver = async (resolverVm) =>
{
var dlg = new ClaudeDo.Ui.Views.Conflicts.ConflictResolverView { DataContext = resolverVm };
await dlg.ShowDialog(this);
};
vm.Dialogs = new WindowDialogService(this);
}
}
@@ -132,47 +74,4 @@ public partial class MainWindow : Window
if (DataContext is IslandsShellViewModel vm) vm.WindowWidth = Bounds.Width;
}
private static System.Threading.Tasks.Task JumpToTaskAsync(IslandsShellViewModel s, string listId, string taskId)
=> JumpToTaskHelper.SelectAsync(s, listId, taskId);
private async System.Threading.Tasks.Task<bool> ShowConfirmAsync(string message)
{
var tcs = new TaskCompletionSource<bool>();
var cancel = new Button { Content = "Cancel", MinWidth = 90 };
var confirm = new Button { Content = "Confirm", MinWidth = 90, Classes = { "danger" } };
var dialog = new Window
{
Title = "Confirm",
Width = 380,
SizeToContent = SizeToContent.Height,
CanResize = false,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
ShowInTaskbar = false,
Background = this.FindResource("SurfaceBrush") as IBrush,
Content = new StackPanel
{
Margin = new Thickness(20),
Spacing = 16,
Children =
{
new TextBlock { Text = message, TextWrapping = TextWrapping.Wrap },
new StackPanel
{
Orientation = Orientation.Horizontal,
HorizontalAlignment = HorizontalAlignment.Right,
Spacing = 8,
Children = { cancel, confirm },
},
},
},
};
cancel.Click += (_, _) => { tcs.TrySetResult(false); dialog.Close(); };
confirm.Click += (_, _) => { tcs.TrySetResult(true); dialog.Close(); };
dialog.Closed += (_, _) => tcs.TrySetResult(false);
_ = dialog.ShowDialog(this);
return await tcs.Task;
}
}