Skip to content

Commit fbe82db

Browse files
committed
refactor: ignore hard-coded Enter/Space key event in AvaloniaUI's ListBox and make it can be handled by app
Signed-off-by: leo <longshuang@msn.cn>
1 parent 5dbb529 commit fbe82db

18 files changed

Lines changed: 209 additions & 184 deletions

‎src/Views/BlameCommandPalette.axaml‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@
5757
FontWeight="Bold"
5858
Foreground="{DynamicResource Brush.FG2}"/>
5959

60-
<ListBox Grid.Row="2"
61-
x:Name="FileListBox"
62-
MaxHeight="360"
63-
Margin="4,8"
64-
BorderThickness="0"
65-
SelectionMode="Single"
66-
Background="Transparent"
67-
Focusable="True"
68-
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
69-
ScrollViewer.VerticalScrollBarVisibility="Auto"
70-
ItemsSource="{Binding VisibleFiles, Mode=OneWay}"
71-
SelectedItem="{Binding SelectedFile, Mode=TwoWay}"
72-
IsVisible="{Binding VisibleFiles, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}">
60+
<v:ListBoxEx Grid.Row="2"
61+
x:Name="FileListBox"
62+
MaxHeight="360"
63+
Margin="4,8"
64+
BorderThickness="0"
65+
SelectionMode="Single"
66+
Background="Transparent"
67+
Focusable="True"
68+
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
69+
ScrollViewer.VerticalScrollBarVisibility="Auto"
70+
ItemsSource="{Binding VisibleFiles, Mode=OneWay}"
71+
SelectedItem="{Binding SelectedFile, Mode=TwoWay}"
72+
IsVisible="{Binding VisibleFiles, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}">
7373
<ListBox.Styles>
7474
<Style Selector="ListBoxItem">
7575
<Setter Property="Padding" Value="8,0"/>
@@ -110,7 +110,7 @@
110110
</Grid>
111111
</DataTemplate>
112112
</ListBox.ItemTemplate>
113-
</ListBox>
113+
</v:ListBoxEx>
114114

115115
<v:LoadingIcon Grid.Row="1"
116116
Width="48" Height="48"

‎src/Views/BranchSelector.axaml‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@
100100
</TextBox.InnerRightContent>
101101
</TextBox>
102102

103-
<ListBox Grid.Row="1"
104-
Focusable="True"
105-
Margin="0,4"
106-
MaxHeight="360"
107-
BorderThickness="0"
108-
Background="Transparent"
109-
ItemsSource="{TemplateBinding VisibleBranches, Mode=OneWay}"
110-
SelectedItem="{TemplateBinding SelectedBranch, Mode=TwoWay}"
111-
KeyDown="OnDropDownListKeyDown">
103+
<v:ListBoxEx Grid.Row="1"
104+
Focusable="True"
105+
Margin="0,4"
106+
MaxHeight="360"
107+
BorderThickness="0"
108+
Background="Transparent"
109+
ItemsSource="{TemplateBinding VisibleBranches, Mode=OneWay}"
110+
SelectedItem="{TemplateBinding SelectedBranch, Mode=TwoWay}"
111+
KeyDown="OnDropDownListKeyDown">
112112
<ListBox.ItemsPanel>
113113
<ItemsPanelTemplate>
114114
<VirtualizingStackPanel Orientation="Vertical"/>
@@ -130,7 +130,7 @@
130130
</StackPanel>
131131
</DataTemplate>
132132
</ListBox.ItemTemplate>
133-
</ListBox>
133+
</v:ListBoxEx>
134134
</Grid>
135135
</Border>
136136
</Popup>

‎src/Views/BranchSelector.axaml.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ private void OnSearchBoxKeyDown(object _, KeyEventArgs e)
182182

183183
e.Handled = true;
184184
}
185+
else if (e.Key == Key.Enter)
186+
{
187+
IsDropDownOpened = false;
188+
e.Handled = true;
189+
}
185190
}
186191

187192
private void OnClearSearchFilter(object sender, RoutedEventArgs e)

‎src/Views/ChangeCollectionView.axaml.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected override void OnPointerPressed(PointerPressedEventArgs e)
2929
}
3030
}
3131

32-
public class ChangeCollectionContainer : ListBox
32+
public class ChangeCollectionContainer : ListBoxEx
3333
{
3434
protected override Type StyleKeyOverride => typeof(ListBox);
3535

@@ -45,7 +45,7 @@ protected override void OnKeyDown(KeyEventArgs e)
4545
}
4646
}
4747

48-
if (!e.Handled && e.Key != Key.Space && e.Key != Key.Enter)
48+
if (!e.Handled)
4949
base.OnKeyDown(e);
5050
}
5151
}

‎src/Views/CheckoutCommandPalette.axaml‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,19 @@
5858
FontWeight="Bold"
5959
Foreground="{DynamicResource Brush.FG2}"/>
6060

