From 12f75315bd9174233d8c7010a30769ba3f86cc22 Mon Sep 17 00:00:00 2001 From: "Dmitrij D. Czarkoff" Date: Sun, 24 Nov 2024 02:53:16 +0000 Subject: [PATCH] feat: context menu for a commit in commit message (#734) * feat: context menu for a commit in commit message When a commit message happens to contain a commit link and the user elects to right-click it, instead of navigating them to the commit, present a menu with options to navigate to it or to copy SHA. * feat: show commit tooltip as well `_lastHover` in the `if` is also swapped for `match`for consistency with the block body --- src/Resources/Locales/de_DE.axaml | 1 + src/Resources/Locales/en_US.axaml | 2 ++ src/Resources/Locales/es_ES.axaml | 1 + src/Resources/Locales/fr_FR.axaml | 1 + src/Resources/Locales/pt_BR.axaml | 1 + src/Resources/Locales/ru_RU.axaml | 2 ++ src/Resources/Locales/zh_CN.axaml | 1 + src/Resources/Locales/zh_TW.axaml | 1 + src/Views/CommitMessagePresenter.cs | 43 +++++++++++++++++++++++++++-- 9 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/Resources/Locales/de_DE.axaml b/src/Resources/Locales/de_DE.axaml index 3b722aa8..6293e5f0 100644 --- a/src/Resources/Locales/de_DE.axaml +++ b/src/Resources/Locales/de_DE.axaml @@ -597,6 +597,7 @@ Diese Version überspringen Software Update Es sind momentan kein Updates verfügbar. + SHA kopieren Squash Commits In: SSH privater Schlüssel: diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 444007c2..8a0ee04e 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -601,6 +601,8 @@ Skip This Version Software Update There are currently no updates available. + Copy SHA + Go to Squash Commits Into: SSH Private Key: diff --git a/src/Resources/Locales/es_ES.axaml b/src/Resources/Locales/es_ES.axaml index 06f295d3..563419be 100644 --- a/src/Resources/Locales/es_ES.axaml +++ b/src/Resources/Locales/es_ES.axaml @@ -592,6 +592,7 @@ Omitir Esta Versión Actualización de Software Actualmente no hay actualizaciones disponibles. + Copiar SHA Squash Commits En: Clave Privada SSH: diff --git a/src/Resources/Locales/fr_FR.axaml b/src/Resources/Locales/fr_FR.axaml index ef416e0b..a9a18be3 100644 --- a/src/Resources/Locales/fr_FR.axaml +++ b/src/Resources/Locales/fr_FR.axaml @@ -590,6 +590,7 @@ Passer cette version Mise à jour du logiciel Il n'y a pas de mise à jour pour le moment. + Copier le SHA Squash Commits Dans : SSH Private Key: diff --git a/src/Resources/Locales/pt_BR.axaml b/src/Resources/Locales/pt_BR.axaml index 428579bd..4d011b32 100644 --- a/src/Resources/Locales/pt_BR.axaml +++ b/src/Resources/Locales/pt_BR.axaml @@ -625,6 +625,7 @@ Ignorar esta versão Atualização de Software Não há atualizações disponíveis no momento. + Copiar SHA Squash Commits Squash commits em: Chave SSH Privada: diff --git a/src/Resources/Locales/ru_RU.axaml b/src/Resources/Locales/ru_RU.axaml index 123c921f..5b908a17 100644 --- a/src/Resources/Locales/ru_RU.axaml +++ b/src/Resources/Locales/ru_RU.axaml @@ -592,6 +592,8 @@ Исправление успешно сохранено! Сканирование хранилищ Корневой каталог: + Копировать SHA + Перейти Проверка для обновления... Доступна новая версия этого программного обеспечения: Не удалось проверить наличие обновлений! diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index fe71caa7..5493434c 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -605,6 +605,7 @@ 忽略此版本 软件更新 当前已是最新版本。 + 复制提交指纹 压缩为单个提交 合并入: SSH密钥 : diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index f1ba12a6..de431e16 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -604,6 +604,7 @@ 忽略此版本 軟體更新 目前已是最新版本。 + 複製提交編號 壓縮為單個提交 合併入: SSH 金鑰: diff --git a/src/Views/CommitMessagePresenter.cs b/src/Views/CommitMessagePresenter.cs index 862ce9e1..c4da7e94 100644 --- a/src/Views/CommitMessagePresenter.cs +++ b/src/Views/CommitMessagePresenter.cs @@ -7,6 +7,7 @@ using Avalonia.Collections; using Avalonia.Controls; using Avalonia.Controls.Documents; using Avalonia.Input; +using Avalonia.Platform.Storage; using Avalonia.VisualTree; namespace SourceGit.Views @@ -149,11 +150,16 @@ namespace SourceGit.Views SetCurrentValue(CursorProperty, Cursor.Parse("Hand")); _lastHover = match; - if (!_lastHover.IsCommitSHA) + if (!match.IsCommitSHA) { ToolTip.SetTip(this, match.Link); ToolTip.SetIsOpen(this, true); } + else if (this.FindAncestorOfType() is { DataContext: ViewModels.CommitDetail detail } && detail.GetParent(match.Link) is Models.Commit c) + { + ToolTip.SetTip(this, c); + ToolTip.SetIsOpen(this, true); + } return; } @@ -172,7 +178,40 @@ namespace SourceGit.Views { var parentView = this.FindAncestorOfType(); if (parentView is { DataContext: ViewModels.CommitDetail detail }) - detail.NavigateTo(_lastHover.Link); + { + var point = e.GetCurrentPoint(this); + var link = _lastHover.Link; + + if (point.Properties.IsLeftButtonPressed) + { + detail.NavigateTo(_lastHover.Link); + } + else if (point.Properties.IsRightButtonPressed) + { + var open = new MenuItem(); + open.Header = App.Text("SHALinkCM.NavigateTo"); + open.Icon = App.CreateMenuIcon("Icons.Commit"); + open.Click += (_, ev) => + { + detail.NavigateTo(_lastHover.Link); + ev.Handled = true; + }; + + var copy = new MenuItem(); + copy.Header = App.Text("SHALinkCM.CopySHA"); + copy.Icon = App.CreateMenuIcon("Icons.Copy"); + copy.Click += (_, ev) => + { + App.CopyText(link); + ev.Handled = true; + }; + + var menu = new ContextMenu(); + menu.Items.Add(open); + menu.Items.Add(copy); + menu.Open(this); + } + } } else {