using Avalonia; using Avalonia.Controls; using Avalonia.Input; using Avalonia.Interactivity; using Avalonia.Layout; using Avalonia.Media; using Avalonia.VisualTree; using ClaudeDo.Ui.ViewModels.Islands; using ClaudeDo.Ui.ViewModels.Modals; using ClaudeDo.Ui.Views.Modals; namespace ClaudeDo.Ui.Views.Islands; public partial class TasksIslandView : UserControl { private static readonly DataFormat TaskRowFormat = DataFormat.CreateStringApplicationFormat("claudedo-task-row"); public TasksIslandView() { InitializeComponent(); AddHandler(PointerPressedEvent, OnTunnelPointerPressed, RoutingStrategies.Tunnel); DataContextChanged += (_, _) => { if (DataContext is TasksIslandViewModel vm) { vm.FocusAddTaskRequested += (_, _) => AddTaskBox.Focus(); vm.ShowUnfinishedPlanningModal = async (modalVm) => { var owner = TopLevel.GetTopLevel(this) as Window; if (owner is null) { modalVm.CancelCommand.Execute(null); return; } var modal = new UnfinishedPlanningModalView { DataContext = modalVm }; // Closing via the OS title-bar (if ever enabled) also resolves the TCS. modal.Closed += (_, _) => modalVm.CancelCommand.Execute(null); await modal.ShowDialog(owner); // ShowDialog completes once the window is closed (CloseAction or OS close). }; vm.ConfirmAsync = ShowConfirmAsync; } }; } private async System.Threading.Tasks.Task ShowConfirmAsync(string message) { var owner = TopLevel.GetTopLevel(this) as Window; if (owner is null) return false; var tcs = new TaskCompletionSource(); 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; } private async void OnTunnelPointerPressed(object? sender, PointerPressedEventArgs e) { if (DataContext is not TasksIslandViewModel vm) return; if (e.Source is not Visual src) return; var button = src as Button ?? src.FindAncestorOfType