diff --git a/README.md b/README.md index ff546cfb..1044d3c3 100644 --- a/README.md +++ b/README.md @@ -176,13 +176,19 @@ This app supports open repository in external tools listed in the table below. | Visual Studio | YES | NO | NO | > [!NOTE] -> This app will try to find those tools based on some pre-defined or expected locations automatically. If you are using one portable version of these tools, it will not be detected by this app. -> To solve this problem you can add a file named `external_editors.json` in app data storage directory and provide the path directly. For example: +> This app will try to find those tools based on some pre-defined or expected locations automatically. If you are using one portable version of these tools, it will not be detected by this app. +> To solve this problem you can add a file named `external_editors.json` in app data storage directory and provide the path directly. +> User can also exclude some editors by using `external_editors.json`. + +The format of `external_editors.json`: ```json { "tools": { "Visual Studio Code": "D:\\VSCode\\Code.exe" - } + }, + "excludes": [ + "Visual Studio Community 2019" + ] } ``` diff --git a/src/App.JsonCodeGen.cs b/src/App.JsonCodeGen.cs index f19480a3..54c1b348 100644 --- a/src/App.JsonCodeGen.cs +++ b/src/App.JsonCodeGen.cs @@ -59,7 +59,7 @@ namespace SourceGit typeof(DataGridLengthConverter), ] )] - [JsonSerializable(typeof(Models.ExternalToolPaths))] + [JsonSerializable(typeof(Models.ExternalToolCustomization))] [JsonSerializable(typeof(Models.HistoryFilterCollection))] [JsonSerializable(typeof(Models.InteractiveRebaseJobCollection))] [JsonSerializable(typeof(Models.JetBrainsState))] diff --git a/src/Models/ExternalTool.cs b/src/Models/ExternalTool.cs index 0042484b..1a51562f 100644 --- a/src/Models/ExternalTool.cs +++ b/src/Models/ExternalTool.cs @@ -95,10 +95,12 @@ namespace SourceGit.Models public string LaunchCommand { get; set; } } - public class ExternalToolPaths + public class ExternalToolCustomization { [JsonPropertyName("tools")] public Dictionary Tools { get; set; } = new Dictionary(); + [JsonPropertyName("excludes")] + public List Excludes { get; set; } = new List(); } public class ExternalToolsFinder @@ -117,7 +119,7 @@ namespace SourceGit.Models if (File.Exists(customPathsConfig)) { using var stream = File.OpenRead(customPathsConfig); - _customPaths = JsonSerializer.Deserialize(stream, JsonCodeGen.Default.ExternalToolPaths); + _customization = JsonSerializer.Deserialize(stream, JsonCodeGen.Default.ExternalToolCustomization); } } catch @@ -125,12 +127,15 @@ namespace SourceGit.Models // Ignore } - _customPaths ??= new ExternalToolPaths(); + _customization ??= new ExternalToolCustomization(); } public void TryAdd(string name, string icon, Func finder, Func execArgsGenerator = null) { - if (_customPaths.Tools.TryGetValue(name, out var customPath) && File.Exists(customPath)) + if (_customization.Excludes.Contains(name)) + return; + + if (_customization.Tools.TryGetValue(name, out var customPath) && File.Exists(customPath)) { Tools.Add(new ExternalTool(name, icon, customPath, execArgsGenerator)); } @@ -201,6 +206,6 @@ namespace SourceGit.Models } } - private ExternalToolPaths _customPaths = null; + private ExternalToolCustomization _customization = null; } }