Skip to content

Added workspaces shortcuts #1328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Resources/Locales/en_US.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@
<x:String x:Key="Text.Hotkeys.Global.GotoPrevTab" xml:space="preserve">Go to previous page</x:String>
<x:String x:Key="Text.Hotkeys.Global.NewTab" xml:space="preserve">Create new page</x:String>
<x:String x:Key="Text.Hotkeys.Global.OpenPreferences" xml:space="preserve">Open Preferences dialog</x:String>
<x:String x:Key="Text.Hotkeys.Global.OpenWorkspaces" xml:space="preserve">Open Workspaces dialog</x:String>
<x:String x:Key="Text.Hotkeys.Global.OpenWorkspaceAtIndex" xml:space="preserve">Switch to corresponding workspace</x:String>
<x:String x:Key="Text.Hotkeys.Repo" xml:space="preserve">REPOSITORY</x:String>
<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>
Expand Down
10 changes: 9 additions & 1 deletion src/ViewModels/Launcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,14 @@ public ContextMenu CreateContextForPageTab(LauncherPage page)
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");
Expand Down Expand Up @@ -493,7 +501,7 @@ private string GetRepositoryGitDir(string repo)

return new Commands.QueryGitDir(repo).Result();
}

private void SwitchWorkspace(Workspace to)
{
foreach (var one in Pages)
Expand Down
8 changes: 7 additions & 1 deletion src/Views/Hotkeys.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>

<Grid RowDefinitions="20,20,20,20,20,20,20,20" ColumnDefinitions="150,*">
<Grid RowDefinitions="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+P, macOS=⌘+\,}"/>
<TextBlock Grid.Row="0" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.OpenPreferences}"/>

Expand All @@ -69,6 +69,12 @@

<TextBlock Grid.Row="7" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Ctrl+Q, macOS=⌘+Q}"/>
<TextBlock Grid.Row="7" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Quit}" />

<TextBlock Grid.Row="8" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Alt+Space, macOS=⌥+␣}"/>
<TextBlock Grid.Row="8" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.OpenWorkspaces}" />

<TextBlock Grid.Row="9" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Alt+1 - Alt+9, macOS=⌥+1 - ⌥+9}"/>
<TextBlock Grid.Row="9" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.OpenWorkspaceAtIndex}" />
</Grid>

<TextBlock Text="{DynamicResource Text.Hotkeys.Repo}"
Expand Down
2 changes: 1 addition & 1 deletion src/Views/Launcher.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
</Button>

<!-- Workspace Switcher -->
<Button Grid.Column="1" Classes="icon_button" VerticalAlignment="Bottom" Margin="0,0,0,1" Click="OnOpenWorkspaceMenu">
<Button Grid.Column="1" Classes="icon_button" Name="WorkspacesButton" VerticalAlignment="Bottom" Margin="0,0,0,1" Click="OnOpenWorkspaceMenu">
<ToolTip.Tip>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{DynamicResource Text.Workspace}" FontWeight="Bold" Foreground="{DynamicResource Brush.FG2}"/>
Expand Down
44 changes: 44 additions & 0 deletions src/Views/Launcher.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,27 @@ protected override void OnKeyDown(KeyEventArgs e)
}
}
}
else if (e.KeyModifiers.HasFlag(KeyModifiers.Alt))
{
if (e.Key == Key.Space && DataContext is ViewModels.Launcher launcher)
{
var menu = launcher.CreateContextForWorkspace();
var workspacesButton = this.FindControl<Button>("WorkspacesButton");
if (menu != null)
{
menu.PlacementTarget = workspacesButton;
menu.Placement = PlacementMode.BottomEdgeAlignedLeft;
menu.Open(workspacesButton);
}
}
else
{
SwitchToWorkspaceIndex(e.Key);
}

e.Handled = true;
return;
}
else if (e.Key == Key.Escape)
{
vm.ActivePage.CancelPopup();
Expand Down Expand Up @@ -282,6 +303,29 @@ protected override void OnKeyDown(KeyEventArgs e)
}
}

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);
Expand Down