feature: hotkeys enhancement. see issue #19

This commit is contained in:
leo 2024-03-05 10:46:08 +08:00
parent b309c1c346
commit acb74a4b95
8 changed files with 167 additions and 13 deletions

View file

@ -83,4 +83,5 @@
<StreamGeometry x:Key="Icons.Empty">M469 235V107h85v128h-85zm-162-94 85 85-60 60-85-85 60-60zm469 60-85 85-60-60 85-85 60 60zm-549 183A85 85 0 01302 341H722a85 85 0 0174 42l131 225A85 85 0 01939 652V832a85 85 0 01-85 85H171a85 85 0 01-85-85v-180a85 85 0 0112-43l131-225zM722 427H302l-100 171h255l10 29a59 59 0 002 5c2 4 5 9 9 14 8 9 18 17 34 17 16 0 26-7 34-17a72 72 0 0011-18l0-0 10-29h255l-100-171zM853 683H624a155 155 0 01-12 17C593 722 560 747 512 747c-48 0-81-25-99-47a155 155 0 01-12-17H171v149h683v-149z</StreamGeometry>
<StreamGeometry x:Key="Icons.VSCode">M719 85 388 417l-209-165L87 299v427l92 47 210-164L720 939 939 850V171zM186 610V412l104 104zm526 55L514 512l198-153z</StreamGeometry>
<StreamGeometry x:Key="Icons.Statistics">M296 912H120c-4.4 0-8-3.6-8-8V520c0-4.4 3.6-8 8-8h176c4.4 0 8 3.6 8 8v384c0 4.4-3.6 8-8 8zM600 912H424c-4.4 0-8-3.6-8-8V121c0-4.4 3.6-8 8-8h176c4.4 0 8 3.6 8 8v783c0 4.4-3.6 8-8 8zM904 912H728c-4.4 0-8-3.6-8-8V280c0-4.4 3.6-8 8-8h176c4.4 0 8 3.6 8 8v624c0 4.4-3.6 8-8 8z</StreamGeometry>
<StreamGeometry x:Key="Icons.Hotkeys">M512 0C229.216 0 0 229.216 0 512c0 282.752 229.216 512 512 512s512-229.248 512-512c0-282.784-229.216-512-512-512z m0 957.92C266.112 957.92 66.08 757.888 66.08 512S266.112 66.08 512 66.08 957.92 266.112 957.92 512 757.888 957.92 512 957.92zM192 416h96a32 32 0 0 0 32-32v-32a32 32 0 0 0-32-32H192a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32zM384 416h96a32 32 0 0 0 32-32v-32a32 32 0 0 0-32-32h-96a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32zM576 416h96a32 32 0 0 0 32-32v-32a32 32 0 0 0-32-32h-96a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32zM832 320h-64a32 32 0 0 0-32 32v128h-160a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32h256a32 32 0 0 0 32-32v-192a32 32 0 0 0-32-32zM320 544v-32a32 32 0 0 0-32-32H192a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32h96a32 32 0 0 0 32-32zM384 576h96a32 32 0 0 0 32-32v-32a32 32 0 0 0-32-32h-96a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32zM800 640H256a32 32 0 0 0-32 32v32a32 32 0 0 0 32 32h544a32 32 0 0 0 32-32v-32a32 32 0 0 0-32-32z</StreamGeometry>
</ResourceDictionary>

View file

@ -470,6 +470,19 @@
<sys:String x:Key="Text.Statistics.Committer">COMMITTER</sys:String>
<sys:String x:Key="Text.Statistics.CommitAmount">COMMITS</sys:String>
<sys:String x:Key="Text.Hotkeys">HotKeys</sys:String>
<sys:String x:Key="Text.Hotkeys.Global">GLOBAL</sys:String>
<sys:String x:Key="Text.Hotkeys.Global.NewTab">Create new page</sys:String>
<sys:String x:Key="Text.Hotkeys.Global.CloseTab">Close current page</sys:String>
<sys:String x:Key="Text.Hotkeys.Global.GotoNextTab">Go to next page</sys:String>
<sys:String x:Key="Text.Hotkeys.Global.CancelPopup">Cancel current popup</sys:String>
<sys:String x:Key="Text.Hotkeys.Repo">REPOSITORY</sys:String>
<sys:String x:Key="Text.Hotkeys.Repo.ViewHistories">Switch to 'Histories'</sys:String>
<sys:String x:Key="Text.Hotkeys.Repo.ViewChanges">Switch to 'Changes'</sys:String>
<sys:String x:Key="Text.Hotkeys.Repo.ViewStashes">Switch to 'Stashes'</sys:String>
<sys:String x:Key="Text.Hotkeys.Repo.ToggleSearch">Toggle commit search</sys:String>
<sys:String x:Key="Text.Hotkeys.Repo.StageOrUnstageSelected">Stage/Unstage selected changes</sys:String>
<sys:String x:Key="Text.NotConfigured">Git has NOT been configured. Please to go [Preference] and configure it first.</sys:String>
<sys:String x:Key="Text.BinaryNotSupported">BINARY FILE NOT SUPPORTED!!!</sys:String>
<sys:String x:Key="Text.BlameTypeNotSupported">BLAME ON THIS FILE IS NOT SUPPORTED!!!</sys:String>

View file

@ -469,6 +469,19 @@
<sys:String x:Key="Text.Statistics.Committer">提交者</sys:String>
<sys:String x:Key="Text.Statistics.CommitAmount">提交次数</sys:String>
<sys:String x:Key="Text.Hotkeys">快捷键</sys:String>
<sys:String x:Key="Text.Hotkeys.Global">全局快捷键</sys:String>
<sys:String x:Key="Text.Hotkeys.Global.NewTab">新建页面</sys:String>
<sys:String x:Key="Text.Hotkeys.Global.CloseTab">关闭当前页面</sys:String>
<sys:String x:Key="Text.Hotkeys.Global.GotoNextTab">切换到下一个页面</sys:String>
<sys:String x:Key="Text.Hotkeys.Global.CancelPopup">取消弹出面板</sys:String>
<sys:String x:Key="Text.Hotkeys.Repo">仓库页面快捷键</sys:String>
<sys:String x:Key="Text.Hotkeys.Repo.ViewHistories">显示历史记录</sys:String>
<sys:String x:Key="Text.Hotkeys.Repo.ViewChanges">显示本地更改</sys:String>
<sys:String x:Key="Text.Hotkeys.Repo.ViewStashes">显示贮藏列表</sys:String>
<sys:String x:Key="Text.Hotkeys.Repo.ToggleSearch">打开/关闭历史搜索</sys:String>
<sys:String x:Key="Text.Hotkeys.Repo.StageOrUnstageSelected">将选中的变更暂存或从暂存列表中移除</sys:String>
<sys:String x:Key="Text.NotConfigured">GIT尚未配置。请打开【偏好设置】配置GIT路径。</sys:String>
<sys:String x:Key="Text.BinaryNotSupported">二进制文件不支持该操作!!!</sys:String>
<sys:String x:Key="Text.BlameTypeNotSupported">选中文件不支持该操作!!!</sys:String>

92
src/Views/Hotkeys.axaml Normal file
View file

@ -0,0 +1,92 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:SourceGit.ViewModels"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.Hotkeys"
Icon="/App.ico"
Title="{DynamicResource Text.Hotkeys}"
Background="{DynamicResource Brush.Window}"
SizeToContent="WidthAndHeight"
CanResize="False"
WindowStartupLocation="CenterOwner"
ExtendClientAreaToDecorationsHint="True"
ExtendClientAreaChromeHints="NoChrome">
<Grid RowDefinitions="30,*">
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto">
<Path Grid.Column="0"
Width="14" Height="14"
Margin="10,0,0,0"
Data="{StaticResource Icons.Hotkeys}"
IsVisible="{Binding Source={x:Static vm:Preference.Instance}, Path=UseMacOSStyle, Converter={x:Static BoolConverters.Not}}"/>
<Grid Grid.Column="0" Classes="caption_button_box" Margin="2,4,0,0" IsVisible="{Binding Source={x:Static vm:Preference.Instance}, Path=UseMacOSStyle}">
<Button Classes="caption_button_macos" Click="CloseWindow">
<Grid>
<Ellipse Fill="{DynamicResource Brush.MacOS.Close}"/>
<Path Height="6" Width="6" Stretch="Fill" Fill="#404040" Stroke="#404040" StrokeThickness="1" Data="{StaticResource Icons.Window.Close}"/>
</Grid>
</Button>
</Grid>
<TextBlock Grid.Column="0" Grid.ColumnSpan="3"
Classes="bold"
Text="{DynamicResource Text.Hotkeys}"
HorizontalAlignment="Center" VerticalAlignment="Center"
IsHitTestVisible="False"/>
<Button Grid.Column="2"
Classes="caption_button"
Click="CloseWindow"
IsVisible="{Binding Source={x:Static vm:Preference.Instance}, Path=UseMacOSStyle, Converter={x:Static BoolConverters.Not}}">
<Path Data="{StaticResource Icons.Window.Close}"/>
</Button>
</Grid>
<StackPanel Grid.Row="1" Orientation="Vertical" Margin="16,8,16,16">
<TextBlock Text="{DynamicResource Text.Hotkeys.Global}"
Foreground="{DynamicResource Brush.FG2}"
FontWeight="Bold"
FontSize="13"
Margin="0,0,0,8"/>
<Grid RowDefinitions="Auto,Auto,Auto,Auto" ColumnDefinitions="Auto,*">
<TextBlock Grid.Row="0" Grid.Column="0" Text="Ctrl+T" FontFamily="{StaticResource JetBrainsMono}"/>
<TextBlock Grid.Row="0" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.NewTab}" />
<TextBlock Grid.Row="1" Grid.Column="0" Text="Ctrl+W" FontFamily="{StaticResource JetBrainsMono}"/>
<TextBlock Grid.Row="1" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.CloseTab}" />
<TextBlock Grid.Row="2" Grid.Column="0" Text="Ctrl+Tab" FontFamily="{StaticResource JetBrainsMono}"/>
<TextBlock Grid.Row="2" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.GotoNextTab}" />
<TextBlock Grid.Row="3" Grid.Column="0" Text="ESC" FontFamily="{StaticResource JetBrainsMono}"/>
<TextBlock Grid.Row="3" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.CancelPopup}" />
</Grid>
<TextBlock Text="{DynamicResource Text.Hotkeys.Repo}"
Foreground="{DynamicResource Brush.FG2}"
FontWeight="Bold"
FontSize="13"
Margin="0,8"/>
<Grid RowDefinitions="Auto,Auto,Auto,Auto,Auto" ColumnDefinitions="Auto,*">
<TextBlock Grid.Row="0" Grid.Column="0" Text="Ctrl+F" FontFamily="{StaticResource JetBrainsMono}"/>
<TextBlock Grid.Row="0" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.ToggleSearch}" />
<TextBlock Grid.Row="1" Grid.Column="0" Text="Ctrl+1" FontFamily="{StaticResource JetBrainsMono}"/>
<TextBlock Grid.Row="1" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.ViewHistories}" />
<TextBlock Grid.Row="2" Grid.Column="0" Text="Ctrl+2" FontFamily="{StaticResource JetBrainsMono}"/>
<TextBlock Grid.Row="2" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.ViewChanges}" />
<TextBlock Grid.Row="3" Grid.Column="0" Text="Ctrl+3" FontFamily="{StaticResource JetBrainsMono}"/>
<TextBlock Grid.Row="3" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.ViewStashes}" />
<TextBlock Grid.Row="4" Grid.Column="0" Text="SPACE" FontFamily="{StaticResource JetBrainsMono}"/>
<TextBlock Grid.Row="4" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.StageOrUnstageSelected}" />
</Grid>
</StackPanel>
</Grid>
</Window>

