Skip to content

Commit 0b4be6e

Browse files
committed
refactor: global hotkeys
Signed-off-by: leo <longshuang@msn.cn>
1 parent 8846bfe commit 0b4be6e

File tree

3 files changed

+22
-36
lines changed

3 files changed

+22
-36
lines changed

src/Views/Launcher.axaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,16 @@
7272
</Button>
7373

7474
<!-- Workspace Dropdown Menu -->
75-
<Button Grid.Column="1" Classes="icon_button" VerticalAlignment="Bottom" Margin="0,0,0,1" Click="OnOpenWorkspaceMenu">
75+
<Button Grid.Column="1" Classes="icon_button" VerticalAlignment="Bottom" Margin="0,0,0,1" Click="OnOpenWorkspaceMenu" HotKey="{OnPlatform Ctrl+Alt+P, macOS=⌘+Alt+P}">
7676
<ToolTip.Tip>
7777
<StackPanel Orientation="Horizontal">
7878
<TextBlock Text="{DynamicResource Text.Workspace}" FontWeight="Bold" Foreground="{DynamicResource MenuFlyoutItemKeyboardAcceleratorTextForeground}"/>
7979
<TextBlock Text="{Binding ActiveWorkspace.Name}"/>
80+
<TextBlock Margin="16,0,0,0"
81+
Text="{OnPlatform Ctrl+Alt+P, macOS=⌘+Alt+P}"
82+
FontSize="11"
83+
Foreground="{DynamicResource MenuFlyoutItemKeyboardAcceleratorTextForeground}"
84+
VerticalAlignment="Center"/>
8085
</StackPanel>
8186
</ToolTip.Tip>
8287
<Path Width="14" Height="14"
@@ -85,7 +90,7 @@
8590
</Button>
8691

8792
<!-- Pages Switcher Toggle Button -->
88-
<Button Grid.Column="2" Classes="icon_button" VerticalAlignment="Bottom" Margin="0,0,0,1" Command="{Binding OpenTabSwitcher}">
93+
<Button Grid.Column="2" Classes="icon_button" VerticalAlignment="Bottom" Margin="0,0,0,1" Command="{Binding OpenTabSwitcher}" HotKey="{OnPlatform Ctrl+P, macOS=⌘+P}">
8994
<ToolTip.Tip>
9095
<StackPanel Orientation="Horizontal">
9196
<TextBlock Text="{DynamicResource Text.Launcher.Pages}"

src/Views/Launcher.axaml.cs

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -150,53 +150,34 @@ protected override async void OnKeyDown(KeyEventArgs e)
150150
return;
151151
}
152152

153-
// Ctrl+, opens preference dialog (macOS use hotkeys in system menu bar)
154-
if (!OperatingSystem.IsMacOS() && e is { KeyModifiers: KeyModifiers.Control, Key: Key.OemComma })
153+
// Register hotkeys for Windows/Linux (macOS has registered these keys in system menu bar)
154+
if (!OperatingSystem.IsMacOS())
155155
{
156-
await App.ShowDialog(new Preferences());
157-
e.Handled = true;
158-
return;
159-
}
160-
161-
// F1 opens preference dialog (macOS use hotkeys in system menu bar)
162-
if (!OperatingSystem.IsMacOS() && e.Key == Key.F1)
163-
{
164-
await App.ShowDialog(new Hotkeys());
165-
return;
166-
}
167-
168-
// Ctrl+Q quits the application (macOS use hotkeys in system menu bar)
169-
if (!OperatingSystem.IsMacOS() && e is { KeyModifiers: KeyModifiers.Control, Key: Key.Q })
170-
{
171-
App.Quit(0);
172-
return;
173-
}
174-
175-
if (e.KeyModifiers.HasFlag(OperatingSystem.IsMacOS() ? KeyModifiers.Meta : KeyModifiers.Control))
176-
{
177-
if (e.Key == Key.P && e.KeyModifiers.HasFlag(KeyModifiers.Shift))
156+
if (e is { KeyModifiers: KeyModifiers.Control, Key: Key.OemComma })
178157
{
179-
// TODO: Command Palette
158+
await App.ShowDialog(new Preferences());
159+
e.Handled = true;
180160
return;
181161
}
182162

183-
if (e.Key == Key.P)
163+
if (e is { KeyModifiers: KeyModifiers.None, Key: Key.F1 })
184164
{
185-
vm.OpenTabSwitcher();
186-
e.Handled = true;
165+
await App.ShowDialog(new Hotkeys());
187166
return;
188167
}
189168

190-
if (e.Key == Key.W)
169+
if (e is { KeyModifiers: KeyModifiers.Control, Key: Key.Q })
191170
{
192-
vm.CloseTab(null);
193-
e.Handled = true;
171+
App.Quit(0);
194172
return;
195173
}
174+
}
196175

197-
if (e.Key == Key.T && !e.KeyModifiers.HasFlag(KeyModifiers.Shift))
176+
if (e.KeyModifiers.HasFlag(OperatingSystem.IsMacOS() ? KeyModifiers.Meta : KeyModifiers.Control))
177+
{
178+
if (e.Key == Key.W)
198179
{
199-
vm.AddNewTab();
180+
vm.CloseTab(null);
200181
e.Handled = true;
201182
return;
202183
}

src/Views/LauncherTabBar.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
<Path Width="8" Height="14" Stretch="Fill" Data="{StaticResource Icons.TriangleRight}"/>
153153
</RepeatButton>
154154

155-
<Button Classes="icon_button" Width="16" Height="16" Margin="4,0,0,0" Command="{Binding AddNewTab}">
155+
<Button Classes="icon_button" Width="16" Height="16" Margin="4,0,0,0" Command="{Binding AddNewTab}" HotKey="{OnPlatform Ctrl+T, macOS=⌘+T}">
156156
<ToolTip.Tip>
157157
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
158158
<TextBlock Text="{DynamicResource Text.PageTabBar.New}" VerticalAlignment="Center"/>

0 commit comments

Comments
 (0)