mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-23 13:14:59 +00:00
style: add .editorconfig for code formatting. see issu #25
This commit is contained in:
parent
a8eeea4f78
commit
18aaa0a143
225 changed files with 7781 additions and 3911 deletions
|
@ -1,29 +1,37 @@
|
|||
using Avalonia;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.Versioning;
|
||||
|
||||
namespace SourceGit.Native {
|
||||
using Avalonia;
|
||||
|
||||
namespace SourceGit.Native
|
||||
{
|
||||
[SupportedOSPlatform("linux")]
|
||||
internal class Linux : OS.IBackend {
|
||||
public void SetupApp(AppBuilder builder) {
|
||||
#if USE_FONT_INTER
|
||||
internal class Linux : OS.IBackend
|
||||
{
|
||||
public void SetupApp(AppBuilder builder)
|
||||
{
|
||||
#if USE_FONT_INTER
|
||||
builder.WithInterFont();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
public string FindGitExecutable() {
|
||||
public string FindGitExecutable()
|
||||
{
|
||||
if (File.Exists("/usr/bin/git")) return "/usr/bin/git";
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public string FindVSCode() {
|
||||
public string FindVSCode()
|
||||
{
|
||||
if (File.Exists("/usr/share/code/code")) return "/usr/share/code/code";
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public void OpenBrowser(string url) {
|
||||
if (!File.Exists("/usr/bin/xdg-open")) {
|
||||
public void OpenBrowser(string url)
|
||||
{
|
||||
if (!File.Exists("/usr/bin/xdg-open"))
|
||||
{
|
||||
App.RaiseException("", $"You should install xdg-open first!");
|
||||
return;
|
||||
}
|
||||
|
@ -31,38 +39,54 @@ namespace SourceGit.Native {
|
|||
Process.Start("xdg-open", $"\"{url}\"");
|
||||
}
|
||||
|
||||
public void OpenInFileManager(string path, bool select) {
|
||||
if (!File.Exists("/usr/bin/xdg-open")) {
|
||||
public void OpenInFileManager(string path, bool select)
|
||||
{
|
||||
if (!File.Exists("/usr/bin/xdg-open"))
|
||||
{
|
||||
App.RaiseException("", $"You should install xdg-open first!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Directory.Exists(path)) {
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
Process.Start("xdg-open", $"\"{path}\"");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
var dir = Path.GetDirectoryName(path);
|
||||
if (Directory.Exists(dir)) {
|
||||
if (Directory.Exists(dir))
|
||||
{
|
||||
Process.Start("xdg-open", $"\"{dir}\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenTerminal(string workdir) {
|
||||
public void OpenTerminal(string workdir)
|
||||
{
|
||||
var dir = string.IsNullOrEmpty(workdir) ? "~" : workdir;
|
||||
if (File.Exists("/usr/bin/gnome-terminal")) {
|
||||
if (File.Exists("/usr/bin/gnome-terminal"))
|
||||
{
|
||||
Process.Start("/usr/bin/gnome-terminal", $"--working-directory=\"{dir}\"");
|
||||
} else if (File.Exists("/usr/bin/konsole")) {
|
||||
}
|
||||
else if (File.Exists("/usr/bin/konsole"))
|
||||
{
|
||||
Process.Start("/usr/bin/konsole", $"--workdir \"{dir}\"");
|
||||
} else if (File.Exists("/usr/bin/xfce4-terminal")) {
|
||||
}
|
||||
else if (File.Exists("/usr/bin/xfce4-terminal"))
|
||||
{
|
||||
Process.Start("/usr/bin/xfce4-terminal", $"--working-directory=\"{dir}\"");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
App.RaiseException("", $"Only supports gnome-terminal/konsole/xfce4-terminal!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenWithDefaultEditor(string file) {
|
||||
if (!File.Exists("/usr/bin/xdg-open")) {
|
||||
public void OpenWithDefaultEditor(string file)
|
||||
{
|
||||
if (!File.Exists("/usr/bin/xdg-open"))
|
||||
{
|
||||
App.RaiseException("", $"You should install xdg-open first!");
|
||||
return;
|
||||
}
|
||||
|
@ -70,11 +94,12 @@ namespace SourceGit.Native {
|
|||
var proc = Process.Start("xdg-open", $"\"{file}\"");
|
||||
proc.WaitForExit();
|
||||
|
||||
if (proc.ExitCode != 0) {
|
||||
if (proc.ExitCode != 0)
|
||||
{
|
||||
App.RaiseException("", $"Failed to open \"{file}\"");
|
||||
}
|
||||
|
||||
proc.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +1,20 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Media;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.Versioning;
|
||||
using System.Text;
|
||||
|
||||
namespace SourceGit.Native {
|
||||
using Avalonia;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace SourceGit.Native
|
||||
{
|
||||
[SupportedOSPlatform("macOS")]
|
||||
internal class MacOS : OS.IBackend {
|
||||
public void SetupApp(AppBuilder builder) {
|
||||
builder.With(new FontManagerOptions() {
|
||||
internal class MacOS : OS.IBackend
|
||||
{
|
||||
public void SetupApp(AppBuilder builder)
|
||||
{
|
||||
builder.With(new FontManagerOptions()
|
||||
{
|
||||
DefaultFamilyName = "PingFang SC",
|
||||
FontFallbacks = [
|
||||
new FontFallback { FontFamily = new FontFamily("PingFang SC") }
|
||||
|
@ -17,32 +22,41 @@ namespace SourceGit.Native {
|
|||
});
|
||||
}
|
||||
|
||||
public string FindGitExecutable() {
|
||||
public string FindGitExecutable()
|
||||
{
|
||||
if (File.Exists("/usr/bin/git")) return "/usr/bin/git";
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public string FindVSCode() {
|
||||
if (File.Exists("/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code")) {
|
||||
public string FindVSCode()
|
||||
{
|
||||
if (File.Exists("/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code"))
|
||||
{
|
||||
return "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code";
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public void OpenBrowser(string url) {
|
||||
public void OpenBrowser(string url)
|
||||
{
|
||||
Process.Start("open", url);
|
||||
}
|
||||
|
||||
public void OpenInFileManager(string path, bool select) {
|
||||
if (Directory.Exists(path)) {
|
||||
public void OpenInFileManager(string path, bool select)
|
||||
{
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
Process.Start("open", path);
|
||||
} else if (File.Exists(path)) {
|
||||
}
|
||||
else if (File.Exists(path))
|
||||
{
|
||||
Process.Start("open", $"\"{path}\" -R");
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenTerminal(string workdir) {
|
||||
public void OpenTerminal(string workdir)
|
||||
{
|
||||
var dir = string.IsNullOrEmpty(workdir) ? "~" : workdir;
|
||||
var builder = new StringBuilder();
|
||||
builder.AppendLine("on run argv");
|
||||
|
@ -59,8 +73,9 @@ namespace SourceGit.Native {
|
|||
proc.Exited += (o, e) => File.Delete(tmp);
|
||||
}
|
||||
|
||||
public void OpenWithDefaultEditor(string file) {
|
||||
public void OpenWithDefaultEditor(string file)
|
||||
{
|
||||
Process.Start("open", file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +1,14 @@
|
|||
using Avalonia;
|
||||
using System;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace SourceGit.Native {
|
||||
public static class OS {
|
||||
public interface IBackend {
|
||||
using Avalonia;
|
||||
|
||||
namespace SourceGit.Native
|
||||
{
|
||||
public static class OS
|
||||
{
|
||||
public interface IBackend
|
||||
{
|
||||
void SetupApp(AppBuilder builder);
|
||||
|
||||
string FindGitExecutable();
|
||||
|
@ -16,62 +20,81 @@ namespace SourceGit.Native {
|
|||
void OpenWithDefaultEditor(string file);
|
||||
}
|
||||
|
||||
public static string GitInstallPath {
|
||||
public static string GitInstallPath
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public static string VSCodeExecutableFile {
|
||||
public static string VSCodeExecutableFile
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
static OS() {
|
||||
if (OperatingSystem.IsMacOS()) {
|
||||
static OS()
|
||||
{
|
||||
if (OperatingSystem.IsMacOS())
|
||||
{
|
||||
_backend = new MacOS();
|
||||
VSCodeExecutableFile = _backend.FindVSCode();
|
||||
} else if (OperatingSystem.IsWindows()) {
|
||||
}
|
||||
else if (OperatingSystem.IsWindows())
|
||||
{
|
||||
_backend = new Windows();
|
||||
VSCodeExecutableFile = _backend.FindVSCode();
|
||||
} else if (OperatingSystem.IsLinux()) {
|
||||
}
|
||||
else if (OperatingSystem.IsLinux())
|
||||
{
|
||||
_backend = new Linux();
|
||||
VSCodeExecutableFile = _backend.FindVSCode();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Platform unsupported!!!");
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetupApp(AppBuilder builder) {
|
||||
public static void SetupApp(AppBuilder builder)
|
||||
{
|
||||
_backend?.SetupApp(builder);
|
||||
}
|
||||
|
||||
public static string FindGitExecutable() {
|
||||
public static string FindGitExecutable()
|
||||
{
|
||||
return _backend?.FindGitExecutable();
|
||||
}
|
||||
|
||||
public static void OpenInFileManager(string path, bool select = false) {
|
||||
public static void OpenInFileManager(string path, bool select = false)
|
||||
{
|
||||
_backend?.OpenInFileManager(path, select);
|
||||
}
|
||||
|
||||
public static void OpenBrowser(string url) {
|
||||
public static void OpenBrowser(string url)
|
||||
{
|
||||
_backend?.OpenBrowser(url);
|
||||
}
|
||||
|
||||
public static void OpenTerminal(string workdir) {
|
||||
public static void OpenTerminal(string workdir)
|
||||
{
|
||||
_backend?.OpenTerminal(workdir);
|
||||
}
|
||||
|
||||
public static void OpenWithDefaultEditor(string file) {
|
||||
public static void OpenWithDefaultEditor(string file)
|
||||
{
|
||||
_backend?.OpenWithDefaultEditor(file);
|
||||
}
|
||||
|
||||
public static void OpenInVSCode(string repo) {
|
||||
if (string.IsNullOrEmpty(VSCodeExecutableFile)) {
|
||||
public static void OpenInVSCode(string repo)
|
||||
{
|
||||
if (string.IsNullOrEmpty(VSCodeExecutableFile))
|
||||
{
|
||||
App.RaiseException(repo, "Visual Studio Code can NOT be found in your system!!!");
|
||||
return;
|
||||
}
|
||||
|
||||
Process.Start(new ProcessStartInfo() {
|
||||
Process.Start(new ProcessStartInfo()
|
||||
{
|
||||
WorkingDirectory = repo,
|
||||
FileName = VSCodeExecutableFile,
|
||||
Arguments = $"\"{repo}\"",
|
||||
|
@ -79,6 +102,6 @@ namespace SourceGit.Native {
|
|||
});
|
||||
}
|
||||
|
||||
private static IBackend _backend = null;
|
||||
private static readonly IBackend _backend = null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,20 +1,25 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Media;
|
||||
using System;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Versioning;
|
||||
using System.Text;
|
||||
|
||||
namespace SourceGit.Native {
|
||||
using Avalonia;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace SourceGit.Native
|
||||
{
|
||||
[SupportedOSPlatform("windows")]
|
||||
internal class Windows : OS.IBackend {
|
||||
internal class Windows : OS.IBackend
|
||||
{
|
||||
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode, SetLastError = false)]
|
||||
private static extern bool PathFindOnPath([In, Out] StringBuilder pszFile, [In] string[] ppszOtherDirs);
|
||||
|
||||
public void SetupApp(AppBuilder builder) {
|
||||
builder.With(new FontManagerOptions() {
|
||||
public void SetupApp(AppBuilder builder)
|
||||
{
|
||||
builder.With(new FontManagerOptions()
|
||||
{
|
||||
DefaultFamilyName = "Microsoft YaHei UI",
|
||||
FontFallbacks = [
|
||||
new FontFallback { FontFamily = new FontFamily("Microsoft YaHei UI") }
|
||||
|
@ -22,18 +27,21 @@ namespace SourceGit.Native {
|
|||
});
|
||||
}
|
||||
|
||||
public string FindGitExecutable() {
|
||||
public string FindGitExecutable()
|
||||
{
|
||||
var reg = Microsoft.Win32.RegistryKey.OpenBaseKey(
|
||||
Microsoft.Win32.RegistryHive.LocalMachine,
|
||||
Microsoft.Win32.RegistryView.Registry64);
|
||||
|
||||
var git = reg.OpenSubKey("SOFTWARE\\GitForWindows");
|
||||
if (git != null) {
|
||||
if (git != null)
|
||||
{
|
||||
return Path.Combine(git.GetValue("InstallPath") as string, "bin", "git.exe");
|
||||
}
|
||||
|
||||
var builder = new StringBuilder("git.exe", 259);
|
||||
if (!PathFindOnPath(builder, null)) {
|
||||
if (!PathFindOnPath(builder, null))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -43,43 +51,51 @@ namespace SourceGit.Native {
|
|||
return exePath;
|
||||
}
|
||||
|
||||
public string FindVSCode() {
|
||||
public string FindVSCode()
|
||||
{
|
||||
var root = Microsoft.Win32.RegistryKey.OpenBaseKey(
|
||||
Microsoft.Win32.RegistryHive.LocalMachine,
|
||||
Environment.Is64BitOperatingSystem ? Microsoft.Win32.RegistryView.Registry64 : Microsoft.Win32.RegistryView.Registry32);
|
||||
|
||||
var vscode = root.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{C26E74D1-022E-4238-8B9D-1E7564A36CC9}_is1");
|
||||
if (vscode != null) {
|
||||
if (vscode != null)
|
||||
{
|
||||
return vscode.GetValue("DisplayIcon") as string;
|
||||
}
|
||||
|
||||
vscode = root.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{1287CAD5-7C8D-410D-88B9-0D1EE4A83FF2}_is1");
|
||||
if (vscode != null) {
|
||||
if (vscode != null)
|
||||
{
|
||||
return vscode.GetValue("DisplayIcon") as string;
|
||||
}
|
||||
|
||||
vscode = root.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{F8A2A208-72B3-4D61-95FC-8A65D340689B}_is1");
|
||||
if (vscode != null) {
|
||||
if (vscode != null)
|
||||
{
|
||||
return vscode.GetValue("DisplayIcon") as string;
|
||||
}
|
||||
|
||||
vscode = root.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{EA457B21-F73E-494C-ACAB-524FDE069978}_is1");
|
||||
if (vscode != null) {
|
||||
if (vscode != null)
|
||||
{
|
||||
return vscode.GetValue("DisplayIcon") as string;
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public void OpenBrowser(string url) {
|
||||
public void OpenBrowser(string url)
|
||||
{
|
||||
var info = new ProcessStartInfo("cmd", $"/c start {url}");
|
||||
info.CreateNoWindow = true;
|
||||
Process.Start(info);
|
||||
}
|
||||
|
||||
public void OpenTerminal(string workdir) {
|
||||
public void OpenTerminal(string workdir)
|
||||
{
|
||||
var bash = Path.Combine(Path.GetDirectoryName(OS.GitInstallPath), "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)}'");
|
||||
return;
|
||||
}
|
||||
|
@ -91,26 +107,34 @@ namespace SourceGit.Native {
|
|||
Process.Start(startInfo);
|
||||
}
|
||||
|
||||
public void OpenInFileManager(string path, bool select) {
|
||||
public void OpenInFileManager(string path, bool select)
|
||||
{
|
||||
var fullpath = string.Empty;
|
||||
if (File.Exists(path)) {
|
||||
if (File.Exists(path))
|
||||
{
|
||||
fullpath = new FileInfo(path).FullName;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
fullpath = new DirectoryInfo(path).FullName;
|
||||
}
|
||||
|
||||
if (select) {
|
||||
if (select)
|
||||
{
|
||||
Process.Start("explorer", $"/select,\"{fullpath}\"");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
Process.Start("explorer", fullpath);
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenWithDefaultEditor(string file) {
|
||||
public void OpenWithDefaultEditor(string file)
|
||||
{
|
||||
var info = new FileInfo(file);
|
||||
var start = new ProcessStartInfo("cmd", $"/c start {info.FullName}");
|
||||
start.CreateNoWindow = true;
|
||||
Process.Start(start);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue