Skip to content

Commit 6538efc

Browse files
committed
feature: allows to go back to repository command palette from sub command
Signed-off-by: leo <longshuang@msn.cn>
1 parent 306fb8f commit 6538efc

File tree

4 files changed

+69
-36
lines changed

4 files changed

+69
-36
lines changed

src/Views/BlameCommandPalette.axaml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
x:Class="SourceGit.Views.BlameCommandPalette"
1010
x:DataType="vm:BlameCommandPalette">
1111
<Grid RowDefinitions="Auto,Auto">
12-
<TextBox Grid.Row="0"
13-
x:Name="FilterTextBox"
14-
Height="24"
15-
Margin="4,8,4,0"
16-
BorderThickness="1"
17-
CornerRadius="12"
18-
Text="{Binding Filter, Mode=TwoWay}"
19-
BorderBrush="{DynamicResource Brush.Border2}"
20-
VerticalContentAlignment="Center"
21-
v:AutoFocusBehaviour.IsEnabled="True">
12+
<v:RepositoryCommandPaletteTextBox Grid.Row="0"
13+
x:Name="FilterTextBox"
14+
Height="24"
15+
Margin="4,8,4,0"
16+
BorderThickness="1"
17+
CornerRadius="12"
18+
Text="{Binding Filter, Mode=TwoWay}"
19+
BorderBrush="{DynamicResource Brush.Border2}"
20+
VerticalContentAlignment="Center">
2221
<TextBox.InnerLeftContent>
2322
<StackPanel Orientation="Horizontal">
2423
<Path Width="14" Height="14"
@@ -29,7 +28,7 @@
2928
Background="{DynamicResource Brush.Badge}"
3029
Height="18"
3130
CornerRadius="4"
32-
Margin="4,0" Padding="4,0">
31+
Margin="4,0,0,0" Padding="4,0">
3332
<TextBlock Text="{DynamicResource Text.Blame}"
3433
Foreground="Black"
3534
FontWeight="Bold"/>
@@ -50,7 +49,7 @@
5049
Data="{StaticResource Icons.Clear}"/>
5150
</Button>
5251
</TextBox.InnerRightContent>
53-
</TextBox>
52+
</v:RepositoryCommandPaletteTextBox>
5453

5554
<ListBox Grid.Row="1"
5655
x:Name="FileListBox"

src/Views/FileHistoryCommandPalette.axaml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
x:Class="SourceGit.Views.FileHistoryCommandPalette"
1010
x:DataType="vm:FileHistoryCommandPalette">
1111
<Grid RowDefinitions="Auto,Auto">
12-
<TextBox Grid.Row="0"
13-
x:Name="FilterTextBox"
14-
Height="24"
15-
Margin="4,8,4,0"
16-
BorderThickness="1"
17-
CornerRadius="12"
18-
Text="{Binding Filter, Mode=TwoWay}"
19-
BorderBrush="{DynamicResource Brush.Border2}"
20-
VerticalContentAlignment="Center"
21-
v:AutoFocusBehaviour.IsEnabled="True">
12+
<v:RepositoryCommandPaletteTextBox Grid.Row="0"
13+
x:Name="FilterTextBox"
14+
Height="24"
15+
Margin="4,8,4,0"
16+
BorderThickness="1"
17+
CornerRadius="12"
18+
Text="{Binding Filter, Mode=TwoWay}"
19+
BorderBrush="{DynamicResource Brush.Border2}"
20+
VerticalContentAlignment="Center">
2221
<TextBox.InnerLeftContent>
2322
<StackPanel Orientation="Horizontal">
2423
<Path Width="14" Height="14"
@@ -29,7 +28,7 @@
2928
Background="{DynamicResource Brush.Badge}"
3029
Height="18"
3130
CornerRadius="4"
32-
Margin="4,0" Padding="4,0">
31+
Margin="4,0,0,0" Padding="4,0">
3332
<TextBlock Text="{DynamicResource Text.FileHistory}"
3433
Foreground="Black"
3534
FontWeight="Bold"/>
@@ -50,7 +49,7 @@
5049
Data="{StaticResource Icons.Clear}"/>
5150
</Button>
5251
</TextBox.InnerRightContent>
53-
</TextBox>
52+
</v:RepositoryCommandPaletteTextBox>
5453

5554
<ListBox Grid.Row="1"
5655
x:Name="FileListBox"

src/Views/MergeCommandPalette.axaml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@
1010
x:Class="SourceGit.Views.MergeCommandPalette"
1111
x:DataType="vm:MergeCommandPalette">
1212
<Grid RowDefinitions="Auto,Auto">
13-
<TextBox Grid.Row="0"
14-
x:Name="FilterTextBox"
15-
Height="24"
16-
Margin="4,8,4,0"
17-
BorderThickness="1"
18-
CornerRadius="12"
19-
Text="{Binding Filter, Mode=TwoWay}"
20-
BorderBrush="{DynamicResource Brush.Border2}"
21-
VerticalContentAlignment="Center"
22-
v:AutoFocusBehaviour.IsEnabled="True">
13+
<v:RepositoryCommandPaletteTextBox Grid.Row="0"
14+
x:Name="FilterTextBox"
15+
Height="24"
16+
Margin="4,8,4,0"
17+
BorderThickness="1"
18+
CornerRadius="12"
19+
Text="{Binding Filter, Mode=TwoWay}"
20+
BorderBrush="{DynamicResource Brush.Border2}"
21+
VerticalContentAlignment="Center">
2322
<TextBox.InnerLeftContent>
2423
<StackPanel Orientation="Horizontal">
2524
<Path Width="14" Height="14"
@@ -30,7 +29,7 @@
3029
Background="{DynamicResource Brush.Badge}"
3130
Height="18"
3231
CornerRadius="4"
33-
Margin="4,0" Padding="4,0">
32+
Margin="4,0,0,0" Padding="4,0">
3433
<TextBlock Text="{DynamicResource Text.Merge}"
3534
Foreground="Black"
3635
FontWeight="Bold"/>
@@ -51,7 +50,7 @@
5150
Data="{StaticResource Icons.Clear}"/>
5251
</Button>
5352
</TextBox.InnerRightContent>
54-
</TextBox>
53+
</v:RepositoryCommandPaletteTextBox>
5554

5655
<ListBox Grid.Row="1"
5756
x:Name="BranchListBox"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using Avalonia;
3+
using Avalonia.Controls;
4+
using Avalonia.Input;
5+
using Avalonia.VisualTree;
6+
7+
namespace SourceGit.Views
8+
{
9+
public class RepositoryCommandPaletteTextBox : TextBox
10+
{
11+
protected override Type StyleKeyOverride => typeof(TextBox);
12+
13+
protected override void OnKeyDown(KeyEventArgs e)
14+
{
15+
if (e.Key == Key.Back && string.IsNullOrEmpty(Text))
16+
{
17+
var launcherView = this.FindAncestorOfType<Launcher>(false);
18+
if (launcherView is { DataContext: ViewModels.Launcher launcher } &&
19+
launcher.ActivePage is { Data: ViewModels.Repository repo })
20+
{
21+
launcher.OpenCommandPalette(new ViewModels.RepositoryCommandPalette(launcher, repo));
22+
e.Handled = true;
23+
return;
24+
}
25+
}
26+
27+
base.OnKeyDown(e);
28+
}
29+
30+
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
31+
{
32+
base.OnAttachedToVisualTree(e);
33+
Focus();
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)