Skip to content

Commit ef36c50

Browse files
committed
feature: add hotkey Ctrl+Shift+P/⌘+⇧+P to open repository command palette
Signed-off-by: leo <longshuang@msn.cn>
1 parent ca544d9 commit ef36c50

18 files changed

+900
-6
lines changed

src/Resources/Icons.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<StreamGeometry x:Key="Icons.Close">M523 398 918 3l113 113-396 396 397 397-113 113-397-397-397 397-113-113 397-397L14 116l113-113 396 396z</StreamGeometry>
2222
<StreamGeometry x:Key="Icons.Code">M853 102H171C133 102 102 133 102 171v683C102 891 133 922 171 922h683C891 922 922 891 922 853V171C922 133 891 102 853 102zM390 600l-48 48L205 512l137-137 48 48L301 512l88 88zM465 819l-66-18L559 205l66 18L465 819zm218-171L634 600 723 512l-88-88 48-48L819 512 683 649z</StreamGeometry>
2323
<StreamGeometry x:Key="Icons.ColorPicker">M128 854h768v86H128zM390 797c13 13 29 19 48 19s35-6 45-19l291-288c26-22 26-64 0-90L435 83l-61 61L426 192l-272 269c-22 22-22 64 0 90l237 246zm93-544 211 211-32 32H240l243-243zM707 694c0 48 38 86 86 86 48 0 86-38 86-86 0-22-10-45-26-61L794 576l-61 61c-13 13-26 35-26 58z</StreamGeometry>
24+
<StreamGeometry x:Key="Icons.Command">M325 312l-60 60L404 513 265 652l60 60 200-200L325 312zm194 345h236v97h-236v-97zM29 77v870h968V77H29zm870 774H125V173h774v678z</StreamGeometry>
2425
<StreamGeometry x:Key="Icons.Commit">M0 512M1024 512M512 0M512 1024M796 471A292 292 0 00512 256a293 293 0 00-284 215H0v144h228A293 293 0 00512 832a291 291 0 00284-217H1024V471h-228M512 688A146 146 0 01366 544A145 145 0 01512 400c80 0 146 63 146 144A146 146 0 01512 688</StreamGeometry>
2526
<StreamGeometry x:Key="Icons.CommitMessageGenerator">M796 561a5 5 0 014 7l-39 90a5 5 0 004 7h100a5 5 0 014 8l-178 247a5 5 0 01-9-4l32-148a5 5 0 00-5-6h-89a5 5 0 01-4-7l86-191a5 5 0 014-3h88zM731 122a73 73 0 0173 73v318a54 54 0 00-8-1H731V195H244v634h408l-16 73H244a73 73 0 01-73-73V195a73 73 0 0173-73h488zm-219 366v73h-195v-73h195zm146-146v73H317v-73h341z</StreamGeometry>
2627
<StreamGeometry x:Key="Icons.Compare">M645 448l64 64 220-221L704 64l-64 64 115 115H128v90h628zM375 576l-64-64-220 224L314 960l64-64-116-115H896v-90H262z</StreamGeometry>

