mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-19 19:34:58 +00:00
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:
parent
ea320d2cdf
commit
f121975a28
8 changed files with 113 additions and 121 deletions
|
@ -386,8 +386,7 @@
|
|||
<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.Global.SwitchWorkspace" 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>
|
||||
|
|
|
@ -390,6 +390,7 @@
|
|||
<x:String x:Key="Text.Hotkeys.Global.GotoPrevTab" xml:space="preserve">切换到上一个页面</x:String>
|
||||
<x:String x:Key="Text.Hotkeys.Global.NewTab" xml:space="preserve">新建页面</x:String>
|
||||
<x:String x:Key="Text.Hotkeys.Global.OpenPreferences" xml:space="preserve">打开偏好设置面板</x:String>
|
||||
<x:String x:Key="Text.Hotkeys.Global.SwitchWorkspace" xml:space="preserve">切换工作区</x:String>
|
||||
<x:String x:Key="Text.Hotkeys.Repo" xml:space="preserve">仓库页面快捷键</x:String>
|
||||
<x:String x:Key="Text.Hotkeys.Repo.Commit" xml:space="preserve">提交暂存区更改</x:String>
|
||||
<x:String x:Key="Text.Hotkeys.Repo.CommitAndPush" xml:space="preserve">提交暂存区更改并推送</x:String>
|
||||
|
|
|
@ -390,6 +390,7 @@
|
|||
<x:String x:Key="Text.Hotkeys.Global.GotoPrevTab" xml:space="preserve">切換到上一個頁面</x:String>
|
||||
<x:String x:Key="Text.Hotkeys.Global.NewTab" xml:space="preserve">新增頁面</x:String>
|
||||
<x:String x:Key="Text.Hotkeys.Global.OpenPreferences" xml:space="preserve">開啟偏好設定面板</x:String>
|
||||
<x:String x:Key="Text.Hotkeys.Global.SwitchWorkspace" xml:space="preserve">切換工作區</x:String>
|
||||
<x:String x:Key="Text.Hotkeys.Repo" xml:space="preserve">存放庫頁面快速鍵</x:String>
|
||||
<x:String x:Key="Text.Hotkeys.Repo.Commit" xml:space="preserve">提交暫存區變更</x:String>
|
||||
<x:String x:Key="Text.Hotkeys.Repo.CommitAndPush" xml:space="preserve">提交暫存區變更並推送</x:String>
|
||||
|
|
|
@ -130,6 +130,66 @@ namespace SourceGit.ViewModels
|
|||
_ignoreIndexChange = false;
|
||||
}
|
||||
|
||||
public void SwitchWorkspace(Workspace to)
|
||||
{
|
||||
foreach (var one in Pages)
|
||||
{
|
||||
if (!one.CanCreatePopup() || one.Data is Repository { IsAutoFetching: true })
|
||||
{
|
||||
App.RaiseException(null, "You have unfinished task(s) in opened pages. Please wait!!!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_ignoreIndexChange = true;
|
||||
|
||||
var pref = Preferences.Instance;
|
||||
foreach (var w in pref.Workspaces)
|
||||
w.IsActive = false;
|
||||
|
||||
ActiveWorkspace = to;
|
||||
to.IsActive = true;
|
||||
|
||||
foreach (var one in Pages)
|
||||
CloseRepositoryInTab(one, false);
|
||||
|
||||
Pages.Clear();
|
||||
AddNewTab();
|
||||
|
||||
var repos = to.Repositories.ToArray();
|
||||
foreach (var repo in repos)
|
||||
{
|
||||
var node = pref.FindNode(repo);
|
||||
if (node == null)
|
||||
{
|
||||
node = new RepositoryNode()
|
||||
{
|
||||
Id = repo,
|
||||
Name = Path.GetFileName(repo),
|
||||
Bookmark = 0,
|
||||
IsRepository = true,
|
||||
};
|
||||
}
|
||||
|
||||
OpenRepositoryInTab(node, null);
|
||||
}
|
||||
|
||||
var activeIdx = to.ActiveIdx;
|
||||
if (activeIdx >= 0 && activeIdx < Pages.Count)
|
||||
{
|
||||
ActivePage = Pages[activeIdx];
|
||||
}
|
||||
else
|
||||
{
|
||||
ActivePage = Pages[0];
|
||||
to.ActiveIdx = 0;
|
||||
}
|
||||
|
||||
_ignoreIndexChange = false;
|
||||
Preferences.Instance.Save();
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
public void AddNewTab()
|
||||
{
|
||||
var page = new LauncherPage();
|
||||
|
@ -463,14 +523,6 @@ 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");
|
||||
|
@ -501,66 +553,6 @@ namespace SourceGit.ViewModels
|
|||
|
||||
return new Commands.QueryGitDir(repo).Result();
|
||||
}
|
||||
|
||||
private void SwitchWorkspace(Workspace to)
|
||||
{
|
||||
foreach (var one in Pages)
|
||||
{
|
||||
if (!one.CanCreatePopup() || one.Data is Repository { IsAutoFetching: true })
|
||||
{
|
||||
App.RaiseException(null, "You have unfinished task(s) in opened pages. Please wait!!!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_ignoreIndexChange = true;
|
||||
|
||||
var pref = Preferences.Instance;
|
||||
foreach (var w in pref.Workspaces)
|
||||
w.IsActive = false;
|
||||
|
||||
ActiveWorkspace = to;
|
||||
to.IsActive = true;
|
||||
|
||||
foreach (var one in Pages)
|
||||
CloseRepositoryInTab(one, false);
|
||||
|
||||
Pages.Clear();
|
||||
AddNewTab();
|
||||
|
||||
var repos = to.Repositories.ToArray();
|
||||
foreach (var repo in repos)
|
||||
{
|
||||
var node = pref.FindNode(repo);
|
||||
if (node == null)
|
||||
{
|
||||
node = new RepositoryNode()
|
||||
{
|
||||
Id = repo,
|
||||
Name = Path.GetFileName(repo),
|
||||
Bookmark = 0,
|
||||
IsRepository = true,
|
||||
};
|
||||
}
|
||||
|
||||
OpenRepositoryInTab(node, null);
|
||||
}
|
||||
|
||||
var activeIdx = to.ActiveIdx;
|
||||
if (activeIdx >= 0 && activeIdx < Pages.Count)
|
||||
{
|
||||
ActivePage = Pages[activeIdx];
|
||||
}
|
||||
else
|
||||
{
|
||||
ActivePage = Pages[0];
|
||||
to.ActiveIdx = 0;
|
||||
}
|
||||
|
||||
_ignoreIndexChange = false;
|
||||
Preferences.Instance.Save();
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
private void CloseRepositoryInTab(LauncherPage page, bool removeFromWorkspace = true)
|
||||
{
|
||||
|
@ -581,7 +573,7 @@ namespace SourceGit.ViewModels
|
|||
return;
|
||||
|
||||
var workspace = _activeWorkspace.Name;
|
||||
if (_activePage is { Data: Repository repo })
|
||||
if (_activePage is { Data: Repository })
|
||||
{
|
||||
var node = _activePage.Node;
|
||||
var name = node.Name;
|
||||
|
|
|
@ -78,10 +78,10 @@ namespace SourceGit.Views
|
|||
if (switches[idx])
|
||||
context.FillRectangle(brush, new Rect(x, y, stepX, stepY));
|
||||
|
||||
if (switches[idx+1])
|
||||
if (switches[idx + 1])
|
||||
context.FillRectangle(brush, new Rect(x + stepX, y, stepX, stepY));
|
||||
|
||||
if (switches[idx+2])
|
||||
if (switches[idx + 2])
|
||||
context.FillRectangle(brush, new Rect(x + stepX * 2, y, stepX, stepY));
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ namespace SourceGit.Views
|
|||
if (switches[idx])
|
||||
context.FillRectangle(brush, new Rect(x, y, stepX, stepY));
|
||||
|
||||
if (switches[idx-1])
|
||||
if (switches[idx - 1])
|
||||
context.FillRectangle(brush, new Rect(x + stepX, y, stepX, stepY));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,20,20" ColumnDefinitions="150,*">
|
||||
<Grid RowDefinitions="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}"/>
|
||||
|
||||
|
@ -70,11 +70,8 @@
|
|||
<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}" />
|
||||
<TextBlock Grid.Row="8" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Alt+[1..9], macOS=⌥+[1..9]}"/>
|
||||
<TextBlock Grid.Row="8" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.SwitchWorkspace}" />
|
||||
</Grid>
|
||||
|
||||
<TextBlock Text="{DynamicResource Text.Hotkeys.Repo}"
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
</Button>
|
||||
|
||||
<!-- Workspace Switcher -->
|
||||
<Button Grid.Column="1" Classes="icon_button" Name="WorkspacesButton" VerticalAlignment="Bottom" Margin="0,0,0,1" Click="OnOpenWorkspaceMenu">
|
||||
<Button Grid.Column="1" Classes="icon_button" 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}"/>
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue