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

This commit is contained in:
李通洲 2021-09-07 10:52:48 +08:00
parent 1a5fdc540c
commit ebc2fc6b91
6 changed files with 70 additions and 33 deletions

View file

@ -73,6 +73,7 @@
<RowDefinition Height="28"/>
<RowDefinition Height="28"/>
<RowDefinition Height="28"/>
<RowDefinition Height="28"/>
<RowDefinition Height="8"/>
<RowDefinition Height="36"/>
<RowDefinition Height="28"/>
@ -230,13 +231,24 @@
Icon="{StaticResource Icon.Folder.Open}"/>
</Grid>
<!-- Default Clone Dir -->
<!-- Git Version -->
<TextBlock
Grid.Row="13" Grid.Column="0"
Text="{DynamicResource Text.Preference.Git.Version}"
HorizontalAlignment="Right"
Margin="0,0,8,0"/>
<TextBlock
Grid.Row="13" Grid.Column="1"
x:Name="textGitVersion"
Text="{Binding ElementName=me, Path=Version}"/>
<!-- Default Clone Dir -->
<TextBlock
Grid.Row="14" Grid.Column="0"
Text="{DynamicResource Text.Preference.Git.Dir}"
HorizontalAlignment="Right"
Margin="0,0,8,0"/>
<Grid Grid.Row="13" Grid.Column="1">
<Grid Grid.Row="14" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
@ -259,12 +271,12 @@
<!-- User -->
<TextBlock
Grid.Row="14" Grid.Column="0"
Grid.Row="15" Grid.Column="0"
Text="{DynamicResource Text.Preference.Git.User}"
HorizontalAlignment="Right"
Margin="0,0,8,0"/>
<controls:TextEdit
Grid.Row="14" Grid.Column="1"
Grid.Row="15" Grid.Column="1"
x:Name="editGitUser"
Height="24"
Text="{Binding ElementName=me, Path=User, Mode=TwoWay}"
@ -272,12 +284,12 @@
<!-- Email -->
<TextBlock
Grid.Row="15" Grid.Column="0"
Grid.Row="16" Grid.Column="0"
Text="{DynamicResource Text.Preference.Git.Email}"
HorizontalAlignment="Right"
Margin="0,0,8,0"/>
<controls:TextEdit
Grid.Row="15" Grid.Column="1"
Grid.Row="16" Grid.Column="1"
x:Name="editGitEmail"
Height="24"
Text="{Binding ElementName=me, Path=Email, Mode=TwoWay}"
@ -285,12 +297,12 @@
<!-- CRLF -->
<TextBlock
Grid.Row="16" Grid.Column="0"
Grid.Row="17" Grid.Column="0"
Text="{DynamicResource Text.Preference.Git.CRLF}"
HorizontalAlignment="Right"
Margin="0,0,8,0"/>
<ComboBox
Grid.Row="16" Grid.Column="1"
Grid.Row="17" Grid.Column="1"
x:Name="editGitCrlf"
Height="24"
ItemsSource="{Binding Source={x:Static models:CRLFOption.Supported}}"
@ -308,19 +320,19 @@
<!-- Merge Tool Group -->
<TextBlock
Grid.Row="18" Grid.Column="0" Grid.ColumnSpan="2"
Grid.Row="19" Grid.Column="0" Grid.ColumnSpan="2"
Text="{DynamicResource Text.Preference.Merger}"
FontSize="17" FontWeight="DemiBold"
Foreground="{DynamicResource Brush.FG2}"/>
<!-- Merge Tool Type -->
<TextBlock
Grid.Row="19" Grid.Column="0"
Grid.Row="20" Grid.Column="0"
Text="{DynamicResource Text.Preference.Merger.Type}"
HorizontalAlignment="Right"
Margin="0,0,8,0"/>
<ComboBox
Grid.Row="19" Grid.Column="1"
Grid.Row="20" Grid.Column="1"
Height="24"
ItemsSource="{Binding Source={x:Static models:MergeTool.Supported}}"
DisplayMemberPath="Name"
@ -330,11 +342,11 @@
<!-- Merge Tool Executable Path -->
<TextBlock
Grid.Row="20" Grid.Column="0"
Grid.Row="21" Grid.Column="0"
Text="{DynamicResource Text.Preference.Merger.Path}"
HorizontalAlignment="Right"
Margin="0,0,8,0"/>
<Grid Grid.Row="20" Grid.Column="1">
<Grid Grid.Row="21" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>

View file

@ -15,6 +15,7 @@ namespace SourceGit.Views {
public string User { get; set; }
public string Email { get; set; }
public string CRLF { get; set; }
public string Version { get; set; }
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathfindonpathw
// https://www.pinvoke.net/default.aspx/shlwapi.PathFindOnPath
@ -24,11 +25,7 @@ namespace SourceGit.Views {
public bool EnableWindowsTerminal { get; set; } = PathFindOnPath(new StringBuilder("wt.exe"), null);
public Preference() {
if (!UpdateGitInfoIfReady()) {
User = "";
Email = "";
CRLF = "false";
}
UpdateGitInfo(false);
if (!EnableWindowsTerminal) {
Models.Preference.Instance.General.UseWindowsTerminal = false;
@ -37,13 +34,27 @@ 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;
private bool UpdateGitInfo(bool updateUi) {
var isReady = Models.Preference.Instance.IsReady;
if (isReady) {
User = new Commands.Config().Get("user.name");
Email = new Commands.Config().Get("user.email");
CRLF = new Commands.Config().Get("core.autocrlf");
Version = new Commands.Version().Query();
if (string.IsNullOrEmpty(CRLF)) CRLF = "false";
} else {
User = "";
Email = "";
CRLF = "false";
Version = "Unknown";
}
if (updateUi) {
editGitUser?.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
editGitEmail?.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
editGitCrlf?.GetBindingExpression(ComboBox.SelectedValueProperty).UpdateTarget();
textGitVersion?.GetBindingExpression(TextBlock.TextProperty).UpdateTarget();
}
return isReady;
}
#region EVENTS
@ -69,11 +80,7 @@ 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();
}
UpdateGitInfo(true);
}
}