refactor: rewrite external editor supports

* supported editors can be different on different platforms.
* display founded editors only
This commit is contained in:
leo 2024-04-06 13:14:22 +08:00
parent bcb83af576
commit 111bf2966a
20 changed files with 417 additions and 220 deletions

View file

@ -37,7 +37,6 @@ You can download the latest stable from [Releases](https://github.com/sourcegit-
For **Windows** users: For **Windows** users:
* **MSYS Git is NOT supported**. Please use official [Git for Windows](https://git-scm.com/download/win) instead. * **MSYS Git is NOT supported**. Please use official [Git for Windows](https://git-scm.com/download/win) instead.
* You can use `Visual Studio Code Insiders` as the same way as `Visual Studio Code` in this software.
For **macOS** users: For **macOS** users:
@ -54,10 +53,17 @@ 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. * 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`. * Modify `SourceGit.desktop.template` (replace SOURCEGIT_LOCAL_FOLDER with real path) and move it into `~/.local/share/applications`.
Other tips: ## External Editors
* You can set `VSCODE_PATH` environment variable if VSCode can NOT be found when you click `Open In Visual Studio Code`. This app supports open repository in external editors listed in the table below.
* You can set `FLEET_PATH` environment variable if JetBrains Fleet can NOT be found when you click `Open In Fleet`.
| Editor | 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 |
You can set the given environment variable for special editor if it can NOT be found by this app automatically.
## Screen Shots ## Screen Shots

View file

@ -32,7 +32,7 @@ namespace SourceGit.Commands
public bool Exec() public bool Exec()
{ {
var start = new ProcessStartInfo(); var start = new ProcessStartInfo();
start.FileName = Native.OS.GitInstallPath; start.FileName = Native.OS.GitExecutable;
start.Arguments = "--no-pager -c core.quotepath=off " + Args; start.Arguments = "--no-pager -c core.quotepath=off " + Args;
start.UseShellExecute = false; start.UseShellExecute = false;
start.CreateNoWindow = true; start.CreateNoWindow = true;
@ -144,7 +144,7 @@ namespace SourceGit.Commands
public ReadToEndResult ReadToEnd() public ReadToEndResult ReadToEnd()
{ {
var start = new ProcessStartInfo(); var start = new ProcessStartInfo();
start.FileName = Native.OS.GitInstallPath; start.FileName = Native.OS.GitExecutable;
start.Arguments = "--no-pager -c core.quotepath=off " + Args; start.Arguments = "--no-pager -c core.quotepath=off " + Args;
start.UseShellExecute = false; start.UseShellExecute = false;
start.CreateNoWindow = true; start.CreateNoWindow = true;

View file

@ -12,7 +12,7 @@ namespace SourceGit.Commands
{ {
var starter = new ProcessStartInfo(); var starter = new ProcessStartInfo();
starter.WorkingDirectory = repo; starter.WorkingDirectory = repo;
starter.FileName = Native.OS.GitInstallPath; starter.FileName = Native.OS.GitExecutable;
starter.Arguments = $"show {revision}:\"{file}\""; starter.Arguments = $"show {revision}:\"{file}\"";
starter.UseShellExecute = false; starter.UseShellExecute = false;
starter.CreateNoWindow = true; starter.CreateNoWindow = true;

View file

@ -27,7 +27,7 @@ namespace SourceGit.Commands
{ {
var starter = new ProcessStartInfo(); var starter = new ProcessStartInfo();
starter.WorkingDirectory = repo; starter.WorkingDirectory = repo;
starter.FileName = Native.OS.GitInstallPath; starter.FileName = Native.OS.GitExecutable;
starter.Arguments = $"diff --ignore-cr-at-eol --unified=4 {opt}"; starter.Arguments = $"diff --ignore-cr-at-eol --unified=4 {opt}";
starter.UseShellExecute = false; starter.UseShellExecute = false;
starter.CreateNoWindow = true; starter.CreateNoWindow = true;

View file

@ -30,7 +30,7 @@ namespace SourceGit.Commands
{ {
var starter = new ProcessStartInfo(); var starter = new ProcessStartInfo();
starter.WorkingDirectory = repo; starter.WorkingDirectory = repo;
starter.FileName = Native.OS.GitInstallPath; starter.FileName = Native.OS.GitExecutable;
starter.Arguments = args; starter.Arguments = args;
starter.UseShellExecute = false; starter.UseShellExecute = false;
starter.CreateNoWindow = true; starter.CreateNoWindow = true;

View file

@ -0,0 +1,24 @@
using System;
using System.Diagnostics;
namespace SourceGit.Models
{
public class ExternalEditor
{
public string Name { get; set; } = string.Empty;
public Uri Icon { get; set; } = null;
public string Executable { get; set; } = string.Empty;
public string OpenCmdArgs { get; set; } = string.Empty;
public void Open(string repo)
{
Process.Start(new ProcessStartInfo()
{
WorkingDirectory = repo,
FileName = Executable,
Arguments = string.Format(OpenCmdArgs, repo),
UseShellExecute = false,
});
}
}
}

View file

@ -20,12 +20,13 @@ namespace SourceGit.Models
{ {
Supported = new List<ExternalMergeTools>() { Supported = new List<ExternalMergeTools>() {
new ExternalMergeTools(0, "Custom", "", "", ""), new ExternalMergeTools(0, "Custom", "", "", ""),
new ExternalMergeTools(1, "Visual Studio Code", "Code.exe;Code - Insiders.exe", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\""), new ExternalMergeTools(1, "Visual Studio Code", "Code.exe", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\""),
new ExternalMergeTools(2, "Visual Studio 2017/2019", "vsDiffMerge.exe", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\" /m", "\"$LOCAL\" \"$REMOTE\""), new ExternalMergeTools(2, "Visual Studio Code - Insiders", "Code - Insiders.exe", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\""),
new ExternalMergeTools(3, "Tortoise Merge", "TortoiseMerge.exe;TortoiseGitMerge.exe", "-base:\"$BASE\" -theirs:\"$REMOTE\" -mine:\"$LOCAL\" -merged:\"$MERGED\"", "-base:\"$LOCAL\" -theirs:\"$REMOTE\""), new ExternalMergeTools(3, "Visual Studio 2017/2019", "vsDiffMerge.exe", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\" /m", "\"$LOCAL\" \"$REMOTE\""),
new ExternalMergeTools(4, "KDiff3", "kdiff3.exe", "\"$REMOTE\" -b \"$BASE\" \"$LOCAL\" -o \"$MERGED\"", "\"$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, "Beyond Compare 4", "BComp.exe", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""), new ExternalMergeTools(5, "KDiff3", "kdiff3.exe", "\"$REMOTE\" -b \"$BASE\" \"$LOCAL\" -o \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""),
new ExternalMergeTools(6, "WinMerge", "WinMergeU.exe", "-u -e \"$REMOTE\" \"$LOCAL\" \"$MERGED\"", "-u -e \"$LOCAL\" \"$REMOTE\""), new ExternalMergeTools(6, "Beyond Compare 4", "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()) else if (OperatingSystem.IsMacOS())
@ -34,8 +35,9 @@ namespace SourceGit.Models
new ExternalMergeTools(0, "Custom", "", "", ""), new ExternalMergeTools(0, "Custom", "", "", ""),
new ExternalMergeTools(1, "FileMerge", "/usr/bin/opendiff", "\"$BASE\" \"$LOCAL\" \"$REMOTE\" -ancestor \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""), 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(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, "KDiff3", "/Applications/kdiff3.app/Contents/MacOS/kdiff3", "\"$REMOTE\" -b \"$BASE\" \"$LOCAL\" -o \"$MERGED\"", "\"$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, "Beyond Compare 4", "/Applications/Beyond Compare.app/Contents/MacOS/bcomp", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\"", "\"$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 4", "/Applications/Beyond Compare.app/Contents/MacOS/bcomp", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""),
}; };
} }
else if (OperatingSystem.IsLinux()) else if (OperatingSystem.IsLinux())
@ -43,8 +45,9 @@ namespace SourceGit.Models
Supported = new List<ExternalMergeTools>() { Supported = new List<ExternalMergeTools>() {
new ExternalMergeTools(0, "Custom", "", "", ""), new ExternalMergeTools(0, "Custom", "", "", ""),
new ExternalMergeTools(1, "Visual Studio Code", "/usr/share/code/code", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\""), new ExternalMergeTools(1, "Visual Studio Code", "/usr/share/code/code", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\""),
new ExternalMergeTools(2, "KDiff3", "/usr/bin/kdiff3", "\"$REMOTE\" -b \"$BASE\" \"$LOCAL\" -o \"$MERGED\"", "\"$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, "Beyond Compare 4", "/usr/bin/bcomp", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""), new ExternalMergeTools(3, "KDiff3", "/usr/bin/kdiff3", "\"$REMOTE\" -b \"$BASE\" \"$LOCAL\" -o \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""),
new ExternalMergeTools(4, "Beyond Compare 4", "/usr/bin/bcomp", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""),
}; };
} }
else else

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Runtime.Versioning; using System.Runtime.Versioning;
@ -30,20 +31,47 @@ namespace SourceGit.Native
return string.Empty; return string.Empty;
} }
public string FindVSCode() public List<Models.ExternalEditor> FindExternalEditors()
{ {
var toolPath = "/usr/share/code/code"; var editors = new List<Models.ExternalEditor>();
if (File.Exists(toolPath))
return toolPath; var vscode = FindVSCode();
return string.Empty; if (!string.IsNullOrEmpty(vscode) && File.Exists(vscode))
{
editors.Add(new Models.ExternalEditor
{
Name = "Visual Studio Code",
Icon = new Uri("avares://SourceGit/Resources/ExternalToolIcons/vscode.png", UriKind.Absolute),
Executable = vscode,
OpenCmdArgs = "\"{0}\"",
});
} }
public string FindFleet() var vscodeInsiders = FindVSCodeInsiders();
if (!string.IsNullOrEmpty(vscodeInsiders) && File.Exists(vscodeInsiders))
{ {
var toolPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/.local/share/JetBrains/Toolbox/apps/fleet/bin/Fleet"; editors.Add(new Models.ExternalEditor
if (File.Exists(toolPath)) {
return toolPath; Name = "Visual Studio Code - Insiders",
return string.Empty; Icon = new Uri("avares://SourceGit/Resources/ExternalToolIcons/vscode_insiders.png", UriKind.Absolute),
Executable = vscodeInsiders,
OpenCmdArgs = "\"{0}\"",
});
}
var fleet = FindFleet();
if (!string.IsNullOrEmpty(fleet) && File.Exists(fleet))
{
editors.Add(new Models.ExternalEditor
{
Name = "JetBrains Fleet",
Icon = new Uri("avares://SourceGit/Resources/ExternalToolIcons/fleet.png", UriKind.Absolute),
Executable = fleet,
OpenCmdArgs = "\"{0}\"",
});
}
return editors;
} }
public void OpenBrowser(string url) public void OpenBrowser(string url)
@ -119,5 +147,46 @@ namespace SourceGit.Native
proc.Close(); proc.Close();
} }
#region EXTERNAL_EDITORS_FINDER
private string FindVSCode()
{
var toolPath = "/usr/share/code/code";
if (File.Exists(toolPath))
return toolPath;
var customPath = Environment.GetEnvironmentVariable("VSCODE_PATH");
if (!string.IsNullOrEmpty(customPath))
return customPath;
return string.Empty;
}
private string FindVSCodeInsiders()
{
var toolPath = "/usr/share/code/code";
if (File.Exists(toolPath))
return toolPath;
var customPath = Environment.GetEnvironmentVariable("VSCODE_INSIDERS_PATH");
if (!string.IsNullOrEmpty(customPath))
return customPath;
return string.Empty;
}
private string FindFleet()
{
var toolPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/.local/share/JetBrains/Toolbox/apps/fleet/bin/Fleet";
if (File.Exists(toolPath))
return toolPath;
var customPath = Environment.GetEnvironmentVariable("FLEET_PATH");
if (!string.IsNullOrEmpty(customPath))
return customPath;
return string.Empty;
}
#endregion
} }
} }

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Runtime.Versioning; using System.Runtime.Versioning;
@ -27,20 +28,47 @@ namespace SourceGit.Native
return string.Empty; return string.Empty;
} }
public string FindVSCode() public List<Models.ExternalEditor> FindExternalEditors()
{ {
var toolPath = "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code"; var editors = new List<Models.ExternalEditor>();
if (File.Exists(toolPath))
return toolPath; var vscode = FindVSCode();
return string.Empty; if (!string.IsNullOrEmpty(vscode) && File.Exists(vscode))
{
editors.Add(new Models.ExternalEditor
{
Name = "Visual Studio Code",
Icon = new Uri("avares://SourceGit/Resources/ExternalToolIcons/vscode.png", UriKind.Absolute),
Executable = vscode,
OpenCmdArgs = "\"{0}\"",
});
} }
public string FindFleet() var vscodeInsiders = FindVSCodeInsiders();
if (!string.IsNullOrEmpty(vscodeInsiders) && File.Exists(vscodeInsiders))
{ {
var toolPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/Applications/Fleet.app/Contents/MacOS/Fleet"; editors.Add(new Models.ExternalEditor
if (File.Exists(toolPath)) {
return toolPath; Name = "Visual Studio Code - Insiders",
return string.Empty; Icon = new Uri("avares://SourceGit/Resources/ExternalToolIcons/vscode_insiders.png", UriKind.Absolute),
Executable = vscodeInsiders,
OpenCmdArgs = "\"{0}\"",
});
}
var fleet = FindFleet();
if (!string.IsNullOrEmpty(fleet) && File.Exists(fleet))
{
editors.Add(new Models.ExternalEditor
{
Name = "JetBrains Fleet",
Icon = new Uri("avares://SourceGit/Resources/ExternalToolIcons/fleet.png", UriKind.Absolute),
Executable = fleet,
OpenCmdArgs = "\"{0}\"",
});
}
return editors;
} }
public void OpenBrowser(string url) public void OpenBrowser(string url)
@ -82,5 +110,46 @@ namespace SourceGit.Native
{ {
Process.Start("open", file); Process.Start("open", file);
} }
#region EXTERNAL_EDITORS_FINDER
private string FindVSCode()
{
var toolPath = "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code";
if (File.Exists(toolPath))
return toolPath;
var customPath = Environment.GetEnvironmentVariable("VSCODE_PATH");
if (!string.IsNullOrEmpty(customPath))
return customPath;
return string.Empty;
}
private string FindVSCodeInsiders()
{
var toolPath = "/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/bin/code";
if (File.Exists(toolPath))
return toolPath;
var customPath = Environment.GetEnvironmentVariable("VSCODE_INSIDERS_PATH");
if (!string.IsNullOrEmpty(customPath))
return customPath;
return string.Empty;
}
private string FindFleet()
{
var toolPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/Applications/Fleet.app/Contents/MacOS/Fleet";
if (File.Exists(toolPath))
return toolPath;
var customPath = Environment.GetEnvironmentVariable("FLEET_PATH");
if (!string.IsNullOrEmpty(customPath))
return customPath;
return string.Empty;
}
#endregion
} }
} }

View file

@ -1,6 +1,5 @@
using System; using System;
using System.Diagnostics; using System.Collections.Generic;
using System.IO;
using Avalonia; using Avalonia;
@ -13,8 +12,7 @@ namespace SourceGit.Native
void SetupApp(AppBuilder builder); void SetupApp(AppBuilder builder);
string FindGitExecutable(); string FindGitExecutable();
string FindVSCode(); List<Models.ExternalEditor> FindExternalEditors();
string FindFleet();
void OpenTerminal(string workdir); void OpenTerminal(string workdir);
void OpenInFileManager(string path, bool select); void OpenInFileManager(string path, bool select);
@ -22,11 +20,8 @@ namespace SourceGit.Native
void OpenWithDefaultEditor(string file); void OpenWithDefaultEditor(string file);
} }
public static string GitInstallPath { get; set; } public static string GitExecutable { get; set; } = string.Empty;
public static List<Models.ExternalEditor> ExternalEditors { get; set; } = new List<Models.ExternalEditor>();
public static string VSCodeExecutableFile { get; set; }
public static string FleetExecutableFile { get; set; }
static OS() static OS()
{ {
@ -47,13 +42,7 @@ namespace SourceGit.Native
throw new Exception("Platform unsupported!!!"); throw new Exception("Platform unsupported!!!");
} }
VSCodeExecutableFile = _backend.FindVSCode(); ExternalEditors = _backend.FindExternalEditors();
if (string.IsNullOrEmpty(VSCodeExecutableFile))
VSCodeExecutableFile = GetPathFromEnvironmentVar("VSCODE_PATH");
FleetExecutableFile = _backend.FindFleet();
if (string.IsNullOrEmpty(FleetExecutableFile))
FleetExecutableFile = GetPathFromEnvironmentVar("FLEET_PATH");
} }
public static void SetupApp(AppBuilder builder) public static void SetupApp(AppBuilder builder)
@ -86,51 +75,6 @@ namespace SourceGit.Native
_backend.OpenWithDefaultEditor(file); _backend.OpenWithDefaultEditor(file);
} }
public static void OpenInVSCode(string repo) private static IBackend _backend = null;
{
if (string.IsNullOrEmpty(VSCodeExecutableFile))
{
App.RaiseException(repo, "Visual Studio Code can NOT be found in your system!!!");
return;
}
Process.Start(new ProcessStartInfo()
{
WorkingDirectory = repo,
FileName = VSCodeExecutableFile,
Arguments = $"\"{repo}\"",
UseShellExecute = false,
});
}
public static void OpenInFleet(string repo)
{
if (string.IsNullOrEmpty(FleetExecutableFile))
{
App.RaiseException(repo, "Fleet can NOT be found in your system!!!");
return;
}
Process.Start(new ProcessStartInfo()
{
WorkingDirectory = repo,
FileName = FleetExecutableFile,
Arguments = $"\"{repo}\"",
UseShellExecute = false,
});
}
private static string GetPathFromEnvironmentVar(string key)
{
var customPath = Environment.GetEnvironmentVariable(key);
if (!string.IsNullOrEmpty(customPath) && File.Exists(customPath))
{
return customPath;
}
return string.Empty;
}
private static readonly IBackend _backend;
} }
} }

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -113,54 +114,47 @@ namespace SourceGit.Native
return null; return null;
} }
public string FindVSCode() public List<Models.ExternalEditor> FindExternalEditors()
{ {
var localMachine = Microsoft.Win32.RegistryKey.OpenBaseKey( var editors = new List<Models.ExternalEditor>();
Microsoft.Win32.RegistryHive.LocalMachine,
Microsoft.Win32.RegistryView.Registry64);
// VSCode (system) var vscode = FindVSCode();
var systemVScode = localMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{EA457B21-F73E-494C-ACAB-524FDE069978}_is1"); if (!string.IsNullOrEmpty(vscode) && File.Exists(vscode))
if (systemVScode != null)
{ {
return systemVScode.GetValue("DisplayIcon") as string; editors.Add(new Models.ExternalEditor
{
Name = "Visual Studio Code",
Icon = new Uri("avares://SourceGit/Resources/ExternalToolIcons/vscode.png", UriKind.Absolute),
Executable = vscode,
OpenCmdArgs = "\"{0}\"",
});
} }
// VSCode - Insiders (system) var vscodeInsiders = FindVSCodeInsiders();
var systemVScodeInsiders = localMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{1287CAD5-7C8D-410D-88B9-0D1EE4A83FF2}_is1"); if (!string.IsNullOrEmpty(vscodeInsiders) && File.Exists(vscodeInsiders))
if (systemVScodeInsiders != null)
{ {
return systemVScodeInsiders.GetValue("DisplayIcon") as string; editors.Add(new Models.ExternalEditor
{
Name = "Visual Studio Code - Insiders",
Icon = new Uri("avares://SourceGit/Resources/ExternalToolIcons/vscode_insiders.png", UriKind.Absolute),
Executable = vscodeInsiders,
OpenCmdArgs = "\"{0}\"",
});
} }
var currentUser = Microsoft.Win32.RegistryKey.OpenBaseKey( var fleet = FindFleet();
Microsoft.Win32.RegistryHive.CurrentUser, if (!string.IsNullOrEmpty(fleet) && File.Exists(fleet))
Microsoft.Win32.RegistryView.Registry64);
// VSCode (user)
var vscode = currentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{771FD6B0-FA20-440A-A002-3B3BAC16DC50}_is1");
if (vscode != null)
{ {
return vscode.GetValue("DisplayIcon") as string; editors.Add(new Models.ExternalEditor
{
Name = "JetBrains Fleet",
Icon = new Uri("avares://SourceGit/Resources/ExternalToolIcons/fleet.png", UriKind.Absolute),
Executable = fleet,
OpenCmdArgs = "\"{0}\"",
});
} }
// VSCode - Insiders (user) return editors;
var vscodeInsiders = currentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{217B4C08-948D-4276-BFBB-BEE930AE5A2C}_is1");
if (vscodeInsiders != null)
{
return vscodeInsiders.GetValue("DisplayIcon") as string;
}
return string.Empty;
}
public string FindFleet()
{
var toolPath = Environment.ExpandEnvironmentVariables($"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}\\AppData\\Local\\Programs\\Fleet\\Fleet.exe");
if (File.Exists(toolPath))
return toolPath;
return string.Empty;
} }
public void OpenBrowser(string url) public void OpenBrowser(string url)
@ -172,10 +166,11 @@ namespace SourceGit.Native
public void OpenTerminal(string workdir) public void OpenTerminal(string workdir)
{ {
var bash = Path.Combine(Path.GetDirectoryName(OS.GitInstallPath), "bash.exe"); var binDir = Path.GetDirectoryName(OS.GitExecutable);
var bash = Path.Combine(binDir, "bash.exe");
if (!File.Exists(bash)) if (!File.Exists(bash))
{ {
App.RaiseException(string.IsNullOrEmpty(workdir) ? "" : workdir, $"Can NOT found bash.exe under '{Path.GetDirectoryName(OS.GitInstallPath)}'"); App.RaiseException(string.IsNullOrEmpty(workdir) ? "" : workdir, $"Can NOT found bash.exe under '{binDir}'");
return; return;
} }
@ -227,6 +222,89 @@ namespace SourceGit.Native
Process.Start(start); Process.Start(start);
} }
#region EXTERNAL_EDITOR_FINDER
private string FindVSCode()
{
var localMachine = Microsoft.Win32.RegistryKey.OpenBaseKey(
Microsoft.Win32.RegistryHive.LocalMachine,
Microsoft.Win32.RegistryView.Registry64);
// VSCode (system)
var systemVScode = localMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{EA457B21-F73E-494C-ACAB-524FDE069978}_is1");
if (systemVScode != null)
{
return systemVScode.GetValue("DisplayIcon") as string;
}
var currentUser = Microsoft.Win32.RegistryKey.OpenBaseKey(
Microsoft.Win32.RegistryHive.CurrentUser,
Microsoft.Win32.RegistryView.Registry64);
// VSCode (user)
var vscode = currentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{771FD6B0-FA20-440A-A002-3B3BAC16DC50}_is1");
if (vscode != null)
{
return vscode.GetValue("DisplayIcon") as string;
}
// ENV
var customPath = Environment.GetEnvironmentVariable("VSCODE_PATH");
if (!string.IsNullOrEmpty(customPath))
{
return customPath;
}
return string.Empty;
}
private string FindVSCodeInsiders()
{
var localMachine = Microsoft.Win32.RegistryKey.OpenBaseKey(
Microsoft.Win32.RegistryHive.LocalMachine,
Microsoft.Win32.RegistryView.Registry64);
// VSCode - Insiders (system)
var systemVScodeInsiders = localMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{1287CAD5-7C8D-410D-88B9-0D1EE4A83FF2}_is1");
if (systemVScodeInsiders != null)
{
return systemVScodeInsiders.GetValue("DisplayIcon") as string;
}
var currentUser = Microsoft.Win32.RegistryKey.OpenBaseKey(
Microsoft.Win32.RegistryHive.CurrentUser,
Microsoft.Win32.RegistryView.Registry64);
// VSCode - Insiders (user)
var vscodeInsiders = currentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{217B4C08-948D-4276-BFBB-BEE930AE5A2C}_is1");
if (vscodeInsiders != null)
{
return vscodeInsiders.GetValue("DisplayIcon") as string;
}
// ENV
var customPath = Environment.GetEnvironmentVariable("VSCODE_INSIDERS_PATH");
if (!string.IsNullOrEmpty(customPath))
{
return customPath;
}
return string.Empty;
}
private string FindFleet()
{
var toolPath = Environment.ExpandEnvironmentVariables($"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}\\AppData\\Local\\Programs\\Fleet\\Fleet.exe");
if (File.Exists(toolPath))
return toolPath;
var customPath = Environment.GetEnvironmentVariable("FLEET_PATH");
if (!string.IsNullOrEmpty(customPath))
return customPath;
return string.Empty;
}
#endregion
private void OpenFolderAndSelectFile(string folderPath) private void OpenFolderAndSelectFile(string folderPath)
{ {
var pidl = ILCreateFromPathW(folderPath); var pidl = ILCreateFromPathW(folderPath);

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View file

@ -1600,7 +1600,7 @@ namespace SourceGit.Resources {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to GIT FLOW. /// Looks up a localized string similar to Git-Flow.
/// </summary> /// </summary>
public static string Text_GitFlow { public static string Text_GitFlow {
get { get {
@ -2985,15 +2985,6 @@ namespace SourceGit.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to Open In Fleet.
/// </summary>
public static string Text_Repository_Fleet {
get {
return ResourceManager.GetString("Text.Repository.Fleet", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to LOCAL BRANCHES. /// Looks up a localized string similar to LOCAL BRANCHES.
/// </summary> /// </summary>
@ -3013,7 +3004,7 @@ namespace SourceGit.Resources {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to NEW BRANCH. /// Looks up a localized string similar to Create Branch.
/// </summary> /// </summary>
public static string Text_Repository_NewBranch { public static string Text_Repository_NewBranch {
get { get {
@ -3021,12 +3012,21 @@ namespace SourceGit.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to Open In {0}.
/// </summary>
public static string Text_Repository_OpenIn {
get {
return ResourceManager.GetString("Text.Repository.OpenIn", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Open In External Tools. /// Looks up a localized string similar to Open In External Tools.
/// </summary> /// </summary>
public static string Text_Repository_OpenWith { public static string Text_Repository_OpenWithExternalTools {
get { get {
return ResourceManager.GetString("Text.Repository.OpenWith", resourceCulture); return ResourceManager.GetString("Text.Repository.OpenWithExternalTools", resourceCulture);
} }
} }
@ -3147,15 +3147,6 @@ namespace SourceGit.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to Open In Visual Studio Code.
/// </summary>
public static string Text_Repository_VSCode {
get {
return ResourceManager.GetString("Text.Repository.VSCode", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to WORKSPACE. /// Looks up a localized string similar to WORKSPACE.
/// </summary> /// </summary>

View file

@ -339,11 +339,8 @@
<data xml:space="preserve" name="Text.Repository.Explore"> <data xml:space="preserve" name="Text.Repository.Explore">
<value>Open In File Browser</value> <value>Open In File Browser</value>
</data> </data>
<data xml:space="preserve" name="Text.Repository.VSCode"> <data xml:space="preserve" name="Text.Repository.OpenIn">
<value>Open In Visual Studio Code</value> <value>Open In {0}</value>
</data>
<data xml:space="preserve" name="Text.Repository.Fleet">
<value>Open In Fleet</value>
</data> </data>
<data xml:space="preserve" name="Text.Repository.Terminal"> <data xml:space="preserve" name="Text.Repository.Terminal">
<value>Open In Terminal</value> <value>Open In Terminal</value>
@ -376,7 +373,7 @@
<value>LOCAL BRANCHES</value> <value>LOCAL BRANCHES</value>
</data> </data>
<data xml:space="preserve" name="Text.Repository.NewBranch"> <data xml:space="preserve" name="Text.Repository.NewBranch">
<value>NEW BRANCH</value> <value>Create Branch</value>
</data> </data>
<data xml:space="preserve" name="Text.Repository.Remotes"> <data xml:space="preserve" name="Text.Repository.Remotes">
<value>REMOTES</value> <value>REMOTES</value>
@ -409,7 +406,7 @@
<value>ABORT</value> <value>ABORT</value>
</data> </data>
<data xml:space="preserve" name="Text.GitFlow"> <data xml:space="preserve" name="Text.GitFlow">
<value>GIT FLOW</value> <value>Git-Flow</value>
</data> </data>
<data xml:space="preserve" name="Text.GitFlow.Init"> <data xml:space="preserve" name="Text.GitFlow.Init">
<value>Initialize Git-Flow</value> <value>Initialize Git-Flow</value>
@ -1293,7 +1290,7 @@
<data name="Text.Preference.Appearance" xml:space="preserve"> <data name="Text.Preference.Appearance" xml:space="preserve">
<value>APPEARANCE</value> <value>APPEARANCE</value>
</data> </data>
<data name="Text.Repository.OpenWith" xml:space="preserve"> <data name="Text.Repository.OpenWithExternalTools" xml:space="preserve">
<value>Open In External Tools</value> <value>Open In External Tools</value>
</data> </data>
<data name="Text.SelfUpdate.Title" xml:space="preserve"> <data name="Text.SelfUpdate.Title" xml:space="preserve">

View file

@ -339,11 +339,8 @@
<data xml:space="preserve" name="Text.Repository.Explore"> <data xml:space="preserve" name="Text.Repository.Explore">
<value>Open In File Browser</value> <value>Open In File Browser</value>
</data> </data>
<data xml:space="preserve" name="Text.Repository.VSCode"> <data xml:space="preserve" name="Text.Repository.OpenIn">
<value>Open In Visual Studio Code</value> <value>Open In {0}</value>
</data>
<data xml:space="preserve" name="Text.Repository.Fleet">
<value>Open In Fleet</value>
</data> </data>
<data xml:space="preserve" name="Text.Repository.Terminal"> <data xml:space="preserve" name="Text.Repository.Terminal">
<value>Open In Terminal</value> <value>Open In Terminal</value>
@ -376,7 +373,7 @@
<value>LOCAL BRANCHES</value> <value>LOCAL BRANCHES</value>
</data> </data>
<data xml:space="preserve" name="Text.Repository.NewBranch"> <data xml:space="preserve" name="Text.Repository.NewBranch">
<value>NEW BRANCH</value> <value>Create Branch</value>
</data> </data>
<data xml:space="preserve" name="Text.Repository.Remotes"> <data xml:space="preserve" name="Text.Repository.Remotes">
<value>REMOTES</value> <value>REMOTES</value>
@ -409,7 +406,7 @@
<value>ABORT</value> <value>ABORT</value>
</data> </data>
<data xml:space="preserve" name="Text.GitFlow"> <data xml:space="preserve" name="Text.GitFlow">
<value>GIT FLOW</value> <value>Git-Flow</value>
</data> </data>
<data xml:space="preserve" name="Text.GitFlow.Init"> <data xml:space="preserve" name="Text.GitFlow.Init">
<value>Initialize Git-Flow</value> <value>Initialize Git-Flow</value>
@ -1293,7 +1290,7 @@
<data name="Text.Preference.Appearance" xml:space="preserve"> <data name="Text.Preference.Appearance" xml:space="preserve">
<value>Appearance</value> <value>Appearance</value>
</data> </data>
<data name="Text.Repository.OpenWith" xml:space="preserve"> <data name="Text.Repository.OpenWithExternalTools" xml:space="preserve">
<value>Open In External Tools</value> <value>Open In External Tools</value>
</data> </data>
<data name="Text.SelfUpdate.Title" xml:space="preserve"> <data name="Text.SelfUpdate.Title" xml:space="preserve">

View file

@ -339,8 +339,8 @@
<data xml:space="preserve" name="Text.Repository.Explore"> <data xml:space="preserve" name="Text.Repository.Explore">
<value>在文件浏览器中打开</value> <value>在文件浏览器中打开</value>
</data> </data>
<data xml:space="preserve" name="Text.Repository.VSCode"> <data xml:space="preserve" name="Text.Repository.OpenIn">
<value>在 Visual Studio Code 中打开</value> <value>在 {0} 中打开</value>
</data> </data>
<data xml:space="preserve" name="Text.Repository.Terminal"> <data xml:space="preserve" name="Text.Repository.Terminal">
<value>在终端中打开</value> <value>在终端中打开</value>
@ -1317,15 +1317,12 @@
<data name="Text.About.SubTitle" xml:space="preserve"> <data name="Text.About.SubTitle" xml:space="preserve">
<value>开源免费的Git客户端</value> <value>开源免费的Git客户端</value>
</data> </data>
<data name="Text.Repository.OpenWith" xml:space="preserve"> <data name="Text.Repository.OpenWithExternalTools" xml:space="preserve">
<value>使用外部工具打开</value> <value>使用外部工具打开</value>
</data> </data>
<data name="Text.About.SourceCode" xml:space="preserve"> <data name="Text.About.SourceCode" xml:space="preserve">
<value>• 项目源代码地址 </value> <value>• 项目源代码地址 </value>
</data> </data>
<data name="Text.Repository.Fleet" xml:space="preserve">
<value>在 Fleet 中打开</value>
</data>
<data name="Text.InProgress.CherryPick" xml:space="preserve"> <data name="Text.InProgress.CherryPick" xml:space="preserve">
<value>挑选Cherry-Pick操作进行中。点击【终止】回滚到操作前的状态。</value> <value>挑选Cherry-Pick操作进行中。点击【终止】回滚到操作前的状态。</value>
</data> </data>

View file

@ -189,12 +189,12 @@ namespace SourceGit.ViewModels
public string GitInstallPath public string GitInstallPath
{ {
get => Native.OS.GitInstallPath; get => Native.OS.GitExecutable;
set set
{ {
if (Native.OS.GitInstallPath != value) if (Native.OS.GitExecutable != value)
{ {
Native.OS.GitInstallPath = value; Native.OS.GitExecutable = value;
OnPropertyChanged(nameof(GitInstallPath)); OnPropertyChanged(nameof(GitInstallPath));
} }
} }

View file

@ -6,6 +6,9 @@ using System.Threading.Tasks;
using Avalonia.Collections; using Avalonia.Collections;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using Avalonia.Threading; using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
@ -279,21 +282,43 @@ namespace SourceGit.ViewModels
Native.OS.OpenInFileManager(_fullpath); Native.OS.OpenInFileManager(_fullpath);
} }
public void OpenInVSCode()
{
Native.OS.OpenInVSCode(_fullpath);
}
public void OpenInFleet()
{
Native.OS.OpenInFleet(_fullpath);
}
public void OpenInTerminal() public void OpenInTerminal()
{ {
Native.OS.OpenTerminal(_fullpath); Native.OS.OpenTerminal(_fullpath);
} }
public ContextMenu CreateContextMenuForExternalEditors()
{
var editors = Native.OS.ExternalEditors;
if (editors.Count == 0)
{
App.RaiseException(_fullpath, "No available external editors found!");
return null;
}
var menu = new ContextMenu();
menu.Placement = PlacementMode.BottomEdgeAlignedLeft;
RenderOptions.SetBitmapInterpolationMode(menu, BitmapInterpolationMode.HighQuality);
foreach (var editor in editors)
{
var dupEditor = editor;
var icon = AssetLoader.Open(dupEditor.Icon);
var item = new MenuItem();
item.Header = App.Text("Repository.OpenIn", dupEditor.Name);
item.Icon = new Image { Width = 16, Height = 16, Source = new Bitmap(icon) };
item.Click += (o, e) =>
{
dupEditor.Open(_fullpath);
e.Handled = true;
};
menu.Items.Add(item);
}
return menu;
}
public void Fetch() public void Fetch()
{ {
if (!PopupHost.CanCreatePopup()) if (!PopupHost.CanCreatePopup())

View file

@ -22,22 +22,8 @@
<Path Width="13" Height="13" Data="{StaticResource Icons.Terminal}"/> <Path Width="13" Height="13" Data="{StaticResource Icons.Terminal}"/>
</Button> </Button>
<Button Classes="icon_button" Width="32" ToolTip.Tip="{DynamicResource Text.Repository.OpenWith}"> <Button Classes="icon_button" Width="32" Click="OnOpenWithExternalEditor" ToolTip.Tip="{DynamicResource Text.Repository.OpenWithExternalTools}">
<Path Width="13" Height="13" Data="{StaticResource Icons.OpenWith}"/> <Path Width="13" Height="13" Data="{StaticResource Icons.OpenWith}"/>
<Button.Flyout>
<MenuFlyout Placement="BottomEdgeAlignedLeft" VerticalOffset="-8">
<MenuItem Header="{DynamicResource Text.Repository.Fleet}" Command="{Binding OpenInFleet}">
<MenuItem.Icon>
<Image Source="/Resources/ExternalToolIcons/fleet.png" Width="16" Height="16" RenderOptions.BitmapInterpolationMode="HighQuality"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="{DynamicResource Text.Repository.VSCode}" Command="{Binding OpenInVSCode}">
<MenuItem.Icon>
<Image Source="/Resources/ExternalToolIcons/vscode.png" Width="16" Height="16" RenderOptions.BitmapInterpolationMode="HighQuality"/>
</MenuItem.Icon>
</MenuItem>
</MenuFlyout>
</Button.Flyout>
</Button> </Button>
<ToggleButton Width="32" <ToggleButton Width="32"

View file

@ -7,8 +7,6 @@ using Avalonia.Controls.Primitives;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using SourceGit.ViewModels;
namespace SourceGit.Views namespace SourceGit.Views
{ {
public class RepositorySubView : Border public class RepositorySubView : Border
@ -63,6 +61,19 @@ namespace SourceGit.Views
InitializeComponent(); InitializeComponent();
} }
private void OnOpenWithExternalEditor(object sender, RoutedEventArgs e)
{
if (sender is Button button && DataContext is ViewModels.Repository repo)
{
var menu = repo.CreateContextMenuForExternalEditors();
if (menu != null)
{
menu.Open(button);
e.Handled = true;
}
}
}
private void OnLocalBranchTreeLostFocus(object sender, RoutedEventArgs e) private void OnLocalBranchTreeLostFocus(object sender, RoutedEventArgs e)
{ {
if (sender is TreeView tree) if (sender is TreeView tree)
@ -275,7 +286,7 @@ namespace SourceGit.Views
private void OnDoubleTappedLocalBranchNode(object sender, TappedEventArgs e) private void OnDoubleTappedLocalBranchNode(object sender, TappedEventArgs e)
{ {
if (!PopupHost.CanCreatePopup()) if (!ViewModels.PopupHost.CanCreatePopup())
return; return;
if (sender is Grid grid && DataContext is ViewModels.Repository repo) if (sender is Grid grid && DataContext is ViewModels.Repository repo)
@ -287,7 +298,7 @@ namespace SourceGit.Views
if (branch.IsCurrent) if (branch.IsCurrent)
return; return;
PopupHost.ShowAndStartPopup(new ViewModels.Checkout(repo, branch.Name)); ViewModels.PopupHost.ShowAndStartPopup(new ViewModels.Checkout(repo, branch.Name));
e.Handled = true; e.Handled = true;
} }
} }