mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-30 13:51:53 +08:00
feature: add hotkeys to open file with default editor
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
@@ -528,6 +528,7 @@ namespace SourceGit.ViewModels
|
||||
var openWith = new MenuItem();
|
||||
openWith.Header = App.Text("OpenWith");
|
||||
openWith.Icon = App.CreateMenuIcon("Icons.OpenWith");
|
||||
openWith.Tag = OperatingSystem.IsMacOS() ? "⌘+O" : "Ctrl+O";
|
||||
openWith.IsEnabled = file.Type == Models.ObjectType.Blob;
|
||||
openWith.Click += async (_, ev) =>
|
||||
{
|
||||
|
||||
@@ -328,6 +328,13 @@ namespace SourceGit.ViewModels
|
||||
});
|
||||
}
|
||||
|
||||
public void OpenWithDefaultEditor(Models.Change c)
|
||||
{
|
||||
var absPath = Native.OS.GetAbsPath(_repo.FullPath, c.Path);
|
||||
if (File.Exists(absPath))
|
||||
Native.OS.OpenWithDefaultEditor(absPath);
|
||||
}
|
||||
|
||||
public void StashAll(bool autoStart)
|
||||
{
|
||||
if (!_repo.CanCreatePopup())
|
||||
@@ -609,10 +616,11 @@ namespace SourceGit.ViewModels
|
||||
var openWith = new MenuItem();
|
||||
openWith.Header = App.Text("OpenWith");
|
||||
openWith.Icon = App.CreateMenuIcon("Icons.OpenWith");
|
||||
openWith.Tag = OperatingSystem.IsMacOS() ? "⌘+O" : "Ctrl+O";
|
||||
openWith.IsEnabled = File.Exists(path);
|
||||
openWith.Click += (_, e) =>
|
||||
{
|
||||
Native.OS.OpenWithDefaultEditor(path);
|
||||
OpenWithDefaultEditor(change);
|
||||
e.Handled = true;
|
||||
};
|
||||
menu.Items.Add(openWith);
|
||||
@@ -1293,10 +1301,11 @@ namespace SourceGit.ViewModels
|
||||
var openWith = new MenuItem();
|
||||
openWith.Header = App.Text("OpenWith");
|
||||
openWith.Icon = App.CreateMenuIcon("Icons.OpenWith");
|
||||
openWith.Tag = OperatingSystem.IsMacOS() ? "⌘+O" : "Ctrl+O";
|
||||
openWith.IsEnabled = File.Exists(path);
|
||||
openWith.Click += (_, e) =>
|
||||
{
|
||||
Native.OS.OpenWithDefaultEditor(path);
|
||||
OpenWithDefaultEditor(change);
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
|
||||
@@ -149,7 +149,14 @@
|
||||
Background="Transparent"
|
||||
Click="OnOpenFileWithDefaultEditor"
|
||||
IsVisible="{Binding CanOpenRevisionFileWithDefaultEditor, Mode=OneWay}"
|
||||
ToolTip.Tip="{DynamicResource Text.OpenWith}">
|
||||
HotKey="{OnPlatform Ctrl+O, macOS=⌘+O}">
|
||||
<ToolTip.Tip>
|
||||
<TextBlock>
|
||||
<Run Text="{DynamicResource Text.OpenWith}"/>
|
||||
<Run Text=" "/>
|
||||
<Run Text="{OnPlatform Ctrl+O, macOS=⌘+O}" Foreground="{DynamicResource Brush.FG2}"/>
|
||||
</TextBlock>
|
||||
</ToolTip.Tip>
|
||||
<Path Width="12" Height="12" Data="{StaticResource Icons.OpenWith}"/>
|
||||
</Button>
|
||||
</Grid>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
@@ -96,12 +97,17 @@ namespace SourceGit.Views
|
||||
vm.StageSelected(next);
|
||||
UnstagedChangesView.TakeFocus();
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.Key is Key.Delete or Key.Back && vm.SelectedUnstaged is { Count: > 0 } selected)
|
||||
else if (e.Key is Key.Delete or Key.Back && vm.SelectedUnstaged is { Count: > 0 })
|
||||
{
|
||||
vm.Discard(selected);
|
||||
vm.Discard(vm.SelectedUnstaged);
|
||||
e.Handled = true;
|
||||
}
|
||||
else if (e.Key is Key.O &&
|
||||
e.KeyModifiers == (OperatingSystem.IsMacOS() ? KeyModifiers.Meta : KeyModifiers.Control) &&
|
||||
vm.SelectedUnstaged is { Count: 1 })
|
||||
{
|
||||
vm.OpenWithDefaultEditor(vm.SelectedUnstaged[0]);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
@@ -109,12 +115,22 @@ namespace SourceGit.Views
|
||||
|
||||
private void OnStagedKeyDown(object _, KeyEventArgs e)
|
||||
{
|
||||
if (DataContext is ViewModels.WorkingCopy vm && e.Key is Key.Space or Key.Enter)
|
||||
if (DataContext is ViewModels.WorkingCopy vm)
|
||||
{
|
||||
var next = StagedChangesView.GetNextChangeWithoutSelection();
|
||||
vm.UnstageSelected(next);
|
||||
StagedChangesView.TakeFocus();
|
||||
e.Handled = true;
|
||||
if (e.Key is Key.Space or Key.Enter)
|
||||
{
|
||||
var next = StagedChangesView.GetNextChangeWithoutSelection();
|
||||
vm.UnstageSelected(next);
|
||||
StagedChangesView.TakeFocus();
|
||||
e.Handled = true;
|
||||
}
|
||||
else if (e.Key is Key.O &&
|
||||
e.KeyModifiers == (OperatingSystem.IsMacOS() ? KeyModifiers.Meta : KeyModifiers.Control) &&
|
||||
vm.SelectedStaged is { Count: 1 })
|
||||
{
|
||||
vm.OpenWithDefaultEditor(vm.SelectedStaged[0]);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user