mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-20 03:34:59 +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.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.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.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.SwitchWorkspace" xml:space="preserve">Switch to corresponding workspace</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" 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.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>
|
<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.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.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.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" 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.Commit" xml:space="preserve">提交暂存区更改</x:String>
|
||||||
<x:String x:Key="Text.Hotkeys.Repo.CommitAndPush" 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.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.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.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" 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.Commit" xml:space="preserve">提交暫存區變更</x:String>
|
||||||
<x:String x:Key="Text.Hotkeys.Repo.CommitAndPush" 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;
|
_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()
|
public void AddNewTab()
|
||||||
{
|
{
|
||||||
var page = new LauncherPage();
|
var page = new LauncherPage();
|
||||||
|
@ -463,14 +523,6 @@ namespace SourceGit.ViewModels
|
||||||
return menu;
|
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)
|
private string GetRepositoryGitDir(string repo)
|
||||||
{
|
{
|
||||||
var fullpath = Path.Combine(repo, ".git");
|
var fullpath = Path.Combine(repo, ".git");
|
||||||
|
@ -502,66 +554,6 @@ namespace SourceGit.ViewModels
|
||||||
return new Commands.QueryGitDir(repo).Result();
|
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)
|
private void CloseRepositoryInTab(LauncherPage page, bool removeFromWorkspace = true)
|
||||||
{
|
{
|
||||||
if (page.Data is Repository repo)
|
if (page.Data is Repository repo)
|
||||||
|
@ -581,7 +573,7 @@ namespace SourceGit.ViewModels
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var workspace = _activeWorkspace.Name;
|
var workspace = _activeWorkspace.Name;
|
||||||
if (_activePage is { Data: Repository repo })
|
if (_activePage is { Data: Repository })
|
||||||
{
|
{
|
||||||
var node = _activePage.Node;
|
var node = _activePage.Node;
|
||||||
var name = node.Name;
|
var name = node.Name;
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Increase}}"
|
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Increase}}"
|
||||||
Margin="0,0,0,8"/>
|
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="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}"/>
|
<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="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="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="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.OpenWorkspaces}" />
|
<TextBlock Grid.Row="8" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.SwitchWorkspace}" />
|
||||||
|
|
||||||
<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>
|
</Grid>
|
||||||
|
|
||||||
<TextBlock Text="{DynamicResource Text.Hotkeys.Repo}"
|
<TextBlock Text="{DynamicResource Text.Hotkeys.Repo}"
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<!-- Workspace Switcher -->
|
<!-- 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>
|
<ToolTip.Tip>
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<TextBlock Text="{DynamicResource Text.Workspace}" FontWeight="Bold" Foreground="{DynamicResource Brush.FG2}"/>
|
<TextBlock Text="{DynamicResource Text.Workspace}" FontWeight="Bold" Foreground="{DynamicResource Brush.FG2}"/>
|
||||||
|
|
|
@ -100,7 +100,7 @@ namespace SourceGit.Views
|
||||||
|
|
||||||
if (change.Property == WindowStateProperty)
|
if (change.Property == WindowStateProperty)
|
||||||
{
|
{
|
||||||
_lastWindowState = (WindowState)change.OldValue;
|
_lastWindowState = (WindowState)change.OldValue!;
|
||||||
|
|
||||||
var state = (WindowState)change.NewValue!;
|
var state = (WindowState)change.NewValue!;
|
||||||
if (!OperatingSystem.IsMacOS() && !UseSystemWindowFrame)
|
if (!OperatingSystem.IsMacOS() && !UseSystemWindowFrame)
|
||||||
|
@ -250,25 +250,12 @@ namespace SourceGit.Views
|
||||||
}
|
}
|
||||||
else if (e.KeyModifiers.HasFlag(KeyModifiers.Alt))
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SwitchToWorkspaceIndex(e.Key);
|
|
||||||
}
|
|
||||||
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (e.Key == Key.Escape)
|
else if (e.Key == Key.Escape)
|
||||||
{
|
{
|
||||||
vm.ActivePage.CancelPopup();
|
vm.ActivePage.CancelPopup();
|
||||||
|
@ -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)
|
protected override void OnKeyUp(KeyEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnKeyUp(e);
|
base.OnKeyUp(e);
|
||||||
|
@ -351,6 +315,44 @@ namespace SourceGit.Views
|
||||||
e.Handled = true;
|
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 KeyModifiers _unhandledModifiers = KeyModifiers.None;
|
||||||
private WindowState _lastWindowState = WindowState.Normal;
|
private WindowState _lastWindowState = WindowState.Normal;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue