feat(ui): add global keyboard shortcuts (Ctrl+N, Ctrl+L, Ctrl+R, Ctrl+Shift+N)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Input;
|
using Avalonia.Input;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
|
using Avalonia.VisualTree;
|
||||||
using ClaudeDo.Ui.ViewModels;
|
using ClaudeDo.Ui.ViewModels;
|
||||||
|
|
||||||
namespace ClaudeDo.Ui.Views;
|
namespace ClaudeDo.Ui.Views;
|
||||||
@@ -18,26 +22,54 @@ public partial class MainWindow : Window
|
|||||||
await vm.InitializeAsync();
|
await vm.InitializeAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnListItemDoubleTapped(object? sender, TappedEventArgs e)
|
private void OnGlobalKeyDown(object? sender, KeyEventArgs e)
|
||||||
{
|
{
|
||||||
if (sender is Control c && c.DataContext is ListItemViewModel
|
if (DataContext is not MainWindowViewModel vm) return;
|
||||||
&& DataContext is MainWindowViewModel vm)
|
|
||||||
|
var ctrl = e.KeyModifiers.HasFlag(KeyModifiers.Control);
|
||||||
|
var shift = e.KeyModifiers.HasFlag(KeyModifiers.Shift);
|
||||||
|
|
||||||
|
if (ctrl && shift && e.Key == Key.N)
|
||||||
{
|
{
|
||||||
vm.EditListCommand.Execute(null);
|
vm.AddListCommand.Execute(null);
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
else if (ctrl && e.Key == Key.N)
|
||||||
|
{
|
||||||
|
var taskListView = this.GetVisualDescendants().OfType<TaskListView>().FirstOrDefault();
|
||||||
|
taskListView?.FocusInlineAdd();
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
else if (ctrl && e.Key == Key.L)
|
||||||
|
{
|
||||||
|
this.FindControl<ListBox>("ListsBox")?.Focus();
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
else if (ctrl && e.Key == Key.R)
|
||||||
|
{
|
||||||
|
if (vm.TaskList.SelectedTask is { } task)
|
||||||
|
{
|
||||||
|
task.RunNowCommand.Execute(null);
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnListItemDoubleTapped(object? sender, TappedEventArgs e)
|
||||||
|
{
|
||||||
|
if (DataContext is MainWindowViewModel vm)
|
||||||
|
vm.EditListCommand.Execute(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnListItemPointerPressed(object? sender, PointerPressedEventArgs e)
|
private void OnListItemPointerPressed(object? sender, PointerPressedEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.GetCurrentPoint(null).Properties.PointerUpdateKind == PointerUpdateKind.RightButtonPressed
|
var props = e.GetCurrentPoint(this).Properties;
|
||||||
&& sender is Control c && c.DataContext is ListItemViewModel item
|
if (!props.IsRightButtonPressed) return;
|
||||||
|
|
||||||
|
if (sender is Grid { DataContext: ListItemViewModel item }
|
||||||
&& DataContext is MainWindowViewModel vm)
|
&& DataContext is MainWindowViewModel vm)
|
||||||
{
|
{
|
||||||
vm.SelectedList = item;
|
vm.SelectedList = item;
|
||||||
e.Handled = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnGlobalKeyDown(object? sender, KeyEventArgs e) { }
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user