Fallback Icon Implementation

This commit is contained in:
Enner Pérez 2024-04-27 02:11:38 -05:00
parent 59c941dd00
commit ad570eec3b

View file

@ -12,16 +12,40 @@ namespace SourceGit.Models
{
public string Name { get; set; } = string.Empty;
public string Icon { get; set; } = string.Empty;
public string FallbackIcon { get; set; } = string.Empty;
public string Executable { get; set; } = string.Empty;
public string OpenCmdArgs { get; set; } = string.Empty;
public Bitmap IconImage
{
get
{
if (string.IsNullOrWhiteSpace(Icon))
{
return null;
}
if (File.Exists(Icon))
{
return new Bitmap(Icon);
}
try
{
var icon = AssetLoader.Open(new Uri($"avares://SourceGit/Resources/ExternalToolIcons/{Icon}.png", UriKind.RelativeOrAbsolute));
return new Bitmap(icon);
}
catch (Exception)
{
if (!string.IsNullOrWhiteSpace(FallbackIcon))
{
var icon = AssetLoader.Open(new Uri($"avares://SourceGit/Resources/ExternalToolIcons/{FallbackIcon}.png", UriKind.RelativeOrAbsolute));
return new Bitmap(icon);
}
return null;
}
}
}
public void Open(string repo)
@ -64,7 +88,7 @@ namespace SourceGit.Models
TryAdd("Sublime Text", "sublime_text", "\"{0}\"", "SUBLIME_TEXT_PATH", platform_finder);
}
public void TryAdd(string name, string icon, string args, string env, Func<string> finder)
public void TryAdd(string name, string icon, string args, string env, Func<string> finder, string fallbackIcon = "")
{
var path = Environment.GetEnvironmentVariable(env);
if (string.IsNullOrEmpty(path) || !File.Exists(path))
@ -76,10 +100,7 @@ namespace SourceGit.Models
Founded.Add(new ExternalTool
{
Name = name,
Icon = icon,
OpenCmdArgs = args,
Executable = path,
Name = name, Icon = icon, OpenCmdArgs = args, Executable = path, FallbackIcon = fallbackIcon
});
}
}