feature<OpenTerminal>: support Windows Terminal

This commit is contained in:
李通洲 2021-09-03 19:27:19 +08:00
parent f041adb2b3
commit 5e706588a0
6 changed files with 123 additions and 86 deletions

View file

@ -77,6 +77,11 @@ namespace SourceGit.Models {
/// 是否启用崩溃上报
/// </summary>
public bool EnableCrashReport { get; set; } = false;
/// <summary>
/// 是否尝试使用 Windows Terminal 打开终端
/// </summary>
public bool UseWindowsTerminal { get; set; } = false;
}
/// <summary>

View file

@ -360,6 +360,7 @@
<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.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.Path">Install Path</sys:String>
<sys:String x:Key="Text.Preference.Git.Path.Placeholder">Input path for git.exe</sys:String>

View file

@ -359,6 +359,7 @@
<sys:String x:Key="Text.Preference.AutoFetch">启用定时自动拉取远程更新(重启生效)</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.UseWindowsTerminal">使用 Windows Terminal 打开 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.Placeholder">填写git.exe所在位置</sys:String>

View file

@ -65,6 +65,7 @@
<RowDefinition Height="28"/>
<RowDefinition Height="28"/>
<RowDefinition Height="28"/>
<RowDefinition Height="28"/>
<RowDefinition Height="8"/>
<RowDefinition Height="36"/>
<RowDefinition Height="28"/>
@ -188,20 +189,27 @@
Content="{DynamicResource Text.Preference.EnableCrashReport}"
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 -->
<TextBlock
Grid.Row="10" Grid.Column="0" Grid.ColumnSpan="2"
Grid.Row="11" Grid.Column="0" Grid.ColumnSpan="2"
Text="{DynamicResource Text.Preference.Git}"
FontSize="16" FontWeight="DemiBold"
Foreground="{DynamicResource Brush.FG2}"/>
<!-- Git Executable Path -->
<TextBlock
Grid.Row="11" Grid.Column="0"
Grid.Row="12" Grid.Column="0"
Text="{DynamicResource Text.Preference.Git.Path}"
HorizontalAlignment="Right"
Margin="0,0,8,0"/>
<Grid Grid.Row="11" Grid.Column="1">
<Grid Grid.Row="12" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
@ -224,11 +232,11 @@
<!-- Default Clone Dir -->
<TextBlock
Grid.Row="12" Grid.Column="0"
Grid.Row="13" Grid.Column="0"
Text="{DynamicResource Text.Preference.Git.Dir}"
HorizontalAlignment="Right"
Margin="0,0,8,0"/>
<Grid Grid.Row="12" Grid.Column="1">
<Grid Grid.Row="13" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
@ -251,36 +259,36 @@
<!-- User -->
<TextBlock
Grid.Row="13" Grid.Column="0"
Grid.Row="14" Grid.Column="0"
Text="{DynamicResource Text.Preference.Git.User}"
HorizontalAlignment="Right"
Margin="0,0,8,0"/>
<controls:TextEdit
Grid.Row="13" Grid.Column="1"
Grid.Row="14" Grid.Column="1"
Height="24"
Text="{Binding ElementName=me, Path=User, Mode=TwoWay}"
Placeholder="{DynamicResource Text.Preference.Git.User.Placeholder}"/>
<!-- Email -->
<TextBlock
Grid.Row="14" Grid.Column="0"
Grid.Row="15" Grid.Column="0"
Text="{DynamicResource Text.Preference.Git.Email}"
HorizontalAlignment="Right"
Margin="0,0,8,0"/>
<controls:TextEdit
Grid.Row="14" Grid.Column="1"
Grid.Row="15" Grid.Column="1"
Height="24"
Text="{Binding ElementName=me, Path=Email, Mode=TwoWay}"
Placeholder="{DynamicResource Text.Preference.Git.Email.Placeholder}"/>
<!-- CRLF -->
<TextBlock
Grid.Row="15" Grid.Column="0"
Grid.Row="16" Grid.Column="0"
Text="{DynamicResource Text.Preference.Git.CRLF}"
HorizontalAlignment="Right"
Margin="0,0,8,0"/>
<ComboBox
Grid.Row="15" Grid.Column="1"
Grid.Row="16" Grid.Column="1"
Height="24"
ItemsSource="{Binding Source={x:Static models:CRLFOption.Supported}}"
SelectedValuePath="Value"
@ -297,19 +305,19 @@
<!-- Merge Tool Group -->
<TextBlock
Grid.Row="17" Grid.Column="0" Grid.ColumnSpan="2"
Grid.Row="18" 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="18" Grid.Column="0"
Grid.Row="19" Grid.Column="0"
Text="{DynamicResource Text.Preference.Merger.Type}"
HorizontalAlignment="Right"
Margin="0,0,8,0"/>
<ComboBox
Grid.Row="18" Grid.Column="1"
Grid.Row="19" Grid.Column="1"
Height="24"
ItemsSource="{Binding Source={x:Static models:MergeTool.Supported}}"
DisplayMemberPath="Name"
@ -319,11 +327,11 @@
<!-- Merge Tool Executable Path -->
<TextBlock
Grid.Row="19" Grid.Column="0"
Grid.Row="20" Grid.Column="0"
Text="{DynamicResource Text.Preference.Merger.Path}"
HorizontalAlignment="Right"
Margin="0,0,8,0"/>
<Grid Grid.Row="19" Grid.Column="1">
<Grid Grid.Row="20" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>

View file

@ -1,5 +1,7 @@
using Microsoft.Win32;
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows;
using System.Windows.Controls;
@ -14,6 +16,13 @@ namespace SourceGit.Views {
public string Email { get; set; }
public string CRLF { 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() {
if (Models.Preference.Instance.IsReady) {
User = new Commands.Config().Get("user.name");
@ -26,6 +35,10 @@ namespace SourceGit.Views {
CRLF = "false";
}
if (!EnableWindowsTerminal) {
Models.Preference.Instance.General.UseWindowsTerminal = false;
}
InitializeComponent();
}

View file

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