optimize<*>: remove Windows Terminal settings because it can be set outside in Windows Terminal

This commit is contained in:
leo 2022-05-20 15:29:56 +08:00
parent 44ed55937d
commit 171f1d1d0c
5 changed files with 511 additions and 546 deletions

View file

@ -68,11 +68,6 @@ namespace SourceGit.Models {
/// 上一次检测的时间(用于控制每天仅第一次启动软件时,检测) /// 上一次检测的时间(用于控制每天仅第一次启动软件时,检测)
/// </summary> /// </summary>
public int LastCheckDay { get; set; } = 0; public int LastCheckDay { get; set; } = 0;
/// <summary>
/// 是否尝试使用 Windows Terminal 打开终端
/// </summary>
public bool UseWindowsTerminal { get; set; } = false;
} }
/// <summary> /// <summary>

View file

@ -1,377 +1,369 @@
<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"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="clr-namespace:SourceGit.Views.Controls" xmlns:controls="clr-namespace:SourceGit.Views.Controls"
xmlns:models="clr-namespace:SourceGit.Models" xmlns:models="clr-namespace:SourceGit.Models"
xmlns:converters="clr-namespace:SourceGit.Views.Converters" xmlns:converters="clr-namespace:SourceGit.Views.Converters"
mc:Ignorable="d" mc:Ignorable="d"
WindowStartupLocation="CenterOwner" WindowStartupLocation="CenterOwner"
ResizeMode="NoResize" ResizeMode="NoResize"
Title="{DynamicResource Text.Preference}" Title="{DynamicResource Text.Preference}"
Width="500" Height="312"> Width="500" Height="312">
<Grid> <Grid>
<Grid.Resources> <Grid.Resources>
<converters:FontFamiliesToName x:Key="FontFamiliesToName"/> <converters:FontFamiliesToName x:Key="FontFamiliesToName"/>
</Grid.Resources> </Grid.Resources>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<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>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>
<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}"/>
<!-- Tabs --> <!-- Tabs -->
<TabControl Grid.Row="2" Margin="0,4"> <TabControl Grid.Row="2" Margin="0,4">
<!-- General Setting --> <!-- General Setting -->
<TabItem Header="{DynamicResource Text.Preference.General}"> <TabItem Header="{DynamicResource Text.Preference.General}">
<Grid Margin="0,8"> <Grid Margin="0,8">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="28"/> </Grid.RowDefinitions>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<Grid.ColumnDefinitions> <ColumnDefinition Width="100"/>
<ColumnDefinition Width="100"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/> </Grid.ColumnDefinitions>
</Grid.ColumnDefinitions>
<!-- Language -->
<!-- Language --> <TextBlock
<TextBlock Grid.Row="0" Grid.Column="0"
Grid.Row="0" 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="0" Grid.Column="1"
Grid.Row="0" 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="1" Grid.Column="0"
Grid.Row="1" Grid.Column="0" Text="{DynamicResource Text.Preference.FontFamilyWindow}"
Text="{DynamicResource Text.Preference.FontFamilyWindow}" 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: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}}" DisplayMemberPath="Name"
DisplayMemberPath="Name" SelectedValuePath="Name"
SelectedValuePath="Name" SelectionChanged="LocaleChanged">
SelectionChanged="LocaleChanged"> <ComboBox.Resources>
<ComboBox.Resources> <Style TargetType="ComboBoxItem">
<Style TargetType="ComboBoxItem"> <Setter Property="FontFamily" Value="{Binding Name}"/>
<Setter Property="FontFamily" Value="{Binding Name}"/> <Setter Property="ToolTip" Value="{Binding Name}"/>
<Setter Property="ToolTip" Value="{Binding Name}"/> </Style>
</Style> </ComboBox.Resources>
</ComboBox.Resources> </ComboBox>
</ComboBox>
<!-- Content Font -->
<!-- Content Font --> <TextBlock
<TextBlock Grid.Row="2" Grid.Column="0"
Grid.Row="2" Grid.Column="0" Text="{DynamicResource Text.Preference.FontFamilyContent}"
Text="{DynamicResource Text.Preference.FontFamilyContent}" HorizontalAlignment="Right"
HorizontalAlignment="Right" Margin="0,0,8,0"/>
Margin="0,0,8,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.FontFamilyContent, Mode=TwoWay, Converter={StaticResource FontFamiliesToName}}"
SelectedValue="{Binding Source={x:Static models:Preference.Instance}, Path=General.FontFamilyContent, Mode=TwoWay, Converter={StaticResource FontFamiliesToName}}" DisplayMemberPath="Name"
DisplayMemberPath="Name" SelectedValuePath="Name"
SelectedValuePath="Name" SelectionChanged="LocaleChanged">
SelectionChanged="LocaleChanged"> <ComboBox.Resources>
<ComboBox.Resources> <Style TargetType="ComboBoxItem">
<Style TargetType="ComboBoxItem"> <Setter Property="FontFamily" Value="{Binding Name}"/>
<Setter Property="FontFamily" Value="{Binding Name}"/> <Setter Property="ToolTip" Value="{Binding Name}"/>
<Setter Property="ToolTip" Value="{Binding Name}"/> </Style>
</Style> </ComboBox.Resources>
</ComboBox.Resources> </ComboBox>
</ComboBox>
<!-- Avatar -->
<!-- Avatar --> <TextBlock
<TextBlock Grid.Row="3" Grid.Column="0"
Grid.Row="3" 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="3" Grid.Column="1"
Grid.Row="3" 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" SelectedValuePath="Url"
SelectedValuePath="Url" SelectedValue="{Binding Source={x:Static models:Preference.Instance}, Path=General.AvatarServer, Mode=TwoWay}"/>
SelectedValue="{Binding Source={x:Static models:Preference.Instance}, Path=General.AvatarServer, Mode=TwoWay}"/>
<!-- Enable Check For Update -->
<!-- Enable Check For Update --> <CheckBox
<CheckBox Grid.Row="4" Grid.Column="1"
Grid.Row="4" 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}"/>
<!-- Enable Dark Theme -->
<!-- Enable Dark Theme --> <CheckBox
<CheckBox Grid.Row="5" Grid.Column="1"
Grid.Row="5" Grid.Column="1" Content="{DynamicResource Text.Preference.UseDarkTheme}"
Content="{DynamicResource Text.Preference.UseDarkTheme}" IsChecked="{Binding Source={x:Static models:Preference.Instance}, Path=General.UseDarkTheme, Mode=TwoWay}"
IsChecked="{Binding Source={x:Static models:Preference.Instance}, Path=General.UseDarkTheme, Mode=TwoWay}" Checked="ChangeTheme" Unchecked="ChangeTheme"/>
Checked="ChangeTheme" Unchecked="ChangeTheme"/>
<!-- Restore Windows -->
<!-- Restore Windows --> <CheckBox
<CheckBox Grid.Row="6" Grid.Column="1"
Grid.Row="6" 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}"/> </Grid>
</TabItem>
<!-- Use Windows Terminal -->
<CheckBox <!-- Git Setting -->
Grid.Row="7" Grid.Column="1" <TabItem Header="{DynamicResource Text.Preference.Git}">
Content="{DynamicResource Text.Preference.UseWindowsTerminal}" <Grid Margin="0,8">
IsEnabled="{Binding ElementName=me, Path=HasWindowsTerminal}" <Grid.RowDefinitions>
IsChecked="{Binding Source={x:Static models:Preference.Instance}, Path=General.UseWindowsTerminal, Mode=TwoWay}"/> <RowDefinition Height="28"/>
</Grid> <RowDefinition Height="28"/>
</TabItem> <RowDefinition Height="28"/>
<RowDefinition Height="28"/>
<!-- Git Setting --> <RowDefinition Height="28"/>
<TabItem Header="{DynamicResource Text.Preference.Git}"> <RowDefinition Height="28"/>
<Grid Margin="0,8"> <RowDefinition Height="28"/>
<Grid.RowDefinitions> </Grid.RowDefinitions>
<RowDefinition Height="28"/>
<RowDefinition Height="28"/> <Grid.ColumnDefinitions>
<RowDefinition Height="28"/> <ColumnDefinition Width="120"/>
<RowDefinition Height="28"/> <ColumnDefinition Width="*"/>
<RowDefinition Height="28"/> </Grid.ColumnDefinitions>
<RowDefinition Height="28"/>
<RowDefinition Height="28"/> <!-- Git Executable Path -->
</Grid.RowDefinitions> <TextBlock
Grid.Row="0" Grid.Column="0"
<Grid.ColumnDefinitions> Text="{DynamicResource Text.Preference.Git.Path}"
<ColumnDefinition Width="120"/> HorizontalAlignment="Right"
<ColumnDefinition Width="*"/> Margin="0,0,8,0"/>
</Grid.ColumnDefinitions> <Grid Grid.Row="0" Grid.Column="1">
<Grid.ColumnDefinitions>
<!-- Git Executable Path --> <ColumnDefinition Width="*"/>
<TextBlock <ColumnDefinition Width="Auto"/>
Grid.Row="0" Grid.Column="0" </Grid.ColumnDefinitions>
Text="{DynamicResource Text.Preference.Git.Path}"
HorizontalAlignment="Right" <controls:TextEdit
Margin="0,0,8,0"/> Grid.Column="0"
<Grid Grid.Row="0" Grid.Column="1"> x:Name="editGitPath"
<Grid.ColumnDefinitions> Height="24"
<ColumnDefinition Width="*"/> Text="{Binding Source={x:Static models:Preference.Instance}, Path=Git.Path, Mode=TwoWay}"
<ColumnDefinition Width="Auto"/> Placeholder="{DynamicResource Text.Preference.Git.Path.Placeholder}"/>
</Grid.ColumnDefinitions> <controls:IconButton
Grid.Column="1"
<controls:TextEdit Click="SelectGitPath"
Grid.Column="0" Width="24" Height="24"
x:Name="editGitPath" Margin="4,0,0,0" Padding="4"
Height="24" BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}"
Text="{Binding Source={x:Static models:Preference.Instance}, Path=Git.Path, Mode=TwoWay}" Icon="{StaticResource Icon.Folder.Open}"/>
Placeholder="{DynamicResource Text.Preference.Git.Path.Placeholder}"/> </Grid>
<controls:IconButton
Grid.Column="1" <!-- Git Version -->
Click="SelectGitPath" <TextBlock
Width="24" Height="24" Grid.Row="1" Grid.Column="0"
Margin="4,0,0,0" Padding="4" Text="{DynamicResource Text.Preference.Git.Version}"
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}" HorizontalAlignment="Right"
Icon="{StaticResource Icon.Folder.Open}"/> Margin="0,0,8,0"/>
</Grid> <TextBlock
Grid.Row="1" Grid.Column="1"
<!-- Git Version --> x:Name="textGitVersion"
<TextBlock Text="{Binding ElementName=me, Path=Version}"/>
Grid.Row="1" Grid.Column="0"
Text="{DynamicResource Text.Preference.Git.Version}" <!-- Default Clone Dir -->
HorizontalAlignment="Right" <TextBlock
Margin="0,0,8,0"/> Grid.Row="2" Grid.Column="0"
<TextBlock Text="{DynamicResource Text.Preference.Git.Dir}"
Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right"
x:Name="textGitVersion" Margin="0,0,8,0"/>
Text="{Binding ElementName=me, Path=Version}"/> <Grid Grid.Row="2" Grid.Column="1">
<Grid.ColumnDefinitions>
<!-- Default Clone Dir --> <ColumnDefinition Width="*"/>
<TextBlock <ColumnDefinition Width="Auto"/>
Grid.Row="2" Grid.Column="0" </Grid.ColumnDefinitions>
Text="{DynamicResource Text.Preference.Git.Dir}"
HorizontalAlignment="Right" <controls:TextEdit
Margin="0,0,8,0"/> Grid.Column="0"
<Grid Grid.Row="2" Grid.Column="1"> x:Name="txtGitCloneDir"
<Grid.ColumnDefinitions> Height="24"
<ColumnDefinition Width="*"/> Placeholder="{DynamicResource Text.Preference.Git.Dir.Placeholder}"
<ColumnDefinition Width="Auto"/> Text="{Binding Source={x:Static models:Preference.Instance}, Path=Git.DefaultCloneDir, Mode=TwoWay}"/>
</Grid.ColumnDefinitions> <controls:IconButton
Grid.Column="1"
<controls:TextEdit Click="SelectGitCloneDir"
Grid.Column="0" Width="24" Height="24"
x:Name="txtGitCloneDir" Margin="4,0,0,0" Padding="4"
Height="24" BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}"
Placeholder="{DynamicResource Text.Preference.Git.Dir.Placeholder}" Icon="{StaticResource Icon.Folder.Open}"/>
Text="{Binding Source={x:Static models:Preference.Instance}, Path=Git.DefaultCloneDir, Mode=TwoWay}"/> </Grid>
<controls:IconButton
Grid.Column="1" <!-- User -->
Click="SelectGitCloneDir" <TextBlock
Width="24" Height="24" Grid.Row="3" Grid.Column="0"
Margin="4,0,0,0" Padding="4" Text="{DynamicResource Text.Preference.Git.User}"
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}" HorizontalAlignment="Right"
Icon="{StaticResource Icon.Folder.Open}"/> Margin="0,0,8,0"/>
</Grid> <controls:TextEdit
Grid.Row="3" Grid.Column="1"
<!-- User --> x:Name="editGitUser"
<TextBlock Height="24"
Grid.Row="3" Grid.Column="0" Text="{Binding ElementName=me, Path=User, Mode=TwoWay}"
Text="{DynamicResource Text.Preference.Git.User}" Placeholder="{DynamicResource Text.Preference.Git.User.Placeholder}"/>
HorizontalAlignment="Right"
Margin="0,0,8,0"/> <!-- Email -->
<controls:TextEdit <TextBlock
Grid.Row="3" Grid.Column="1" Grid.Row="4" Grid.Column="0"
x:Name="editGitUser" Text="{DynamicResource Text.Preference.Git.Email}"
Height="24" HorizontalAlignment="Right"
Text="{Binding ElementName=me, Path=User, Mode=TwoWay}" Margin="0,0,8,0"/>
Placeholder="{DynamicResource Text.Preference.Git.User.Placeholder}"/> <controls:TextEdit
Grid.Row="4" Grid.Column="1"
<!-- Email --> x:Name="editGitEmail"
<TextBlock Height="24"
Grid.Row="4" Grid.Column="0" Text="{Binding ElementName=me, Path=Email, Mode=TwoWay}"
Text="{DynamicResource Text.Preference.Git.Email}" Placeholder="{DynamicResource Text.Preference.Git.Email.Placeholder}"/>
HorizontalAlignment="Right"
Margin="0,0,8,0"/> <!-- CRLF -->
<controls:TextEdit <TextBlock
Grid.Row="4" Grid.Column="1" Grid.Row="5" Grid.Column="0"
x:Name="editGitEmail" Text="{DynamicResource Text.Preference.Git.CRLF}"
Height="24" HorizontalAlignment="Right"
Text="{Binding ElementName=me, Path=Email, Mode=TwoWay}" Margin="0,0,8,0"/>
Placeholder="{DynamicResource Text.Preference.Git.Email.Placeholder}"/> <ComboBox
Grid.Row="5" Grid.Column="1"
<!-- CRLF --> x:Name="editGitCrlf"
<TextBlock Height="24"
Grid.Row="5" Grid.Column="0" ItemsSource="{Binding Source={x:Static models:CRLFOption.Supported}}"
Text="{DynamicResource Text.Preference.Git.CRLF}" SelectedValuePath="Value"
HorizontalAlignment="Right" SelectedValue="{Binding ElementName=me, Path=CRLF, Mode=TwoWay}">
Margin="0,0,8,0"/> <ComboBox.ItemTemplate>
<ComboBox <DataTemplate>
Grid.Row="5" Grid.Column="1" <StackPanel Orientation="Horizontal" Height="20">
x:Name="editGitCrlf" <TextBlock Text="{Binding Display}" Margin="2,0"/>
Height="24" <TextBlock Text="{Binding Desc}" Margin="8,0,0,0" FontSize="11" Foreground="{DynamicResource Brush.FG2}"/>
ItemsSource="{Binding Source={x:Static models:CRLFOption.Supported}}" </StackPanel>
SelectedValuePath="Value" </DataTemplate>
SelectedValue="{Binding ElementName=me, Path=CRLF, Mode=TwoWay}"> </ComboBox.ItemTemplate>
<ComboBox.ItemTemplate> </ComboBox>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="20"> <!-- Auto Fetch -->
<TextBlock Text="{Binding Display}" Margin="2,0"/> <CheckBox
<TextBlock Text="{Binding Desc}" Margin="8,0,0,0" FontSize="11" Foreground="{DynamicResource Brush.FG2}"/> Grid.Row="6" Grid.Column="1"
</StackPanel> VerticalAlignment="Bottom"
</DataTemplate> Content="{DynamicResource Text.Preference.Git.AutoFetch}"
</ComboBox.ItemTemplate> IsChecked="{Binding Source={x:Static models:Preference.Instance}, Path=Git.AutoFetchRemotes, Mode=TwoWay}"/>
</ComboBox> </Grid>
</TabItem>
<!-- Auto Fetch -->
<CheckBox <TabItem Header="{DynamicResource Text.Preference.Merger}">
Grid.Row="6" Grid.Column="1" <Grid Margin="0,8">
VerticalAlignment="Bottom" <Grid.RowDefinitions>
Content="{DynamicResource Text.Preference.Git.AutoFetch}" <RowDefinition Height="28"/>
IsChecked="{Binding Source={x:Static models:Preference.Instance}, Path=Git.AutoFetchRemotes, Mode=TwoWay}"/> <RowDefinition Height="28"/>
</Grid> </Grid.RowDefinitions>
</TabItem>
<Grid.ColumnDefinitions>
<TabItem Header="{DynamicResource Text.Preference.Merger}"> <ColumnDefinition Width="100"/>
<Grid Margin="0,8"> <ColumnDefinition Width="*"/>
<Grid.RowDefinitions> </Grid.ColumnDefinitions>
<RowDefinition Height="28"/>
<RowDefinition Height="28"/> <!-- Merge Tool Type -->
</Grid.RowDefinitions> <TextBlock
Grid.Row="0" Grid.Column="0"
<Grid.ColumnDefinitions> Text="{DynamicResource Text.Preference.Merger.Type}"
<ColumnDefinition Width="100"/> HorizontalAlignment="Right"
<ColumnDefinition Width="*"/> Margin="0,0,8,0"/>
</Grid.ColumnDefinitions> <ComboBox
Grid.Row="0" Grid.Column="1"
<!-- Merge Tool Type --> Height="24"
<TextBlock ItemsSource="{Binding Source={x:Static models:MergeTool.Supported}}"
Grid.Row="0" Grid.Column="0" DisplayMemberPath="Name"
Text="{DynamicResource Text.Preference.Merger.Type}" SelectedValuePath="Type"
HorizontalAlignment="Right" SelectedValue="{Binding Source={x:Static models:Preference.Instance}, Path=MergeTool.Type, Mode=TwoWay}"
Margin="0,0,8,0"/> SelectionChanged="MergeToolChanged"/>
<ComboBox
Grid.Row="0" Grid.Column="1" <!-- Merge Tool Executable Path -->
Height="24" <TextBlock
ItemsSource="{Binding Source={x:Static models:MergeTool.Supported}}" Grid.Row="1" Grid.Column="0"
DisplayMemberPath="Name" Text="{DynamicResource Text.Preference.Merger.Path}"
SelectedValuePath="Type" HorizontalAlignment="Right"
SelectedValue="{Binding Source={x:Static models:Preference.Instance}, Path=MergeTool.Type, Mode=TwoWay}" Margin="0,0,8,0"/>
SelectionChanged="MergeToolChanged"/> <Grid Grid.Row="1" Grid.Column="1">
<Grid.ColumnDefinitions>
<!-- Merge Tool Executable Path --> <ColumnDefinition Width="*"/>
<TextBlock <ColumnDefinition Width="Auto"/>
Grid.Row="1" Grid.Column="0" </Grid.ColumnDefinitions>
Text="{DynamicResource Text.Preference.Merger.Path}"
HorizontalAlignment="Right" <controls:TextEdit
Margin="0,0,8,0"/> Grid.Column="0"
<Grid Grid.Row="1" Grid.Column="1"> Height="24"
<Grid.ColumnDefinitions> x:Name="txtMergeExec"
<ColumnDefinition Width="*"/> Placeholder="{DynamicResource Text.Preference.Merger.Path.Placeholder}"
<ColumnDefinition Width="Auto"/> Text="{Binding Source={x:Static models:Preference.Instance}, Path=MergeTool.Path, Mode=TwoWay}"/>
</Grid.ColumnDefinitions> <controls:IconButton
Grid.Column="1"
<controls:TextEdit Click="SelectMergeTool"
Grid.Column="0" Width="24" Height="24"
Height="24" Margin="4,0,0,0" Padding="4"
x:Name="txtMergeExec" BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}"
Placeholder="{DynamicResource Text.Preference.Merger.Path.Placeholder}" Icon="{StaticResource Icon.Folder.Open}"/>
Text="{Binding Source={x:Static models:Preference.Instance}, Path=MergeTool.Path, Mode=TwoWay}"/> </Grid>
<controls:IconButton </Grid>
Grid.Column="1" </TabItem>
Click="SelectMergeTool" </TabControl>
Width="24" Height="24" </Grid>
Margin="4,0,0,0" Padding="4" </controls:Window>
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}"
Icon="{StaticResource Icon.Folder.Open}"/>
</Grid>
</Grid>
</TabItem>
</TabControl>
</Grid>
</controls:Window>