src/Resources/Locales/en_US.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@
477477
<x:String x:Key="Text.Hotkeys.Repo.CommitWithAutoStage" xml:space="preserve">Stage all changes and commit</x:String>
478478
<x:String x:Key="Text.Hotkeys.Repo.Fetch" xml:space="preserve">Fetch, starts directly</x:String>
479479
<x:String x:Key="Text.Hotkeys.Repo.GoHome" xml:space="preserve">Dashboard mode (Default)</x:String>
480+
<x:String x:Key="Text.Hotkeys.Repo.OpenCommandPalette" xml:space="preserve">Open command palette</x:String>
480481
<x:String x:Key="Text.Hotkeys.Repo.OpenSearchCommits" xml:space="preserve">Commit search mode</x:String>
481482
<x:String x:Key="Text.Hotkeys.Repo.Pull" xml:space="preserve">Pull, starts directly</x:String>
482483
<x:String x:Key="Text.Hotkeys.Repo.Push" xml:space="preserve">Push, starts directly</x:String>
@@ -510,6 +511,7 @@
510511
<x:String x:Key="Text.InteractiveRebase.Target" xml:space="preserve">Target Branch:</x:String>
511512
<x:String x:Key="Text.IssueLinkCM.CopyLink" xml:space="preserve">Copy Link</x:String>
512513
<x:String x:Key="Text.IssueLinkCM.OpenInBrowser" xml:space="preserve">Open in Browser</x:String>
514+
<x:String x:Key="Text.Launcher.Commands" xml:space="preserve">Commands</x:String>
513515
<x:String x:Key="Text.Launcher.Error" xml:space="preserve">ERROR</x:String>
514516
<x:String x:Key="Text.Launcher.Info" xml:space="preserve">NOTICE</x:String>
515517
<x:String x:Key="Text.Launcher.OpenRepository" xml:space="preserve">Open Repositories</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@
481481
<x:String x:Key="Text.Hotkeys.Repo.CommitWithAutoStage" xml:space="preserve">自动暂存全部变更并提交</x:String>
482482
<x:String x:Key="Text.Hotkeys.Repo.Fetch" xml:space="preserve">拉取 (fetch) 远程变更</x:String>
483483
<x:String x:Key="Text.Hotkeys.Repo.GoHome" xml:space="preserve">切换左边栏为分支/标签等显示模式(默认)</x:String>
484+
<x:String x:Key="Text.Hotkeys.Repo.OpenCommandPalette" xml:space="preserve">打开快捷命令面板</x:String>
484485
<x:String x:Key="Text.Hotkeys.Repo.OpenSearchCommits" xml:space="preserve">切换左边栏为提交搜索模式</x:String>
485486
<x:String x:Key="Text.Hotkeys.Repo.Pull" xml:space="preserve">拉回 (pull) 远程变更</x:String>
486487
<x:String x:Key="Text.Hotkeys.Repo.Push" xml:space="preserve">推送本地变更到远程</x:String>
@@ -514,6 +515,7 @@
514515
<x:String x:Key="Text.InteractiveRebase.Target" xml:space="preserve">目标分支 :</x:String>
515516
<x:String x:Key="Text.IssueLinkCM.CopyLink" xml:space="preserve">复制链接地址</x:String>
516517
<x:String x:Key="Text.IssueLinkCM.OpenInBrowser" xml:space="preserve">在浏览器中访问</x:String>
518+
<x:String x:Key="Text.Launcher.Commands" xml:space="preserve">命令列表</x:String>
517519
<x:String x:Key="Text.Launcher.Error" xml:space="preserve">出错了</x:String>
518520
<x:String x:Key="Text.Launcher.Info" xml:space="preserve">系统提示</x:String>
519521
<x:String x:Key="Text.Launcher.OpenRepository" xml:space="preserve">打开其他仓库</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@
481481
<x:String x:Key="Text.Hotkeys.Repo.CommitWithAutoStage" xml:space="preserve">自動暫存全部變更並提交</x:String>
482482
<x:String x:Key="Text.Hotkeys.Repo.Fetch" xml:space="preserve">提取 (fetch) 遠端的變更</x:String>
483483
<x:String x:Key="Text.Hotkeys.Repo.GoHome" xml:space="preserve">切換左邊欄為分支/標籤等顯示模式 (預設)</x:String>
484+
<x:String x:Key="Text.Hotkeys.Repo.OpenCommandPalette" xml:space="preserve">開啟命令面板</x:String>
484485
<x:String x:Key="Text.Hotkeys.Repo.OpenSearchCommits" xml:space="preserve">切換左邊欄為歷史搜尋模式</x:String>
485486
<x:String x:Key="Text.Hotkeys.Repo.Pull" xml:space="preserve">拉取 (pull) 遠端的變更</x:String>
486487
<x:String x:Key="Text.Hotkeys.Repo.Push" xml:space="preserve">推送 (push) 本機變更到遠端存放庫</x:String>
@@ -514,6 +515,7 @@
514515
<x:String x:Key="Text.InteractiveRebase.Target" xml:space="preserve">目標分支:</x:String>
515516
<x:String x:Key="Text.IssueLinkCM.CopyLink" xml:space="preserve">複製連結</x:String>
516517
<x:String x:Key="Text.IssueLinkCM.OpenInBrowser" xml:space="preserve">在瀏覽器中開啟連結</x:String>
518+
<x:String x:Key="Text.Launcher.Commands" xml:space="preserve">命令列表</x:String>
517519
<x:String x:Key="Text.Launcher.Error" xml:space="preserve">發生錯誤</x:String>
518520
<x:String x:Key="Text.Launcher.Info" xml:space="preserve">系統提示</x:String>
519521
<x:String x:Key="Text.Launcher.OpenRepository" xml:space="preserve">開啟存放庫</x:String>
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
using Avalonia.Threading;
5+
using CommunityToolkit.Mvvm.ComponentModel;
6+
7+
namespace SourceGit.ViewModels
8+
{
9+
public class BlameCommandPalette : ObservableObject, IDisposable
10+
{
11+
public bool IsLoading
12+
{
13+
get => _isLoading;
14+
private set => SetProperty(ref _isLoading, value);
15+
}
16+
17+
public List<string> VisibleFiles
18+
{
19+
get => _visibleFiles;
20+
private set => SetProperty(ref _visibleFiles, value);
21+
}
22+
23+
public string Filter
24+
{
25+
get => _filter;
26+
set
27+
{
28+
if (SetProperty(ref _filter, value))
29+
UpdateVisible();
30+
}
31+
}
32+
33+
public string SelectedFile
34+
{
35+
get => _selectedFile;
36+
set => SetProperty(ref _selectedFile, value);
37+
}
38+
39+
public BlameCommandPalette(Launcher launcher, string repo)
40+
{
41+
_launcher = launcher;
42+
_repo = repo;
43+
_isLoading = true;
44+
45+
Task.Run(async () =>
46+
{
47+
var files = await new Commands.QueryRevisionFileNames(_repo, "HEAD")
48+
.GetResultAsync()
49+
.ConfigureAwait(false);
50+
51+
var head = await new Commands.QuerySingleCommit(_repo, "HEAD")
52+
.GetResultAsync()
53+
.ConfigureAwait(false);
54+
55+
Dispatcher.UIThread.Post(() =>
56+
{
57+
IsLoading = false;
58+
_repoFiles = files;
59+
_head = head;
60+
UpdateVisible();
61+
});
62+
});
63+
}
64+
65+
public void Dispose()
66+
{
67+
_launcher = null;
68+
_repo = null;
69+
_head = null;
70+
_repoFiles.Clear();
71+
_filter = null;
72+
_visibleFiles.Clear();
73+
_selectedFile = null;
74+
}
75+
76+
public void ClearFilter()
77+
{
78+
Filter = string.Empty;
79+
}
80+
81+
public void Launch()
82+
{
83+
if (!string.IsNullOrEmpty(_selectedFile))
84+
App.ShowWindow(new Blame(_repo, _selectedFile, _head));
85+
_launcher.CancelCommandPalette();
86+
}
87+
88+
private void UpdateVisible()
89+
{
90+
if (_repoFiles is { Count: > 0 })
91+
{
92+
if (string.IsNullOrEmpty(_filter))
93+
{
94+
VisibleFiles = _repoFiles;
95+
}
96+
else
97+
{
98+
var visible = new List<string>();
99+
foreach (var f in _repoFiles)
100+
{
101+
if (f.Contains(_filter, StringComparison.OrdinalIgnoreCase))
102+
visible.Add(f);
103+
}
104+
VisibleFiles = visible;
105+
}
106+
}
107+
}
108+
109+
private Launcher _launcher = null;
110+
private string _repo = null;
111+
private bool _isLoading = false;
112+
private Models.Commit _head = null;
113+
private List<string> _repoFiles = null;
114+
private string _filter = string.Empty;
115+
private List<string> _visibleFiles = [];
116+
private string _selectedFile = null;
117+
}
118+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
using Avalonia.Threading;
5+
using CommunityToolkit.Mvvm.ComponentModel;
6+
7+
namespace SourceGit.ViewModels
8+
{
9+
public class FileHistoryCommandPalette : ObservableObject, IDisposable
10+
{
11+
public bool IsLoading
12+
{
13+
get => _isLoading;
14+
private set => SetProperty(ref _isLoading, value);
15+
}
16+
17+
public List<string> VisibleFiles
18+
{
19+
get => _visibleFiles;
20+
private set => SetProperty(ref _visibleFiles, value);
21+
}
22+
23+
public string Filter
24+
{
25+
get => _filter;
26+
set
27+
{
28+
if (SetProperty(ref _filter, value))
29+
UpdateVisible();
30+
}
31+
}
32+
33+
public string SelectedFile
34+
{
35+
get => _selectedFile;
36+
set => SetProperty(ref _selectedFile, value);
37+
}
38+
39+
public FileHistoryCommandPalette(Launcher launcher, string repo)
40+
{
41+
_launcher = launcher;
42+
_repo = repo;
43+
_isLoading = true;
44+
45+
Task.Run(async () =>
46+
{
47+
var files = await new Commands.QueryRevisionFileNames(_repo, "HEAD")
48+
.GetResultAsync()
49+
.ConfigureAwait(false);
50+
51+
Dispatcher.UIThread.Post(() =>
52+
{
53+
IsLoading = false;
54+
_repoFiles = files;
55+
UpdateVisible();
56+
});
57+
});
58+
}
59+
60+
public void Dispose()
61+
{
62+
_launcher = null;
63+
_repo = null;
64+
_repoFiles.Clear();
65+
_filter = null;
66+
_visibleFiles.Clear();
67+
_selectedFile = null;
68+
}
69+
70+
public void ClearFilter()
71+
{
72+
Filter = string.Empty;
73+
}
74+
75+
public void Launch()
76+
{
77+
if (!string.IsNullOrEmpty(_selectedFile))
78+
App.ShowWindow(new FileHistories(_repo, _selectedFile));
79+
_launcher.CancelCommandPalette();
80+
}
81+
82+
private void UpdateVisible()
83+
{
84+
if (_repoFiles is { Count: > 0 })
85+
{
86+
if (string.IsNullOrEmpty(_filter))
87+
{
88+
VisibleFiles = _repoFiles;
89+
}
90+
else
91+
{
92+
var visible = new List<string>();
93+
foreach (var f in _repoFiles)
94+
{
95+
if (f.Contains(_filter, StringComparison.OrdinalIgnoreCase))
96+
visible.Add(f);
97+
}
98+
VisibleFiles = visible;
99+
}
100+
}
101+
}
102+
103+
private Launcher _launcher = null;
104+
private string _repo = null;
105+
private bool _isLoading = false;
106+
private List<string> _repoFiles = null;
107+
private string _filter = string.Empty;
108+
private List<string> _visibleFiles = [];
109+
private string _selectedFile = null;
110+
}
111+
}

src/ViewModels/LauncherPagesCommandPalette.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void OpenOrSwitchTo()
8484
else if (_selectedRepo != null)
8585
_launcher.OpenRepositoryInTab(_selectedRepo, null);
8686

87-
_launcher.CancelCommandPalette();
87+
_launcher?.CancelCommandPalette();
8888
}
8989

9090
private void UpdateVisible()

0 commit comments

Comments
 (0)