!25 配置窗口增加实用功能

Merge pull request !25 from carterl/preference
This commit is contained in:
ZCShou 2021-09-08 00:07:51 +00:00 committed by Gitee
commit 441d91a1da
7 changed files with 192 additions and 100 deletions

18
src/Commands/Version.cs Normal file
View file

@ -0,0 +1,18 @@
using System;
namespace SourceGit.Commands {
/// <summary>
/// 检测git是否可用并获取git版本信息
/// </summary>
public class Version : Command {
const string GitVersionPrefix = "git version ";
public string Query() {
Args = $"--version";
var result = ReadToEnd();
if (!result.IsSuccess || string.IsNullOrEmpty(result.Output)) return null;
var version = result.Output.Trim();
if (!version.StartsWith(GitVersionPrefix, StringComparison.Ordinal)) return null;
return version.Substring(GitVersionPrefix.Length);
}
}
}

View file

@ -77,6 +77,11 @@ namespace SourceGit.Models {
/// 是否启用崩溃上报 /// 是否启用崩溃上报
/// </summary> /// </summary>
public bool EnableCrashReport { get; set; } = false; public bool EnableCrashReport { get; set; } = false;
/// <summary>
/// 是否尝试使用 Windows Terminal 打开终端
/// </summary>
public bool UseWindowsTerminal { get; set; } = false;
} }
/// <summary> /// <summary>
@ -189,13 +194,11 @@ namespace SourceGit.Models {
} }
/// <summary> /// <summary>
/// 检测配置是否 /// 检测配置是否正常
/// </summary> /// </summary>
[JsonIgnore] [JsonIgnore]
public bool IsReady { public bool IsReady {
get { get => File.Exists(Git.Path) && new Commands.Version().Query() != null;
return !string.IsNullOrEmpty(Git.Path) && File.Exists(Git.Path);
}
} }
#region DATA #region DATA

View file

@ -360,9 +360,11 @@
<sys:String x:Key="Text.Preference.AutoFetch">Fetch remotes automatically (need restart)</sys:String> <sys:String x:Key="Text.Preference.AutoFetch">Fetch remotes automatically (need restart)</sys:String>
<sys:String x:Key="Text.Preference.RestoreTabs">Restore windows</sys:String> <sys:String x:Key="Text.Preference.RestoreTabs">Restore windows</sys:String>
<sys:String x:Key="Text.Preference.EnableCrashReport">Enable crash report (maybe include related path)</sys:String> <sys:String x:Key="Text.Preference.EnableCrashReport">Enable crash report (maybe include related path)</sys:String>
<sys:String x:Key="Text.Preference.UseWindowsTerminal">Use Windows Terminal to open Git terminal</sys:String>
<sys:String x:Key="Text.Preference.Git">GIT SETTING</sys:String> <sys:String x:Key="Text.Preference.Git">GIT SETTING</sys:String>
<sys:String x:Key="Text.Preference.Git.Path">Install Path</sys:String> <sys:String x:Key="Text.Preference.Git.Path">Install Path</sys:String>
<sys:String x:Key="Text.Preference.Git.Path.Placeholder">Input path for git.exe</sys:String> <sys:String x:Key="Text.Preference.Git.Path.Placeholder">Input path for git.exe</sys:String>
<sys:String x:Key="Text.Preference.Git.Version">Git version</sys:String>
<sys:String x:Key="Text.Preference.Git.Dir">Default Clone Dir</sys:String> <sys:String x:Key="Text.Preference.Git.Dir">Default Clone Dir</sys:String>
<sys:String x:Key="Text.Preference.Git.Dir.Placeholder">Default path to clone repo into</sys:String> <sys:String x:Key="Text.Preference.Git.Dir.Placeholder">Default path to clone repo into</sys:String>
<sys:String x:Key="Text.Preference.Git.User">User Name</sys:String> <sys:String x:Key="Text.Preference.Git.User">User Name</sys:String>

View file

@ -359,9 +359,11 @@
<sys:String x:Key="Text.Preference.AutoFetch">启用定时自动拉取远程更新(重启生效)</sys:String> <sys:String x:Key="Text.Preference.AutoFetch">启用定时自动拉取远程更新(重启生效)</sys:String>
<sys:String x:Key="Text.Preference.RestoreTabs">启动时恢复上次打开的仓库</sys:String> <sys:String x:Key="Text.Preference.RestoreTabs">启动时恢复上次打开的仓库</sys:String>
<sys:String x:Key="Text.Preference.EnableCrashReport">开启崩溃上报(可能涉及上报相关路径)</sys:String> <sys:String x:Key="Text.Preference.EnableCrashReport">开启崩溃上报(可能涉及上报相关路径)</sys:String>
<sys:String x:Key="Text.Preference.UseWindowsTerminal">使用 Windows Terminal 打开 Git 终端</sys:String>
<sys:String x:Key="Text.Preference.Git">GIT配置</sys:String> <sys:String x:Key="Text.Preference.Git">GIT配置</sys:String>
<sys:String x:Key="Text.Preference.Git.Path">安装路径</sys:String> <sys:String x:Key="Text.Preference.Git.Path">安装路径</sys:String>
<sys:String x:Key="Text.Preference.Git.Path.Placeholder">填写git.exe所在位置</sys:String> <sys:String x:Key="Text.Preference.Git.Path.Placeholder">填写git.exe所在位置</sys:String>
<sys:String x:Key="Text.Preference.Git.Version">Git 版本</sys:String>
<sys:String x:Key="Text.Preference.Git.Dir">默认克隆路径</sys:String> <sys:String x:Key="Text.Preference.Git.Dir">默认克隆路径</sys:String>
<sys:String x:Key="Text.Preference.Git.Dir.Placeholder">默认的仓库本地存放位置</sys:String> <sys:String x:Key="Text.Preference.Git.Dir.Placeholder">默认的仓库本地存放位置</sys:String>
<sys:String x:Key="Text.Preference.Git.User">用户名</sys:String> <sys:String x:Key="Text.Preference.Git.User">用户名</sys:String>

View file