View file

@ -1,138 +1,133 @@
using Microsoft.Win32; using Microsoft.Win32;
using System; using System;
using System.IO; using System.IO;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
namespace SourceGit.Views { namespace SourceGit.Views {
/// <summary> /// <summary>
/// 设置面板 /// 设置面板
/// </summary> /// </summary>
public partial class Preference : Controls.Window { public partial class Preference : Controls.Window {
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; } public string Version { get; set; }
public bool HasWindowsTerminal { get; set; }
public Preference() {
public Preference() { UpdateGitInfo(false);
UpdateGitInfo(false); InitializeComponent();
}
HasWindowsTerminal = Models.ExecutableFinder.Find("wt.exe") != null;
if (!HasWindowsTerminal) Models.Preference.Instance.General.UseWindowsTerminal = false; private bool UpdateGitInfo(bool updateUi) {
var isReady = Models.Preference.Instance.IsReady;
InitializeComponent(); if (isReady) {
} User = new Commands.Config().Get("user.name");
Email = new Commands.Config().Get("user.email");
private bool UpdateGitInfo(bool updateUi) { CRLF = new Commands.Config().Get("core.autocrlf");
var isReady = Models.Preference.Instance.IsReady; Version = new Commands.Version().Query();
if (isReady) { if (string.IsNullOrEmpty(CRLF)) CRLF = "false";
User = new Commands.Config().Get("user.name"); } else {
Email = new Commands.Config().Get("user.email"); User = "";
CRLF = new Commands.Config().Get("core.autocrlf"); Email = "";
Version = new Commands.Version().Query(); CRLF = "false";
if (string.IsNullOrEmpty(CRLF)) CRLF = "false"; Version = "Unknown";
} else { }
User = ""; if (updateUi) {
Email = ""; editGitUser?.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
CRLF = "false"; editGitEmail?.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
Version = "Unknown"; editGitCrlf?.GetBindingExpression(ComboBox.SelectedValueProperty).UpdateTarget();
} textGitVersion?.GetBindingExpression(TextBlock.TextProperty).UpdateTarget();
if (updateUi) { }
editGitUser?.GetBindingExpression(TextBox.TextProperty).UpdateTarget(); return isReady;
editGitEmail?.GetBindingExpression(TextBox.TextProperty).UpdateTarget(); }
editGitCrlf?.GetBindingExpression(ComboBox.SelectedValueProperty).UpdateTarget();
textGitVersion?.GetBindingExpression(TextBlock.TextProperty).UpdateTarget(); #region EVENTS
} private void LocaleChanged(object sender, SelectionChangedEventArgs e) {
return isReady; Models.Locale.Change();
} }
#region EVENTS private void ChangeTheme(object sender, RoutedEventArgs e) {
private void LocaleChanged(object sender, SelectionChangedEventArgs e) { Models.Theme.Change();
Models.Locale.Change(); }
}
private void SelectGitPath(object sender, RoutedEventArgs e) {
private void ChangeTheme(object sender, RoutedEventArgs e) { var initDir = Models.ExecutableFinder.Find("git.exe");
Models.Theme.Change(); if (initDir == null) initDir = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
} else initDir = Path.GetDirectoryName(initDir);
private void SelectGitPath(object sender, RoutedEventArgs e) { var dialog = new OpenFileDialog {
var initDir = Models.ExecutableFinder.Find("git.exe"); Filter = "Git Executable|git.exe",
if (initDir == null) initDir = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); FileName = "git.exe",
else initDir = Path.GetDirectoryName(initDir); Title = App.Text("Preference.Dialog.GitExe"),
InitialDirectory = initDir,
var dialog = new OpenFileDialog { CheckFileExists = true,
Filter = "Git Executable|git.exe", };
FileName = "git.exe",
Title = App.Text("Preference.Dialog.GitExe"), if (dialog.ShowDialog() == true) {
InitialDirectory = initDir, Models.Preference.Instance.Git.Path = dialog.FileName;
CheckFileExists = true, editGitPath?.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
}; UpdateGitInfo(true);
}
if (dialog.ShowDialog() == true) { }
Models.Preference.Instance.Git.Path = dialog.FileName;
editGitPath?.GetBindingExpression(TextBox.TextProperty).UpdateTarget(); private void SelectGitCloneDir(object sender, RoutedEventArgs e) {
UpdateGitInfo(true); var dialog = new Controls.FolderDialog();
} if (dialog.ShowDialog() == true) {
} Models.Preference.Instance.Git.DefaultCloneDir = dialog.SelectedPath;
txtGitCloneDir?.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
private void SelectGitCloneDir(object sender, RoutedEventArgs e) { }
var dialog = new Controls.FolderDialog(); }
if (dialog.ShowDialog() == true) {
Models.Preference.Instance.Git.DefaultCloneDir = dialog.SelectedPath; private void SelectMergeTool(object sender, RoutedEventArgs e) {
txtGitCloneDir?.GetBindingExpression(TextBox.TextProperty).UpdateTarget(); var type = Models.Preference.Instance.MergeTool.Type;
} var tool = Models.MergeTool.Supported.Find(x => x.Type == type);
}
if (tool == null || tool.Type == 0) return;
private void SelectMergeTool(object sender, RoutedEventArgs e) {
var type = Models.Preference.Instance.MergeTool.Type; var dialog = new OpenFileDialog();
var tool = Models.MergeTool.Supported.Find(x => x.Type == type); dialog.Filter = $"{tool.Name} Executable|{tool.Exec}";
dialog.Title = App.Text("Preference.Dialog.Merger", tool.Name);
if (tool == null || tool.Type == 0) return; dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
dialog.CheckFileExists = true;
var dialog = new OpenFileDialog();
dialog.Filter = $"{tool.Name} Executable|{tool.Exec}"; if (dialog.ShowDialog() == true) {
dialog.Title = App.Text("Preference.Dialog.Merger", tool.Name); Models.Preference.Instance.MergeTool.Path = dialog.FileName;
dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); txtMergeExec?.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
dialog.CheckFileExists = true; }
}
if (dialog.ShowDialog() == true) {
Models.Preference.Instance.MergeTool.Path = dialog.FileName; private void MergeToolChanged(object sender, SelectionChangedEventArgs e) {
txtMergeExec?.GetBindingExpression(TextBox.TextProperty).UpdateTarget(); var type = (int)(sender as ComboBox).SelectedValue;
} var tool = Models.MergeTool.Supported.Find(x => x.Type == type);
} if (tool == null) return;
private void MergeToolChanged(object sender, SelectionChangedEventArgs e) { if (IsLoaded) {
var type = (int)(sender as ComboBox).SelectedValue; Models.Preference.Instance.MergeTool.Path = tool.Finder();
var tool = Models.MergeTool.Supported.Find(x => x.Type == type); txtMergeExec?.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
if (tool == null) return; }
if (IsLoaded) { e.Handled = true;
Models.Preference.Instance.MergeTool.Path = tool.Finder(); }
txtMergeExec?.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
} private void Quit(object sender, RoutedEventArgs e) {
if (Models.Preference.Instance.IsReady) {
e.Handled = true; var cmd = new Commands.Config();
} var oldUser = cmd.Get("user.name");
if (oldUser != User) cmd.Set("user.name", User);
private void Quit(object sender, RoutedEventArgs e) {
if (Models.Preference.Instance.IsReady) { var oldEmail = cmd.Get("user.email");
var cmd = new Commands.Config(); if (oldEmail != Email) cmd.Set("user.email", Email);
var oldUser = cmd.Get("user.name");
if (oldUser != User) cmd.Set("user.name", User); var oldCRLF = cmd.Get("core.autocrlf");
if (oldCRLF != CRLF) cmd.Set("core.autocrlf", CRLF);
var oldEmail = cmd.Get("user.email"); }
if (oldEmail != Email) cmd.Set("user.email", Email);
Models.Preference.Save();
var oldCRLF = cmd.Get("core.autocrlf"); Close();
if (oldCRLF != CRLF) cmd.Set("core.autocrlf", CRLF); }
} #endregion
}
Models.Preference.Save(); }
Close();
}
#endregion
}
}

