Skip to content

Commit 2e6eca2

Browse files
authored
Adding hotkeys for creating branch, pushing and pulling (#657)
1 parent fdf30aa commit 2e6eca2

File tree

5 files changed

+47
-12
lines changed

5 files changed

+47
-12
lines changed

src/Resources/Locales/en_US.axaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@
371371
<x:String x:Key="Text.Hotkeys.Repo.ViewChanges" xml:space="preserve">Switch to 'Changes'</x:String>
372372
<x:String x:Key="Text.Hotkeys.Repo.ViewHistories" xml:space="preserve">Switch to 'Histories'</x:String>
373373
<x:String x:Key="Text.Hotkeys.Repo.ViewStashes" xml:space="preserve">Switch to 'Stashes'</x:String>
374+
<x:String x:Key="Text.Hotkeys.Repo.Pull" xml:space="preserve">Pull, starts directly</x:String>
375+
<x:String x:Key="Text.Hotkeys.Repo.Push" xml:space="preserve">Push, starts directly</x:String>
376+
<x:String x:Key="Text.Hotkeys.Repo.CreateBranchOnCommit" xml:space="preserve">Creates a new branch based on selected commit</x:String>
374377
<x:String x:Key="Text.Hotkeys.TextEditor" xml:space="preserve">TEXT EDITOR</x:String>
375378
<x:String x:Key="Text.Hotkeys.TextEditor.CloseSearch" xml:space="preserve">Close search panel</x:String>
376379
<x:String x:Key="Text.Hotkeys.TextEditor.GotoNextMatch" xml:space="preserve">Find next match</x:String>

src/ViewModels/Histories.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Text;
55

66
using Avalonia.Controls;
7+
using Avalonia.Input;
78
using Avalonia.Platform.Storage;
89

910
using CommunityToolkit.Mvvm.ComponentModel;
@@ -544,6 +545,7 @@ public ContextMenu MakeContextMenu(ListBox list)
544545
var createBranch = new MenuItem();
545546
createBranch.Icon = App.CreateMenuIcon("Icons.Branch.Add");
546547
createBranch.Header = App.Text("CreateBranch");
548+
createBranch.HotKey = new KeyGesture(Key.B, KeyModifiers.Control);
547549
createBranch.Click += (_, e) =>
548550
{
549551
if (PopupHost.CanCreatePopup())

src/Views/Histories.axaml.cs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Avalonia.Media;
1313
using Avalonia.Threading;
1414
using Avalonia.VisualTree;
15+
using SourceGit.ViewModels;
1516

1617
namespace SourceGit.Views
1718
{
@@ -722,19 +723,38 @@ private void OnCommitListDoubleTapped(object sender, TappedEventArgs e)
722723

723724
private void OnCommitListKeyDown(object sender, KeyEventArgs e)
724725
{
726+
// These shortcuts are not mentioned in the Shortcut Reference window. Is this expected?
725727
if (sender is ListBox { SelectedItems: { Count: > 0 } selected } &&
726-
e.Key == Key.C &&
727728
e.KeyModifiers.HasFlag(KeyModifiers.Control))
728729
{
729-
var builder = new StringBuilder();
730-
foreach (var item in selected)
730+
// CTRL + C -> Copy selected commit SHA and subject.
731+
if (e.Key == Key.C)
731732
{
732-
if (item is Models.Commit commit)
733-
builder.AppendLine($"{commit.SHA.Substring(0, 10)} - {commit.Subject}");
733+
var builder = new StringBuilder();
734+
foreach (var item in selected)
735+
{
736+
if (item is Models.Commit commit)
737+
builder.AppendLine($"{commit.SHA.Substring(0, 10)} - {commit.Subject}");
738+
}
739+
740+
App.CopyText(builder.ToString());
741+
e.Handled = true;
742+
return;
734743
}
735744

736-
App.CopyText(builder.ToString());
737-
e.Handled = true;
745+
// CTRL + B -> shows Create Branch pop-up at selected commit.
746+
if (e.Key == Key.B)
747+
{
748+
if (selected.Count == 1 &&
749+
selected[0] is Models.Commit commit &&
750+
DataContext is ViewModels.Histories histories &&
751+
PopupHost.CanCreatePopup())
752+
{
753+
PopupHost.ShowPopup(new ViewModels.CreateBranch(histories.Repo, commit));
754+
e.Handled = true;
755+
756+
}
757+
}
738758
}
739759
}
740760

src/Views/Hotkeys.axaml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
FontSize="{Binding Source={x:Static vm:Preference.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Increase}}"
7272
Margin="0,8"/>
7373

74-
<Grid RowDefinitions="20,20,20,20,20,20,20,20,20,20,20" ColumnDefinitions="150,*">
74+
<Grid RowDefinitions="20,20,20,20,20,20,20,20,20,20,20,20,20,20" ColumnDefinitions="150,*">
7575
<TextBlock Grid.Row="0" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Ctrl+Shift+H, macOS=⌘+⇧+H}"/>
7676
<TextBlock Grid.Row="0" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.GoHome}" />
7777

@@ -102,8 +102,17 @@
102102
<TextBlock Grid.Row="9" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Alt+Enter, macOS=⌥+Enter}"/>
103103
<TextBlock Grid.Row="9" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.CommitAndPush}" />
104104