@ -1,4 +1,4 @@
<controls:Window <controls:Window
x:Class="SourceGit.Views.Preference" x:Class="SourceGit.Views.Preference"
x:Name="me" x:Name="me"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
@ -22,7 +22,7 @@
<RowDefinition Height="1"/> <RowDefinition Height="1"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<!-- Title bar --> <!-- Title bar -->
<Grid Grid.Row="0" Background="{DynamicResource Brush.TitleBar}"> <Grid Grid.Row="0" Background="{DynamicResource Brush.TitleBar}">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
@ -31,24 +31,24 @@
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<!-- Icon --> <!-- Icon -->
<Path Grid.Column="0" Width="14" Height="14" Margin="6,0" Data="{StaticResource Icon.Preference}"/> <Path Grid.Column="0" Width="14" Height="14" Margin="6,0" Data="{StaticResource Icon.Preference}"/>
<!-- Title --> <!-- Title -->
<TextBlock Grid.Column="1" Text="{DynamicResource Text.Preference}"/> <TextBlock Grid.Column="1" Text="{DynamicResource Text.Preference}"/>
<!-- Close --> <!-- Close -->
<controls:IconButton <controls:IconButton
Grid.Column="3" Grid.Column="3"
Click="Quit" Click="Quit"
Width="28" Padding="8" Width="28" Padding="8"
Icon="{StaticResource Icon.Close}" Icon="{StaticResource Icon.Close}"
HoverBackground="Red" HoverBackground="Red"
WindowChrome.IsHitTestVisibleInChrome="True"/> WindowChrome.IsHitTestVisibleInChrome="True"/>
</Grid> </Grid>
<Rectangle <Rectangle
Grid.Row="1" Grid.Row="1"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
Fill="{DynamicResource Brush.Border0}"/> Fill="{DynamicResource Brush.Border0}"/>
@ -65,6 +65,7 @@
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="28"/>
<RowDefinition Height="8"/> <RowDefinition Height="8"/>
<RowDefinition Height="36"/> <RowDefinition Height="36"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
@ -72,6 +73,7 @@
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="28"/>
<RowDefinition Height="8"/> <RowDefinition Height="8"/>
<RowDefinition Height="36"/> <RowDefinition Height="36"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
@ -87,33 +89,33 @@
<!-- General Group --> <!-- General Group -->
<TextBlock <TextBlock
Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"
Text="{DynamicResource Text.Preference.General}" Text="{DynamicResource Text.Preference.General}"
FontSize="16" FontWeight="DemiBold" FontSize="16" FontWeight="DemiBold"
Foreground="{DynamicResource Brush.FG2}"/> Foreground="{DynamicResource Brush.FG2}"/>
<!-- Language --> <!-- Language -->
<TextBlock <TextBlock
Grid.Row="1" Grid.Column="0" Grid.Row="1" Grid.Column="0"
Text="{DynamicResource Text.Preference.Locale}" Text="{DynamicResource Text.Preference.Locale}"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Margin="0,0,8,0"/> Margin="0,0,8,0"/>
<ComboBox <ComboBox
Grid.Row="1" Grid.Column="1" Grid.Row="1" Grid.Column="1"
Height="24" Height="24"
ItemsSource="{Binding Source={x:Static models:Locale.Supported}}" ItemsSource="{Binding Source={x:Static models:Locale.Supported}}"
DisplayMemberPath="Name" DisplayMemberPath="Name"
SelectedValuePath="Resource" SelectedValuePath="Resource"
SelectedValue="{Binding Source={x:Static models:Preference.Instance}, Path=General.Locale, Mode=TwoWay}" SelectedValue="{Binding Source={x:Static models:Preference.Instance}, Path=General.Locale, Mode=TwoWay}"
SelectionChanged="LocaleChanged"/> SelectionChanged="LocaleChanged"/>
<!-- System Font --> <!-- System Font -->
<TextBlock <TextBlock
Grid.Row="2" Grid.Column="0" Grid.Row="2" Grid.Column="0"
Text="{DynamicResource Text.Preference.FontFamilyWindow}" Text="{DynamicResource Text.Preference.FontFamilyWindow}"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Margin="0,0,6,0"/> Margin="0,0,6,0"/>
<ComboBox <ComboBox
Grid.Row="2" Grid.Column="1" Grid.Row="2" Grid.Column="1"
Height="24" Height="24"
ItemsSource="{Binding Source={x:Static models:InstalledFont.GetFonts}}" ItemsSource="{Binding Source={x:Static models:InstalledFont.GetFonts}}"
SelectedValue="{Binding Source={x:Static models:Preference.Instance}, Path=General.FontFamilyWindow, Mode=TwoWay, Converter={StaticResource FontFamiliesToName}}" SelectedValue="{Binding Source={x:Static models:Preference.Instance}, Path=General.FontFamilyWindow, Mode=TwoWay, Converter={StaticResource FontFamiliesToName}}"
@ -129,13 +131,13 @@
</ComboBox> </ComboBox>
<!-- Content Font --> <!-- Content Font -->
<TextBlock <TextBlock
Grid.Row="3" Grid.Column="0" Grid.Row="3" Grid.Column="0"
Text="{DynamicResource Text.Preference.FontFamilyContent}" Text="{DynamicResource Text.Preference.FontFamilyContent}"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Margin="0,0,6,0"/> Margin="0,0,6,0"/>
<ComboBox <ComboBox
Grid.Row="3" Grid.Column="1" Grid.Row="3" Grid.Column="1"
Height="24" Height="24"
ItemsSource="{Binding Source={x:Static models:InstalledFont.GetFonts}}" ItemsSource="{Binding Source={x:Static models:InstalledFont.GetFonts}}"
SelectedValue="{Binding Source={x:Static models:Preference.Instance}, Path=General.FontFamilyContent, Mode=TwoWay, Converter={StaticResource FontFamiliesToName}}" SelectedValue="{Binding Source={x:Static models:Preference.Instance}, Path=General.FontFamilyContent, Mode=TwoWay, Converter={StaticResource FontFamiliesToName}}"
@ -151,13 +153,13 @@
</ComboBox> </ComboBox>
<!-- Avatar --> <!-- Avatar -->
<TextBlock <TextBlock
Grid.Row="4" Grid.Column="0" Grid.Row="4" Grid.Column="0"
Text="{DynamicResource Text.Preference.AvatarServer}" Text="{DynamicResource Text.Preference.AvatarServer}"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Margin="0,0,8,0"/> Margin="0,0,8,0"/>
<ComboBox <ComboBox
Grid.Row="4" Grid.Column="1" Grid.Row="4" Grid.Column="1"
Height="24" Height="24"
ItemsSource="{Binding Source={x:Static models:AvatarServer.Supported}}" ItemsSource="{Binding Source={x:Static models:AvatarServer.Supported}}"
DisplayMemberPath="Name" DisplayMemberPath="Name"
@ -169,7 +171,7 @@
Grid.Row="5" Grid.Column="1" Grid.Row="5" Grid.Column="1"
Content="{DynamicResource Text.Preference.CheckUpdate}" Content="{DynamicResource Text.Preference.CheckUpdate}"
IsChecked="{Binding Source={x:Static models:Preference.Instance}, Path=General.CheckForUpdate, Mode=TwoWay}"/> IsChecked="{Binding Source={x:Static models:Preference.Instance}, Path=General.CheckForUpdate, Mode=TwoWay}"/>
<!-- Auto Fetch --> <!-- Auto Fetch -->
<CheckBox <CheckBox
Grid.Row="6" Grid.Column="1" Grid.Row="6" Grid.Column="1"
@ -181,27 +183,34 @@
Grid.Row="7" Grid.Column="1" Grid.Row="7" Grid.Column="1"
Content="{DynamicResource Text.Preference.RestoreTabs}" Content="{DynamicResource Text.Preference.RestoreTabs}"
IsChecked="{Binding Source={x:Static models:Preference.Instance}, Path=Restore.IsEnabled, Mode=TwoWay}"/> IsChecked="{Binding Source={x:Static models:Preference.Instance}, Path=Restore.IsEnabled, Mode=TwoWay}"/>
<!-- Crash Report --> <!-- Crash Report -->
<CheckBox <CheckBox
Grid.Row="8" Grid.Column="1" Grid.Row="8" Grid.Column="1"
Content="{DynamicResource Text.Preference.EnableCrashReport}" Content="{DynamicResource Text.Preference.EnableCrashReport}"
IsChecked="{Binding Source={x:Static models:Preference.Instance}, Path=General.EnableCrashReport, Mode=TwoWay}"/> IsChecked="{Binding Source={x:Static models:Preference.Instance}, Path=General.EnableCrashReport, Mode=TwoWay}"/>
<!-- Use Windows Terminal -->
<CheckBox
Grid.Row="9" Grid.Column="1"
Content="{DynamicResource Text.Preference.UseWindowsTerminal}"
IsEnabled="{Binding ElementName=me, Path=EnableWindowsTerminal}"
IsChecked="{Binding Source={x:Static models:Preference.Instance}, Path=General.UseWindowsTerminal, Mode=TwoWay}"/>
<!-- Git Group --> <!-- Git Group -->
<TextBlock <TextBlock
Grid.Row="10" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="11" Grid.Column="0" Grid.ColumnSpan="2"
Text="{DynamicResource Text.Preference.Git}" Text="{DynamicResource Text.Preference.Git}"
FontSize="16" FontWeight="DemiBold" FontSize="16" FontWeight="DemiBold"
Foreground="{DynamicResource Brush.FG2}"/> Foreground="{DynamicResource Brush.FG2}"/>
<!-- Git Executable Path --> <!-- Git Executable Path -->
<TextBlock <TextBlock
Grid.Row="11" Grid.Column="0" Grid.Row="12" Grid.Column="0"
Text="{DynamicResource Text.Preference.Git.Path}" Text="{DynamicResource Text.Preference.Git.Path}"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Margin="0,0,8,0"/> Margin="0,0,8,0"/>
<Grid Grid.Row="11" Grid.Column="1"> <Grid Grid.Row="12" Grid.Column="1">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>
@ -221,14 +230,25 @@
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}" BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}"
Icon="{StaticResource Icon.Folder.Open}"/> Icon="{StaticResource Icon.Folder.Open}"/>
</Grid> </Grid>
<!-- Default Clone Dir --> <!-- Git Version -->
<TextBlock <TextBlock
Grid.Row="12" Grid.Column="0" Grid.Row="13" Grid.Column="0"
Text="{DynamicResource Text.Preference.Git.Dir}" Text="{DynamicResource Text.Preference.Git.Version}"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Margin="0,0,8,0"/> Margin="0,0,8,0"/>
<Grid Grid.Row="12" Grid.Column="1"> <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="14" Grid.Column="1">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>
@ -248,39 +268,42 @@
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}" BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}"
Icon="{StaticResource Icon.Folder.Open}"/> Icon="{StaticResource Icon.Folder.Open}"/>
</Grid> </Grid>
<!-- User --> <!-- User -->
<TextBlock <TextBlock
Grid.Row="13" Grid.Column="0" Grid.Row="15" Grid.Column="0"
Text="{DynamicResource Text.Preference.Git.User}" Text="{DynamicResource Text.Preference.Git.User}"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Margin="0,0,8,0"/> Margin="0,0,8,0"/>
<controls:TextEdit <controls:TextEdit
Grid.Row="13" Grid.Column="1" Grid.Row="15" Grid.Column="1"
x:Name="editGitUser"
Height="24" Height="24"
Text="{Binding ElementName=me, Path=User, Mode=TwoWay}" Text="{Binding ElementName=me, Path=User, Mode=TwoWay}"
Placeholder="{DynamicResource Text.Preference.Git.User.Placeholder}"/> Placeholder="{DynamicResource Text.Preference.Git.User.Placeholder}"/>
<!-- Email --> <!-- Email -->
<TextBlock <TextBlock
Grid.Row="14" Grid.Column="0" Grid.Row="16" Grid.Column="0"
Text="{DynamicResource Text.Preference.Git.Email}" Text="{DynamicResource Text.Preference.Git.Email}"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Margin="0,0,8,0"/> Margin="0,0,8,0"/>
<controls:TextEdit <controls:TextEdit
Grid.Row="14" Grid.Column="1" Grid.Row="16" Grid.Column="1"
x:Name="editGitEmail"
Height="24" Height="24"
Text="{Binding ElementName=me, Path=Email, Mode=TwoWay}" Text="{Binding ElementName=me, Path=Email, Mode=TwoWay}"
Placeholder="{DynamicResource Text.Preference.Git.Email.Placeholder}"/> Placeholder="{DynamicResource Text.Preference.Git.Email.Placeholder}"/>
<!-- CRLF --> <!-- CRLF -->
<TextBlock <TextBlock
Grid.Row="15" Grid.Column="0" Grid.Row="17" Grid.Column="0"
Text="{DynamicResource Text.Preference.Git.CRLF}" Text="{DynamicResource Text.Preference.Git.CRLF}"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Margin="0,0,8,0"/> Margin="0,0,8,0"/>
<ComboBox <ComboBox
Grid.Row="15" Grid.Column="1" Grid.Row="17" Grid.Column="1"
x:Name="editGitCrlf"
Height="24" Height="24"
ItemsSource="{Binding Source={x:Static models:CRLFOption.Supported}}" ItemsSource="{Binding Source={x:Static models:CRLFOption.Supported}}"
SelectedValuePath="Value" SelectedValuePath="Value"
@ -297,19 +320,19 @@
<!-- Merge Tool Group --> <!-- Merge Tool Group -->
<TextBlock <TextBlock
Grid.Row="17" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="19" Grid.Column="0" Grid.ColumnSpan="2"
Text="{DynamicResource Text.Preference.Merger}" Text="{DynamicResource Text.Preference.Merger}"
FontSize="17" FontWeight="DemiBold" FontSize="17" FontWeight="DemiBold"
Foreground="{DynamicResource Brush.FG2}"/> Foreground="{DynamicResource Brush.FG2}"/>
<!-- Merge Tool Type --> <!-- Merge Tool Type -->
<TextBlock <TextBlock
Grid.Row="18" Grid.Column="0" Grid.Row="20" Grid.Column="0"
Text="{DynamicResource Text.Preference.Merger.Type}" Text="{DynamicResource Text.Preference.Merger.Type}"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Margin="0,0,8,0"/> Margin="0,0,8,0"/>
<ComboBox <ComboBox
Grid.Row="18" Grid.Column="1" Grid.Row="20" Grid.Column="1"
Height="24" Height="24"
ItemsSource="{Binding Source={x:Static models:MergeTool.Supported}}" ItemsSource="{Binding Source={x:Static models:MergeTool.Supported}}"
DisplayMemberPath="Name" DisplayMemberPath="Name"
@ -318,12 +341,12 @@
SelectionChanged="MergeToolChanged"/> SelectionChanged="MergeToolChanged"/>
<!-- Merge Tool Executable Path --> <!-- Merge Tool Executable Path -->
<TextBlock <TextBlock
Grid.Row="19" Grid.Column="0" Grid.Row="21" Grid.Column="0"
Text="{DynamicResource Text.Preference.Merger.Path}" Text="{DynamicResource Text.Preference.Merger.Path}"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Margin="0,0,8,0"/> Margin="0,0,8,0"/>
<Grid Grid.Row="19" Grid.Column="1"> <Grid Grid.Row="21" Grid.Column="1">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>

View file

@ -1,5 +1,7 @@
using Microsoft.Win32; using Microsoft.Win32;
using System; using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
@ -13,20 +15,46 @@ namespace SourceGit.Views {
public string User { get; set; } public string User { get; set; }
public string Email { get; set; } public string Email { get; set; }
public string CRLF { 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
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode, SetLastError = false)]
private static extern bool PathFindOnPath([In, Out] StringBuilder pszFile, [In] string[] ppszOtherDirs);
public bool EnableWindowsTerminal { get; set; } = PathFindOnPath(new StringBuilder("wt.exe"), null);
public Preference() { public Preference() {
if (Models.Preference.Instance.IsReady) { UpdateGitInfo(false);
if (!EnableWindowsTerminal) {
Models.Preference.Instance.General.UseWindowsTerminal = false;
}
InitializeComponent();
}
private bool UpdateGitInfo(bool updateUi) {
var isReady = Models.Preference.Instance.IsReady;
if (isReady) {
User = new Commands.Config().Get("user.name"); User = new Commands.Config().Get("user.name");
Email = new Commands.Config().Get("user.email"); Email = new Commands.Config().Get("user.email");
CRLF = new Commands.Config().Get("core.autocrlf"); CRLF = new Commands.Config().Get("core.autocrlf");
Version = new Commands.Version().Query();
if (string.IsNullOrEmpty(CRLF)) CRLF = "false"; if (string.IsNullOrEmpty(CRLF)) CRLF = "false";
} else { } else {
User = ""; User = "";
Email = ""; Email = "";
CRLF = "false"; CRLF = "false";
Version = "Unknown";
} }
if (updateUi) {
InitializeComponent(); editGitUser?.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
editGitEmail?.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
editGitCrlf?.GetBindingExpression(ComboBox.SelectedValueProperty).UpdateTarget();
textGitVersion?.GetBindingExpression(TextBlock.TextProperty).UpdateTarget();
}
return isReady;
} }
#region EVENTS #region EVENTS
@ -36,16 +64,23 @@ namespace SourceGit.Views {
} }
private void SelectGitPath(object sender, RoutedEventArgs e) { private void SelectGitPath(object sender, RoutedEventArgs e) {
var dialog = new OpenFileDialog(); var sb = new StringBuilder("git.exe");
dialog.Filter = "Git Executable|git.exe"; string dir = PathFindOnPath(sb, null)
dialog.FileName = "git.exe"; ? sb.ToString()
dialog.Title = App.Text("Preference.Dialog.GitExe"); : Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
dialog.CheckFileExists = true; var dialog = new OpenFileDialog {
Filter = "Git Executable|git.exe",
FileName = "git.exe",
Title = App.Text("Preference.Dialog.GitExe"),
InitialDirectory = dir,
CheckFileExists = true,
};
if (dialog.ShowDialog() == true) { if (dialog.ShowDialog() == true) {
Models.Preference.Instance.Git.Path = dialog.FileName; Models.Preference.Instance.Git.Path = dialog.FileName;
editGitPath?.GetBindingExpression(TextBox.TextProperty).UpdateTarget(); editGitPath?.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
UpdateGitInfo(true);
} }
} }

View file

@ -315,11 +315,20 @@ namespace SourceGit.Views.Widgets {
Models.Exception.Raise(App.Text("MissingBash")); Models.Exception.Raise(App.Text("MissingBash"));
return; return;
} }
if (Models.Preference.Instance.General.UseWindowsTerminal) {
var start = new ProcessStartInfo(); Process.Start(new ProcessStartInfo {
start.WorkingDirectory = repo.Path; WorkingDirectory = repo.Path,
start.FileName = bash; FileName = "wt",
Process.Start(start); Arguments = bash,
UseShellExecute = false,
});
} else {
Process.Start(new ProcessStartInfo {
WorkingDirectory = repo.Path,
FileName = bash,
UseShellExecute = true,
});
}
e.Handled = true; e.Handled = true;
} }