View file

@ -320,20 +320,11 @@ namespace SourceGit.Views.Widgets {
return; return;
} }
if (Models.Preference.Instance.General.UseWindowsTerminal) { Process.Start(new ProcessStartInfo {
Process.Start(new ProcessStartInfo { WorkingDirectory = repo.Path,
WorkingDirectory = repo.Path, FileName = bash,
FileName = "wt", UseShellExecute = true,
Arguments = $"-d \"{repo.Path}\" \"{bash}\"", });
UseShellExecute = false,
});
} else {
Process.Start(new ProcessStartInfo {
WorkingDirectory = repo.Path,
FileName = bash,
UseShellExecute = true,
});
}
} }
private void OpenInVSCode(object sender, RoutedEventArgs e) { private void OpenInVSCode(object sender, RoutedEventArgs e) {

View file

@ -86,18 +86,10 @@ namespace SourceGit.Views.Widgets {
return; return;
} }
if (Models.Preference.Instance.General.UseWindowsTerminal) { Process.Start(new ProcessStartInfo {
Process.Start(new ProcessStartInfo { FileName = bash,
FileName = "wt", UseShellExecute = true,
Arguments = $"\"{bash}\"", });
UseShellExecute = false,
});
} else {
Process.Start(new ProcessStartInfo {
FileName = bash,
UseShellExecute = true,
});
}
e.Handled = true; e.Handled = true;
} }