61-
<ListBox Grid.Row="2"
62-
x:Name="BranchListBox"
63-
MaxHeight="360"
64-
Margin="4,8"
65-
BorderThickness="0"
66-
SelectionMode="Single"
67-
Background="Transparent"
68-
Focusable="True"
69-
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
70-
ScrollViewer.VerticalScrollBarVisibility="Auto"
71-
ItemsSource="{Binding Branches, Mode=OneWay}"
72-
SelectedItem="{Binding SelectedBranch, Mode=TwoWay}"
73-
IsVisible="{Binding Branches, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}">
61+
<v:ListBoxEx Grid.Row="2"
62+
x:Name="BranchListBox"
63+
MaxHeight="360"
64+
Margin="4,8"
65+
BorderThickness="0"
66+
SelectionMode="Single"
67+
Background="Transparent"
68+
Focusable="True"
69+
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
70+
ScrollViewer.VerticalScrollBarVisibility="Auto"
71+
ItemsSource="{Binding Branches, Mode=OneWay}"
72+
SelectedItem="{Binding SelectedBranch, Mode=TwoWay}"
73+
IsVisible="{Binding Branches, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}">
7474
<ListBox.Styles>
7575
<Style Selector="ListBoxItem">
7676
<Setter Property="Padding" Value="8,0"/>
@@ -108,6 +108,6 @@
108108
</Grid>
109109
</DataTemplate>
110110
</ListBox.ItemTemplate>
111-
</ListBox>
111+
</v:ListBoxEx>
112112
</Grid>
113113
</UserControl>

‎src/Views/CompareCommandPalette.axaml‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,19 @@
7070
FontWeight="Bold"
7171
Foreground="{DynamicResource Brush.FG2}"/>
7272

73-
<ListBox Grid.Row="2"
74-
x:Name="RefsListBox"
75-
MaxHeight="360"
76-
Margin="4,8"
77-
BorderThickness="0"
78-
SelectionMode="Single"
79-
Background="Transparent"
80-
Focusable="True"
81-
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
82-
ScrollViewer.VerticalScrollBarVisibility="Auto"
83-
ItemsSource="{Binding Refs, Mode=OneWay}"
84-
SelectedItem="{Binding CompareTo, Mode=TwoWay}"
85-
IsVisible="{Binding Refs, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}">
73+
<v:ListBoxEx Grid.Row="2"
74+
x:Name="RefsListBox"
75+
MaxHeight="360"
76+
Margin="4,8"
77+
BorderThickness="0"
78+
SelectionMode="Single"
79+
Background="Transparent"
80+
Focusable="True"
81+
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
82+
ScrollViewer.VerticalScrollBarVisibility="Auto"
83+
ItemsSource="{Binding Refs, Mode=OneWay}"
84+
SelectedItem="{Binding CompareTo, Mode=TwoWay}"
85+
IsVisible="{Binding Refs, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}">
8686
<ListBox.Styles>
8787
<Style Selector="ListBoxItem">
8888
<Setter Property="Padding" Value="8,0"/>
@@ -134,6 +134,6 @@
134134
</Grid>
135135
</DataTemplate>
136136
</ListBox.DataTemplates>
137-
</ListBox>
137+
</v:ListBoxEx>
138138
</Grid>
139139
</UserControl>

‎src/Views/ExecuteCustomActionCommandPalette.axaml‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@
5757
FontWeight="Bold"
5858
Foreground="{DynamicResource Brush.FG2}"/>
5959

60-
<ListBox Grid.Row="2"
61-
x:Name="ActionListBox"
62-
MaxHeight="360"
63-
Margin="4,8"
64-
BorderThickness="0"
65-
SelectionMode="Single"
66-
Background="Transparent"
67-
Focusable="True"
68-
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
69-
ScrollViewer.VerticalScrollBarVisibility="Auto"
70-
ItemsSource="{Binding VisibleActions, Mode=OneWay}"
71-
SelectedItem="{Binding Selected, Mode=TwoWay}"
72-
IsVisible="{Binding VisibleActions, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}">
60+
<v:ListBoxEx Grid.Row="2"
61+
x:Name="ActionListBox"
62+
MaxHeight="360"
63+
Margin="4,8"
64+
BorderThickness="0"
65+
SelectionMode="Single"
66+
Background="Transparent"
67+
Focusable="True"
68+
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
69+
ScrollViewer.VerticalScrollBarVisibility="Auto"
70+
ItemsSource="{Binding VisibleActions, Mode=OneWay}"
71+
SelectedItem="{Binding Selected, Mode=TwoWay}"
72+
IsVisible="{Binding VisibleActions, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}">
7373
<ListBox.Styles>
7474
<Style Selector="ListBoxItem">
7575
<Setter Property="Padding" Value="8,0"/>
@@ -110,7 +110,7 @@
110110
</Grid>
111111
</DataTemplate>
112112
</ListBox.ItemTemplate>
113-
</ListBox>
113+
</v:ListBoxEx>
114114

115115
<Path Grid.Row="2"
116116
Width="64" Height="64"

‎src/Views/FileHistoryCommandPalette.axaml‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@
5757
FontWeight="Bold"
5858
Foreground="{DynamicResource Brush.FG2}"/>
5959

60-
<ListBox Grid.Row="2"
61-
x:Name="FileListBox"
62-
MaxHeight="360"
63-
Margin="4,8"
64-
BorderThickness="0"
65-
SelectionMode="Single"
66-
Background="Transparent"
67-
Focusable="True"
68-
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
69-
ScrollViewer.VerticalScrollBarVisibility="Auto"
70-
ItemsSource="{Binding VisibleFiles, Mode=OneWay}"
71-
SelectedItem="{Binding SelectedFile, Mode=TwoWay}"
72-
IsVisible="{Binding VisibleFiles, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}">
60+
<v:ListBoxEx Grid.Row="2"
61+
x:Name="FileListBox"
62+
MaxHeight="360"
63+
Margin="4,8"
64+
BorderThickness="0"
65+
SelectionMode="Single"
66+
Background="Transparent"
67+
Focusable="True"
68+
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
69+
ScrollViewer.VerticalScrollBarVisibility="Auto"
70+
ItemsSource="{Binding VisibleFiles, Mode=OneWay}"
71+
SelectedItem="{Binding SelectedFile, Mode=TwoWay}"
72+
IsVisible="{Binding VisibleFiles, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}">
7373
<ListBox.Styles>
7474
<Style Selector="ListBoxItem">
7575
<Setter Property="Padding" Value="8,0"/>
@@ -110,7 +110,7 @@
110110
</Grid>
111111
</DataTemplate>
112112
</ListBox.ItemTemplate>
113-
</ListBox>
113+
</v:ListBoxEx>
114114

115115
<v:LoadingIcon Grid.Row="1"
116116
Width="48" Height="48"

‎src/Views/GotoRevisionSelector.axaml‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@
3636
IsVisible="{OnPlatform True, macOS=False}"/>
3737
</Grid>
3838

39-
<ListBox Grid.Row="1"
40-
x:Name="RevisionList"
41-
Focusable="True"
42-
Margin="8" Padding="4"
43-
SelectionMode="AlwaysSelected"
44-
BorderThickness="0"
45-
Background="Transparent"
46-
Grid.IsSharedSizeScope="True"
47-
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
48-
ScrollViewer.VerticalScrollBarVisibility="Disabled"
49-
KeyDown="OnListKeyDown">
39+
<v:ListBoxEx Grid.Row="1"
40+
x:Name="RevisionList"
41+
Focusable="True"
42+
Margin="8" Padding="4"
43+
SelectionMode="AlwaysSelected"
44+
BorderThickness="0"
45+
Background="Transparent"
46+
Grid.IsSharedSizeScope="True"
47+
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
48+
ScrollViewer.VerticalScrollBarVisibility="Disabled"
49+
KeyDown="OnRevisionListKeyDown">
5050
<ListBox.Styles>
5151
<Style Selector="ListBoxItem">
5252
<Setter Property="Margin" Value="0"/>
@@ -64,7 +64,7 @@
6464

6565
<ListBox.ItemTemplate>
6666
<DataTemplate DataType="m:Commit">
67-
<Grid Background="Transparent" Tapped="OnListItemTapped">
67+
<Grid Background="Transparent" Tapped="OnRevisionListItemTapped">
6868
<Grid.ColumnDefinitions>
6969
<ColumnDefinition Width="24"/>
7070
<ColumnDefinition Width="*"/>
@@ -95,6 +95,6 @@
9595
</Grid>
9696
</DataTemplate>
9797
</ListBox.ItemTemplate>
98-
</ListBox>
98+
</v:ListBoxEx>
9999
</Grid>
100100
</v:ChromelessWindow>

‎src/Views/GotoRevisionSelector.axaml.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected override void OnLoaded(RoutedEventArgs e)
1818
RevisionList.Focus();
1919
}
2020

21-
private void OnListKeyDown(object sender, KeyEventArgs e)
21+
private void OnRevisionListKeyDown(object sender, KeyEventArgs e)
2222
{
2323
if (e is not { Key: Key.Enter, KeyModifiers: KeyModifiers.None })
2424
return;
@@ -30,7 +30,7 @@ private void OnListKeyDown(object sender, KeyEventArgs e)
3030
e.Handled = true;
3131
}
3232

33-
private void OnListItemTapped(object sender, TappedEventArgs e)
33+
private void OnRevisionListItemTapped(object sender, TappedEventArgs e)
3434
{
3535
if (sender is not Control { DataContext: Models.Commit commit })
3636
return;

0 commit comments

Comments
 (0)