mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-23 05:05:00 +00:00
refactor: add ExternalEditorFinder to detect supported external editors
This commit is contained in:
parent
482fab97c0
commit
b5b1f0cb8d
4 changed files with 70 additions and 300 deletions
|
@ -1,4 +1,7 @@
|
|||
using System.Diagnostics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace SourceGit.Models
|
||||
{
|
||||
|
@ -20,4 +23,52 @@ namespace SourceGit.Models
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class ExternalEditorFinder
|
||||
{
|
||||
public List<ExternalEditor> Editors
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = new List<ExternalEditor>();
|
||||
|
||||
public void VSCode(Func<string> platform_finder)
|
||||
{
|
||||
TryAdd("Visual Studio Code", "vscode.png", "\"{0}\"", "VSCODE_PATH", platform_finder);
|
||||
}
|
||||
|
||||
public void VSCodeInsiders(Func<string> platform_finder)
|
||||
{
|
||||
TryAdd("Visual Studio Code - Insiders", "vscode_insiders.png", "\"{0}\"", "VSCODE_INSIDERS_PATH", platform_finder);
|
||||
}
|
||||
|
||||
public void Fleet(Func<string> platform_finder)
|
||||
{
|
||||
TryAdd("JetBrains Fleet", "fleet.png", "\"{0}\"", "FLEET_PATH", platform_finder);
|
||||
}
|
||||
|
||||
public void SublimeText(Func<string> platform_finder)
|
||||
{
|
||||
TryAdd("Sublime Text", "sublime_text.png", "\"{0}\"", "SUBLIME_TEXT_PATH", platform_finder);
|
||||
}
|
||||
|
||||
private void TryAdd(string name, string icon, string args, string env, Func<string> finder)
|
||||
{
|
||||
var path = Environment.GetEnvironmentVariable(env);
|
||||
if (string.IsNullOrEmpty(path) || !File.Exists(path))
|
||||
{
|
||||
path = finder();
|
||||
if (string.IsNullOrEmpty(path) || !File.Exists(path))
|
||||
return;
|
||||
}
|
||||
|
||||
Editors.Add(new ExternalEditor
|
||||
{
|
||||
Name = name,
|
||||
Icon = icon,
|
||||
OpenCmdArgs = args,
|
||||
Executable = path,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue