8000 Added workspaces shortcuts (#1328) · sourcegit-scm/sourcegit@01945f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 01945f2

Browse files
authored
Added workspaces shortcuts (#1328)
- added Alt+Space for opening Workspaces context menu (which can then be navigated normally with arrows) - added Alt+1 through Alt+9 for switching to corresponding workspace
1 parent 506dbc2 commit 01945f2

File tree

5 files changed

+63
-3
lines changed

5 files changed

+63
-3
lines changed

src/Resources/Locales/en_US.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,8 @@
386386
<x:String x:Key="Text.Hotkeys.Global.GotoPrevTab" xml:space="preserve">Go to previous page</x:String>
387387
<x:String x:Key="Text.Hotkeys.Global.NewTab" xml:space="preserve">Create new page</x:String>
388388
<x:String x:Key="Text.Hotkeys.Global.OpenPreferences" xml:space="preserve">Open Preferences dialog</x:String>
389+
<x:String x:Key="Text.Hotkeys.Global.OpenWorkspaces" xml:space="preserve">Open Workspaces dialog</x:String>
390+
<x:String x:Key="Text.Hotkeys.Global.OpenWorkspaceAtIndex" xml:space="preserve">Switch to corresponding workspace</x:String>
389391
<x:String x:Key="Text.Hotkeys.Repo" xml:space="preserve">REPOSITORY</x:String>
390392
<x:String x:Key="Text.Hotkeys.Repo.Commit" xml:space="preserve">Commit staged changes</x:String>
391393
<x:String x:Key="Text.Hotkeys.Repo.CommitAndPush" xml:space="preserve">Commit and push staged changes</x:String>

src/ViewModels/Launcher.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,14 @@ public ContextMenu CreateContextForPageTab(LauncherPage page)
463463
return menu;
464464
}
465465

466+
public void SwitchWorkspace(int idx)
467+
{
468+
var pref = Preferences.Instance;
469+
if (idx >= pref.Workspaces.Count || pref.Workspaces[idx].IsActive) return;
470+
471+
SwitchWorkspace(pref.Workspaces[idx]);
472+
}
473+
466474
private string GetRepositoryGitDir(string repo)
467475
{
468476
var fullpath = Path.Combine(repo, ".git");
@@ -493,7 +501,7 @@ private string GetRepositoryGitDir(string repo)
493501

494502
return new Commands.QueryGitDir(repo).Result();
495503
}
496-
504+
497505
private void SwitchWorkspace(Workspace to)
498506
{
499507
foreach (var one in Pages)

src/Views/Hotkeys.axaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Increase}}"
4646
Margin="0,0,0,8"/>
4747

48-
<Grid RowDefinitions="20,20,20,20,20,20,20,20" ColumnDefinitions="150,*">
48+
<Grid RowDefinitions="20,20,20,20,20,20,20,20,20,20" ColumnDefinitions="150,*">
4949
<TextBlock Grid.Row="0" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Ctrl+Shift+P, macOS=⌘+\,}"/>
5050
<TextBlock Grid.Row="0" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.OpenPreferences}"/>
5151

@@ -69,6 +69,12 @@
6969

7070
<TextBlock Grid.Row="7" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Ctrl+Q, macOS=⌘+Q}"/>
7171
<TextBlock Grid.Row="7" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Quit}" />
72+
73+
<TextBlock Grid.Row="8" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Alt+Space, macOS=⌥+␣}"/>
74+
<TextBlock Grid.Row="8" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.OpenWorkspaces}" />
75+
76+
<TextBlock Grid.Row="9" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Alt+1 - Alt+9, macOS=⌥+1 - ⌥+9}"/>
77+
<TextBlock Grid.Row="9" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.OpenWorkspaceAtIndex}" />
7278
</Grid>
7379

7480
<TextBlock Text="{DynamicResource Text.Hotkeys.Repo}"

src/Views/Launcher.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
</Button>
7474

7575
<!-- Workspace Switcher -->
76-
<Button Grid.Column="1" Classes="icon_button" VerticalAlignment="Bottom" Margin="0,0,0,1" Click="OnOpenWorkspaceMenu">
76+
<Button Grid.Column="1" Classes="icon_button" Name="WorkspacesButton" VerticalAlignment="Bottom" Margin="0,0,0,1" Click="OnOpenWorkspaceMenu">
7777
<ToolTip.Tip>
7878
<StackPanel Orientation="Horizontal">
7979
<TextBlock Text="{DynamicResource Text.Workspace}" FontWeight="Bold" Foreground="{DynamicResource Brush.FG2}"/>

src/Views/Launcher.axaml.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,27 @@ protected override void OnKeyDown(KeyEventArgs e)
248248
}
249249
}
250250
}
251+
else if (e.KeyModifiers.HasFlag(KeyModifiers.Alt))
252+
{
253+
if (e.Key == Key.Space && DataContext is ViewModels.Launcher launcher)
254+
{
255+
var menu = launcher.CreateContextForWorkspace();
256+
var workspacesButton = this.FindControl<Button>("WorkspacesButton");
257+
if (menu != null)
258+
{
259+
menu.PlacementTarget = workspacesButton;
260+
menu.Placement = PlacementMode.BottomEdgeAlignedLeft;
261+
menu.Open(workspacesButton);
262+
}
263+
}
264+
else
265+
{
266+
SwitchToWorkspaceIndex(e.Key);
267+
}
268+
269+
e.Handled = true;
270+
return;
271+
}
251272
else if (e.Key == Key.Escape)
252273
{
253274
vm.ActivePage.CancelPopup();
@@ -282,6 +303,29 @@ protected override void OnKeyDown(KeyEventArgs e)
282303
}
283304
}
284305

306+
private void SwitchToWorkspaceIndex(Key eKey)
307+
{
308+
int newIndex;
309+
switch (eKey)
310+
{
311+
case Key.D1 or Key.NumPad1: newIndex = 0; break;
312+
case Key.D2 or Key.NumPad2: newIndex = 1; break;
313+
case Key.D3 or Key.NumPad3: newIndex = 2; break;
314+
case Key.D4 or Key.NumPad4: newIndex = 3; break;
315+
case Key.D5 or Key.NumPad5: newIndex = 4; break;
316+
case Key.D6 or Key.NumPad6: newIndex = 5; break;
317+
case Key.D7 or Key.NumPad7: newIndex = 6; break;
318+
case Key.D8 or Key.NumPad8: newIndex = 7; break;
319+
case Key.D9 or Key.NumPad9: newIndex = 8; break;
320+
default: return;
321+
}
322+
323+
if (DataContext is ViewModels.Launcher launcher)
324+
{
325+
launcher.SwitchWorkspace(newIndex);
326+
}
327+
}
328+
285329
protected override void OnKeyUp(KeyEventArgs e)
286330
{
287331
base.OnKeyUp(e);

0 commit comments

Comments
 (0)
0