Skip to content

Commit 81da026

Browse files
enhance: enable focus for custom action edits (#1478)
1 parent 2a1a537 commit 81da026

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

src/Views/ExecuteCustomAction.axaml

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
xmlns:c="using:SourceGit.Converters"
88
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450"
99
x:Class="SourceGit.Views.ExecuteCustomAction"
10-
x:DataType="vm:ExecuteCustomAction">
10+
x:DataType="vm:ExecuteCustomAction"
11+
Loaded="OnLoaded">
1112
<StackPanel Orientation="Vertical" Margin="8,0">
1213
<TextBlock FontSize="18"
1314
Classes="bold"
@@ -24,14 +25,14 @@
2425
<DataTemplate DataType="m:Null">
2526
<StackPanel Orientation="Horizontal">
2627
<Path Width="14" Height="14" Data="{StaticResource Icons.Repositories}"/>
27-
<SelectableTextBlock VerticalAlignment="Center" Text="{DynamicResource Text.ExecuteCustomAction.Repository}" Margin="8,0,0,0"/>
28+
<SelectableTextBlock VerticalAlignment="Center" Text="{DynamicResource Text.ExecuteCustomAction.Repository}" Margin="8,0,0,0" IsTabStop="False"/>
2829
</StackPanel>
2930
</DataTemplate>
3031

3132
<DataTemplate DataType="m:Branch">
3233
<StackPanel Orientation="Horizontal">
3334
<Path Width="14" Height="14" Data="{StaticResource Icons.Branch}"/>
34-
<SelectableTextBlock VerticalAlignment="Center" Text="{Binding FriendlyName}" Margin="8,0,0,0"/>
35+
<SelectableTextBlock VerticalAlignment="Center" Text="{Binding FriendlyName}" Margin="8,0,0,0" IsTabStop="False"/>
3536
</StackPanel>
3637
</DataTemplate>
3738

@@ -53,34 +54,27 @@
5354
</ContentControl>
5455
</Grid>
5556

56-
<ListBox IsVisible="{Binding ControlParameters, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}"
57-
ItemsSource="{Binding ControlParameters, Mode=OneWay}">
58-
<ListBox.Styles>
59-
<Style Selector="ListBoxItem">
60-
<Setter Property="Height" Value="32"/>
61-
<Setter Property="Margin" Value="0"/>
62-
<Setter Property="Padding" Value="0"/>
63-
<Setter Property="BorderThickness" Value="0"/>
57+
<ItemsControl IsVisible="{Binding ControlParameters, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}"
58+
ItemsSource="{Binding ControlParameters, Mode=OneWay}">
59+
<ItemsControl.Styles>
60+
<Style Selector="ContentPresenter">
61+
<Setter Property="Margin" Value="0,1,0,1"/>
6462
</Style>
65-
<Style Selector="ListBoxItem:pointerover /template/ ContentPresenter#PART_ContentPresenter, ListBoxItem:selected /template/ ContentPresenter#PART_ContentPresenter">
66-
<Setter Property="Background" Value="Transparent"/>
67-
</Style>
68-
</ListBox.Styles>
63+
</ItemsControl.Styles>
6964

70-
<ListBox.ItemsPanel>
65+
<ItemsControl.ItemsPanel>
7166
<ItemsPanelTemplate>
7267
<StackPanel Orientation="Vertical"/>
7368
</ItemsPanelTemplate>
74-
</ListBox.ItemsPanel>
75-
76-
<ListBox.DataTemplates>
69+
</ItemsControl.ItemsPanel>
70+
71+
<ItemsControl.DataTemplates>
7772
<DataTemplate DataType="vm:CustomActionControlTextBox">
7873
<Grid ColumnDefinitions="150,*">
7974
<TextBlock Grid.Column="0"
8075
Text="{Binding Label}"
8176
HorizontalAlignment="Right" VerticalAlignment="Center"
8277
Margin="0,0,8,0"/>
83-
8478
<TextBox Grid.Column="1"
8579
Height="28"
8680
VerticalAlignment="Center"
@@ -105,7 +99,6 @@
10599
Text="{Binding Label}"
106100
HorizontalAlignment="Right" VerticalAlignment="Center"
107101
Margin="0,0,8,0"/>
108-
109102
<TextBox Grid.Column="1"
110103
Height="28"
111104
CornerRadius="3"
@@ -119,7 +112,7 @@
119112
</TextBox>
120113
</Grid>
121114
</DataTemplate>
122-
</ListBox.DataTemplates>
123-
</ListBox>
115+
</ItemsControl.DataTemplates>
116+
</ItemsControl>
124117
</StackPanel>
125118
</UserControl>

src/Views/ExecuteCustomAction.axaml.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
2-
2+
using System.Linq;
33
using Avalonia.Controls;
4+
using Avalonia.Input;
45
using Avalonia.Interactivity;
56
using Avalonia.Platform.Storage;
7+
using Avalonia.VisualTree;
68

79
namespace SourceGit.Views
810
{
@@ -13,6 +15,15 @@ public ExecuteCustomAction()
1315
InitializeComponent();
1416
}
1517

18+
private void OnLoaded(object sender, RoutedEventArgs e)
19+
{
20+
var firstFocusable = this
21+
.GetVisualDescendants()
22+
.OfType<InputElement>()
23+
.FirstOrDefault(x => x.Focusable && x.IsTabStop);
24+
firstFocusable?.Focus();
25+
}
26+
1627
private async void SelectPath(object sender, RoutedEventArgs e)
1728
{
1829
var topLevel = TopLevel.GetTopLevel(this);

0 commit comments

Comments
 (0)