mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-11-01 13:13:21 -07:00
Fallback Icon Implementation
This commit is contained in:
parent
59c941dd00
commit
ad570eec3b
1 changed files with 28 additions and 7 deletions
|
@ -12,16 +12,40 @@ namespace SourceGit.Models
|
||||||
{
|
{
|
||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
public string Icon { 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 Executable { get; set; } = string.Empty;
|
||||||
public string OpenCmdArgs { get; set; } = string.Empty;
|
public string OpenCmdArgs { get; set; } = string.Empty;
|
||||||
|
|
||||||
public Bitmap IconImage
|
public Bitmap IconImage
|
||||||
{
|
{
|
||||||
get
|
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));
|
var icon = AssetLoader.Open(new Uri($"avares://SourceGit/Resources/ExternalToolIcons/{Icon}.png", UriKind.RelativeOrAbsolute));
|
||||||
return new Bitmap(icon);
|
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)
|
public void Open(string repo)
|
||||||
|
@ -64,7 +88,7 @@ namespace SourceGit.Models
|
||||||
TryAdd("Sublime Text", "sublime_text", "\"{0}\"", "SUBLIME_TEXT_PATH", platform_finder);
|
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);
|
var path = Environment.GetEnvironmentVariable(env);
|
||||||
if (string.IsNullOrEmpty(path) || !File.Exists(path))
|
if (string.IsNullOrEmpty(path) || !File.Exists(path))
|
||||||
|
@ -76,10 +100,7 @@ namespace SourceGit.Models
|
||||||
|
|
||||||
Founded.Add(new ExternalTool
|
Founded.Add(new ExternalTool
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name, Icon = icon, OpenCmdArgs = args, Executable = path, FallbackIcon = fallbackIcon
|
||||||
Icon = icon,
|
|
||||||
OpenCmdArgs = args,
|
|
||||||
Executable = path,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue