From 171f1d1d0cdd2c0bcf647e65340efc10387e8bf6 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 20 May 2022 15:29:56 +0800 Subject: [PATCH] optimize<*>: remove Windows Terminal settings because it can be set outside in Windows Terminal --- src/Models/Preference.cs | 5 - src/Views/Preference.xaml | 746 ++++++++++++++-------------- src/Views/Preference.xaml.cs | 271 +++++----- src/Views/Widgets/Dashboard.xaml.cs | 19 +- src/Views/Widgets/Welcome.xaml.cs | 16 +- 5 files changed, 511 insertions(+), 546 deletions(-) diff --git a/src/Models/Preference.cs b/src/Models/Preference.cs index a3ce8ec3..0def93b7 100644 --- a/src/Models/Preference.cs +++ b/src/Models/Preference.cs @@ -68,11 +68,6 @@ namespace SourceGit.Models { /// 上一次检测的时间(用于控制每天仅第一次启动软件时,检测) /// public int LastCheckDay { get; set; } = 0; - - /// - /// 是否尝试使用 Windows Terminal 打开终端 - /// - public bool UseWindowsTerminal { get; set; } = false; } /// diff --git a/src/Views/Preference.xaml b/src/Views/Preference.xaml index 95a48339..e61f1e68 100644 --- a/src/Views/Preference.xaml +++ b/src/Views/Preference.xaml @@ -1,377 +1,369 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Views/Preference.xaml.cs b/src/Views/Preference.xaml.cs index 252e5846..fae97234 100644 --- a/src/Views/Preference.xaml.cs +++ b/src/Views/Preference.xaml.cs @@ -1,138 +1,133 @@ -using Microsoft.Win32; -using System; -using System.IO; -using System.Windows; -using System.Windows.Controls; - -namespace SourceGit.Views { - - /// - /// 设置面板 - /// - public partial class Preference : Controls.Window { - - public string User { get; set; } - public string Email { get; set; } - public string CRLF { get; set; } - public string Version { get; set; } - public bool HasWindowsTerminal { get; set; } - - public Preference() { - UpdateGitInfo(false); - - HasWindowsTerminal = Models.ExecutableFinder.Find("wt.exe") != null; - if (!HasWindowsTerminal) 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"); - 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 - private void LocaleChanged(object sender, SelectionChangedEventArgs e) { - Models.Locale.Change(); - } - - private void ChangeTheme(object sender, RoutedEventArgs e) { - Models.Theme.Change(); - } - - private void SelectGitPath(object sender, RoutedEventArgs e) { - var initDir = Models.ExecutableFinder.Find("git.exe"); - if (initDir == null) initDir = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); - else initDir = Path.GetDirectoryName(initDir); - - var dialog = new OpenFileDialog { - Filter = "Git Executable|git.exe", - FileName = "git.exe", - Title = App.Text("Preference.Dialog.GitExe"), - InitialDirectory = initDir, - CheckFileExists = true, - }; - - if (dialog.ShowDialog() == true) { - Models.Preference.Instance.Git.Path = dialog.FileName; - editGitPath?.GetBindingExpression(TextBox.TextProperty).UpdateTarget(); - UpdateGitInfo(true); - } - } - - private void SelectGitCloneDir(object sender, RoutedEventArgs e) { - var dialog = new Controls.FolderDialog(); - if (dialog.ShowDialog() == true) { - Models.Preference.Instance.Git.DefaultCloneDir = dialog.SelectedPath; - txtGitCloneDir?.GetBindingExpression(TextBox.TextProperty).UpdateTarget(); - } - } - - private void SelectMergeTool(object sender, RoutedEventArgs e) { - var type = Models.Preference.Instance.MergeTool.Type; - var tool = Models.MergeTool.Supported.Find(x => x.Type == type); - - if (tool == null || tool.Type == 0) return; - - var dialog = new OpenFileDialog(); - dialog.Filter = $"{tool.Name} Executable|{tool.Exec}"; - dialog.Title = App.Text("Preference.Dialog.Merger", tool.Name); - dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); - dialog.CheckFileExists = true; - - if (dialog.ShowDialog() == true) { - Models.Preference.Instance.MergeTool.Path = dialog.FileName; - txtMergeExec?.GetBindingExpression(TextBox.TextProperty).UpdateTarget(); - } - } - - private void MergeToolChanged(object sender, SelectionChangedEventArgs e) { - var type = (int)(sender as ComboBox).SelectedValue; - var tool = Models.MergeTool.Supported.Find(x => x.Type == type); - if (tool == null) return; - - if (IsLoaded) { - Models.Preference.Instance.MergeTool.Path = tool.Finder(); - txtMergeExec?.GetBindingExpression(TextBox.TextProperty).UpdateTarget(); - } - - e.Handled = true; - } - - private void Quit(object sender, RoutedEventArgs e) { - if (Models.Preference.Instance.IsReady) { - var cmd = new Commands.Config(); - var oldUser = cmd.Get("user.name"); - if (oldUser != User) cmd.Set("user.name", User); - - var oldEmail = cmd.Get("user.email"); - if (oldEmail != Email) cmd.Set("user.email", Email); - - var oldCRLF = cmd.Get("core.autocrlf"); - if (oldCRLF != CRLF) cmd.Set("core.autocrlf", CRLF); - } - - Models.Preference.Save(); - Close(); - } - #endregion - } -} +using Microsoft.Win32; +using System; +using System.IO; +using System.Windows; +using System.Windows.Controls; + +namespace SourceGit.Views { + + /// + /// 设置面板 + /// + public partial class Preference : Controls.Window { + + public string User { get; set; } + public string Email { get; set; } + public string CRLF { get; set; } + public string Version { get; set; } + + public Preference() { + UpdateGitInfo(false); + InitializeComponent(); + } + + 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 + private void LocaleChanged(object sender, SelectionChangedEventArgs e) { + Models.Locale.Change(); + } + + private void ChangeTheme(object sender, RoutedEventArgs e) { + Models.Theme.Change(); + } + + private void SelectGitPath(object sender, RoutedEventArgs e) { + var initDir = Models.ExecutableFinder.Find("git.exe"); + if (initDir == null) initDir = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); + else initDir = Path.GetDirectoryName(initDir); + + var dialog = new OpenFileDialog { + Filter = "Git Executable|git.exe", + FileName = "git.exe", + Title = App.Text("Preference.Dialog.GitExe"), + InitialDirectory = initDir, + CheckFileExists = true, + }; + + if (dialog.ShowDialog() == true) { + Models.Preference.Instance.Git.Path = dialog.FileName; + editGitPath?.GetBindingExpression(TextBox.TextProperty).UpdateTarget(); + UpdateGitInfo(true); + } + } + + private void SelectGitCloneDir(object sender, RoutedEventArgs e) { + var dialog = new Controls.FolderDialog(); + if (dialog.ShowDialog() == true) { + Models.Preference.Instance.Git.DefaultCloneDir = dialog.SelectedPath; + txtGitCloneDir?.GetBindingExpression(TextBox.TextProperty).UpdateTarget(); + } + } + + private void SelectMergeTool(object sender, RoutedEventArgs e) { + var type = Models.Preference.Instance.MergeTool.Type; + var tool = Models.MergeTool.Supported.Find(x => x.Type == type); + + if (tool == null || tool.Type == 0) return; + + var dialog = new OpenFileDialog(); + dialog.Filter = $"{tool.Name} Executable|{tool.Exec}"; + dialog.Title = App.Text("Preference.Dialog.Merger", tool.Name); + dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); + dialog.CheckFileExists = true; + + if (dialog.ShowDialog() == true) { + Models.Preference.Instance.MergeTool.Path = dialog.FileName; + txtMergeExec?.GetBindingExpression(TextBox.TextProperty).UpdateTarget(); + } + } + + private void MergeToolChanged(object sender, SelectionChangedEventArgs e) { + var type = (int)(sender as ComboBox).SelectedValue; + var tool = Models.MergeTool.Supported.Find(x => x.Type == type); + if (tool == null) return; + + if (IsLoaded) { + Models.Preference.Instance.MergeTool.Path = tool.Finder(); + txtMergeExec?.GetBindingExpression(TextBox.TextProperty).UpdateTarget(); + } + + e.Handled = true; + } + + private void Quit(object sender, RoutedEventArgs e) { + if (Models.Preference.Instance.IsReady) { + var cmd = new Commands.Config(); + var oldUser = cmd.Get("user.name"); + if (oldUser != User) cmd.Set("user.name", User); + + var oldEmail = cmd.Get("user.email"); + if (oldEmail != Email) cmd.Set("user.email", Email); + + var oldCRLF = cmd.Get("core.autocrlf"); + if (oldCRLF != CRLF) cmd.Set("core.autocrlf", CRLF); + } + + Models.Preference.Save(); + Close(); + } + #endregion + } +} diff --git a/src/Views/Widgets/Dashboard.xaml.cs b/src/Views/Widgets/Dashboard.xaml.cs index 648e30e2..24edd9fd 100644 --- a/src/Views/Widgets/Dashboard.xaml.cs +++ b/src/Views/Widgets/Dashboard.xaml.cs @@ -320,20 +320,11 @@ namespace SourceGit.Views.Widgets { return; } - if (Models.Preference.Instance.General.UseWindowsTerminal) { - Process.Start(new ProcessStartInfo { - WorkingDirectory = repo.Path, - FileName = "wt", - Arguments = $"-d \"{repo.Path}\" \"{bash}\"", - UseShellExecute = false, - }); - } else { - Process.Start(new ProcessStartInfo { - WorkingDirectory = repo.Path, - FileName = bash, - UseShellExecute = true, - }); - } + Process.Start(new ProcessStartInfo { + WorkingDirectory = repo.Path, + FileName = bash, + UseShellExecute = true, + }); } private void OpenInVSCode(object sender, RoutedEventArgs e) { diff --git a/src/Views/Widgets/Welcome.xaml.cs b/src/Views/Widgets/Welcome.xaml.cs index 6c61ba31..5d880d59 100644 --- a/src/Views/Widgets/Welcome.xaml.cs +++ b/src/Views/Widgets/Welcome.xaml.cs @@ -86,18 +86,10 @@ namespace SourceGit.Views.Widgets { return; } - if (Models.Preference.Instance.General.UseWindowsTerminal) { - Process.Start(new ProcessStartInfo { - FileName = "wt", - Arguments = $"\"{bash}\"", - UseShellExecute = false, - }); - } else { - Process.Start(new ProcessStartInfo { - FileName = bash, - UseShellExecute = true, - }); - } + Process.Start(new ProcessStartInfo { + FileName = bash, + UseShellExecute = true, + }); e.Handled = true; }