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

@ -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();
}
}
}