mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-21 18:35: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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@
|
|||
Height="26"
|
||||
BorderBrush="{DynamicResource Brush.Border2}" BorderThickness="0,0,0,1"
|
||||
IsVisible="{Binding ViewRevisionFilePath, Converter={x:Static StringConverters.IsNotNullOrEmpty}}">
|
||||
<Grid ColumnDefinitions="Auto,*,Auto">
|
||||
<Grid ColumnDefinitions="Auto,*,Auto,Auto">
|
||||
<Path Grid.Column="0" Width="12" Height="12" Data="{StaticResource Icons.File}" Margin="8,0,0,0"/>
|
||||
<TextBlock Grid.Column="1"
|
||||
Classes="primary"
|
||||
|
@ -140,8 +140,18 @@
|
|||
Converter="{x:Static c:ObjectConverters.IsTypeOf}"
|
||||
ConverterParameter="{x:Type m:RevisionTextFile}"/>
|
||||
</ToggleButton.IsVisible>
|
||||
<Path Width="13" Height="13" Data="{StaticResource Icons.SyntaxHighlight}" Margin="0,3,0,0"/>
|
||||
<Path Width="13" Height="13" Data="{StaticResource Icons.SyntaxHighlight}" Margin="0,2,0,0"/>
|
||||
</ToggleButton>
|
||||
|
||||
<Button Grid.Column="3"
|
||||
Classes="icon_button"
|
||||
Width="28"
|
||||
Background="Transparent"
|
||||
Click="OnOpenFileWithDefaultEditor"
|
||||
IsVisible="{Binding CanOpenRevisionFileWithDefaultEditor, Mode=OneWay}"
|
||||
ToolTip.Tip="{DynamicResource Text.OpenWith}">
|
||||
<Path Width="12" Height="12" Data="{StaticResource Icons.OpenWith}"/>
|
||||
</Button>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
|
@ -80,5 +81,13 @@ namespace SourceGit.Views
|
|||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private async void OnOpenFileWithDefaultEditor(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (DataContext is ViewModels.CommitDetail { CanOpenRevisionFileWithDefaultEditor: true } vm)
|
||||
await vm.OpenRevisionFileWithDefaultEditor(vm.ViewRevisionFilePath);
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue