feat: show tooltip if git version too low

This commit is contained in:
Gadfly 2024-05-29 17:00:17 +08:00
parent 0b09d210be
commit 2f7ef1ef2b
5 changed files with 37 additions and 4 deletions

View file

@ -69,5 +69,22 @@ namespace SourceGit.Converters
public static readonly FuncValueConverter<string, string> ToShortSHA =
new FuncValueConverter<string, string>(v => v.Length > 10 ? v.Substring(0, 10) : v);
public static readonly FuncValueConverter<string, bool> UnderRecommendGitVersion =
new(v =>
{
if (string.IsNullOrEmpty(v))
return true;
var versionParts = v.Split(new[] { '.', '-' }, StringSplitOptions.RemoveEmptyEntries);
if (versionParts.Length < 3)
return true;
if (!int.TryParse(versionParts[0], out var major) ||
!int.TryParse(versionParts[1], out var minor) ||
!int.TryParse(versionParts[2], out var build))
return true;
var gitVersion = new Version(major, minor, build);
var targetVersion = new Version(2, 23, 0);
return gitVersion < targetVersion;
});
}
}

View file

@ -308,6 +308,7 @@
<x:String x:Key="Text.Preference.Git.User" xml:space="preserve">User Name</x:String>
<x:String x:Key="Text.Preference.Git.User.Placeholder" xml:space="preserve">Global git user name</x:String>
<x:String x:Key="Text.Preference.Git.Version" xml:space="preserve">Git version</x:String>
<x:String x:Key="Text.Preference.Git.VersionUnderRecommend" xml:space="preserve">Git version is empty or lower than the recommended 2.23.0, exceptions may occur</x:String>
<x:String x:Key="Text.Preference.GPG" xml:space="preserve">GPG SIGNING</x:String>
<x:String x:Key="Text.Preference.GPG.Enabled" xml:space="preserve">Commit GPG signing</x:String>
<x:String x:Key="Text.Preference.GPG.Path" xml:space="preserve">Install Path</x:String>

View file

@ -308,6 +308,7 @@
<x:String x:Key="Text.Preference.Git.User" xml:space="preserve">用户名</x:String>
<x:String x:Key="Text.Preference.Git.User.Placeholder" xml:space="preserve">默认GIT用户名</x:String>
<x:String x:Key="Text.Preference.Git.Version" xml:space="preserve">Git 版本</x:String>
<x:String x:Key="Text.Preference.Git.VersionUnderRecommend" xml:space="preserve">Git 版本为空或低于推荐的2.23.0,可能出现异常</x:String>
<x:String x:Key="Text.Preference.GPG" xml:space="preserve">GPG签名</x:String>
<x:String x:Key="Text.Preference.GPG.Enabled" xml:space="preserve">启用提交签名</x:String>
<x:String x:Key="Text.Preference.GPG.Path" xml:space="preserve">可执行文件位置</x:String>

View file

@ -251,8 +251,13 @@
Text="{DynamicResource Text.Preference.Git.Version}"
HorizontalAlignment="Right"
Margin="0,0,16,0"/>
<TextBlock Grid.Row="1" Grid.Column="1"
x:Name="txtVersion"/>
<Grid Grid.Row="1" Grid.Column="1" ColumnDefinitions="Auto,Auto">
<TextBlock Grid.Column="0" Text="{Binding #me.GitVersion, Mode=TwoWay}"/>
<Grid Grid.Column="1" ToolTip.Tip="{DynamicResource Text.Preference.Git.VersionUnderRecommend}" HorizontalAlignment="Left"
Background="Transparent" IsVisible="{Binding #me.GitVersion, Converter={x:Static c:StringConverters.UnderRecommendGitVersion}}">
<Path Width="14" Height="14" Margin="10,0,0,0" Data="{StaticResource Icons.Error}" Fill="Red"/>
</Grid>
</Grid>
<Border Grid.Row="2" Grid.Column="0"
Height="32"

View file

@ -45,6 +45,15 @@ namespace SourceGit.Views
set;
}
public static readonly StyledProperty<string> GitVersionProperty =
AvaloniaProperty.Register<Preference, string>(nameof(GitVersion));
public string GitVersion
{
get => GetValue(GitVersionProperty);
set => SetValue(GitVersionProperty, value);
}
public bool EnableGPGSigning
{
get;
@ -140,7 +149,7 @@ namespace SourceGit.Views
}
InitializeComponent();
txtVersion.Text = ver;
GitVersion = ver;
}
private void BeginMoveWindow(object sender, PointerPressedEventArgs e)
@ -189,7 +198,7 @@ namespace SourceGit.Views
if (selected.Count == 1)
{
ViewModels.Preference.Instance.GitInstallPath = selected[0].Path.LocalPath;
txtVersion.Text = new Commands.Version().Query();
GitVersion = new Commands.Version().Query();
}
e.Handled = true;