feature: supports to exclude some editors (#2033)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2026-01-07 16:51:08 +08:00
parent 5690193657
commit 5a67a9f1aa
3 changed files with 20 additions and 9 deletions

View File

@@ -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"
]
}
```

View File

@@ -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))]

View File

@@ -95,10 +95,12 @@ namespace SourceGit.Models
public string LaunchCommand { get; set; }
}
public class ExternalToolPaths
public class ExternalToolCustomization
{
[JsonPropertyName("tools")]
public Dictionary<string, string> Tools { get; set; } = new Dictionary<string, string>();
[JsonPropertyName("excludes")]
public List<string> Excludes { get; set; } = new List<string>();
}
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<string> finder, Func<string, string> 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;
}
}