From 7c98ed49902205fb6b3909fbdbc1781f9ba54aa0 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 2 Jun 2021 17:46:19 +0800 Subject: [PATCH] feature: add common hotkeys 1. `Ctrl + Tab` goto next page 2. `Ctrl + W` close current active page 3. `Ctrl + T` open new page 4. `Ctrl + F` open search bar if possible 5. `Ctrl + [0-9]` go to page at given index if possible 6. `F5` refresh current repository if possible --- src/Resources/Styles/ListBox.xaml | 1 + src/Views/Launcher.xaml.cs | 50 ++++++++++++++++++++++++++++ src/Views/Widgets/Dashboard.xaml.cs | 2 +- src/Views/Widgets/PageTabBar.xaml | 1 + src/Views/Widgets/PageTabBar.xaml.cs | 22 ++++++++++-- 5 files changed, 73 insertions(+), 3 deletions(-) diff --git a/src/Resources/Styles/ListBox.xaml b/src/Resources/Styles/ListBox.xaml index ee55ea0d..2fda7c79 100644 --- a/src/Resources/Styles/ListBox.xaml +++ b/src/Resources/Styles/ListBox.xaml @@ -4,6 +4,7 @@ + diff --git a/src/Views/Launcher.xaml.cs b/src/Views/Launcher.xaml.cs index 2f2d3964..6aff44de 100644 --- a/src/Views/Launcher.xaml.cs +++ b/src/Views/Launcher.xaml.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using System.Windows; +using System.Windows.Input; namespace SourceGit.Views { @@ -94,5 +95,54 @@ namespace SourceGit.Views { GC.Collect(); } #endregion + + #region HOTKEYS + protected override void OnPreviewKeyDown(KeyEventArgs e) { + if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) { + if (Keyboard.IsKeyDown(Key.Tab)) { + tabs.Next(); + e.Handled = true; + return; + } + + if (Keyboard.IsKeyDown(Key.W)) { + tabs.CloseCurrent(); + e.Handled = true; + return; + } + + if (Keyboard.IsKeyDown(Key.T)) { + OnTabAdding(null, null); + e.Handled = true; + return; + } + + if (Keyboard.IsKeyDown(Key.F)) { + var dashboard = container.Get(tabs.Current) as Widgets.Dashboard; + if (dashboard != null) { + dashboard.OpenSearch(null, null); + e.Handled = true; + return; + } + } + + for (int i = 0; i < 10; i++) { + if (Keyboard.IsKeyDown(Key.D1 + i)) { + if (tabs.Tabs.Count > i) { + tabs.Goto(tabs.Tabs[i].Id); + e.Handled = true; + return; + } + } + } + } + + if (Keyboard.IsKeyDown(Key.F5)) { + Models.Watcher.Get(tabs.Current)?.Refresh(); + e.Handled = true; + return; + } + } + #endregion } } diff --git a/src/Views/Widgets/Dashboard.xaml.cs b/src/Views/Widgets/Dashboard.xaml.cs index 0ed1c376..5a12e642 100644 --- a/src/Views/Widgets/Dashboard.xaml.cs +++ b/src/Views/Widgets/Dashboard.xaml.cs @@ -319,7 +319,7 @@ namespace SourceGit.Views.Widgets { e.Handled = true; } - private void OpenSearch(object sender, RoutedEventArgs e) { + public void OpenSearch(object sender, RoutedEventArgs e) { if (popup.IsLocked) return; popup.Close(); diff --git a/src/Views/Widgets/PageTabBar.xaml b/src/Views/Widgets/PageTabBar.xaml index c180eee3..55773d47 100644 --- a/src/Views/Widgets/PageTabBar.xaml +++ b/src/Views/Widgets/PageTabBar.xaml @@ -49,6 +49,7 @@