code_review: PR #657

* add hotkey `Ctrl+Down/⌘+Down` to fetch directly
* keep translation keys of en_US in order
* add translations for zh_CN and zh_TW
* do NOT using namespace under `SourceGit`
* use `⇧` instead of `Shift` in hotkey tips
* hotkey mismatch on macOS
* hotkeys to start fetch/pull/push directly not work on macOS
* remove the hotkey of `Create Branch` context menu item
   - there are other objects (such as branch and tag) also have the `Create Branch` context menu item without hotkeys
   - on macOS, we already use `⌘+B` to create branch with selected commit, not `Ctrl + B`

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2024-11-06 09:44:52 +08:00
parent dc49c1bf76
commit d50b2c0298
No known key found for this signature in database
10 changed files with 84 additions and 49 deletions

View file

@ -47,7 +47,7 @@
## Translation Status
[![en_US](https://img.shields.io/badge/en__US-100%25-brightgreen)](TRANSLATION.md) [![de__DE](https://img.shields.io/badge/de__DE-95.22%25-yellow)](TRANSLATION.md) [![es__ES](https://img.shields.io/badge/es__ES-99.57%25-yellow)](TRANSLATION.md) [![fr__FR](https://img.shields.io/badge/fr__FR-86.96%25-yellow)](TRANSLATION.md) [![pt__BR](https://img.shields.io/badge/pt__BR-90.00%25-yellow)](TRANSLATION.md) [![ru__RU](https://img.shields.io/badge/ru__RU-99.13%25-yellow)](TRANSLATION.md) [![zh__CN](https://img.shields.io/badge/zh__CN-99.57%25-yellow)](TRANSLATION.md) [![zh__TW](https://img.shields.io/badge/zh__TW-99.57%25-yellow)](TRANSLATION.md)
[![en_US](https://img.shields.io/badge/en__US-100%25-brightgreen)](TRANSLATION.md) [![de__DE](https://img.shields.io/badge/de__DE-95.08%25-yellow)](TRANSLATION.md) [![es__ES](https://img.shields.io/badge/es__ES-99.42%25-yellow)](TRANSLATION.md) [![fr__FR](https://img.shields.io/badge/fr__FR-86.83%25-yellow)](TRANSLATION.md) [![pt__BR](https://img.shields.io/badge/pt__BR-89.87%25-yellow)](TRANSLATION.md) [![ru__RU](https://img.shields.io/badge/ru__RU-98.99%25-yellow)](TRANSLATION.md) [![zh__CN](https://img.shields.io/badge/zh__CN-100.00%25-brightgreen)](TRANSLATION.md) [![zh__TW](https://img.shields.io/badge/zh__TW-100.00%25-brightgreen)](TRANSLATION.md)
## How to Use

View file

@ -1,4 +1,4 @@
### de_DE.axaml: 95.22%
### de_DE.axaml: 95.08%
<details>
@ -25,9 +25,10 @@
- Text.Diff.VisualLines.All
- Text.ExecuteCustomAction
- Text.ExecuteCustomAction.Name
- Text.Hotkeys.Repo.CreateBranchOnCommit
- Text.Hotkeys.Repo.Fetch
- Text.Hotkeys.Repo.Pull
- Text.Hotkeys.Repo.Push
- Text.Hotkeys.Repo.CreateBranchOnCommit
- Text.IssueLinkCM.OpenInBrowser
- Text.IssueLinkCM.CopyLink
- Text.Preference.AI.AnalyzeDiffPrompt
@ -40,19 +41,20 @@
</details>
### es_ES.axaml: 99.57%
### es_ES.axaml: 99.42%
<details>
<summary>Missing Keys</summary>
- Text.Hotkeys.Repo.CreateBranchOnCommit
- Text.Hotkeys.Repo.Fetch
- Text.Hotkeys.Repo.Pull
- Text.Hotkeys.Repo.Push
- Text.Hotkeys.Repo.CreateBranchOnCommit
</details>
### fr_FR.axaml: 86.96%
### fr_FR.axaml: 86.83%
<details>
@ -108,10 +110,11 @@
- Text.Histories.Tips.MacOS
- Text.Histories.Tips.Prefix
- Text.Hotkeys.Repo.CommitWithAutoStage
- Text.Hotkeys.Repo.CreateBranchOnCommit
- Text.Hotkeys.Repo.DiscardSelected
- Text.Hotkeys.Repo.Fetch
- Text.Hotkeys.Repo.Pull
- Text.Hotkeys.Repo.Push
- Text.Hotkeys.Repo.CreateBranchOnCommit
- Text.IssueLinkCM.OpenInBrowser
- Text.IssueLinkCM.CopyLink
- Text.MoveRepositoryNode
@ -151,7 +154,7 @@
</details>
### pt_BR.axaml: 90.00%
### pt_BR.axaml: 89.87%
<details>
@ -205,9 +208,10 @@
- Text.FileHistory.FileContent
- Text.FileHistory.FileChange
- Text.GitLFS.Locks.OnlyMine
- Text.Hotkeys.Repo.CreateBranchOnCommit
- Text.Hotkeys.Repo.Fetch
- Text.Hotkeys.Repo.Pull
- Text.Hotkeys.Repo.Push
- Text.Hotkeys.Repo.CreateBranchOnCommit
- Text.IssueLinkCM.OpenInBrowser
- Text.IssueLinkCM.CopyLink
- Text.MoveRepositoryNode
@ -229,41 +233,38 @@
</details>
### ru_RU.axaml: 99.13%
### ru_RU.axaml: 98.99%
<details>
<summary>Missing Keys</summary>
- Text.Diff.VisualLines.All
- Text.Hotkeys.Repo.CreateBranchOnCommit
- Text.Hotkeys.Repo.Fetch
- Text.Hotkeys.Repo.Pull
- Text.Hotkeys.Repo.Push
- Text.Hotkeys.Repo.CreateBranchOnCommit
- Text.IssueLinkCM.OpenInBrowser
- Text.IssueLinkCM.CopyLink
</details>
### zh_CN.axaml: 99.57%
### zh_CN.axaml: 100.00%
<details>
<summary>Missing Keys</summary>
- Text.Hotkeys.Repo.Pull
- Text.Hotkeys.Repo.Push
- Text.Hotkeys.Repo.CreateBranchOnCommit
</details>
### zh_TW.axaml: 99.57%
### zh_TW.axaml: 100.00%
<details>
<summary>Missing Keys</summary>
- Text.Hotkeys.Repo.Pull
- Text.Hotkeys.Repo.Push
- Text.Hotkeys.Repo.CreateBranchOnCommit
</details>

View file

@ -363,17 +363,18 @@
<x:String x:Key="Text.Hotkeys.Repo.Commit" xml:space="preserve">Commit staged changes</x:String>
<x:String x:Key="Text.Hotkeys.Repo.CommitAndPush" xml:space="preserve">Commit and push staged changes</x:String>
<x:String x:Key="Text.Hotkeys.Repo.CommitWithAutoStage" xml:space="preserve">Stage all changes and commit</x:String>
<x:String x:Key="Text.Hotkeys.Repo.CreateBranchOnCommit" xml:space="preserve">Creates a new branch based on selected commit</x:String>
<x:String x:Key="Text.Hotkeys.Repo.DiscardSelected" xml:space="preserve">Discard selected changes</x:String>
<x:String x:Key="Text.Hotkeys.Repo.Fetch" xml:space="preserve">Fetch, starts directly</x:String>
<x:String x:Key="Text.Hotkeys.Repo.GoHome" xml:space="preserve">Dashboard mode (Default)</x:String>
<x:String x:Key="Text.Hotkeys.Repo.Pull" xml:space="preserve">Pull, starts directly</x:String>
<x:String x:Key="Text.Hotkeys.Repo.Push" xml:space="preserve">Push, starts directly</x:String>
<x:String x:Key="Text.Hotkeys.Repo.Refresh" xml:space="preserve">Force to reload this repository</x:String>
<x:String x:Key="Text.Hotkeys.Repo.StageOrUnstageSelected" xml:space="preserve">Stage/Unstage selected changes</x:String>
<x:String x:Key="Text.Hotkeys.Repo.OpenSearchCommits" xml:space="preserve">Commit search mode</x:String>
<x:String x:Key="Text.Hotkeys.Repo.ViewChanges" xml:space="preserve">Switch to 'Changes'</x:String>
<x:String x:Key="Text.Hotkeys.Repo.ViewHistories" xml:space="preserve">Switch to 'Histories'</x:String>
<x:String x:Key="Text.Hotkeys.Repo.ViewStashes" xml:space="preserve">Switch to 'Stashes'</x:String>
<x:String x:Key="Text.Hotkeys.Repo.Pull" xml:space="preserve">Pull, starts directly</x:String>
<x:String x:Key="Text.Hotkeys.Repo.Push" xml:space="preserve">Push, starts directly</x:String>
<x:String x:Key="Text.Hotkeys.Repo.CreateBranchOnCommit" xml:space="preserve">Creates a new branch based on selected commit</x:String>
<x:String x:Key="Text.Hotkeys.TextEditor" xml:space="preserve">TEXT EDITOR</x:String>
<x:String x:Key="Text.Hotkeys.TextEditor.CloseSearch" xml:space="preserve">Close search panel</x:String>
<x:String x:Key="Text.Hotkeys.TextEditor.GotoNextMatch" xml:space="preserve">Find next match</x:String>

View file

@ -366,8 +366,12 @@
<x:String x:Key="Text.Hotkeys.Repo.Commit" xml:space="preserve">提交暂存区更改</x:String>
<x:String x:Key="Text.Hotkeys.Repo.CommitAndPush" xml:space="preserve">提交暂存区更改并推送</x:String>
<x:String x:Key="Text.Hotkeys.Repo.CommitWithAutoStage" xml:space="preserve">自动暂存全部变更并提交</x:String>
<x:String x:Key="Text.Hotkeys.Repo.CreateBranchOnCommit" xml:space="preserve">基于选中提交创建新分支</x:String>
<x:String x:Key="Text.Hotkeys.Repo.DiscardSelected" xml:space="preserve">丢弃选中的更改</x:String>
<x:String x:Key="Text.Hotkeys.Repo.Fetch" xml:space="preserve">拉取 (fetch) 远程变更</x:String>
<x:String x:Key="Text.Hotkeys.Repo.GoHome" xml:space="preserve">切换左边栏为分支/标签等显示模式(默认)</x:String>
<x:String x:Key="Text.Hotkeys.Repo.Pull" xml:space="preserve">拉回 (pull) 远程变更</x:String>
<x:String x:Key="Text.Hotkeys.Repo.Push" xml:space="preserve">推送本地变更到远程</x:String>
<x:String x:Key="Text.Hotkeys.Repo.Refresh" xml:space="preserve">重新加载仓库状态</x:String>
<x:String x:Key="Text.Hotkeys.Repo.StageOrUnstageSelected" xml:space="preserve">将选中的变更暂存或从暂存列表中移除</x:String>
<x:String x:Key="Text.Hotkeys.Repo.OpenSearchCommits" xml:space="preserve">切换左边栏为提交搜索模式</x:String>

View file

@ -366,8 +366,12 @@
<x:String x:Key="Text.Hotkeys.Repo.Commit" xml:space="preserve">提交暫存區變更</x:String>
<x:String x:Key="Text.Hotkeys.Repo.CommitAndPush" xml:space="preserve">提交暫存區變更並推送</x:String>
<x:String x:Key="Text.Hotkeys.Repo.CommitWithAutoStage" xml:space="preserve">自動暫存全部變更並提交</x:String>
<x:String x:Key="Text.Hotkeys.Repo.CreateBranchOnCommit" xml:space="preserve">根據選取的提交建立新的分支</x:String>
<x:String x:Key="Text.Hotkeys.Repo.DiscardSelected" xml:space="preserve">捨棄選取的變更</x:String>
<x:String x:Key="Text.Hotkeys.Repo.Fetch" xml:space="preserve">提取 (fetch) 遠端的變更</x:String>
<x:String x:Key="Text.Hotkeys.Repo.GoHome" xml:space="preserve">切換左邊欄為分支/標籤等顯示模式 (預設)</x:String>
<x:String x:Key="Text.Hotkeys.Repo.Pull" xml:space="preserve">拉取 (pull) 遠端的變更</x:String>
<x:String x:Key="Text.Hotkeys.Repo.Push" xml:space="preserve">推送 (push) 本地變更到遠端存放庫</x:String>
<x:String x:Key="Text.Hotkeys.Repo.Refresh" xml:space="preserve">強制重新載入存放庫</x:String>
<x:String x:Key="Text.Hotkeys.Repo.StageOrUnstageSelected" xml:space="preserve">暫存或取消暫存選取的變更</x:String>
<x:String x:Key="Text.Hotkeys.Repo.OpenSearchCommits" xml:space="preserve">切換左邊欄為歷史搜尋模式</x:String>

View file

@ -4,7 +4,6 @@ using System.Collections.Generic;
using System.Text;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Platform.Storage;
using CommunityToolkit.Mvvm.ComponentModel;
@ -545,7 +544,6 @@ namespace SourceGit.ViewModels
var createBranch = new MenuItem();
createBranch.Icon = App.CreateMenuIcon("Icons.Branch.Add");
createBranch.Header = App.Text("CreateBranch");
createBranch.HotKey = new KeyGesture(Key.B, KeyModifiers.Control);
createBranch.Click += (_, e) =>
{
if (PopupHost.CanCreatePopup())

View file

@ -12,7 +12,6 @@ using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.Threading;
using Avalonia.VisualTree;
using SourceGit.ViewModels;
namespace SourceGit.Views
{
@ -723,11 +722,15 @@ namespace SourceGit.Views
private void OnCommitListKeyDown(object sender, KeyEventArgs e)
{
bool isSystemCmdKeyDown = (OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Meta)) ||
(!OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Control));
if (!isSystemCmdKeyDown)
return;
// These shortcuts are not mentioned in the Shortcut Reference window. Is this expected?
if (sender is ListBox { SelectedItems: { Count: > 0 } selected } &&
e.KeyModifiers.HasFlag(KeyModifiers.Control))
if (sender is ListBox { SelectedItems: { Count: > 0 } selected })
{
// CTRL + C -> Copy selected commit SHA and subject.
// CTRL/COMMAND + C -> Copy selected commit SHA and subject.
if (e.Key == Key.C)
{
var builder = new StringBuilder();
@ -742,17 +745,16 @@ namespace SourceGit.Views
return;
}
// CTRL + B -> shows Create Branch pop-up at selected commit.
// CTRL/COMMAND + B -> shows Create Branch pop-up at selected commit.
if (e.Key == Key.B)
{
if (selected.Count == 1 &&
selected[0] is Models.Commit commit &&
DataContext is ViewModels.Histories histories &&
PopupHost.CanCreatePopup())
ViewModels.PopupHost.CanCreatePopup())
{
PopupHost.ShowPopup(new ViewModels.CreateBranch(histories.Repo, commit));
ViewModels.PopupHost.ShowPopup(new ViewModels.CreateBranch(histories.Repo, commit));
e.Handled = true;
}
}
}

View file

@ -71,7 +71,7 @@
FontSize="{Binding Source={x:Static vm:Preference.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Increase}}"
Margin="0,8"/>
<Grid RowDefinitions="20,20,20,20,20,20,20,20,20,20,20,20,20,20" ColumnDefinitions="150,*">
<Grid RowDefinitions="20,20,20,20,20,20,20,20,20,20,20,20,20,20,20" ColumnDefinitions="150,*">
<TextBlock Grid.Row="0" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Ctrl+Shift+H, macOS=⌘+⇧+H}"/>
<TextBlock Grid.Row="0" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.GoHome}" />
@ -102,17 +102,20 @@
<TextBlock Grid.Row="9" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Alt+Enter, macOS=⌥+Enter}"/>
<TextBlock Grid.Row="9" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.CommitAndPush}" />
<TextBlock Grid.Row="10" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Ctrl+Shift+Down, macOS=⌘+Shift+Down}"/>
<TextBlock Grid.Row="10" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.Pull}" />
<TextBlock Grid.Row="10" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Ctrl+Down, macOS=⌘+Down}"/>
<TextBlock Grid.Row="10" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.Fetch}" />
<TextBlock Grid.Row="11" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Ctrl+Shift+Up, macOS=⌘+Shift+Up}"/>
<TextBlock Grid.Row="11" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.Push}" />
<TextBlock Grid.Row="11" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Ctrl+Shift+Down, macOS=⌘+⇧+Down}"/>
<TextBlock Grid.Row="11" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.Pull}" />
<TextBlock Grid.Row="12" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Ctrl+B, macOS=⌘+B}"/>
<TextBlock Grid.Row="12" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.CreateBranchOnCommit}" />
<TextBlock Grid.Row="12" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Ctrl+Shift+Up, macOS=⌘+⇧+Up}"/>
<TextBlock Grid.Row="12" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.Push}" />
<TextBlock Grid.Row="13" Grid.Column="0" Classes="primary bold" Text="F5"/>
<TextBlock Grid.Row="13" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.Refresh}" />
<TextBlock Grid.Row="13" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Ctrl+B, macOS=⌘+B}"/>
<TextBlock Grid.Row="13" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.CreateBranchOnCommit}" />
<TextBlock Grid.Row="14" Grid.Column="0" Classes="primary bold" Text="F5"/>
<TextBlock Grid.Row="14" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.Refresh}" />
</Grid>
<TextBlock Text="{DynamicResource Text.Hotkeys.TextEditor}"

