From 503f700fc2ad6530525cd8cdaae7c6322176c167 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 11 Nov 2024 20:24:17 +0800 Subject: [PATCH] refactor: open selected revision file (#681) * Instead of opening the file from current worktree, save the selected revision file to the temp dir and the open it with default editor * Do NOT set the `IsEnable` property, since the revision file is always available Signed-off-by: leo --- src/ViewModels/CommitDetail.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ViewModels/CommitDetail.cs b/src/ViewModels/CommitDetail.cs index 71b9ddb6..51056f67 100644 --- a/src/ViewModels/CommitDetail.cs +++ b/src/ViewModels/CommitDetail.cs @@ -381,10 +381,13 @@ namespace SourceGit.ViewModels var openWith = new MenuItem(); openWith.Header = App.Text("OpenWith"); openWith.Icon = App.CreateMenuIcon("Icons.OpenWith"); - openWith.IsEnabled = File.Exists(fullPath); openWith.Click += (_, ev) => { - Native.OS.OpenWithDefaultEditor(fullPath); + var fileName = Path.GetFileNameWithoutExtension(fullPath) ?? ""; + var fileExt = Path.GetExtension(fullPath) ?? ""; + var tmpFile = Path.Combine(Path.GetTempPath(), $"{fileName}~{_commit.SHA.Substring(0, 10)}{fileExt}"); + Commands.SaveRevisionFile.Run(_repo.FullPath, _commit.SHA, file.Path, tmpFile); + Native.OS.OpenWithDefaultEditor(tmpFile); ev.Handled = true; };