Skip to content

Commit 12f7531

Browse files
authored
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
1 parent 6939403 commit 12f7531

File tree

9 files changed

+51
-2
lines changed

9 files changed

+51
-2
lines changed

src/Resources/Locales/de_DE.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@
597597
<x:String x:Key="Text.SelfUpdate.IgnoreThisVersion" xml:space="preserve">Diese Version überspringen</x:String>
598598
<x:String x:Key="Text.SelfUpdate.Title" xml:space="preserve">Software Update</x:String>
599599
<x:String x:Key="Text.SelfUpdate.UpToDate" xml:space="preserve">Es sind momentan kein Updates verfügbar.</x:String>
600+
<x:String x:Key="Text.SHALinkCM.CopySHA" xml:space="preserve">SHA kopieren</x:String>
600601
<x:String x:Key="Text.Squash" xml:space="preserve">Squash Commits</x:String>
601602
<x:String x:Key="Text.Squash.Into" xml:space="preserve">In:</x:String>
602603
<x:String x:Key="Text.SSHKey" xml:space="preserve">SSH privater Schlüssel:</x:String>

src/Resources/Locales/en_US.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,8 @@
601601
<x:String x:Key="Text.SelfUpdate.IgnoreThisVersion" xml:space="preserve">Skip This Version</x:String>
602602
<x:String x:Key="Text.SelfUpdate.Title" xml:space="preserve">Software Update</x:String>
603603
<x:String x:Key="Text.SelfUpdate.UpToDate" xml:space="preserve">There are currently no updates available.</x:String>
604+
<x:String x:Key="Text.SHALinkCM.CopySHA" xml:space="preserve">Copy SHA</x:String>
605+
<x:String x:Key="Text.SHALinkCM.NavigateTo" xml:space="preserve">Go to</x:String>
604606
<x:String x:Key="Text.Squash" xml:space="preserve">Squash Commits</x:String>
605607
<x:String x:Key="Text.Squash.Into" xml:space="preserve">Into:</x:String>
606608
<x:String x:Key="Text.SSHKey" xml:space="preserve">SSH Private Key:</x:String>

src/Resources/Locales/es_ES.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@
592592
<x:String x:Key="Text.SelfUpdate.IgnoreThisVersion" xml:space="preserve">Omitir Esta Versión</x:String>
593593
<x:String x:Key="Text.SelfUpdate.Title" xml:space="preserve">Actualización de Software</x:String>
594594
<x:String x:Key="Text.SelfUpdate.UpToDate" xml:space="preserve">Actualmente no hay actualizaciones disponibles.</x:String>
595+
<x:String x:Key="Text.SHALinkCM.CopySHA" xml:space="preserve">Copiar SHA</x:String>
595596
<x:String x:Key="Text.Squash" xml:space="preserve">Squash Commits</x:String>
596597
<x:String x:Key="Text.Squash.Into" xml:space="preserve">En:</x:String>
597598
<x:String x:Key="Text.SSHKey" xml:space="preserve">Clave Privada SSH:</x:String>

src/Resources/Locales/fr_FR.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@
590590
<x:String x:Key="Text.SelfUpdate.IgnoreThisVersion" xml:space="preserve">Passer cette version</x:String>
591591
<x:String x:Key="Text.SelfUpdate.Title" xml:space="preserve">Mise à jour du logiciel</x:String>
592592
<x:String x:Key="Text.SelfUpdate.UpToDate" xml:space="preserve">Il n'y a pas de mise à jour pour le moment.</x:String>
593+
<x:String x:Key="Text.SHALinkCM.CopySHA" xml:space="preserve">Copier le SHA</x:String>
593594
<x:String x:Key="Text.Squash" xml:space="preserve">Squash Commits</x:String>
594595
<x:String x:Key="Text.Squash.Into" xml:space="preserve">Dans :</x:String>
595596
<x:String x:Key="Text.SSHKey" xml:space="preserve">SSH Private Key:</x:String>

src/Resources/Locales/pt_BR.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@
625625
<x:String x:Key="Text.SelfUpdate.IgnoreThisVersion" xml:space="preserve">Ignorar esta versão</x:String>
626626
<x:String x:Key="Text.SelfUpdate.Title" xml:space="preserve">Atualização de Software</x:String>
627627
<x:String x:Key="Text.SelfUpdate.UpToDate" xml:space="preserve">Não há atualizações disponíveis no momento.</x:String>
628+
<x:String x:Key="Text.SHALinkCM.CopySHA" xml:space="preserve">Copiar SHA</x:String>
628629
<x:String x:Key="Text.Squash" xml:space="preserve">Squash Commits</x:String>
629630
<x:String x:Key="Text.Squash.Into" xml:space="preserve">Squash commits em:</x:String>
630631
<x:String x:Key="Text.SSHKey" xml:space="preserve">Chave SSH Privada:</x:String>