View file

@ -31,7 +31,7 @@
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<Button Classes="icon_button" Width="32" Click="Fetch">
<Button Classes="icon_button" Width="32" Click="Fetch" HotKey="{OnPlatform Ctrl+Down, macOS=⌘+Down}">
<ToolTip.Tip>
<StackPanel Orientation="Vertical">
<TextBlock Text="{DynamicResource Text.Fetch}"/>
@ -85,7 +85,6 @@
Fill="{DynamicResource Brush.Border2}"/>
<Button Classes="icon_button" Width="32" Margin="16,0,0,0" Command="{Binding CreateNewBranch}" ToolTip.Tip="{DynamicResource Text.Repository.NewBranch}">
<Path Width="14" Height="14" Data="{StaticResource Icons.Branch.Add}"/>
</Button>

View file

@ -1,3 +1,5 @@
using System;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
@ -45,23 +47,44 @@ namespace SourceGit.Views
private void Fetch(object _, RoutedEventArgs e)
{
var launcher = this.FindAncestorOfType<Launcher>();
(DataContext as ViewModels.Repository)?.Fetch(launcher?.HasKeyModifier(KeyModifiers.Control) ?? false);
if (launcher is not null && DataContext is ViewModels.Repository repo)
{
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
if (!startDirectly && OperatingSystem.IsMacOS())
startDirectly = launcher.HasKeyModifier(KeyModifiers.Meta);
repo.Fetch(startDirectly);
e.Handled = true;
}
}
private void Pull(object _, RoutedEventArgs e)
{
var launcher = this.FindAncestorOfType<Launcher>();
(DataContext as ViewModels.Repository)?.Pull(launcher?.HasKeyModifier(KeyModifiers.Control) ?? false);
if (launcher is not null && DataContext is ViewModels.Repository repo)
{
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
if (!startDirectly && OperatingSystem.IsMacOS())
startDirectly = launcher.HasKeyModifier(KeyModifiers.Meta);
repo.Pull(startDirectly);
e.Handled = true;
}
}
private void Push(object _, RoutedEventArgs e)
{
var launcher = this.FindAncestorOfType<Launcher>();
(DataContext as ViewModels.Repository)?.Push(launcher?.HasKeyModifier(KeyModifiers.Control) ?? false);
if (launcher is not null && DataContext is ViewModels.Repository repo)
{
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
if (!startDirectly && OperatingSystem.IsMacOS())
startDirectly = launcher.HasKeyModifier(KeyModifiers.Meta);
repo.Push(startDirectly);
e.Handled = true;
}
}
private void StashAll(object _, RoutedEventArgs e)
{