mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
feature: select and open repository by keyboard in Welcome page (#391)
This commit is contained in:
parent
10e5c7aa6c
commit
71d36698f8
2 changed files with 43 additions and 1 deletions
|
@ -19,6 +19,7 @@
|
||||||
BorderThickness="1"
|
BorderThickness="1"
|
||||||
Background="{DynamicResource Brush.Contents}"
|
Background="{DynamicResource Brush.Contents}"
|
||||||
Watermark="{DynamicResource Text.Welcome.Search}"
|
Watermark="{DynamicResource Text.Welcome.Search}"
|
||||||
|
KeyDown="OnSearchBoxKeyDown"
|
||||||
VerticalContentAlignment="Center"
|
VerticalContentAlignment="Center"
|
||||||
Text="{Binding SearchFilter, Mode=TwoWay}"
|
Text="{Binding SearchFilter, Mode=TwoWay}"
|
||||||
v:AutoFocusBehaviour.IsEnabled="True">
|
v:AutoFocusBehaviour.IsEnabled="True">
|
||||||
|
@ -34,12 +35,14 @@
|
||||||
</TextBox>
|
</TextBox>
|
||||||
|
|
||||||
<TreeView Grid.Row="1"
|
<TreeView Grid.Row="1"
|
||||||
|
x:Name="ReposTree"
|
||||||
Margin="0,8,8,0"
|
Margin="0,8,8,0"
|
||||||
ItemsSource="{Binding RepositoryNodes}"
|
ItemsSource="{Binding RepositoryNodes}"
|
||||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||||
Loaded="SetupTreeViewDragAndDrop"
|
Loaded="SetupTreeViewDragAndDrop"
|
||||||
LostFocus="OnTreeViewLostFocus">
|
LostFocus="OnTreeViewLostFocus"
|
||||||
|
KeyDown="OnTreeViewKeyDown">
|
||||||
<TreeView.ContextMenu>
|
<TreeView.ContextMenu>
|
||||||
<ContextMenu>
|
<ContextMenu>
|
||||||
<MenuItem Header="{DynamicResource Text.Welcome.AddRootFolder}" Command="{Binding AddRootNode}">
|
<MenuItem Header="{DynamicResource Text.Welcome.AddRootFolder}" Command="{Binding AddRootNode}">
|
||||||
|
@ -55,6 +58,11 @@
|
||||||
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
|
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
|
||||||
<Setter Property="IsVisible" Value="{Binding IsVisible}"/>
|
<Setter Property="IsVisible" Value="{Binding IsVisible}"/>
|
||||||
<Setter Property="CornerRadius" Value="4"/>
|
<Setter Property="CornerRadius" Value="4"/>
|
||||||
|
<Setter Property="FocusAdorner">
|
||||||
|
<FocusAdornerTemplate>
|
||||||
|
<Border Background="Transparent" BorderThickness="0"/>
|
||||||
|
</FocusAdornerTemplate>
|
||||||
|
</Setter>
|
||||||
</Style>
|
</Style>
|
||||||
</TreeView.Styles>
|
</TreeView.Styles>
|
||||||
|
|
||||||
|
|
|
@ -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)
|
private void OnTreeNodeContextRequested(object sender, ContextRequestedEventArgs e)
|
||||||
{
|
{
|
||||||
if (sender is Grid grid)
|
if (sender is Grid grid)
|
||||||
|
|
Loading…
Reference in a new issue