fix: crash when open external tool drop down menu

This commit is contained in:
leo 2024-04-06 15:01:07 +08:00
parent 111bf2966a
commit d873f21b6a
5 changed files with 12 additions and 13 deletions

View file

@ -1,12 +1,11 @@
using System; using System.Diagnostics;
using System.Diagnostics;
namespace SourceGit.Models namespace SourceGit.Models
{ {
public class ExternalEditor public class ExternalEditor
{ {
public string Name { get; set; } = string.Empty; public string Name { get; set; } = string.Empty;
public Uri Icon { get; set; } = null; public string Icon { 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;

View file

@ -41,7 +41,7 @@ namespace SourceGit.Native
editors.Add(new Models.ExternalEditor editors.Add(new Models.ExternalEditor
{ {
Name = "Visual Studio Code", Name = "Visual Studio Code",
Icon = new Uri("avares://SourceGit/Resources/ExternalToolIcons/vscode.png", UriKind.Absolute), Icon = "vscode.png",
Executable = vscode, Executable = vscode,
OpenCmdArgs = "\"{0}\"", OpenCmdArgs = "\"{0}\"",
}); });
@ -53,7 +53,7 @@ namespace SourceGit.Native
editors.Add(new Models.ExternalEditor editors.Add(new Models.ExternalEditor
{ {
Name = "Visual Studio Code - Insiders", Name = "Visual Studio Code - Insiders",
Icon = new Uri("avares://SourceGit/Resources/ExternalToolIcons/vscode_insiders.png", UriKind.Absolute), Icon = "vscode_insiders.png",
Executable = vscodeInsiders, Executable = vscodeInsiders,
OpenCmdArgs = "\"{0}\"", OpenCmdArgs = "\"{0}\"",
}); });
@ -65,7 +65,7 @@ namespace SourceGit.Native
editors.Add(new Models.ExternalEditor editors.Add(new Models.ExternalEditor
{ {
Name = "JetBrains Fleet", Name = "JetBrains Fleet",
Icon = new Uri("avares://SourceGit/Resources/ExternalToolIcons/fleet.png", UriKind.Absolute), Icon = "fleet.png",
Executable = fleet, Executable = fleet,
OpenCmdArgs = "\"{0}\"", OpenCmdArgs = "\"{0}\"",
}); });

View file

@ -38,7 +38,7 @@ namespace SourceGit.Native
editors.Add(new Models.ExternalEditor editors.Add(new Models.ExternalEditor
{ {
Name = "Visual Studio Code", Name = "Visual Studio Code",
Icon = new Uri("avares://SourceGit/Resources/ExternalToolIcons/vscode.png", UriKind.Absolute), Icon = "vscode.png",
Executable = vscode, Executable = vscode,
OpenCmdArgs = "\"{0}\"", OpenCmdArgs = "\"{0}\"",
}); });
@ -50,7 +50,7 @@ namespace SourceGit.Native
editors.Add(new Models.ExternalEditor editors.Add(new Models.ExternalEditor
{ {
Name = "Visual Studio Code - Insiders", Name = "Visual Studio Code - Insiders",
Icon = new Uri("avares://SourceGit/Resources/ExternalToolIcons/vscode_insiders.png", UriKind.Absolute), Icon = "vscode_insiders.png",
Executable = vscodeInsiders, Executable = vscodeInsiders,
OpenCmdArgs = "\"{0}\"", OpenCmdArgs = "\"{0}\"",
}); });
@ -62,7 +62,7 @@ namespace SourceGit.Native
editors.Add(new Models.ExternalEditor editors.Add(new Models.ExternalEditor
{ {
Name = "JetBrains Fleet", Name = "JetBrains Fleet",
Icon = new Uri("avares://SourceGit/Resources/ExternalToolIcons/fleet.png", UriKind.Absolute), Icon = "fleet.png",
Executable = fleet, Executable = fleet,
OpenCmdArgs = "\"{0}\"", OpenCmdArgs = "\"{0}\"",
}); });

View file

@ -124,7 +124,7 @@ namespace SourceGit.Native
editors.Add(new Models.ExternalEditor editors.Add(new Models.ExternalEditor
{ {
Name = "Visual Studio Code", Name = "Visual Studio Code",
Icon = new Uri("avares://SourceGit/Resources/ExternalToolIcons/vscode.png", UriKind.Absolute), Icon = "vscode.png",
Executable = vscode, Executable = vscode,
OpenCmdArgs = "\"{0}\"", OpenCmdArgs = "\"{0}\"",
}); });
@ -136,7 +136,7 @@ namespace SourceGit.Native
editors.Add(new Models.ExternalEditor editors.Add(new Models.ExternalEditor
{ {
Name = "Visual Studio Code - Insiders", Name = "Visual Studio Code - Insiders",
Icon = new Uri("avares://SourceGit/Resources/ExternalToolIcons/vscode_insiders.png", UriKind.Absolute), Icon = "vscode_insiders.png",
Executable = vscodeInsiders, Executable = vscodeInsiders,
OpenCmdArgs = "\"{0}\"", OpenCmdArgs = "\"{0}\"",
}); });
@ -148,7 +148,7 @@ namespace SourceGit.Native
editors.Add(new Models.ExternalEditor editors.Add(new Models.ExternalEditor
{ {
Name = "JetBrains Fleet", Name = "JetBrains Fleet",
Icon = new Uri("avares://SourceGit/Resources/ExternalToolIcons/fleet.png", UriKind.Absolute), Icon = "fleet.png",
Executable = fleet, Executable = fleet,
OpenCmdArgs = "\"{0}\"", OpenCmdArgs = "\"{0}\"",
}); });

View file

@ -303,7 +303,7 @@ namespace SourceGit.ViewModels
foreach (var editor in editors) foreach (var editor in editors)
{ {
var dupEditor = editor; var dupEditor = editor;
var icon = AssetLoader.Open(dupEditor.Icon); var icon = AssetLoader.Open(new Uri($"avares://SourceGit/Resources/ExternalToolIcons/{dupEditor.Icon}", UriKind.RelativeOrAbsolute));
var item = new MenuItem(); var item = new MenuItem();
item.Header = App.Text("Repository.OpenIn", dupEditor.Name); item.Header = App.Text("Repository.OpenIn", dupEditor.Name);
item.Icon = new Image { Width = 16, Height = 16, Source = new Bitmap(icon) }; item.Icon = new Image { Width = 16, Height = 16, Source = new Bitmap(icon) };