mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-19 19:34:58 +00:00
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
This commit is contained in:
parent
506dbc218c
commit
01945f231e
5 changed files with 63 additions and 3 deletions
|
@ -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>
|
||||
|
|
|
@ -463,6 +463,14 @@ 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");
|
||||
|
@ -493,7 +501,7 @@ namespace SourceGit.ViewModels
|
|||
|
||||
return new Commands.QueryGitDir(repo).Result();
|
||||
}
|
||||
|
||||
|
||||
private void SwitchWorkspace(Workspace to)
|
||||
{
|
||||
foreach (var one in Pages)
|
||||
|
|
|
@ -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}"/>
|
||||
|
||||
|
@ -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}"
|
||||
|
|
|
@ -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}"/>
|
||||
|
|
|
@ -248,6 +248,27 @@ namespace SourceGit.Views
|
|||
}
|
||||
}
|
||||
}
|
||||
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();
|
||||
|
@ -282,6 +303,29 @@ 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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue