feature<Launcher>: 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
This commit is contained in:
leo 2021-06-02 17:46:19 +08:00
parent c3b1b6d502
commit 7c98ed4990
5 changed files with 73 additions and 3 deletions

View file

@ -4,6 +4,7 @@
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="VirtualizingPanel.IsVirtualizing" Value="True"/>

View file

@ -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
}
}

View file

@ -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();

View file

@ -49,6 +49,7 @@
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="AllowDrop" Value="True"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">

View file

@ -114,6 +114,25 @@ namespace SourceGit.Views.Widgets {
return false;
}
public void Next() {
container.SelectedIndex = (container.SelectedIndex + 1) % Tabs.Count;
}
public void CloseCurrent() {
var curTab = container.SelectedItem as Tab;
if (Tabs.Count == 1) {
Application.Current.Shutdown();
} else {
var idx = container.SelectedIndex;
Tabs.Remove(curTab);
RaiseEvent(new TabEventArgs(TabClosedEvent, this, curTab.Id));
var next = Tabs[idx % Tabs.Count];
container.SelectedItem = next;
RaiseEvent(new TabEventArgs(TabSelectedEvent, this, next.Id));
}
}
private void CalcScrollerVisibilty(object sender, SizeChangedEventArgs e) {
if ((sender as StackPanel).ActualWidth > scroller.ActualWidth) {
leftScroller.Visibility = Visibility.Visible;
@ -143,8 +162,7 @@ namespace SourceGit.Views.Widgets {
}
private void CloseTab(object sender, RoutedEventArgs e) {
var btn = (sender as Button);
var tab = btn.DataContext as Tab;
var tab = (sender as Button).DataContext as Tab;
if (tab == null) return;
var curTab = container.SelectedItem as Tab;