feature: select and open repository by keyboard in Welcome page (#391)

This commit is contained in:
leo 2024-08-22 15:45:50 +08:00
parent 10e5c7aa6c
commit 71d36698f8
No known key found for this signature in database
2 changed files with 43 additions and 1 deletions

View file

@ -35,6 +35,40 @@ namespace SourceGit.Views
}
}
private void OnSearchBoxKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Down || e.Key == Key.FnDownArrow)
{
var containers = ReposTree.GetRealizedContainers();
if (containers == null)
return;
foreach (var c in containers)
{
if (c is TreeViewItem { IsVisible: true } item)
{
ReposTree.SelectedItem = item.DataContext;
item.Focus();
break;
}
}
e.Handled = true;
}
}
private void OnTreeViewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Space && ReposTree.SelectedItem is ViewModels.RepositoryNode { IsRepository: true } node)
{
var parent = this.FindAncestorOfType<Launcher>();
if (parent?.DataContext is ViewModels.Launcher launcher)
launcher.OpenRepositoryInTab(node, null);
e.Handled = true;
}
}
private void OnTreeNodeContextRequested(object sender, ContextRequestedEventArgs e)
{
if (sender is Grid grid)