From 2e6eca26f7cd0207821af33dcb6df4e31c7c651c Mon Sep 17 00:00:00 2001 From: Fernando Medeiros Date: Wed, 6 Nov 2024 01:14:56 +0000 Subject: [PATCH] Adding hotkeys for creating branch, pushing and pulling (#657) --- src/Resources/Locales/en_US.axaml | 3 +++ src/ViewModels/Histories.cs | 2 ++ src/Views/Histories.axaml.cs | 34 ++++++++++++++++++++++++------- src/Views/Hotkeys.axaml | 15 +++++++++++--- src/Views/RepositoryToolbar.axaml | 5 +++-- 5 files changed, 47 insertions(+), 12 deletions(-) diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index eb1c6de3..2b6c8ce9 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -371,6 +371,9 @@ Switch to 'Changes' Switch to 'Histories' Switch to 'Stashes' + Pull, starts directly + Push, starts directly + Creates a new branch based on selected commit TEXT EDITOR Close search panel Find next match diff --git a/src/ViewModels/Histories.cs b/src/ViewModels/Histories.cs index 713e1635..3fb048ae 100644 --- a/src/ViewModels/Histories.cs +++ b/src/ViewModels/Histories.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Text; using Avalonia.Controls; +using Avalonia.Input; using Avalonia.Platform.Storage; using CommunityToolkit.Mvvm.ComponentModel; @@ -544,6 +545,7 @@ namespace SourceGit.ViewModels var createBranch = new MenuItem(); createBranch.Icon = App.CreateMenuIcon("Icons.Branch.Add"); createBranch.Header = App.Text("CreateBranch"); + createBranch.HotKey = new KeyGesture(Key.B, KeyModifiers.Control); createBranch.Click += (_, e) => { if (PopupHost.CanCreatePopup()) diff --git a/src/Views/Histories.axaml.cs b/src/Views/Histories.axaml.cs index 43258dd7..e621a0aa 100644 --- a/src/Views/Histories.axaml.cs +++ b/src/Views/Histories.axaml.cs @@ -12,6 +12,7 @@ using Avalonia.Interactivity; using Avalonia.Media; using Avalonia.Threading; using Avalonia.VisualTree; +using SourceGit.ViewModels; namespace SourceGit.Views { @@ -722,19 +723,38 @@ namespace SourceGit.Views private void OnCommitListKeyDown(object sender, KeyEventArgs e) { + // These shortcuts are not mentioned in the Shortcut Reference window. Is this expected? if (sender is ListBox { SelectedItems: { Count: > 0 } selected } && - e.Key == Key.C && e.KeyModifiers.HasFlag(KeyModifiers.Control)) { - var builder = new StringBuilder(); - foreach (var item in selected) + // CTRL + C -> Copy selected commit SHA and subject. + if (e.Key == Key.C) { - if (item is Models.Commit commit) - builder.AppendLine($"{commit.SHA.Substring(0, 10)} - {commit.Subject}"); + var builder = new StringBuilder(); + foreach (var item in selected) + { + if (item is Models.Commit commit) + builder.AppendLine($"{commit.SHA.Substring(0, 10)} - {commit.Subject}"); + } + + App.CopyText(builder.ToString()); + e.Handled = true; + return; } - App.CopyText(builder.ToString()); - e.Handled = true; + // CTRL + B -> shows Create Branch pop-up at selected commit. + if (e.Key == Key.B) + { + if (selected.Count == 1 && + selected[0] is Models.Commit commit && + DataContext is ViewModels.Histories histories && + PopupHost.CanCreatePopup()) + { + PopupHost.ShowPopup(new ViewModels.CreateBranch(histories.Repo, commit)); + e.Handled = true; + + } + } } } diff --git a/src/Views/Hotkeys.axaml b/src/Views/Hotkeys.axaml index a28bc566..cb6f6e64 100644 --- a/src/Views/Hotkeys.axaml +++ b/src/Views/Hotkeys.axaml @@ -71,7 +71,7 @@ FontSize="{Binding Source={x:Static vm:Preference.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Increase}}" Margin="0,8"/> - + @@ -102,8 +102,17 @@ - - + + + + + + + + + + + - -