feature<ExternalMergeTool>: use default path if file exists after tool changed

This commit is contained in:
leo 2024-02-19 16:19:12 +08:00
parent 1a27b1dfb1
commit e7219b4278
2 changed files with 13 additions and 5 deletions

View file

@ -123,7 +123,14 @@ namespace SourceGit.ViewModels {
public int ExternalMergeToolType { public int ExternalMergeToolType {
get => _externalMergeToolType; get => _externalMergeToolType;
set => SetProperty(ref _externalMergeToolType, value); set {
var changed = SetProperty(ref _externalMergeToolType, value);
if (changed && !OperatingSystem.IsWindows() && value >= 0 && value < Models.ExternalMergeTools.Supported.Count) {
var tool = Models.ExternalMergeTools.Supported[value];
if (File.Exists(tool.Exec)) ExternalMergeToolPath = tool.Exec;
else ExternalMergeToolPath = string.Empty;
}
}
} }
public string ExternalMergeToolPath { public string ExternalMergeToolPath {

View file

@ -115,14 +115,15 @@ namespace SourceGit.Views {
private async void SelectExternalMergeTool(object sender, RoutedEventArgs e) { private async void SelectExternalMergeTool(object sender, RoutedEventArgs e) {
var type = ViewModels.Preference.Instance.ExternalMergeToolType; var type = ViewModels.Preference.Instance.ExternalMergeToolType;
if (type == 0 || type >= Models.ExternalMergeTools.Supported.Count) { if (type < 0 || type >= Models.ExternalMergeTools.Supported.Count) {
ViewModels.Preference.Instance.ExternalMergeToolType = 1; ViewModels.Preference.Instance.ExternalMergeToolType = 0;
type = 1; type = 0;
} }
var tool = Models.ExternalMergeTools.Supported[type]; var tool = Models.ExternalMergeTools.Supported[type];
var pattern = Path.GetFileName(tool.Exec);
var options = new FilePickerOpenOptions() { var options = new FilePickerOpenOptions() {
FileTypeFilter = [new FilePickerFileType(tool.Name) { Patterns = [tool.Exec] }], FileTypeFilter = [new FilePickerFileType(tool.Name) { Patterns = [pattern] }],
AllowMultiple = false, AllowMultiple = false,
}; };