feature<Preference>: query git config after selecting git path

This commit is contained in:
李通洲 2021-09-06 19:58:41 +08:00
parent adce866716
commit 1a5fdc540c
3 changed files with 19 additions and 7 deletions

View file

@ -194,7 +194,7 @@ namespace SourceGit.Models {
}
/// <summary>
/// 检测配置是否
/// 检测配置是否正常
/// </summary>
[JsonIgnore]
public bool IsReady {

View file

@ -265,6 +265,7 @@
Margin="0,0,8,0"/>
<controls:TextEdit
Grid.Row="14" Grid.Column="1"
x:Name="editGitUser"
Height="24"
Text="{Binding ElementName=me, Path=User, Mode=TwoWay}"
Placeholder="{DynamicResource Text.Preference.Git.User.Placeholder}"/>
@ -277,6 +278,7 @@
Margin="0,0,8,0"/>
<controls:TextEdit
Grid.Row="15" Grid.Column="1"
x:Name="editGitEmail"
Height="24"
Text="{Binding ElementName=me, Path=Email, Mode=TwoWay}"
Placeholder="{DynamicResource Text.Preference.Git.Email.Placeholder}"/>
@ -289,6 +291,7 @@
Margin="0,0,8,0"/>
<ComboBox
Grid.Row="16" Grid.Column="1"
x:Name="editGitCrlf"
Height="24"
ItemsSource="{Binding Source={x:Static models:CRLFOption.Supported}}"
SelectedValuePath="Value"

View file

@ -24,12 +24,7 @@ namespace SourceGit.Views {
public bool EnableWindowsTerminal { get; set; } = PathFindOnPath(new StringBuilder("wt.exe"), null);
public Preference() {
if (Models.Preference.Instance.IsReady) {
User = new Commands.Config().Get("user.name");
Email = new Commands.Config().Get("user.email");
CRLF = new Commands.Config().Get("core.autocrlf");
if (string.IsNullOrEmpty(CRLF)) CRLF = "false";
} else {
if (!UpdateGitInfoIfReady()) {
User = "";
Email = "";
CRLF = "false";
@ -42,6 +37,15 @@ namespace SourceGit.Views {
InitializeComponent();
}
private bool UpdateGitInfoIfReady() {
if (!Models.Preference.Instance.IsReady) return false;
User = new Commands.Config().Get("user.name");
Email = new Commands.Config().Get("user.email");
CRLF = new Commands.Config().Get("core.autocrlf");
if (string.IsNullOrEmpty(CRLF)) CRLF = "false";
return true;
}
#region EVENTS
private void LocaleChanged(object sender, SelectionChangedEventArgs e) {
Models.Locale.Change();
@ -65,6 +69,11 @@ namespace SourceGit.Views {
if (dialog.ShowDialog() == true) {
Models.Preference.Instance.Git.Path = dialog.FileName;
editGitPath?.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
if (UpdateGitInfoIfReady()) {
editGitUser?.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
editGitEmail?.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
editGitCrlf?.GetBindingExpression(ComboBox.SelectedValueProperty).UpdateTarget();
}
}
}