View file

@ -0,0 +1,14 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
namespace SourceGit.Views {
public partial class Hotkeys : Window {
public Hotkeys() {
InitializeComponent();
}
private void CloseWindow(object sender, RoutedEventArgs e) {
Close();
}
}
}

View file

@ -47,6 +47,11 @@
<Path Width="14" Height="14" Data="{StaticResource Icons.Settings2}"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="{DynamicResource Text.Hotkeys}" Click="OpenHotkeys">
<MenuItem.Icon>
<Path Width="14" Height="14" Data="{StaticResource Icons.Hotkeys}"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="{DynamicResource Text.About}" Click="OpenAboutDialog">
<MenuItem.Icon>
<Path Width="14" Height="14" Data="{StaticResource Icons.Info}"/>
@ -212,6 +217,10 @@
<Path Width="16" Height="16" Data="{StaticResource Icons.Settings2}"/>
</Button>
<Button Classes="icon_button" Width="32" Height="28" Click="OpenHotkeys" ToolTip.Tip="{DynamicResource Text.Hotkeys}">
<Path Width="16" Height="16" Data="{StaticResource Icons.Hotkeys}"/>
</Button>
<Button Classes="icon_button" Width="32" Height="28" Click="OpenAboutDialog" ToolTip.Tip="{DynamicResource Text.About}">
<Path Width="16" Height="16" Data="{StaticResource Icons.Info}"/>
</Button>

View file

@ -82,6 +82,24 @@ namespace SourceGit.Views {
vm.GotoNextTab();
e.Handled = true;
return;
} else if (vm.ActivePage.Data is ViewModels.Repository repo) {
if (e.Key == Key.D1 || e.Key == Key.NumPad1) {
repo.SelectedViewIndex = 0;
e.Handled = true;
return;
} else if (e.Key == Key.D2 || e.Key == Key.NumPad2) {
repo.SelectedViewIndex = 1;
e.Handled = true;
return;
} else if (e.Key == Key.D3 || e.Key == Key.NumPad3) {
repo.SelectedViewIndex = 2;
e.Handled = true;
return;
} else if (e.Key == Key.F) {
repo.IsSearching = !repo.IsSearching;
e.Handled = true;
return;
}
}
} else if (e.Key == Key.Escape) {
vm.ActivePage.CancelPopup();
@ -213,6 +231,12 @@ namespace SourceGit.Views {
e.Handled = true;
}
private async void OpenHotkeys(object sender, RoutedEventArgs e) {
var dialog = new Hotkeys();
await dialog.ShowDialog(this);
e.Handled = true;
}
private async void OpenAboutDialog(object sender, RoutedEventArgs e) {
var dialog = new About();
await dialog.ShowDialog(this);

View file

@ -45,18 +45,6 @@ namespace SourceGit.Views {
InitializeComponent();
}
protected override void OnKeyDown(KeyEventArgs e) {
if (e.Key == Key.F && e.KeyModifiers == KeyModifiers.Control) {
if (DataContext is ViewModels.Repository repo) {
repo.IsSearching = true;
e.Handled = true;
return;
}
}
base.OnKeyDown(e);
}
private void OnLocalBranchTreeLostFocus(object sender, RoutedEventArgs e) {
if (sender is TreeView tree) tree.UnselectAll();
}