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

@@ -25,61 +25,7 @@ public partial class ListsIslandView : UserControl
DataContextChanged += (_, _) =>
{
if (DataContext is ListsIslandViewModel vm)
{
vm.FocusSearchRequested += (_, _) => SearchBox.Focus();
vm.ShowSettingsModal = ShowSettingsAsync;
vm.ShowListSettingsModal = async modal =>
{
var window = new ListSettingsModalView { DataContext = modal };
modal.CloseAction = () => window.Close();
modal.ConfirmAsync = ShowConfirmAsync;
modal.ShowErrorAsync = ShowErrorDialogAsync;
var top = TopLevel.GetTopLevel(this) as Window;
if (top is null) window.Show();
else await window.ShowDialog(top);
};
vm.ShowRepoImportModal = async modal =>
{
var window = new RepoImportModalView { DataContext = modal };
modal.CloseAction = () => window.Close();
var top = TopLevel.GetTopLevel(this) as Window;
if (top is null) window.Show();
else await window.ShowDialog(top);
};
vm.ShowWorktreesOverviewModal = async modal =>
{
var top = TopLevel.GetTopLevel(this) as Window;
var shell = top?.DataContext as IslandsShellViewModel;
var window = new WorktreesOverviewModalView { DataContext = modal };
modal.CloseAction = () => window.Close();
modal.JumpToTaskAction = (listId, taskId) =>
{
if (shell is not null)
_ = JumpToTaskAsync(shell, listId, taskId);
};
modal.ShowDiffAction = diffVm =>
{
if (top is null) return;
var dlg = new WorktreeModalView { DataContext = diffVm };
diffVm.CloseAction = () => dlg.Close();
_ = diffVm.LoadAsync();
_ = dlg.ShowDialog(top);
};
modal.ConfirmAction = ShowConfirmAsync;
if (shell is not null)
{
modal.ResolveMergeVm = shell.ResolveMergeVm;
modal.ShowMergeAction = async mergeVm =>
{
if (top is null) return;
var mergeDlg = new MergeModalView { DataContext = mergeVm };
await mergeDlg.ShowDialog(top);
};
}
if (top is null) window.Show();
else await window.ShowDialog(top);
};
}
};
}
@@ -211,95 +157,4 @@ public partial class ListsIslandView : UserControl
return idx + 1 < vm.UserLists.Count ? vm.UserLists[idx + 1] : null;
}
private async System.Threading.Tasks.Task ShowSettingsAsync(SettingsModalViewModel settingsVm)
{
var owner = TopLevel.GetTopLevel(this) as Window;
if (owner == null) return;
var modal = new SettingsModalView { DataContext = settingsVm };
await modal.ShowDialog(owner);
}
private static System.Threading.Tasks.Task JumpToTaskAsync(IslandsShellViewModel s, string listId, string taskId)
=> JumpToTaskHelper.SelectAsync(s, listId, taskId);
private async System.Threading.Tasks.Task ShowErrorDialogAsync(string message)
{
var owner = TopLevel.GetTopLevel(this) as Window;
if (owner is null) return;
var ok = new Button { Content = "OK", MinWidth = 90 };
var dialog = new Window
{
Title = "Error",
Width = 360,
SizeToContent = SizeToContent.Height,
CanResize = false,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
ShowInTaskbar = false,
Background = this.FindResource("SurfaceBrush") as IBrush,
Content = new StackPanel
{
Spacing = 16,
Margin = new Thickness(20),
Children =
{
new TextBlock { Text = message, TextWrapping = TextWrapping.Wrap },
new StackPanel
{
Orientation = Orientation.Horizontal,
Spacing = 8,
HorizontalAlignment = HorizontalAlignment.Right,
Children = { ok },
},
},
},
};
ok.Click += (_, _) => dialog.Close();
await dialog.ShowDialog(owner);
}
private async System.Threading.Tasks.Task<bool> ShowConfirmAsync(string message)
{
var owner = TopLevel.GetTopLevel(this) as Window;
if (owner is null) return false;
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(owner);
return await tcs.Task;
}
}