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 <longshuang@msn.cn>
This commit is contained in:
leo 2025-05-17 18:37:02 +08:00
parent ea320d2cdf
commit f121975a28
No known key found for this signature in database
8 changed files with 113 additions and 121 deletions

View file

@ -100,7 +100,7 @@ namespace SourceGit.Views
if (change.Property == WindowStateProperty)
{
_lastWindowState = (WindowState)change.OldValue;
_lastWindowState = (WindowState)change.OldValue!;
var state = (WindowState)change.NewValue!;
if (!OperatingSystem.IsMacOS() && !UseSystemWindowFrame)
@ -250,24 +250,11 @@ namespace SourceGit.Views
}
else if (e.KeyModifiers.HasFlag(KeyModifiers.Alt))
{
if (e.Key == Key.Space && DataContext is ViewModels.Launcher launcher)
if (SwitchWorkspace(e.Key))
{
var menu = launcher.CreateContextForWorkspace();
var workspacesButton = this.FindControl<Button>("WorkspacesButton");
if (menu != null)
{
menu.PlacementTarget = workspacesButton;
menu.Placement = PlacementMode.BottomEdgeAlignedLeft;
menu.Open(workspacesButton);
}
e.Handled = true;
return;
}
else
{
SwitchToWorkspaceIndex(e.Key);
}
e.Handled = true;
return;
}
else if (e.Key == Key.Escape)
{
@ -303,29 +290,6 @@ namespace SourceGit.Views
}
}
private void SwitchToWorkspaceIndex(Key eKey)
{
int newIndex;
switch (eKey)
{
case Key.D1 or Key.NumPad1: newIndex = 0; break;
case Key.D2 or Key.NumPad2: newIndex = 1; break;
case Key.D3 or Key.NumPad3: newIndex = 2; break;
case Key.D4 or Key.NumPad4: newIndex = 3; break;
case Key.D5 or Key.NumPad5: newIndex = 4; break;
case Key.D6 or Key.NumPad6: newIndex = 5; break;
case Key.D7 or Key.NumPad7: newIndex = 6; break;
case Key.D8 or Key.NumPad8: newIndex = 7; break;
case Key.D9 or Key.NumPad9: newIndex = 8; break;
default: return;
}
if (DataContext is ViewModels.Launcher launcher)
{
launcher.SwitchWorkspace(newIndex);
}
}
protected override void OnKeyUp(KeyEventArgs e)
{
base.OnKeyUp(e);
@ -350,6 +314,44 @@ 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;