From addfb449ccc55075a13f45ca3805d6f8662d3983 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 30 Jul 2024 11:47:58 +0800 Subject: [PATCH] feature: double click on commit (#295) * when commit is current branch head, do nothing * when commit is head of some local branch which is not current, try to checkout this branch * otherwise, ask user should checkout selected commit as deteched --- src/ViewModels/Histories.cs | 22 ++++++++++++++++++++++ src/Views/Histories.axaml | 3 ++- src/Views/Histories.axaml.cs | 10 ++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/ViewModels/Histories.cs b/src/ViewModels/Histories.cs index 61b33a9b..9ec3a897 100644 --- a/src/ViewModels/Histories.cs +++ b/src/ViewModels/Histories.cs @@ -142,6 +142,28 @@ namespace SourceGit.ViewModels } } + public void DoubleTapped(Models.Commit commit) + { + if (commit == null || commit.IsCurrentHead) + return; + + foreach (var d in commit.Decorators) + { + if (d.Type == Models.DecoratorType.LocalBranchHead) + { + var b = _repo.Branches.Find(x => x.FriendlyName == d.Name); + if (b != null) + { + _repo.CheckoutBranch(b); + return; + } + } + } + + if (PopupHost.CanCreatePopup()) + PopupHost.ShowPopup(new CheckoutCommit(_repo, commit)); + } + public ContextMenu MakeContextMenu(DataGrid datagrid) { if (datagrid.SelectedItems.Count != 1) diff --git a/src/Views/Histories.axaml b/src/Views/Histories.axaml index f04cdb02..63d4da95 100644 --- a/src/Views/Histories.axaml +++ b/src/Views/Histories.axaml @@ -29,7 +29,8 @@ VerticalScrollBarVisibility="Auto" LayoutUpdated="OnCommitDataGridLayoutUpdated" SelectionChanged="OnCommitDataGridSelectionChanged" - ContextRequested="OnCommitDataGridContextRequested"> + ContextRequested="OnCommitDataGridContextRequested" + DoubleTapped="OnCommitDataGridDoubleTapped">