ux: auto focus the first input element in popup widget (#49)

This commit is contained in:
leo 2024-04-02 16:23:47 +08:00
parent ddd152df59
commit 96e60da7ad
45 changed files with 401 additions and 333 deletions

View file

@ -568,6 +568,9 @@ namespace SourceGit.ViewModels
public void RefreshWorkingCopyChanges()
{
var changes = new Commands.QueryLocalChanges(FullPath, _includeUntracked).Result();
if (_workingCopy == null)
return;
var hasUnsolvedConflict = _workingCopy.SetData(changes);
var inProgress = null as InProgressContext;

View file

@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:m="using:SourceGit.Models"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:v="using:SourceGit.Views"
xmlns:c="using:SourceGit.Converters"
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450"
x:Class="SourceGit.Views.AddRemote"
@ -23,7 +24,8 @@
VerticalAlignment="Center"
CornerRadius="2"
Watermark="{DynamicResource Text.Remote.Name.Placeholder}"
Text="{Binding Name, Mode=TwoWay}"/>
Text="{Binding Name, Mode=TwoWay}"
v:AutoFocusBehaviour.IsEnabled="True"/>
<TextBlock Grid.Row="1" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"

View file

@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:m="using:SourceGit.Models"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:v="using:SourceGit.Views"
xmlns:c="using:SourceGit.Converters"
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450"
x:Class="SourceGit.Views.AddSubmodule"
@ -22,7 +23,8 @@
VerticalAlignment="Center"
CornerRadius="2"
Watermark="{DynamicResource Text.RepositoryURL}"
Text="{Binding Url, Mode=TwoWay}"/>
Text="{Binding Url, Mode=TwoWay}"
v:AutoFocusBehaviour.IsEnabled="True"/>
<TextBlock Grid.Row="1" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"

View file

@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:m="using:SourceGit.Models"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:v="using:SourceGit.Views"
xmlns:c="using:SourceGit.Converters"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.Apply"
@ -23,7 +24,8 @@
Height="28"
CornerRadius="3"
Watermark="{DynamicResource Text.Apply.File.Placeholder}"
Text="{Binding PatchFile, Mode=TwoWay}">
Text="{Binding PatchFile, Mode=TwoWay}"
v:AutoFocusBehaviour.IsEnabled="True">
<TextBox.InnerRightContent>
<Button Classes="icon_button" Width="30" Height="30" Click="SelectPatchFile">
<Path Data="{StaticResource Icons.Folder.Open}" Fill="{DynamicResource Brush.FG1}"/>

View file

@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:m="using:SourceGit.Models"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:v="using:SourceGit.Views"
xmlns:c="using:SourceGit.Converters"
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450"
x:Class="SourceGit.Views.Archive"
@ -52,7 +53,8 @@
Height="28"
CornerRadius="3"
Watermark="{DynamicResource Text.Archive.File.Placeholder}"
Text="{Binding SaveFile, Mode=TwoWay}">
Text="{Binding SaveFile, Mode=TwoWay}"
v:AutoFocusBehaviour.IsEnabled="True">
<TextBox.InnerRightContent>
<Button Classes="icon_button" Width="30" Height="30" Click="SelectOutputFile">
<Path Data="{StaticResource Icons.Folder.Open}" Fill="{DynamicResource Brush.FG1}"/>

View file

@ -0,0 +1,32 @@
using Avalonia;
using Avalonia.Input;
namespace SourceGit.Views
{
public class AutoFocusBehaviour : AvaloniaObject
{
public static readonly AttachedProperty<bool> IsEnabledProperty =
AvaloniaProperty.RegisterAttached<AutoFocusBehaviour, InputElement, bool>("IsEnabled", false, false);
static AutoFocusBehaviour()
{
IsEnabledProperty.Changed.AddClassHandler<InputElement>((input, e) =>
{
if (input.GetValue(IsEnabledProperty))
{
input.AttachedToVisualTree += (o, _) => (o as InputElement).Focus(NavigationMethod.Directional);
}
});
}
public static bool GetIsEnabled(AvaloniaObject elem)
{
return elem.GetValue(IsEnabledProperty);
}
public static void SetIsEnabled(AvaloniaObject elem, bool value)
{
elem.SetValue(IsEnabledProperty, value);
}
}
}

View file

@ -13,7 +13,7 @@
<Grid Margin="8,16,0,0" Height="28" ColumnDefinitions="120,*">
<TextBlock Grid.Column="0" HorizontalAlignment="Right" Margin="0,0,8,0" Text="{DynamicResource Text.Clone.RemoteURL}"/>
<TextBox Grid.Column="1" CornerRadius="3" Text="{Binding Remote, Mode=TwoWay}"/>
<TextBox Grid.Column="1" CornerRadius="3" Text="{Binding Remote, Mode=TwoWay}" v:AutoFocusBehaviour.IsEnabled="True"/>
</Grid>
<Grid Margin="8,4,0,0" Height="28" ColumnDefinitions="120,*" IsVisible="{Binding UseSSH}">
<TextBlock Grid.Column="0" HorizontalAlignment="Right" Margin="0,0,8,0" Text="{DynamicResource Text.SSHKey}"/>

View file

@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:m="using:SourceGit.Models"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:v="using:SourceGit.Views"
xmlns:c="using:SourceGit.Converters"
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450"
x:Class="SourceGit.Views.CreateBranch"
@ -51,7 +52,8 @@
Height="26"
VerticalAlignment="Center"
CornerRadius="2"
Text="{Binding Name, Mode=TwoWay}"/>
Text="{Binding Name, Mode=TwoWay}"
v:AutoFocusBehaviour.IsEnabled="True"/>
<TextBlock Grid.Row="2" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"

View file

@ -3,6 +3,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:v="using:SourceGit.Views"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.CreateGroup"
x:DataType="vm:CreateGroup">
@ -11,7 +12,7 @@
<Grid Margin="8,16,0,0" Height="28" ColumnDefinitions="Auto,*">
<TextBlock Grid.Column="0" HorizontalAlignment="Right" Margin="8,0" Text="{DynamicResource Text.Name}"/>
<TextBox Grid.Column="1" CornerRadius="3" Text="{Binding Name, Mode=TwoWay}"/>
<TextBox Grid.Column="1" CornerRadius="3" v:AutoFocusBehaviour.IsEnabled="True" Text="{Binding Name, Mode=TwoWay}"/>
</Grid>
</StackPanel>
</UserControl>

View file

@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:m="using:SourceGit.Models"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:v="using:SourceGit.Views"
xmlns:c="using:SourceGit.Converters"
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450"
x:Class="SourceGit.Views.CreateTag"
@ -44,7 +45,8 @@
Height="26"
VerticalAlignment="Center"
CornerRadius="2"
Text="{Binding TagName, Mode=TwoWay}"/>
Text="{Binding TagName, Mode=TwoWay}"
v:AutoFocusBehaviour.IsEnabled="True"/>
<TextBlock Grid.Row="2" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Top"

View file

@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:m="using:SourceGit.Models"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:v="using:SourceGit.Views"
xmlns:c="using:SourceGit.Converters"
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450"
x:Class="SourceGit.Views.EditRemote"
@ -23,7 +24,8 @@
VerticalAlignment="Center"
CornerRadius="2"
Watermark="{DynamicResource Text.Remote.Name.Placeholder}"
Text="{Binding Name, Mode=TwoWay}"/>
Text="{Binding Name, Mode=TwoWay}"
v:AutoFocusBehaviour.IsEnabled="True"/>
<TextBlock Grid.Row="1" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"

View file

@ -27,7 +27,7 @@
</Grid>
<Grid Height="28" Margin="8,4,0,0" ColumnDefinitions="120,*">
<TextBlock Grid.Column="0" HorizontalAlignment="Right" Margin="0,0,8,0" Text="{DynamicResource Text.EditRepositoryNode.Name}"/>
<TextBox Grid.Column="1" CornerRadius="3" Text="{Binding Name, Mode=TwoWay}"/>
<TextBox Grid.Column="1" CornerRadius="3" Text="{Binding Name, Mode=TwoWay}" v:AutoFocusBehaviour.IsEnabled="True"/>
</Grid>
<Grid Height="28" Margin="8,4,0,0" ColumnDefinitions="120,*" IsVisible="{Binding IsRepository}">
<TextBlock Grid.Column="0" HorizontalAlignment="Right" Margin="0,0,8,0" Text="{DynamicResource Text.EditRepositoryNode.Bookmark}"/>

View file

@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:m="using:SourceGit.Models"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:v="using:SourceGit.Views"
xmlns:c="using:SourceGit.Converters"
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450"
x:Class="SourceGit.Views.GitFlowStart"
@ -31,7 +32,8 @@
VerticalAlignment="Center"
CornerRadius="2"
Watermark="{DynamicResource Text.GitFlow.StartPlaceholder}"
Text="{Binding Name, Mode=TwoWay}"/>
Text="{Binding Name, Mode=TwoWay}"
v:AutoFocusBehaviour.IsEnabled="True"/>
</Grid>
</StackPanel>
</UserControl>

View file

@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:m="using:SourceGit.Models"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:v="using:SourceGit.Views"
xmlns:c="using:SourceGit.Converters"
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450"
x:Class="SourceGit.Views.InitGitFlow"
@ -21,7 +22,8 @@
Height="26"
VerticalAlignment="Center"
CornerRadius="2"
Text="{Binding Master, Mode=TwoWay}"/>
Text="{Binding Master, Mode=TwoWay}"
v:AutoFocusBehaviour.IsEnabled="True"/>
<TextBlock Grid.Row="1" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"

View file

@ -284,7 +284,8 @@
<Button Classes="flat primary"
Width="80"
Content="{DynamicResource Text.Sure}"
Click="OnPopupSure"/>
Click="OnPopupSure"
HotKey="Enter"/>
<Button Classes="flat"
Width="80"
Margin="8,0,0,0"

View file

@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:m="using:SourceGit.Models"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:v="using:SourceGit.Views"
xmlns:c="using:SourceGit.Converters"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.RenameBranch"
@ -31,7 +32,8 @@
VerticalAlignment="Center"
CornerRadius="2"
Text="{Binding Name, Mode=TwoWay}"
Watermark="{DynamicResource Text.RenameBranch.Name.Placeholder}"/>
Watermark="{DynamicResource Text.RenameBranch.Name.Placeholder}"
v:AutoFocusBehaviour.IsEnabled="True"/>
</Grid>
</StackPanel>
</UserControl>

View file

@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:m="using:SourceGit.Models"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:v="using:SourceGit.Views"
xmlns:c="using:SourceGit.Converters"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.RepositoryConfigure"
@ -22,7 +23,8 @@
Height="28"
CornerRadius="3"
Watermark="{DynamicResource Text.Configure.User.Placeholder}"
Text="{Binding UserName, Mode=TwoWay}"/>
Text="{Binding UserName, Mode=TwoWay}"
v:AutoFocusBehaviour.IsEnabled="True"/>
<TextBlock Grid.Row="1" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"

View file

@ -3,6 +3,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:v="using:SourceGit.Views"
xmlns:c="using:SourceGit.Converters"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.Reword"
@ -30,7 +31,8 @@
CornerRadius="2"
AcceptsReturn="True"
VerticalContentAlignment="Top"
Text="{Binding Message, Mode=TwoWay}"/>
Text="{Binding Message, Mode=TwoWay}"
v:AutoFocusBehaviour.IsEnabled="True"/>
</Grid>
</StackPanel>
</UserControl>

View file

@ -3,6 +3,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:v="using:SourceGit.Views"
xmlns:c="using:SourceGit.Converters"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.Squash"
@ -40,7 +41,8 @@
CornerRadius="2"
AcceptsReturn="True"
VerticalContentAlignment="Top"
Text="{Binding Message, Mode=TwoWay}"/>
Text="{Binding Message, Mode=TwoWay}"
v:AutoFocusBehaviour.IsEnabled="True"/>
</Grid>
</StackPanel>
</UserControl>

View file

@ -15,7 +15,12 @@
Text="{DynamicResource Text.Stash.Title}"/>
<Grid Margin="8,16,0,0" RowDefinitions="32,Auto" ColumnDefinitions="Auto,*">
<TextBlock Grid.Column="0" HorizontalAlignment="Right" Margin="8,0" Text="{DynamicResource Text.Stash.Message}"/>
<TextBox Grid.Column="1" Height="26" CornerRadius="3" Text="{Binding Message, Mode=TwoWay}" Watermark="{DynamicResource Text.Stash.Message.Placeholder}"/>
<TextBox Grid.Column="1"
Height="26"
CornerRadius="3"
Text="{Binding Message, Mode=TwoWay}"
Watermark="{DynamicResource Text.Stash.Message.Placeholder}"
v:AutoFocusBehaviour.IsEnabled="True"/>
<CheckBox Grid.Row="1" Grid.Column="1"
Height="32"