mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-21 10:25:00 +00:00
feature: add a button to open current revision file with default editor
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
e102e49f45
commit
efa6e46471
3 changed files with 48 additions and 7 deletions
|
@ -133,6 +133,12 @@ namespace SourceGit.ViewModels
|
|||
private set => SetProperty(ref _revisionFileSearchSuggestion, value);
|
||||
}
|
||||
|
||||
public bool CanOpenRevisionFileWithDefaultEditor
|
||||
{
|
||||
get => _canOpenRevisionFileWithDefaultEditor;
|
||||
private set => SetProperty(ref _canOpenRevisionFileWithDefaultEditor, value);
|
||||
}
|
||||
|
||||
public CommitDetail(Repository repo)
|
||||
{
|
||||
_repo = repo;
|
||||
|
@ -197,6 +203,7 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
ViewRevisionFilePath = string.Empty;
|
||||
ViewRevisionFileContent = null;
|
||||
CanOpenRevisionFileWithDefaultEditor = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -205,6 +212,7 @@ namespace SourceGit.ViewModels
|
|||
switch (file.Type)
|
||||
{
|
||||
case Models.ObjectType.Blob:
|
||||
CanOpenRevisionFileWithDefaultEditor = true;
|
||||
Task.Run(() =>
|
||||
{
|
||||
var isBinary = new Commands.IsBinary(_repo.FullPath, _commit.SHA, file.Path).Result();
|
||||
|
@ -252,6 +260,7 @@ namespace SourceGit.ViewModels
|
|||
});
|
||||
break;
|
||||
case Models.ObjectType.Commit:
|
||||
CanOpenRevisionFileWithDefaultEditor = false;
|
||||
Task.Run(() =>
|
||||
{
|
||||
var submoduleRoot = Path.Combine(_repo.FullPath, file.Path).Replace('\\', '/').Trim('/');
|
||||
|
@ -267,11 +276,26 @@ namespace SourceGit.ViewModels
|
|||
});
|
||||
break;
|
||||
default:
|
||||
CanOpenRevisionFileWithDefaultEditor = false;
|
||||
ViewRevisionFileContent = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public Task OpenRevisionFileWithDefaultEditor(string file)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var fullPath = Native.OS.GetAbsPath(_repo.FullPath, file);
|
||||
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, tmpFile);
|
||||
Native.OS.OpenWithDefaultEditor(tmpFile);
|
||||
});
|
||||
}
|
||||
|
||||
public ContextMenu CreateChangeContextMenu(Models.Change change)
|
||||
{
|
||||
var diffWithMerger = new MenuItem();
|
||||
|
@ -421,13 +445,10 @@ namespace SourceGit.ViewModels
|
|||
var openWith = new MenuItem();
|
||||
openWith.Header = App.Text("OpenWith");
|
||||
openWith.Icon = App.CreateMenuIcon("Icons.OpenWith");
|
||||
openWith.IsEnabled = file.Type == Models.ObjectType.Blob;
|
||||
openWith.Click += async (_, ev) =>
|
||||
{
|
||||
var fileName = Path.GetFileNameWithoutExtension(fullPath) ?? "";
|
||||
var fileExt = Path.GetExtension(fullPath) ?? "";
|
||||
var tmpFile = Path.Combine(Path.GetTempPath(), $"{fileName}~{_commit.SHA.Substring(0, 10)}{fileExt}");
|
||||
await Task.Run(() => Commands.SaveRevisionFile.Run(_repo.FullPath, _commit.SHA, file.Path, tmpFile));
|
||||
Native.OS.OpenWithDefaultEditor(tmpFile);
|
||||
await OpenRevisionFileWithDefaultEditor(file.Path);
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
|
@ -887,5 +908,6 @@ namespace SourceGit.ViewModels
|
|||
private List<string> _revisionFiles = null;
|
||||
private string _revisionFileSearchFilter = string.Empty;
|
||||
private List<string> _revisionFileSearchSuggestion = null;
|
||||
private bool _canOpenRevisionFileWithDefaultEditor = false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue