diff --git a/README.md b/README.md index 351fecb0..9af7f471 100644 --- a/README.md +++ b/README.md @@ -53,20 +53,20 @@ For **Linux** users: * Maybe you need to set environment variable `AVALONIA_SCREEN_SCALE_FACTORS`. See https://github.com/AvaloniaUI/Avalonia/wiki/Configuring-X11-per-monitor-DPI. * Modify `SourceGit.desktop.template` (replace SOURCEGIT_LOCAL_FOLDER with real path) and move it into `~/.local/share/applications`. -## External Editors +## External Tools -This app supports open repository in external editors listed in the table below. +This app supports open repository in external tools listed in the table below. -| Editor | Windows | macOS | Linux | Environment Variable | +| Tool | Windows | macOS | Linux | Environment Variable | | --- | --- | --- | --- | --- | | Visual Studio Code | YES | YES | YES | VSCODE_PATH | | Visual Studio Code - Insiders | YES | YES | YES | VSCODE_INSIDERS_PATH | | JetBrains Fleet | YES | YES | YES | FLEET_PATH | | Sublime Text | YES | YES | YES | SUBLIME_TEXT_PATH | -You can set the given environment variable for special editor if it can NOT be found by this app automatically. +You can set the given environment variable for special tool if it can NOT be found by this app automatically. -## Screen Shots +## Screenshots * Dark Theme diff --git a/src/Models/ExternalMergeTools.cs b/src/Models/ExternalMergeTools.cs deleted file mode 100644 index f07ef088..00000000 --- a/src/Models/ExternalMergeTools.cs +++ /dev/null @@ -1,88 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; - -namespace SourceGit.Models -{ - public class ExternalMergeTools - { - public int Type { get; set; } - public string Name { get; set; } - public string Exec { get; set; } - public string Cmd { get; set; } - public string DiffCmd { get; set; } - - public static readonly List Supported; - - static ExternalMergeTools() - { - if (OperatingSystem.IsWindows()) - { - Supported = new List() { - new ExternalMergeTools(0, "Custom", "", "", ""), - new ExternalMergeTools(1, "Visual Studio Code", "Code.exe", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\""), - new ExternalMergeTools(2, "Visual Studio Code - Insiders", "Code - Insiders.exe", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\""), - new ExternalMergeTools(3, "Visual Studio 2017/2019/2022", "vsDiffMerge.exe", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\" /m", "\"$LOCAL\" \"$REMOTE\""), - new ExternalMergeTools(4, "Tortoise Merge", "TortoiseMerge.exe;TortoiseGitMerge.exe", "-base:\"$BASE\" -theirs:\"$REMOTE\" -mine:\"$LOCAL\" -merged:\"$MERGED\"", "-base:\"$LOCAL\" -theirs:\"$REMOTE\""), - new ExternalMergeTools(5, "KDiff3", "kdiff3.exe", "\"$REMOTE\" -b \"$BASE\" \"$LOCAL\" -o \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""), - new ExternalMergeTools(6, "Beyond Compare", "BComp.exe", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""), - new ExternalMergeTools(7, "WinMerge", "WinMergeU.exe", "-u -e \"$REMOTE\" \"$LOCAL\" \"$MERGED\"", "-u -e \"$LOCAL\" \"$REMOTE\""), - }; - } - else if (OperatingSystem.IsMacOS()) - { - Supported = new List() { - new ExternalMergeTools(0, "Custom", "", "", ""), - new ExternalMergeTools(1, "FileMerge", "/usr/bin/opendiff", "\"$BASE\" \"$LOCAL\" \"$REMOTE\" -ancestor \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""), - new ExternalMergeTools(2, "Visual Studio Code", "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\""), - new ExternalMergeTools(3, "Visual Studio Code - Insiders", "/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/bin/code", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\""), - new ExternalMergeTools(4, "KDiff3", "/Applications/kdiff3.app/Contents/MacOS/kdiff3", "\"$REMOTE\" -b \"$BASE\" \"$LOCAL\" -o \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""), - new ExternalMergeTools(5, "Beyond Compare", "/Applications/Beyond Compare.app/Contents/MacOS/bcomp", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""), - }; - } - else if (OperatingSystem.IsLinux()) - { - Supported = new List() { - new ExternalMergeTools(0, "Custom", "", "", ""), - new ExternalMergeTools(1, "Visual Studio Code", "/usr/share/code/code", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\""), - new ExternalMergeTools(2, "Visual Studio Code - Insiders", "/usr/share/code-insiders/code-insiders", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\""), - new ExternalMergeTools(3, "KDiff3", "/usr/bin/kdiff3", "\"$REMOTE\" -b \"$BASE\" \"$LOCAL\" -o \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""), - new ExternalMergeTools(4, "Beyond Compare", "/usr/bin/bcomp", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""), - }; - } - else - { - Supported = new List() { - new ExternalMergeTools(0, "Custom", "", "", ""), - }; - } - } - - public ExternalMergeTools(int type, string name, string exec, string cmd, string diffCmd) - { - Type = type; - Name = name; - Exec = exec; - Cmd = cmd; - DiffCmd = diffCmd; - } - - public string[] GetPatterns() - { - if (OperatingSystem.IsWindows()) - { - return Exec.Split(';'); - } - else - { - var patterns = new List(); - var choices = Exec.Split(';', StringSplitOptions.RemoveEmptyEntries); - foreach (var c in choices) - { - patterns.Add(Path.GetFileName(c)); - } - return patterns.ToArray(); - } - } - } -} diff --git a/src/Models/ExternalMerger.cs b/src/Models/ExternalMerger.cs new file mode 100644 index 00000000..6643bbbb --- /dev/null +++ b/src/Models/ExternalMerger.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.IO; + +namespace SourceGit.Models +{ + public class ExternalMerger + { + public int Type { get; set; } + public string Name { get; set; } + public string Exec { get; set; } + public string Cmd { get; set; } + public string DiffCmd { get; set; } + + public static readonly List Supported; + + static ExternalMerger() + { + if (OperatingSystem.IsWindows()) + { + Supported = new List() { + new ExternalMerger(0, "Custom", "", "", ""), + new ExternalMerger(1, "Visual Studio Code", "Code.exe", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\""), + new ExternalMerger(2, "Visual Studio Code - Insiders", "Code - Insiders.exe", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\""), + new ExternalMerger(3, "Visual Studio 2017/2019/2022", "vsDiffMerge.exe", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\" /m", "\"$LOCAL\" \"$REMOTE\""), + new ExternalMerger(4, "Tortoise Merge", "TortoiseMerge.exe;TortoiseGitMerge.exe", "-base:\"$BASE\" -theirs:\"$REMOTE\" -mine:\"$LOCAL\" -merged:\"$MERGED\"", "-base:\"$LOCAL\" -theirs:\"$REMOTE\""), + new ExternalMerger(5, "KDiff3", "kdiff3.exe", "\"$REMOTE\" -b \"$BASE\" \"$LOCAL\" -o \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""), + new ExternalMerger(6, "Beyond Compare", "BComp.exe", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""), + new ExternalMerger(7, "WinMerge", "WinMergeU.exe", "-u -e \"$REMOTE\" \"$LOCAL\" \"$MERGED\"", "-u -e \"$LOCAL\" \"$REMOTE\""), + }; + } + else if (OperatingSystem.IsMacOS()) + { + Supported = new List() { + new ExternalMerger(0, "Custom", "", "", ""), + new ExternalMerger(1, "FileMerge", "/usr/bin/opendiff", "\"$BASE\" \"$LOCAL\" \"$REMOTE\" -ancestor \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""), + new ExternalMerger(2, "Visual Studio Code", "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\""), + new ExternalMerger(3, "Visual Studio Code - Insiders", "/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/bin/code", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\""), + new ExternalMerger(4, "KDiff3", "/Applications/kdiff3.app/Contents/MacOS/kdiff3", "\"$REMOTE\" -b \"$BASE\" \"$LOCAL\" -o \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""), + new ExternalMerger(5, "Beyond Compare", "/Applications/Beyond Compare.app/Contents/MacOS/bcomp", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""), + }; + } + else if (OperatingSystem.IsLinux()) + { + Supported = new List() { + new ExternalMerger(0, "Custom", "", "", ""), + new ExternalMerger(1, "Visual Studio Code", "/usr/share/code/code", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\""), + new ExternalMerger(2, "Visual Studio Code - Insiders", "/usr/share/code-insiders/code-insiders", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\""), + new ExternalMerger(3, "KDiff3", "/usr/bin/kdiff3", "\"$REMOTE\" -b \"$BASE\" \"$LOCAL\" -o \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""), + new ExternalMerger(4, "Beyond Compare", "/usr/bin/bcomp", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""), + }; + } + else + { + Supported = new List() { + new ExternalMerger(0, "Custom", "", "", ""), + }; + } + } + + public ExternalMerger(int type, string name, string exec, string cmd, string diffCmd) + { + Type = type; + Name = name; + Exec = exec; + Cmd = cmd; + DiffCmd = diffCmd; + } + + public string[] GetPatterns() + { + if (OperatingSystem.IsWindows()) + { + return Exec.Split(';'); + } + else + { + var patterns = new List(); + var choices = Exec.Split(';', StringSplitOptions.RemoveEmptyEntries); + foreach (var c in choices) + { + patterns.Add(Path.GetFileName(c)); + } + return patterns.ToArray(); + } + } + } +} diff --git a/src/Models/ExternalEditor.cs b/src/Models/ExternalTool.cs similarity index 86% rename from src/Models/ExternalEditor.cs rename to src/Models/ExternalTool.cs index 094d0a5f..5383a6bf 100644 --- a/src/Models/ExternalEditor.cs +++ b/src/Models/ExternalTool.cs @@ -5,7 +5,7 @@ using System.IO; namespace SourceGit.Models { - public class ExternalEditor + public class ExternalTool { public string Name { get; set; } = string.Empty; public string Icon { get; set; } = string.Empty; @@ -24,13 +24,13 @@ namespace SourceGit.Models } } - public class ExternalEditorFinder + public class ExternalToolsFinder { - public List Editors + public List Founded { get; private set; - } = new List(); + } = new List(); public void VSCode(Func platform_finder) { @@ -52,7 +52,7 @@ namespace SourceGit.Models TryAdd("Sublime Text", "sublime_text.png", "\"{0}\"", "SUBLIME_TEXT_PATH", platform_finder); } - private void TryAdd(string name, string icon, string args, string env, Func finder) + public void TryAdd(string name, string icon, string args, string env, Func finder) { var path = Environment.GetEnvironmentVariable(env); if (string.IsNullOrEmpty(path) || !File.Exists(path)) @@ -62,7 +62,7 @@ namespace SourceGit.Models return; } - Editors.Add(new ExternalEditor + Founded.Add(new ExternalTool { Name = name, Icon = icon, diff --git a/src/Models/Shell.cs b/src/Models/Shell.cs new file mode 100644 index 00000000..9960d136 --- /dev/null +++ b/src/Models/Shell.cs @@ -0,0 +1,10 @@ +namespace SourceGit.Models +{ + public enum Shell + { + Default = 0, + PowerShell, + CommandPrompt, + DefaultShellOfWindowsTerminal, + } +} diff --git a/src/Native/Linux.cs b/src/Native/Linux.cs index 7a31ebc5..4d4d3fc3 100644 --- a/src/Native/Linux.cs +++ b/src/Native/Linux.cs @@ -31,14 +31,14 @@ namespace SourceGit.Native return string.Empty; } - public List FindExternalEditors() + public List FindExternalTools() { - var finder = new Models.ExternalEditorFinder(); + var finder = new Models.ExternalToolsFinder(); finder.VSCode(() => "/usr/share/code/code"); finder.VSCodeInsiders(() => "/usr/share/code-insiders/code-insiders"); finder.Fleet(() => $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}/JetBrains/Toolbox/apps/fleet/bin/Fleet"); finder.SublimeText(() => File.Exists("/usr/bin/subl") ? "/usr/bin/subl" : "/usr/local/bin/subl"); - return finder.Editors; + return finder.Founded; } public void OpenBrowser(string url) diff --git a/src/Native/MacOS.cs b/src/Native/MacOS.cs index ac864986..28519e40 100644 --- a/src/Native/MacOS.cs +++ b/src/Native/MacOS.cs @@ -28,14 +28,14 @@ namespace SourceGit.Native return string.Empty; } - public List FindExternalEditors() + public List FindExternalTools() { - var finder = new Models.ExternalEditorFinder(); + var finder = new Models.ExternalToolsFinder(); finder.VSCode(() => "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code"); finder.VSCodeInsiders(() => "/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/bin/code"); finder.Fleet(() => $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/Applications/Fleet.app/Contents/MacOS/Fleet"); finder.SublimeText(() => "/Applications/Sublime Text.app/Contents/SharedSupport/bin"); - return finder.Editors; + return finder.Founded; } public void OpenBrowser(string url) diff --git a/src/Native/OS.cs b/src/Native/OS.cs index 61a33ed6..259b6a22 100644 --- a/src/Native/OS.cs +++ b/src/Native/OS.cs @@ -12,7 +12,7 @@ namespace SourceGit.Native void SetupApp(AppBuilder builder); string FindGitExecutable(); - List FindExternalEditors(); + List FindExternalTools(); void OpenTerminal(string workdir); void OpenInFileManager(string path, bool select); @@ -21,7 +21,7 @@ namespace SourceGit.Native } public static string GitExecutable { get; set; } = string.Empty; - public static List ExternalEditors { get; set; } = new List(); + public static List ExternalTools { get; set; } = new List(); static OS() { @@ -42,7 +42,34 @@ namespace SourceGit.Native throw new Exception("Platform unsupported!!!"); } - ExternalEditors = _backend.FindExternalEditors(); + ExternalTools = _backend.FindExternalTools(); + } + + public static Models.Shell GetShell() + { + if (OperatingSystem.IsWindows()) + { + return (_backend as Windows).Shell; + } + else + { + return Models.Shell.Default; + } + } + + public static bool SetShell(Models.Shell shell) + { + if (OperatingSystem.IsWindows()) + { + var windows = (_backend as Windows); + if (windows.Shell != shell) + { + windows.Shell = shell; + return true; + } + } + + return false; } public static void SetupApp(AppBuilder builder) diff --git a/src/Native/Windows.cs b/src/Native/Windows.cs index 78fef704..e2dbc5d2 100644 --- a/src/Native/Windows.cs +++ b/src/Native/Windows.cs @@ -54,6 +54,12 @@ namespace SourceGit.Native [DllImport("shell32.dll", CharSet = CharSet.Unicode, SetLastError = false)] private static extern int SHOpenFolderAndSelectItems(IntPtr pidlFolder, int cild, IntPtr apidl, int dwFlags); + public Models.Shell Shell + { + get; + set; + } = Models.Shell.Default; + public void SetupApp(AppBuilder builder) { builder.With(new FontManagerOptions() @@ -114,14 +120,14 @@ namespace SourceGit.Native return null; } - public List FindExternalEditors() + public List FindExternalTools() { - var finder = new Models.ExternalEditorFinder(); + var finder = new Models.ExternalToolsFinder(); finder.VSCode(FindVSCode); finder.VSCodeInsiders(FindVSCodeInsiders); finder.Fleet(() => $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\Programs\\Fleet\\Fleet.exe"); finder.SublimeText(FindSublimeText); - return finder.Editors; + return finder.Founded; } public void OpenBrowser(string url) @@ -133,19 +139,49 @@ namespace SourceGit.Native public void OpenTerminal(string workdir) { - var binDir = Path.GetDirectoryName(OS.GitExecutable); - var bash = Path.Combine(binDir, "bash.exe"); - if (!File.Exists(bash)) + if (string.IsNullOrEmpty(workdir) || !Path.Exists(workdir)) { - App.RaiseException(string.IsNullOrEmpty(workdir) ? "" : workdir, $"Can NOT found bash.exe under '{binDir}'"); - return; + workdir = "."; } var startInfo = new ProcessStartInfo(); - startInfo.UseShellExecute = true; - startInfo.FileName = bash; - if (!string.IsNullOrEmpty(workdir) && Path.Exists(workdir)) - startInfo.WorkingDirectory = workdir; + startInfo.WorkingDirectory = workdir; + + switch (Shell) + { + case Models.Shell.Default: + var binDir = Path.GetDirectoryName(OS.GitExecutable); + var bash = Path.Combine(binDir, "bash.exe"); + if (!File.Exists(bash)) + { + App.RaiseException(workdir, $"Can NOT found bash.exe under '{binDir}'"); + return; + } + + startInfo.FileName = bash; + break; + case Models.Shell.PowerShell: + startInfo.FileName = ChoosePowerShell(); + startInfo.Arguments = startInfo.FileName.EndsWith("pswd.exe") ? $"-WorkingDirectory \"{workdir}\" -Nologo" : "-Nologo"; + break; + case Models.Shell.CommandPrompt: + startInfo.FileName = "cmd"; + break; + case Models.Shell.DefaultShellOfWindowsTerminal: + var wt = FindWindowsTerminalApp(); + if (!File.Exists(wt)) + { + App.RaiseException(workdir, $"Can NOT found wt.exe on your system!"); + return; + } + + startInfo.FileName = FindWindowsTerminalApp(); + break; + default: + App.RaiseException(workdir, $"Bad shell configuration!"); + return; + } + Process.Start(startInfo); } @@ -189,6 +225,52 @@ namespace SourceGit.Native Process.Start(start); } + // There are two versions of PowerShell : pwsh.exe (preferred) and powershell.exe (system default) + private string ChoosePowerShell() + { + if (!string.IsNullOrEmpty(_powershellPath)) + return _powershellPath; + + var localMachine = Microsoft.Win32.RegistryKey.OpenBaseKey( + Microsoft.Win32.RegistryHive.LocalMachine, + Microsoft.Win32.RegistryView.Registry64); + + var pwsh = localMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\pwsh.exe"); + if (pwsh != null) + { + var path = pwsh.GetValue(null) as string; + if (File.Exists(path)) + { + _powershellPath = path; + return _powershellPath; + } + } + + var finder = new StringBuilder("powershell.exe", 512); + if (PathFindOnPath(finder, null)) + { + _powershellPath = finder.ToString(); + return _powershellPath; + } + + return string.Empty; + } + + private string FindWindowsTerminalApp() + { + if (!string.IsNullOrEmpty(_wtPath)) + return _wtPath; + + var finder = new StringBuilder("wt.exe", 512); + if (PathFindOnPath(finder, null)) + { + _wtPath = finder.ToString(); + return _wtPath; + } + + return string.Empty; + } + #region EXTERNAL_EDITOR_FINDER private string FindVSCode() { @@ -250,6 +332,7 @@ namespace SourceGit.Native Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64); + // Sublime Text 4 var sublime = localMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Sublime Text_is1"); if (sublime != null) { @@ -257,6 +340,7 @@ namespace SourceGit.Native return Path.Combine(Path.GetDirectoryName(icon), "subl.exe"); } + // Sublime Text 3 var sublime3 = localMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Sublime Text 3_is1"); if (sublime3 != null) { @@ -281,5 +365,8 @@ namespace SourceGit.Native ILFree(pidl); } } + + private string _powershellPath = string.Empty; + private string _wtPath = string.Empty; } } diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 68e57b4c..8277d3c5 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -266,6 +266,7 @@ User Email Global git user email Install Path + Shell User Name Global git user name Git version diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 79cf9973..fb7fecc3 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -266,6 +266,7 @@ 邮箱 默认GIT用户邮箱 安装路径 + 终端Shell 用户名 默认GIT用户名 Git 版本 diff --git a/src/Resources/ShellIcons/cmd.png b/src/Resources/ShellIcons/cmd.png new file mode 100644 index 00000000..4a3aa218 Binary files /dev/null and b/src/Resources/ShellIcons/cmd.png differ diff --git a/src/Resources/ShellIcons/git-bash.png b/src/Resources/ShellIcons/git-bash.png new file mode 100644 index 00000000..1f7a2ced Binary files /dev/null and b/src/Resources/ShellIcons/git-bash.png differ diff --git a/src/Resources/ShellIcons/pwsh.png b/src/Resources/ShellIcons/pwsh.png new file mode 100644 index 00000000..67fa8c91 Binary files /dev/null and b/src/Resources/ShellIcons/pwsh.png differ diff --git a/src/Resources/ShellIcons/wt.png b/src/Resources/ShellIcons/wt.png new file mode 100644 index 00000000..3462cc6e Binary files /dev/null and b/src/Resources/ShellIcons/wt.png differ diff --git a/src/SourceGit.csproj b/src/SourceGit.csproj index 0a3ef8a6..d439eee8 100644 --- a/src/SourceGit.csproj +++ b/src/SourceGit.csproj @@ -22,8 +22,9 @@ - + + diff --git a/src/ViewModels/CommitDetail.cs b/src/ViewModels/CommitDetail.cs index fe719517..f290fd4c 100644 --- a/src/ViewModels/CommitDetail.cs +++ b/src/ViewModels/CommitDetail.cs @@ -205,7 +205,7 @@ namespace SourceGit.ViewModels var type = Preference.Instance.ExternalMergeToolType; var exec = Preference.Instance.ExternalMergeToolPath; - var tool = Models.ExternalMergeTools.Supported.Find(x => x.Type == type); + var tool = Models.ExternalMerger.Supported.Find(x => x.Type == type); if (tool == null || !File.Exists(exec)) { App.RaiseException(_repo, "Invalid merge tool in preference setting!"); diff --git a/src/ViewModels/DiffContext.cs b/src/ViewModels/DiffContext.cs index 728c4f43..17514656 100644 --- a/src/ViewModels/DiffContext.cs +++ b/src/ViewModels/DiffContext.cs @@ -152,7 +152,7 @@ namespace SourceGit.ViewModels var type = Preference.Instance.ExternalMergeToolType; var exec = Preference.Instance.ExternalMergeToolPath; - var tool = Models.ExternalMergeTools.Supported.Find(x => x.Type == type); + var tool = Models.ExternalMerger.Supported.Find(x => x.Type == type); if (tool == null || !File.Exists(exec)) { App.RaiseException(_repo, "Invalid merge tool in preference setting!"); diff --git a/src/ViewModels/Preference.cs b/src/ViewModels/Preference.cs index ee8f96a9..8d0520c8 100644 --- a/src/ViewModels/Preference.cs +++ b/src/ViewModels/Preference.cs @@ -200,6 +200,18 @@ namespace SourceGit.ViewModels } } + public Models.Shell GitShell + { + get => Native.OS.GetShell(); + set + { + if (Native.OS.SetShell(value)) + { + OnPropertyChanged(nameof(GitShell)); + } + } + } + public string GitDefaultCloneDir { get => _gitDefaultCloneDir; @@ -225,9 +237,9 @@ namespace SourceGit.ViewModels set { var changed = SetProperty(ref _externalMergeToolType, value); - if (changed && !OperatingSystem.IsWindows() && value > 0 && value < Models.ExternalMergeTools.Supported.Count) + if (changed && !OperatingSystem.IsWindows() && value > 0 && value < Models.ExternalMerger.Supported.Count) { - var tool = Models.ExternalMergeTools.Supported[value]; + var tool = Models.ExternalMerger.Supported[value]; if (File.Exists(tool.Exec)) ExternalMergeToolPath = tool.Exec; else diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 61f034ff..89740d7d 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -287,10 +287,10 @@ namespace SourceGit.ViewModels Native.OS.OpenTerminal(_fullpath); } - public ContextMenu CreateContextMenuForExternalEditors() + public ContextMenu CreateContextMenuForExternalTools() { - var editors = Native.OS.ExternalEditors; - if (editors.Count == 0) + var tools = Native.OS.ExternalTools; + if (tools.Count == 0) { App.RaiseException(_fullpath, "No available external editors found!"); return null; @@ -300,16 +300,16 @@ namespace SourceGit.ViewModels menu.Placement = PlacementMode.BottomEdgeAlignedLeft; RenderOptions.SetBitmapInterpolationMode(menu, BitmapInterpolationMode.HighQuality); - foreach (var editor in editors) + foreach (var tool in tools) { - var dupEditor = editor; - var icon = AssetLoader.Open(new Uri($"avares://SourceGit/Resources/ExternalToolIcons/{dupEditor.Icon}", UriKind.RelativeOrAbsolute)); + var dupTool = tool; + var icon = AssetLoader.Open(new Uri($"avares://SourceGit/Resources/ExternalToolIcons/{dupTool.Icon}", UriKind.RelativeOrAbsolute)); var item = new MenuItem(); - item.Header = App.Text("Repository.OpenIn", dupEditor.Name); + item.Header = App.Text("Repository.OpenIn", dupTool.Name); item.Icon = new Image { Width = 16, Height = 16, Source = new Bitmap(icon) }; item.Click += (o, e) => { - dupEditor.Open(_fullpath); + dupTool.Open(_fullpath); e.Handled = true; }; diff --git a/src/ViewModels/RevisionCompare.cs b/src/ViewModels/RevisionCompare.cs index 167f3a41..1ed85c9e 100644 --- a/src/ViewModels/RevisionCompare.cs +++ b/src/ViewModels/RevisionCompare.cs @@ -166,7 +166,7 @@ namespace SourceGit.ViewModels var type = Preference.Instance.ExternalMergeToolType; var exec = Preference.Instance.ExternalMergeToolPath; - var tool = Models.ExternalMergeTools.Supported.Find(x => x.Type == type); + var tool = Models.ExternalMerger.Supported.Find(x => x.Type == type); if (tool == null || !File.Exists(exec)) { App.RaiseException(_repo, "Invalid merge tool in preference setting!"); diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index 6aa9d999..a52a31df 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -423,7 +423,7 @@ namespace SourceGit.ViewModels var type = Preference.Instance.ExternalMergeToolType; var exec = Preference.Instance.ExternalMergeToolPath; - var tool = Models.ExternalMergeTools.Supported.Find(x => x.Type == type); + var tool = Models.ExternalMerger.Supported.Find(x => x.Type == type); if (tool == null) { App.RaiseException(_repo.FullPath, "Invalid merge tool in preference setting!"); diff --git a/src/Views/Preference.axaml b/src/Views/Preference.axaml index 24d10e8d..a6918a1a 100644 --- a/src/Views/Preference.axaml +++ b/src/Views/Preference.axaml @@ -231,7 +231,7 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + - @@ -269,31 +308,31 @@ - - - + + + - - - @@ -370,8 +409,8 @@ MinHeight="28" Padding="8,0" HorizontalAlignment="Stretch" - ItemsSource="{Binding Source={x:Static m:ExternalMergeTools.Supported}}" - DisplayMemberBinding="{Binding Name, x:DataType=m:ExternalMergeTools}" + ItemsSource="{Binding Source={x:Static m:ExternalMerger.Supported}}" + DisplayMemberBinding="{Binding Name, x:DataType=m:ExternalMerger}" SelectedIndex="{Binding ExternalMergeToolType, Mode=TwoWay}"/> = Models.ExternalMergeTools.Supported.Count) + if (type < 0 || type >= Models.ExternalMerger.Supported.Count) { ViewModels.Preference.Instance.ExternalMergeToolType = 0; type = 0; } - var tool = Models.ExternalMergeTools.Supported[type]; + var tool = Models.ExternalMerger.Supported[type]; var options = new FilePickerOpenOptions() { FileTypeFilter = [new FilePickerFileType(tool.Name) { Patterns = tool.GetPatterns() }], diff --git a/src/Views/Repository.axaml b/src/Views/Repository.axaml index 4bfb98a6..d618ea4c 100644 --- a/src/Views/Repository.axaml +++ b/src/Views/Repository.axaml @@ -22,7 +22,7 @@ - diff --git a/src/Views/Repository.axaml.cs b/src/Views/Repository.axaml.cs index 858f5f3d..43d9ee11 100644 --- a/src/Views/Repository.axaml.cs +++ b/src/Views/Repository.axaml.cs @@ -61,11 +61,11 @@ namespace SourceGit.Views InitializeComponent(); } - private void OnOpenWithExternalEditor(object sender, RoutedEventArgs e) + private void OnOpenWithExternalTools(object sender, RoutedEventArgs e) { if (sender is Button button && DataContext is ViewModels.Repository repo) { - var menu = repo.CreateContextMenuForExternalEditors(); + var menu = repo.CreateContextMenuForExternalTools(); if (menu != null) { menu.Open(button);