feat(ui): add inline add handlers, checkbox click, and task keyboard shortcuts
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.VisualTree;
|
||||
using ClaudeDo.Ui.ViewModels;
|
||||
|
||||
namespace ClaudeDo.Ui.Views;
|
||||
@@ -11,30 +13,92 @@ public partial class TaskListView : UserControl
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void OnTaskItemDoubleTapped(object? sender, TappedEventArgs e)
|
||||
private void OnInlineAddKeyDown(object? sender, KeyEventArgs e)
|
||||
{
|
||||
if (sender is Control c && c.DataContext is TaskItemViewModel
|
||||
&& DataContext is TaskListViewModel vm)
|
||||
if (DataContext is not TaskListViewModel vm) return;
|
||||
|
||||
if (e.Key == Key.Enter)
|
||||
{
|
||||
vm.EditTaskCommand.Execute(null);
|
||||
vm.InlineAddCommand.Execute(null);
|
||||
e.Handled = true;
|
||||
}
|
||||
else if (e.Key == Key.Escape)
|
||||
{
|
||||
vm.InlineAddTitle = "";
|
||||
this.FindControl<ListBox>("TaskListBox")?.Focus();
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnInlineAddGotFocus(object? sender, FocusChangedEventArgs e)
|
||||
{
|
||||
if (sender is TextBox tb)
|
||||
tb.BorderBrush = Avalonia.Application.Current?.FindResource("AccentBrush") as Avalonia.Media.IBrush;
|
||||
}
|
||||
|
||||
private void OnInlineAddLostFocus(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is TextBox tb)
|
||||
tb.BorderBrush = Avalonia.Application.Current?.FindResource("BorderSubtleBrush") as Avalonia.Media.IBrush;
|
||||
}
|
||||
|
||||
private void OnTaskListKeyDown(object? sender, KeyEventArgs e)
|
||||
{
|
||||
if (DataContext is not TaskListViewModel vm || vm.SelectedTask is null) return;
|
||||
|
||||
switch (e.Key)
|
||||
{
|
||||
case Key.Delete:
|
||||
vm.DeleteTaskCommand.Execute(null);
|
||||
e.Handled = true;
|
||||
break;
|
||||
case Key.Space:
|
||||
if (vm.SelectedTask.CanToggleDone)
|
||||
{
|
||||
vm.SelectedTask.ToggleDoneCommand.Execute(null);
|
||||
e.Handled = true;
|
||||
}
|
||||
break;
|
||||
case Key.Enter:
|
||||
case Key.F2:
|
||||
var detailView = this.GetVisualAncestors().OfType<Window>().FirstOrDefault()
|
||||
?.GetVisualDescendants().OfType<TaskDetailView>().FirstOrDefault();
|
||||
detailView?.FocusTitle();
|
||||
e.Handled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCheckboxPressed(object? sender, PointerPressedEventArgs e)
|
||||
{
|
||||
if (sender is not Border { DataContext: TaskItemViewModel task }) return;
|
||||
if (task.CanToggleDone)
|
||||
{
|
||||
task.ToggleDoneCommand.Execute(null);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTaskItemDoubleTapped(object? sender, TappedEventArgs e)
|
||||
{
|
||||
if (DataContext is TaskListViewModel vm)
|
||||
vm.EditTaskCommand.Execute(null);
|
||||
}
|
||||
|
||||
private void OnTaskItemPointerPressed(object? sender, PointerPressedEventArgs e)
|
||||
{
|
||||
if (e.GetCurrentPoint(null).Properties.PointerUpdateKind == PointerUpdateKind.RightButtonPressed
|
||||
&& sender is Control c && c.DataContext is TaskItemViewModel item
|
||||
var props = e.GetCurrentPoint(this).Properties;
|
||||
if (!props.IsRightButtonPressed) return;
|
||||
|
||||
if (sender is Grid { DataContext: TaskItemViewModel item }
|
||||
&& DataContext is TaskListViewModel vm)
|
||||
{
|
||||
vm.SelectedTask = item;
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnInlineAddKeyDown(object? sender, Avalonia.Input.KeyEventArgs e) { }
|
||||
private void OnInlineAddGotFocus(object? sender, Avalonia.Interactivity.RoutedEventArgs e) { }
|
||||
private void OnInlineAddLostFocus(object? sender, Avalonia.Interactivity.RoutedEventArgs e) { }
|
||||
private void OnTaskListKeyDown(object? sender, Avalonia.Input.KeyEventArgs e) { }
|
||||
private void OnCheckboxPressed(object? sender, Avalonia.Input.PointerPressedEventArgs e) { }
|
||||
public void FocusInlineAdd()
|
||||
{
|
||||
this.FindControl<TextBox>("InlineAddBox")?.Focus();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user