src/Resources/Locales/ru_RU.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,8 @@
592592
<x:String x:Key="Text.SaveAsPatchSuccess" xml:space="preserve">Исправление успешно сохранено!</x:String>
593593
<x:String x:Key="Text.ScanRepositories" xml:space="preserve">Сканирование хранилищ</x:String>
594594
<x:String x:Key="Text.ScanRepositories.RootDir" xml:space="preserve">Корневой каталог:</x:String>
595+
<x:String x:Key="Text.SHALinkCM.CopySHA" xml:space="preserve">Копировать SHA</x:String>
596+
<x:String x:Key="Text.SHALinkCM.NavigateTo" xml:space="preserve">Перейти</x:String>
595597
<x:String x:Key="Text.SelfUpdate" xml:space="preserve">Проверка для обновления...</x:String>
596598
<x:String x:Key="Text.SelfUpdate.Available" xml:space="preserve">Доступна новая версия этого программного обеспечения: </x:String>
597599
<x:String x:Key="Text.SelfUpdate.Error" xml:space="preserve">Не удалось проверить наличие обновлений!</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@
605605
<x:String x:Key="Text.SelfUpdate.IgnoreThisVersion" xml:space="preserve">忽略此版本</x:String>
606606
<x:String x:Key="Text.SelfUpdate.Title" xml:space="preserve">软件更新</x:String>
607607
<x:String x:Key="Text.SelfUpdate.UpToDate" xml:space="preserve">当前已是最新版本。</x:String>
608+
<x:String x:Key="Text.SHALinkCM.CopySHA" xml:space="preserve">复制提交指纹</x:String>
608609
<x:String x:Key="Text.Squash" xml:space="preserve">压缩为单个提交</x:String>
609610
<x:String x:Key="Text.Squash.Into" xml:space="preserve">合并入:</x:String>
610611
<x:String x:Key="Text.SSHKey" xml:space="preserve">SSH密钥 :</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@
604604
<x:String x:Key="Text.SelfUpdate.IgnoreThisVersion" xml:space="preserve">忽略此版本</x:String>
605605
<x:String x:Key="Text.SelfUpdate.Title" xml:space="preserve">軟體更新</x:String>
606606
<x:String x:Key="Text.SelfUpdate.UpToDate" xml:space="preserve">目前已是最新版本。</x:String>
607+
<x:String x:Key="Text.SHALinkCM.CopySHA" xml:space="preserve">複製提交編號</x:String>
607608
<x:String x:Key="Text.Squash" xml:space="preserve">壓縮為單個提交</x:String>
608609
<x:String x:Key="Text.Squash.Into" xml:space="preserve">合併入:</x:String>
609610
<x:String x:Key="Text.SSHKey" xml:space="preserve">SSH 金鑰:</x:String>

src/Views/CommitMessagePresenter.cs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Avalonia.Controls;
88
using Avalonia.Controls.Documents;
99
using Avalonia.Input;
10+
using Avalonia.Platform.Storage;
1011
using Avalonia.VisualTree;
1112

1213
namespace SourceGit.Views
@@ -149,11 +150,16 @@ protected override void OnPointerMoved(PointerEventArgs e)
149150
SetCurrentValue(CursorProperty, Cursor.Parse("Hand"));
150151

151152
_lastHover = match;
152-
if (!_lastHover.IsCommitSHA)
153+
if (!match.IsCommitSHA)
153154
{
154155
ToolTip.SetTip(this, match.Link);
155156
ToolTip.SetIsOpen(this, true);
156157
}
158+
else if (this.FindAncestorOfType<CommitBaseInfo>() is { DataContext: ViewModels.CommitDetail detail } && detail.GetParent(match.Link) is Models.Commit c)
159+
{
160+
ToolTip.SetTip(this, c);
161+
ToolTip.SetIsOpen(this, true);
162+
}
157163

158164
return;
159165
}
@@ -172,7 +178,40 @@ protected override void OnPointerPressed(PointerPressedEventArgs e)
172178
{
173179
var parentView = this.FindAncestorOfType<CommitBaseInfo>();
174180
if (parentView is { DataContext: ViewModels.CommitDetail detail })
175-
detail.NavigateTo(_lastHover.Link);
181+
{
182+
var point = e.GetCurrentPoint(this);
183+
var link = _lastHover.Link;
184+
185+
if (point.Properties.IsLeftButtonPressed)
186+
{
187+
detail.NavigateTo(_lastHover.Link);
188+
}
189+
else if (point.Properties.IsRightButtonPressed)
190+
{
191+
var open = new MenuItem();
192+
open.Header = App.Text("SHALinkCM.NavigateTo");
193+
open.Icon = App.CreateMenuIcon("Icons.Commit");
194+
open.Click += (_, ev) =>
195+
{
196+
detail.NavigateTo(_lastHover.Link);
197+
ev.Handled = true;
198+
};
199+
200+
var copy = new MenuItem();
201+
copy.Header = App.Text("SHALinkCM.CopySHA");
202+
copy.Icon = App.CreateMenuIcon("Icons.Copy");
203+
copy.Click += (_, ev) =>
204+
{
205+
App.CopyText(link);
206+
ev.Handled = true;
207+
};
208+
209+
var menu = new ContextMenu();
210+
menu.Items.Add(open);
211+
menu.Items.Add(copy);
212+
menu.Open(this);
213+
}
214+
}
176215
}
177216
else
178217
{

0 commit comments

Comments
 (0)