mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
code_review: PR (#152)
This commit is contained in:
parent
13f7279c45
commit
025d468b40
4 changed files with 32 additions and 22 deletions
|
@ -1,12 +1,13 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
using Avalonia.Data.Converters;
|
using Avalonia.Data.Converters;
|
||||||
using Avalonia.Styling;
|
using Avalonia.Styling;
|
||||||
|
|
||||||
namespace SourceGit.Converters
|
namespace SourceGit.Converters
|
||||||
{
|
{
|
||||||
public static class StringConverters
|
public static partial class StringConverters
|
||||||
{
|
{
|
||||||
public class ToLocaleConverter : IValueConverter
|
public class ToLocaleConverter : IValueConverter
|
||||||
{
|
{
|
||||||
|
@ -73,18 +74,22 @@ namespace SourceGit.Converters
|
||||||
public static readonly FuncValueConverter<string, bool> UnderRecommendGitVersion =
|
public static readonly FuncValueConverter<string, bool> UnderRecommendGitVersion =
|
||||||
new(v =>
|
new(v =>
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(v))
|
var match = REG_GIT_VERSION().Match(v ?? "");
|
||||||
return true;
|
if (match.Success)
|
||||||
var versionParts = v.Split(new[] { '.', '-' }, StringSplitOptions.RemoveEmptyEntries);
|
{
|
||||||
if (versionParts.Length < 3)
|
var major = int.Parse(match.Groups[1].Value);
|
||||||
return true;
|
var minor = int.Parse(match.Groups[2].Value);
|
||||||
if (!int.TryParse(versionParts[0], out var major) ||
|
var build = int.Parse(match.Groups[3].Value);
|
||||||
!int.TryParse(versionParts[1], out var minor) ||
|
|
||||||
!int.TryParse(versionParts[2], out var build))
|
return new Version(major, minor, build) < MINIMAL_GIT_VERSION;
|
||||||
return true;
|
}
|
||||||
var gitVersion = new Version(major, minor, build);
|
|
||||||
var targetVersion = new Version(2, 23, 0);
|
return true;
|
||||||
return gitVersion < targetVersion;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
[GeneratedRegex(@"^[\s\w]*(\d+)\.(\d+)\.(\d+).*$")]
|
||||||
|
private static partial Regex REG_GIT_VERSION();
|
||||||
|
|
||||||
|
private static readonly Version MINIMAL_GIT_VERSION = new Version(2, 23, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -308,7 +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" 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.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.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.Git.Invalid" xml:space="preserve">Git (>= 2.23.0) is required by this app</x:String>
|
||||||
<x:String x:Key="Text.Preference.GPG" xml:space="preserve">GPG SIGNING</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.Enabled" xml:space="preserve">Commit GPG signing</x:String>
|
||||||
<x:String x:Key="Text.Preference.GPG.Path" xml:space="preserve">Install Path</x:String>
|
<x:String x:Key="Text.Preference.GPG.Path" xml:space="preserve">Install Path</x:String>
|
||||||
|
|
|
@ -308,7 +308,7 @@
|
||||||
<x:String x:Key="Text.Preference.Git.User" xml:space="preserve">用户名</x:String>
|
<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.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.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.Git.Invalid" 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" 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.Enabled" xml:space="preserve">启用提交签名</x:String>
|
||||||
<x:String x:Key="Text.Preference.GPG.Path" xml:space="preserve">可执行文件位置</x:String>
|
<x:String x:Key="Text.Preference.GPG.Path" xml:space="preserve">可执行文件位置</x:String>
|
||||||
|
|
|
@ -251,13 +251,18 @@
|
||||||
Text="{DynamicResource Text.Preference.Git.Version}"
|
Text="{DynamicResource Text.Preference.Git.Version}"
|
||||||
HorizontalAlignment="Right"
|
HorizontalAlignment="Right"
|
||||||
Margin="0,0,16,0"/>
|
Margin="0,0,16,0"/>
|
||||||
<Grid Grid.Row="1" Grid.Column="1" ColumnDefinitions="Auto,Auto">
|
<StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal">
|
||||||
<TextBlock Grid.Column="0" Text="{Binding #me.GitVersion, Mode=TwoWay}"/>
|
<TextBlock Classes="monospace"
|
||||||
<Grid Grid.Column="1" ToolTip.Tip="{DynamicResource Text.Preference.Git.VersionUnderRecommend}" HorizontalAlignment="Left"
|
Margin="0,0,8,0"
|
||||||
Background="Transparent" IsVisible="{Binding #me.GitVersion, Converter={x:Static c:StringConverters.UnderRecommendGitVersion}}">
|
Text="{Binding #me.GitVersion}"
|
||||||
<Path Width="14" Height="14" Margin="10,0,0,0" Data="{StaticResource Icons.Error}" Fill="Red"/>
|
IsVisible="{Binding #me.GitVersion, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"/>
|
||||||
</Grid>
|
|
||||||
</Grid>
|
<Border Background="Transparent"
|
||||||
|
ToolTip.Tip="{DynamicResource Text.Preference.Git.Invalid}"
|
||||||
|
IsVisible="{Binding #me.GitVersion, Converter={x:Static c:StringConverters.UnderRecommendGitVersion}}">
|
||||||
|
<Path Width="14" Height="14" Data="{StaticResource Icons.Error}" Fill="Red"/>
|
||||||
|
</Border>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
<Border Grid.Row="2" Grid.Column="0"
|
<Border Grid.Row="2" Grid.Column="0"
|
||||||
Height="32"
|
Height="32"
|
||||||
|
|
Loading…
Reference in a new issue