From f121975a284321c1fccdf01c3ec12cd4a87a1d1d Mon Sep 17 00:00:00 2001 From: leo Date: Sat, 17 May 2025 18:37:02 +0800 Subject: [PATCH 1/4] code_review: PR #1328 * remove hotkey to open workspace dropdown menu * call orignal `ViewModels.Launcher.SwitchWorkspace` directly in view * add missing translation for Chinese Signed-off-by: leo --- src/Resources/Locales/en_US.axaml | 3 +- src/Resources/Locales/zh_CN.axaml | 1 + src/Resources/Locales/zh_TW.axaml | 1 + src/ViewModels/Launcher.cs | 130 ++++++++++++++---------------- src/Views/Avatar.cs | 6 +- src/Views/Hotkeys.axaml | 9 +-- src/Views/Launcher.axaml | 2 +- src/Views/Launcher.axaml.cs | 82 ++++++++++--------- 8 files changed, 113 insertions(+), 121 deletions(-) diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 63c9815d..a9114e21 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -386,8 +386,7 @@ Go to previous page Create new page Open Preferences dialog - Open Workspaces dialog - Switch to corresponding workspace + Switch to corresponding workspace REPOSITORY Commit staged changes Commit and push staged changes diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 56227607..d196906f 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -390,6 +390,7 @@ 切换到上一个页面 新建页面 打开偏好设置面板 + 切换工作区 仓库页面快捷键 提交暂存区更改 提交暂存区更改并推送 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 204e1cf7..09b11406 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -390,6 +390,7 @@ 切換到上一個頁面 新增頁面 開啟偏好設定面板 + 切換工作區 存放庫頁面快速鍵 提交暫存區變更 提交暫存區變更並推送 diff --git a/src/ViewModels/Launcher.cs b/src/ViewModels/Launcher.cs index 5eaca763..420d7af9 100644 --- a/src/ViewModels/Launcher.cs +++ b/src/ViewModels/Launcher.cs @@ -130,6 +130,66 @@ namespace SourceGit.ViewModels _ignoreIndexChange = false; } + public void SwitchWorkspace(Workspace to) + { + foreach (var one in Pages) + { + if (!one.CanCreatePopup() || one.Data is Repository { IsAutoFetching: true }) + { + App.RaiseException(null, "You have unfinished task(s) in opened pages. Please wait!!!"); + return; + } + } + + _ignoreIndexChange = true; + + var pref = Preferences.Instance; + foreach (var w in pref.Workspaces) + w.IsActive = false; + + ActiveWorkspace = to; + to.IsActive = true; + + foreach (var one in Pages) + CloseRepositoryInTab(one, false); + + Pages.Clear(); + AddNewTab(); + + var repos = to.Repositories.ToArray(); + foreach (var repo in repos) + { + var node = pref.FindNode(repo); + if (node == null) + { + node = new RepositoryNode() + { + Id = repo, + Name = Path.GetFileName(repo), + Bookmark = 0, + IsRepository = true, + }; + } + + OpenRepositoryInTab(node, null); + } + + var activeIdx = to.ActiveIdx; + if (activeIdx >= 0 && activeIdx < Pages.Count) + { + ActivePage = Pages[activeIdx]; + } + else + { + ActivePage = Pages[0]; + to.ActiveIdx = 0; + } + + _ignoreIndexChange = false; + Preferences.Instance.Save(); + GC.Collect(); + } + public void AddNewTab() { var page = new LauncherPage(); @@ -463,14 +523,6 @@ namespace SourceGit.ViewModels return menu; } - public void SwitchWorkspace(int idx) - { - var pref = Preferences.Instance; - if (idx >= pref.Workspaces.Count || pref.Workspaces[idx].IsActive) return; - - SwitchWorkspace(pref.Workspaces[idx]); - } - private string GetRepositoryGitDir(string repo) { var fullpath = Path.Combine(repo, ".git"); @@ -501,66 +553,6 @@ namespace SourceGit.ViewModels return new Commands.QueryGitDir(repo).Result(); } - - private void SwitchWorkspace(Workspace to) - { - foreach (var one in Pages) - { - if (!one.CanCreatePopup() || one.Data is Repository { IsAutoFetching: true }) - { - App.RaiseException(null, "You have unfinished task(s) in opened pages. Please wait!!!"); - return; - } - } - - _ignoreIndexChange = true; - - var pref = Preferences.Instance; - foreach (var w in pref.Workspaces) - w.IsActive = false; - - ActiveWorkspace = to; - to.IsActive = true; - - foreach (var one in Pages) - CloseRepositoryInTab(one, false); - - Pages.Clear(); - AddNewTab(); - - var repos = to.Repositories.ToArray(); - foreach (var repo in repos) - { - var node = pref.FindNode(repo); - if (node == null) - { - node = new RepositoryNode() - { - Id = repo, - Name = Path.GetFileName(repo), - Bookmark = 0, - IsRepository = true, - }; - } - - OpenRepositoryInTab(node, null); - } - - var activeIdx = to.ActiveIdx; - if (activeIdx >= 0 && activeIdx < Pages.Count) - { - ActivePage = Pages[activeIdx]; - } - else - { - ActivePage = Pages[0]; - to.ActiveIdx = 0; - } - - _ignoreIndexChange = false; - Preferences.Instance.Save(); - GC.Collect(); - } private void CloseRepositoryInTab(LauncherPage page, bool removeFromWorkspace = true) { @@ -581,7 +573,7 @@ namespace SourceGit.ViewModels return; var workspace = _activeWorkspace.Name; - if (_activePage is { Data: Repository repo }) + if (_activePage is { Data: Repository }) { var node = _activePage.Node; var name = node.Name; diff --git a/src/Views/Avatar.cs b/src/Views/Avatar.cs index 87bc7ce3..5dacac69 100644 --- a/src/Views/Avatar.cs +++ b/src/Views/Avatar.cs @@ -78,10 +78,10 @@ namespace SourceGit.Views if (switches[idx]) context.FillRectangle(brush, new Rect(x, y, stepX, stepY)); - if (switches[idx+1]) + if (switches[idx + 1]) context.FillRectangle(brush, new Rect(x + stepX, y, stepX, stepY)); - if (switches[idx+2]) + if (switches[idx + 2]) context.FillRectangle(brush, new Rect(x + stepX * 2, y, stepX, stepY)); } @@ -94,7 +94,7 @@ namespace SourceGit.Views if (switches[idx]) context.FillRectangle(brush, new Rect(x, y, stepX, stepY)); - if (switches[idx-1]) + if (switches[idx - 1]) context.FillRectangle(brush, new Rect(x + stepX, y, stepX, stepY)); } } diff --git a/src/Views/Hotkeys.axaml b/src/Views/Hotkeys.axaml index b1d436a4..e64ab1e3 100644 --- a/src/Views/Hotkeys.axaml +++ b/src/Views/Hotkeys.axaml @@ -45,7 +45,7 @@ FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Increase}}" Margin="0,0,0,8"/> - + @@ -70,11 +70,8 @@ - - - - - + + - - + - + - + @@ -102,5 +102,22 @@ + + + + + + + + + + + + + + + diff --git a/src/Views/Launcher.axaml.cs b/src/Views/Launcher.axaml.cs index 24fd6dcc..02cc4f08 100644 --- a/src/Views/Launcher.axaml.cs +++ b/src/Views/Launcher.axaml.cs @@ -157,6 +157,12 @@ namespace SourceGit.Views if (e.KeyModifiers.HasFlag(OperatingSystem.IsMacOS() ? KeyModifiers.Meta : KeyModifiers.Control)) { + if (e.Key == Key.P) + { + vm.OpenWorkspaceSwitcher(); + e.Handled = true; + } + if (e.Key == Key.W) { vm.CloseTab(null); @@ -248,17 +254,10 @@ namespace SourceGit.Views } } } - else if (e.KeyModifiers.HasFlag(KeyModifiers.Alt)) - { - if (SwitchWorkspace(e.Key)) - { - e.Handled = true; - return; - } - } else if (e.Key == Key.Escape) { vm.ActivePage.CancelPopup(); + vm.CancelWorkspaceSwitcher(); e.Handled = true; return; } @@ -314,44 +313,6 @@ namespace SourceGit.Views e.Handled = true; } - - private bool SwitchWorkspace(Key eKey) - { - var exec = (ViewModels.Launcher l, int idx) => - { - var pref = ViewModels.Preferences.Instance; - if (idx < pref.Workspaces.Count) - l.SwitchWorkspace(pref.Workspaces[idx]); - return true; // Alt+1..9 (or Option+1..9) always mark handled - }; - - if (DataContext is ViewModels.Launcher launcher) - { - switch (eKey) - { - case Key.D1 or Key.NumPad1: - return exec(launcher, 0); - case Key.D2 or Key.NumPad2: - return exec(launcher, 1); - case Key.D3 or Key.NumPad3: - return exec(launcher, 2); - case Key.D4 or Key.NumPad4: - return exec(launcher, 3); - case Key.D5 or Key.NumPad5: - return exec(launcher, 4); - case Key.D6 or Key.NumPad6: - return exec(launcher, 5); - case Key.D7 or Key.NumPad7: - return exec(launcher, 6); - case Key.D8 or Key.NumPad8: - return exec(launcher, 7); - case Key.D9 or Key.NumPad9: - return exec(launcher, 8); - } - } - - return false; - } private KeyModifiers _unhandledModifiers = KeyModifiers.None; private WindowState _lastWindowState = WindowState.Normal; diff --git a/src/Views/WorkspaceSwitcher.axaml b/src/Views/WorkspaceSwitcher.axaml new file mode 100644 index 00000000..49fed451 --- /dev/null +++ b/src/Views/WorkspaceSwitcher.axaml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Views/WorkspaceSwitcher.axaml.cs b/src/Views/WorkspaceSwitcher.axaml.cs new file mode 100644 index 00000000..04bdae1a --- /dev/null +++ b/src/Views/WorkspaceSwitcher.axaml.cs @@ -0,0 +1,49 @@ +using Avalonia.Controls; +using Avalonia.Input; + +namespace SourceGit.Views +{ + public partial class WorkspaceSwitcher : UserControl + { + public WorkspaceSwitcher() + { + InitializeComponent(); + } + + protected override void OnKeyDown(KeyEventArgs e) + { + base.OnKeyDown(e); + + if (e.Key == Key.Enter && DataContext is ViewModels.WorkspaceSwitcher switcher) + { + switcher.Switch(); + e.Handled = true; + } + } + + private void OnItemDoubleTapped(object sender, TappedEventArgs e) + { + if (DataContext is ViewModels.WorkspaceSwitcher switcher) + { + switcher.Switch(); + e.Handled = true; + } + } + + private void OnSearchBoxKeyDown(object sender, KeyEventArgs e) + { + if (e.Key == Key.Down && WorkspaceListBox.ItemCount > 0) + { + WorkspaceListBox.Focus(NavigationMethod.Directional); + + if (WorkspaceListBox.SelectedIndex < 0) + WorkspaceListBox.SelectedIndex = 0; + else if (WorkspaceListBox.SelectedIndex < WorkspaceListBox.ItemCount) + WorkspaceListBox.SelectedIndex++; + + e.Handled = true; + } + } + } +} + From d429a6426a99d441869d9727929b879dd4037717 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 17 May 2025 12:14:32 +0000 Subject: [PATCH 4/4] doc: Update translation status and sort locale files --- TRANSLATION.md | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/TRANSLATION.md b/TRANSLATION.md index 2795c890..aee0e2a0 100644 --- a/TRANSLATION.md +++ b/TRANSLATION.md @@ -6,7 +6,7 @@ This document shows the translation status of each locale file in the repository ### ![en_US](https://img.shields.io/badge/en__US-%E2%88%9A-brightgreen) -### ![de__DE](https://img.shields.io/badge/de__DE-98.60%25-yellow) +### ![de__DE](https://img.shields.io/badge/de__DE-98.48%25-yellow)
Missing keys in de_DE.axaml @@ -16,6 +16,7 @@ This document shows the translation status of each locale file in the repository - Text.Hotkeys.Global.SwitchWorkspace - Text.Hotkeys.TextEditor.OpenExternalMergeTool - Text.Repository.ShowSubmodulesAsTree +- Text.Repository.WorkspaceSwitcher - Text.Submodule.Status - Text.Submodule.Status.Modified - Text.Submodule.Status.NotInited @@ -25,16 +26,17 @@ This document shows the translation status of each locale file in the repository
-### ![es__ES](https://img.shields.io/badge/es__ES-99.87%25-yellow) +### ![es__ES](https://img.shields.io/badge/es__ES-99.75%25-yellow)
Missing keys in es_ES.axaml - Text.Hotkeys.Global.SwitchWorkspace +- Text.Repository.WorkspaceSwitcher
-### ![fr__FR](https://img.shields.io/badge/fr__FR-94.41%25-yellow) +### ![fr__FR](https://img.shields.io/badge/fr__FR-94.29%25-yellow)
Missing keys in fr_FR.axaml @@ -68,6 +70,7 @@ This document shows the translation status of each locale file in the repository - Text.Repository.ShowSubmodulesAsTree - Text.Repository.ViewLogs - Text.Repository.Visit +- Text.Repository.WorkspaceSwitcher - Text.Submodule.Status - Text.Submodule.Status.Modified - Text.Submodule.Status.NotInited @@ -86,16 +89,17 @@ This document shows the translation status of each locale file in the repository
-### ![it__IT](https://img.shields.io/badge/it__IT-99.87%25-yellow) +### ![it__IT](https://img.shields.io/badge/it__IT-99.75%25-yellow)
Missing keys in it_IT.axaml - Text.Hotkeys.Global.SwitchWorkspace +- Text.Repository.WorkspaceSwitcher
-### ![ja__JP](https://img.shields.io/badge/ja__JP-94.16%25-yellow) +### ![ja__JP](https://img.shields.io/badge/ja__JP-94.04%25-yellow)
Missing keys in ja_JP.axaml @@ -131,6 +135,7 @@ This document shows the translation status of each locale file in the repository - Text.Repository.Tags.OrderByNameDes - Text.Repository.ViewLogs - Text.Repository.Visit +- Text.Repository.WorkspaceSwitcher - Text.Submodule.Status - Text.Submodule.Status.Modified - Text.Submodule.Status.NotInited @@ -149,7 +154,7 @@ This document shows the translation status of each locale file in the repository
-### ![pt__BR](https://img.shields.io/badge/pt__BR-85.90%25-yellow) +### ![pt__BR](https://img.shields.io/badge/pt__BR-85.79%25-yellow)
Missing keys in pt_BR.axaml @@ -240,6 +245,7 @@ This document shows the translation status of each locale file in the repository - Text.Repository.UseRelativeTimeInHistories - Text.Repository.ViewLogs - Text.Repository.Visit +- Text.Repository.WorkspaceSwitcher - Text.SetUpstream - Text.SetUpstream.Local - Text.SetUpstream.Unset @@ -268,17 +274,18 @@ This document shows the translation status of each locale file in the repository
-### ![ru__RU](https://img.shields.io/badge/ru__RU-99.75%25-yellow) +### ![ru__RU](https://img.shields.io/badge/ru__RU-99.62%25-yellow)
Missing keys in ru_RU.axaml - Text.Hotkeys.Global.SwitchWorkspace - Text.Repository.ShowSubmodulesAsTree +- Text.Repository.WorkspaceSwitcher
-### ![ta__IN](https://img.shields.io/badge/ta__IN-94.41%25-yellow) +### ![ta__IN](https://img.shields.io/badge/ta__IN-94.29%25-yellow)
Missing keys in ta_IN.axaml @@ -312,6 +319,7 @@ This document shows the translation status of each locale file in the repository - Text.Repository.ShowSubmodulesAsTree - Text.Repository.ViewLogs - Text.Repository.Visit +- Text.Repository.WorkspaceSwitcher - Text.Submodule.Status - Text.Submodule.Status.Modified - Text.Submodule.Status.NotInited @@ -330,7 +338,7 @@ This document shows the translation status of each locale file in the repository
-### ![uk__UA](https://img.shields.io/badge/uk__UA-95.55%25-yellow) +### ![uk__UA](https://img.shields.io/badge/uk__UA-95.43%25-yellow)
Missing keys in uk_UA.axaml @@ -360,6 +368,7 @@ This document shows the translation status of each locale file in the repository - Text.Repository.ShowSubmodulesAsTree - Text.Repository.ViewLogs - Text.Repository.Visit +- Text.Repository.WorkspaceSwitcher - Text.Submodule.Status - Text.Submodule.Status.Modified - Text.Submodule.Status.NotInited