105-
<TextBlock Grid.Row="10" Grid.Column="0" Classes="primary bold" Text="F5"/>
106-
<TextBlock Grid.Row="10" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.Refresh}" />
105+
<TextBlock Grid.Row="10" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Ctrl+Shift+Down, macOS=⌘+Shift+Down}"/>
106+
<TextBlock Grid.Row="10" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.Pull}" />
107+
108+
<TextBlock Grid.Row="11" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Ctrl+Shift+Up, macOS=⌘+Shift+Up}"/>
109+
<TextBlock Grid.Row="11" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.Push}" />
110+
111+
<TextBlock Grid.Row="12" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Ctrl+B, macOS=⌘+B}"/>
112+
<TextBlock Grid.Row="12" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.CreateBranchOnCommit}" />
113+
114+
<TextBlock Grid.Row="13" Grid.Column="0" Classes="primary bold" Text="F5"/>
115+
<TextBlock Grid.Row="13" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.Refresh}" />
107116
</Grid>
108117

109118
<TextBlock Text="{DynamicResource Text.Hotkeys.TextEditor}"

src/Views/RepositoryToolbar.axaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<Path Width="14" Height="14" Data="{StaticResource Icons.Fetch}"/>
4343
</Button>
4444

45-
<Button Classes="icon_button" Width="32" Margin="16,0,0,0" Click="Pull">
45+
<Button Classes="icon_button" Width="32" Margin="16,0,0,0" Click="Pull" HotKey="{OnPlatform Ctrl+Shift+Down, macOS=⌘+Shift+Down}">
4646
<ToolTip.Tip>
4747
<StackPanel Orientation="Vertical">
4848
<TextBlock Text="{DynamicResource Text.Pull}"/>
@@ -53,7 +53,7 @@
5353
<Path Width="14" Height="14" Data="{StaticResource Icons.Pull}"/>
5454
</Button>
5555

56-
<Button Classes="icon_button" Width="32" Margin="16,0,0,0" Click="Push">
56+
<Button Classes="icon_button" Width="32" Margin="16,0,0,0" Click="Push" HotKey="{OnPlatform Ctrl+Shift+Up, macOS=⌘+Shift+Up}">
5757
<ToolTip.Tip>
5858
<StackPanel Orientation="Vertical">
5959
<TextBlock Text="{DynamicResource Text.Push}"/>
@@ -85,6 +85,7 @@
8585
Fill="{DynamicResource Brush.Border2}"/>
8686

8787
<Button Classes="icon_button" Width="32" Margin="16,0,0,0" Command="{Binding CreateNewBranch}" ToolTip.Tip="{DynamicResource Text.Repository.NewBranch}">
88+
8889
<Path Width="14" Height="14" Data="{StaticResource Icons.Branch.Add}"/>
8990
</Button>
9091

0 commit comments

Comments
 (0)