refactor: workspace/page switcher (#1330)

- add `Switch Tab` popup
- change hotkey to open `Preferences` to `Ctrl+,/⌘+,`
- change hotkey to open `Switch Workspace` to `Ctrl+Shift+P/⌘+⇧+P`
- change hotkey to open `Switch Tab` to `Ctrl+P/⌘+P`

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-05-18 19:36:17 +08:00
parent 36c2e083cc
commit 9614b995d8
No known key found for this signature in database
17 changed files with 418 additions and 180 deletions

View file

@ -387,6 +387,7 @@
<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.SwitchWorkspace" xml:space="preserve">Switch active workspace</x:String> <x:String x:Key="Text.Hotkeys.Global.SwitchWorkspace" xml:space="preserve">Switch active workspace</x:String>
<x:String x:Key="Text.Hotkeys.Global.SwitchTab" xml:space="preserve">Switch active page</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>
@ -429,6 +430,8 @@
<x:String x:Key="Text.IssueLinkCM.OpenInBrowser" xml:space="preserve">Open in Browser</x:String> <x:String x:Key="Text.IssueLinkCM.OpenInBrowser" xml:space="preserve">Open in Browser</x:String>
<x:String x:Key="Text.Launcher.Error" xml:space="preserve">ERROR</x:String> <x:String x:Key="Text.Launcher.Error" xml:space="preserve">ERROR</x:String>
<x:String x:Key="Text.Launcher.Info" xml:space="preserve">NOTICE</x:String> <x:String x:Key="Text.Launcher.Info" xml:space="preserve">NOTICE</x:String>
<x:String x:Key="Text.Launcher.SwitchWorkspace" xml:space="preserve">Switch Workspace</x:String>
<x:String x:Key="Text.Launcher.SwitchTab" xml:space="preserve">Switch Tab</x:String>
<x:String x:Key="Text.Merge" xml:space="preserve">Merge Branch</x:String> <x:String x:Key="Text.Merge" xml:space="preserve">Merge Branch</x:String>
<x:String x:Key="Text.Merge.Into" xml:space="preserve">Into:</x:String> <x:String x:Key="Text.Merge.Into" xml:space="preserve">Into:</x:String>
<x:String x:Key="Text.Merge.Mode" xml:space="preserve">Merge Option:</x:String> <x:String x:Key="Text.Merge.Mode" xml:space="preserve">Merge Option:</x:String>
@ -635,7 +638,6 @@
<x:String x:Key="Text.Repository.UseRelativeTimeInHistories" xml:space="preserve">Use relative time in histories</x:String> <x:String x:Key="Text.Repository.UseRelativeTimeInHistories" xml:space="preserve">Use relative time in histories</x:String>
<x:String x:Key="Text.Repository.ViewLogs" xml:space="preserve">View Logs</x:String> <x:String x:Key="Text.Repository.ViewLogs" xml:space="preserve">View Logs</x:String>
<x:String x:Key="Text.Repository.Visit" xml:space="preserve">Visit '{0}' in Browser</x:String> <x:String x:Key="Text.Repository.Visit" xml:space="preserve">Visit '{0}' in Browser</x:String>
<x:String x:Key="Text.Repository.WorkspaceSwitcher" xml:space="preserve">Switch Workspace</x:String>
<x:String x:Key="Text.Repository.Worktrees" xml:space="preserve">WORKTREES</x:String> <x:String x:Key="Text.Repository.Worktrees" xml:space="preserve">WORKTREES</x:String>
<x:String x:Key="Text.Repository.Worktrees.Add" xml:space="preserve">Add Worktree</x:String> <x:String x:Key="Text.Repository.Worktrees.Add" xml:space="preserve">Add Worktree</x:String>
<x:String x:Key="Text.Repository.Worktrees.Prune" xml:space="preserve">Prune</x:String> <x:String x:Key="Text.Repository.Worktrees.Prune" xml:space="preserve">Prune</x:String>

View file

@ -433,6 +433,7 @@
<x:String x:Key="Text.IssueLinkCM.OpenInBrowser" xml:space="preserve">Открыть в браузере</x:String> <x:String x:Key="Text.IssueLinkCM.OpenInBrowser" xml:space="preserve">Открыть в браузере</x:String>
<x:String x:Key="Text.Launcher.Error" xml:space="preserve">ОШИБКА</x:String> <x:String x:Key="Text.Launcher.Error" xml:space="preserve">ОШИБКА</x:String>
<x:String x:Key="Text.Launcher.Info" xml:space="preserve">УВЕДОМЛЕНИЕ</x:String> <x:String x:Key="Text.Launcher.Info" xml:space="preserve">УВЕДОМЛЕНИЕ</x:String>
<x:String x:Key="Text.Launcher.SwitchWorkspace" xml:space="preserve">Переключить рабочее место</x:String>
<x:String x:Key="Text.Merge" xml:space="preserve">Влить ветку</x:String> <x:String x:Key="Text.Merge" xml:space="preserve">Влить ветку</x:String>
<x:String x:Key="Text.Merge.Into" xml:space="preserve">В:</x:String> <x:String x:Key="Text.Merge.Into" xml:space="preserve">В:</x:String>
<x:String x:Key="Text.Merge.Mode" xml:space="preserve">Опции слияния:</x:String> <x:String x:Key="Text.Merge.Mode" xml:space="preserve">Опции слияния:</x:String>
@ -639,7 +640,6 @@
<x:String x:Key="Text.Repository.UseRelativeTimeInHistories" xml:space="preserve">Использовать относительное время в историях</x:String> <x:String x:Key="Text.Repository.UseRelativeTimeInHistories" xml:space="preserve">Использовать относительное время в историях</x:String>
<x:String x:Key="Text.Repository.ViewLogs" xml:space="preserve">Просмотр журналов</x:String> <x:String x:Key="Text.Repository.ViewLogs" xml:space="preserve">Просмотр журналов</x:String>
<x:String x:Key="Text.Repository.Visit" xml:space="preserve">Посетить '{0}' в браузере</x:String> <x:String x:Key="Text.Repository.Visit" xml:space="preserve">Посетить '{0}' в браузере</x:String>
<x:String x:Key="Text.Repository.WorkspaceSwitcher" xml:space="preserve">Переключить рабочее место</x:String>
<x:String x:Key="Text.Repository.Worktrees" xml:space="preserve">РАБОЧИЕ КАТАЛОГИ</x:String> <x:String x:Key="Text.Repository.Worktrees" xml:space="preserve">РАБОЧИЕ КАТАЛОГИ</x:String>
<x:String x:Key="Text.Repository.Worktrees.Add" xml:space="preserve">ДОБАВИТЬ РАБОЧИЙ КАТАЛОГ</x:String> <x:String x:Key="Text.Repository.Worktrees.Add" xml:space="preserve">ДОБАВИТЬ РАБОЧИЙ КАТАЛОГ</x:String>
<x:String x:Key="Text.Repository.Worktrees.Prune" xml:space="preserve">ОБРЕЗАТЬ</x:String> <x:String x:Key="Text.Repository.Worktrees.Prune" xml:space="preserve">ОБРЕЗАТЬ</x:String>

View file

@ -391,6 +391,7 @@
<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.Global.SwitchWorkspace" xml:space="preserve">切换工作区</x:String>
<x:String x:Key="Text.Hotkeys.Global.SwitchTab" 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>
@ -433,6 +434,8 @@
<x:String x:Key="Text.IssueLinkCM.OpenInBrowser" xml:space="preserve">在浏览器中访问</x:String> <x:String x:Key="Text.IssueLinkCM.OpenInBrowser" xml:space="preserve">在浏览器中访问</x:String>
<x:String x:Key="Text.Launcher.Error" xml:space="preserve">出错了</x:String> <x:String x:Key="Text.Launcher.Error" xml:space="preserve">出错了</x:String>
<x:String x:Key="Text.Launcher.Info" xml:space="preserve">系统提示</x:String> <x:String x:Key="Text.Launcher.Info" xml:space="preserve">系统提示</x:String>
<x:String x:Key="Text.Launcher.SwitchWorkspace" xml:space="preserve">切换工作区</x:String>
<x:String x:Key="Text.Launcher.SwitchTab" xml:space="preserve">切换页面</x:String>
<x:String x:Key="Text.Merge" xml:space="preserve">合并分支</x:String> <x:String x:Key="Text.Merge" xml:space="preserve">合并分支</x:String>
<x:String x:Key="Text.Merge.Into" xml:space="preserve">目标分支 </x:String> <x:String x:Key="Text.Merge.Into" xml:space="preserve">目标分支 </x:String>
<x:String x:Key="Text.Merge.Mode" xml:space="preserve">合并方式 </x:String> <x:String x:Key="Text.Merge.Mode" xml:space="preserve">合并方式 </x:String>
@ -639,7 +642,6 @@
<x:String x:Key="Text.Repository.UseRelativeTimeInHistories" xml:space="preserve">在提交列表中使用相对时间</x:String> <x:String x:Key="Text.Repository.UseRelativeTimeInHistories" xml:space="preserve">在提交列表中使用相对时间</x:String>
<x:String x:Key="Text.Repository.ViewLogs" xml:space="preserve">查看命令日志</x:String> <x:String x:Key="Text.Repository.ViewLogs" xml:space="preserve">查看命令日志</x:String>
<x:String x:Key="Text.Repository.Visit" xml:space="preserve">访问远程仓库 '{0}'</x:String> <x:String x:Key="Text.Repository.Visit" xml:space="preserve">访问远程仓库 '{0}'</x:String>
<x:String x:Key="Text.Repository.WorkspaceSwitcher" xml:space="preserve">切换工作区</x:String>
<x:String x:Key="Text.Repository.Worktrees" xml:space="preserve">工作树列表</x:String> <x:String x:Key="Text.Repository.Worktrees" xml:space="preserve">工作树列表</x:String>
<x:String x:Key="Text.Repository.Worktrees.Add" xml:space="preserve">新增工作树</x:String> <x:String x:Key="Text.Repository.Worktrees.Add" xml:space="preserve">新增工作树</x:String>
<x:String x:Key="Text.Repository.Worktrees.Prune" xml:space="preserve">清理</x:String> <x:String x:Key="Text.Repository.Worktrees.Prune" xml:space="preserve">清理</x:String>

View file

@ -391,6 +391,7 @@
<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.Global.SwitchWorkspace" xml:space="preserve">切換工作區</x:String>
<x:String x:Key="Text.Hotkeys.Global.SwitchTab" 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>
@ -433,6 +434,8 @@
<x:String x:Key="Text.IssueLinkCM.OpenInBrowser" xml:space="preserve">在瀏覽器中開啟連結</x:String> <x:String x:Key="Text.IssueLinkCM.OpenInBrowser" xml:space="preserve">在瀏覽器中開啟連結</x:String>
<x:String x:Key="Text.Launcher.Error" xml:space="preserve">發生錯誤</x:String> <x:String x:Key="Text.Launcher.Error" xml:space="preserve">發生錯誤</x:String>
<x:String x:Key="Text.Launcher.Info" xml:space="preserve">系統提示</x:String> <x:String x:Key="Text.Launcher.Info" xml:space="preserve">系統提示</x:String>
<x:String x:Key="Text.Launcher.SwitchWorkspace" xml:space="preserve">切換工作區</x:String>
<x:String x:Key="Text.Launcher.SwitchTab" xml:space="preserve">切換目前頁面</x:String>
<x:String x:Key="Text.Merge" xml:space="preserve">合併分支</x:String> <x:String x:Key="Text.Merge" xml:space="preserve">合併分支</x:String>
<x:String x:Key="Text.Merge.Into" xml:space="preserve">目標分支:</x:String> <x:String x:Key="Text.Merge.Into" xml:space="preserve">目標分支:</x:String>
<x:String x:Key="Text.Merge.Mode" xml:space="preserve">合併方式:</x:String> <x:String x:Key="Text.Merge.Mode" xml:space="preserve">合併方式:</x:String>
@ -639,7 +642,6 @@
<x:String x:Key="Text.Repository.UseRelativeTimeInHistories" xml:space="preserve">在提交列表中使用相對時間</x:String> <x:String x:Key="Text.Repository.UseRelativeTimeInHistories" xml:space="preserve">在提交列表中使用相對時間</x:String>
<x:String x:Key="Text.Repository.ViewLogs" xml:space="preserve">檢視 Git 指令記錄</x:String> <x:String x:Key="Text.Repository.ViewLogs" xml:space="preserve">檢視 Git 指令記錄</x:String>
<x:String x:Key="Text.Repository.Visit" xml:space="preserve">檢視遠端存放庫 '{0}'</x:String> <x:String x:Key="Text.Repository.Visit" xml:space="preserve">檢視遠端存放庫 '{0}'</x:String>
<x:String x:Key="Text.Repository.WorkspaceSwitcher" xml:space="preserve">切換工作區</x:String>
<x:String x:Key="Text.Repository.Worktrees" xml:space="preserve">工作區列表</x:String> <x:String x:Key="Text.Repository.Worktrees" xml:space="preserve">工作區列表</x:String>
<x:String x:Key="Text.Repository.Worktrees.Add" xml:space="preserve">新增工作區</x:String> <x:String x:Key="Text.Repository.Worktrees.Add" xml:space="preserve">新增工作區</x:String>
<x:String x:Key="Text.Repository.Worktrees.Prune" xml:space="preserve">清理</x:String> <x:String x:Key="Text.Repository.Worktrees.Prune" xml:space="preserve">清理</x:String>

View file

@ -23,12 +23,6 @@ namespace SourceGit.ViewModels
private set; private set;
} }
public WorkspaceSwitcher WorkspaceSwitcher
{
get => _workspaceSwitcher;
set => SetProperty(ref _workspaceSwitcher, value);
}
public Workspace ActiveWorkspace public Workspace ActiveWorkspace
{ {
get => _activeWorkspace; get => _activeWorkspace;
@ -50,6 +44,12 @@ namespace SourceGit.ViewModels
} }
} }
public object Switcher
{
get => _switcher;
set => SetProperty(ref _switcher, value);
}
public Launcher(string startupRepo) public Launcher(string startupRepo)
{ {
_ignoreIndexChange = true; _ignoreIndexChange = true;
@ -138,12 +138,17 @@ namespace SourceGit.ViewModels
public void OpenWorkspaceSwitcher() public void OpenWorkspaceSwitcher()
{ {
WorkspaceSwitcher = new WorkspaceSwitcher(this); Switcher = new WorkspaceSwitcher(this);
} }
public void CancelWorkspaceSwitcher() public void OpenTabSwitcher()
{ {
WorkspaceSwitcher = null; Switcher = new LauncherPageSwitcher(this);
}
public void CancelSwitcher()
{
Switcher = null;
} }
public void SwitchWorkspace(Workspace to) public void SwitchWorkspace(Workspace to)
@ -618,6 +623,6 @@ namespace SourceGit.ViewModels
private LauncherPage _activePage = null; private LauncherPage _activePage = null;
private bool _ignoreIndexChange = false; private bool _ignoreIndexChange = false;
private string _title = string.Empty; private string _title = string.Empty;
private WorkspaceSwitcher _workspaceSwitcher = null; private object _switcher = null;
} }
} }

View file

@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using CommunityToolkit.Mvvm.ComponentModel;
namespace SourceGit.ViewModels
{
public class LauncherPageSwitcher : ObservableObject
{
public List<LauncherPage> VisiblePages
{
get => _visiblePages;
private set => SetProperty(ref _visiblePages, value);
}
public string SearchFilter
{
get => _searchFilter;
set
{
if (SetProperty(ref _searchFilter, value))
UpdateVisiblePages();
}
}
public LauncherPage SelectedPage
{
get => _selectedPage;
set => SetProperty(ref _selectedPage, value);
}
public LauncherPageSwitcher(Launcher launcher)
{
_launcher = launcher;
UpdateVisiblePages();
}
public void ClearFilter()
{
SearchFilter = string.Empty;
}
public void Switch()
{
if (_selectedPage is { })
_launcher.ActivePage = _selectedPage;
_launcher.CancelSwitcher();
}
private void UpdateVisiblePages()
{
var visible = new List<LauncherPage>();
if (string.IsNullOrEmpty(_searchFilter))
{
visible.AddRange(_launcher.Pages);
}
else
{
foreach (var page in _launcher.Pages)
{
if (page.Node.Name.Contains(_searchFilter, StringComparison.OrdinalIgnoreCase) ||
(page.Node.IsRepository && page.Node.Id.Contains(_searchFilter, StringComparison.OrdinalIgnoreCase)))
{
visible.Add(page);
}
}
}
VisiblePages = visible;
}
private Launcher _launcher = null;
private List<LauncherPage> _visiblePages = [];
private string _searchFilter = string.Empty;
private LauncherPage _selectedPage = null;
}
}

View file

@ -2632,7 +2632,7 @@ namespace SourceGit.ViewModels
if (node.Path.Equals(path, StringComparison.Ordinal)) if (node.Path.Equals(path, StringComparison.Ordinal))
return node; return node;
if (path!.StartsWith(node.Path, StringComparison.Ordinal)) if (path.StartsWith(node.Path, StringComparison.Ordinal))
{ {
var founded = FindBranchNode(node.Children, path); var founded = FindBranchNode(node.Children, path);
if (founded != null) if (founded != null)

View file

@ -44,7 +44,7 @@ namespace SourceGit.ViewModels
if (_selectedWorkspace is { }) if (_selectedWorkspace is { })
_launcher.SwitchWorkspace(_selectedWorkspace); _launcher.SwitchWorkspace(_selectedWorkspace);
_launcher.CancelWorkspaceSwitcher(); _launcher.CancelSwitcher();
} }
private void UpdateVisibleWorkspaces() private void UpdateVisibleWorkspaces()

View file

@ -45,8 +45,8 @@
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" 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="0" Classes="primary bold" Text="{OnPlatform Ctrl+\,, 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}"/>
<TextBlock Grid.Row="1" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Ctrl+T, macOS=⌘+T}"/> <TextBlock Grid.Row="1" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Ctrl+T, macOS=⌘+T}"/>
@ -55,7 +55,7 @@
<TextBlock Grid.Row="2" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Ctrl+W, macOS=⌘+W}" /> <TextBlock Grid.Row="2" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Ctrl+W, macOS=⌘+W}" />
<TextBlock Grid.Row="2" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.CloseTab}" /> <TextBlock Grid.Row="2" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.CloseTab}" />
<TextBlock Grid.Row="3" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Shift+Ctrl+Tab, macOS=⌘+⌥+←}"/> <TextBlock Grid.Row="3" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Ctrl+Shift+Tab, macOS=⌘+⌥+←}"/>
<TextBlock Grid.Row="3" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.GotoPrevTab}" /> <TextBlock Grid.Row="3" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.GotoPrevTab}" />
<TextBlock Grid.Row="4" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Ctrl+Tab, macOS=⌘+⌥+→}"/> <TextBlock Grid.Row="4" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Ctrl+Tab, macOS=⌘+⌥+→}"/>
@ -70,8 +70,11 @@
<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 Ctrl+P, macOS=⌘+P}"/> <TextBlock Grid.Row="8" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Ctrl+Shift+P, macOS=⌘+⇧+P}"/>
<TextBlock Grid.Row="8" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.SwitchWorkspace}" /> <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 Ctrl+P, macOS=⌘+P}"/>
<TextBlock Grid.Row="9" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.SwitchTab}" />
</Grid> </Grid>
<TextBlock Text="{DynamicResource Text.Hotkeys.Repo}" <TextBlock Text="{DynamicResource Text.Hotkeys.Repo}"

View file

@ -106,14 +106,18 @@
<!-- Workspace Switcher --> <!-- Workspace Switcher -->
<Border Grid.Row="1" <Border Grid.Row="1"
Background="Transparent" Background="Transparent"
IsVisible="{Binding WorkspaceSwitcher, Converter={x:Static ObjectConverters.IsNotNull}}"> IsVisible="{Binding Switcher, Converter={x:Static ObjectConverters.IsNotNull}}">
<Border HorizontalAlignment="Center" VerticalAlignment="Center" Effect="drop-shadow(0 0 12 #A0000000)"> <Border HorizontalAlignment="Center" VerticalAlignment="Center" Effect="drop-shadow(0 0 12 #A0000000)">
<Border Background="{DynamicResource Brush.Popup}" CornerRadius="8"> <Border Background="{DynamicResource Brush.Popup}" CornerRadius="8">
<ContentControl Margin="16" Content="{Binding WorkspaceSwitcher}"> <ContentControl Margin="16" Content="{Binding Switcher}">
<ContentControl.DataTemplates> <ContentControl.DataTemplates>
<DataTemplate DataType="vm:WorkspaceSwitcher"> <DataTemplate DataType="vm:WorkspaceSwitcher">
<v:WorkspaceSwitcher/> <v:WorkspaceSwitcher/>
</DataTemplate> </DataTemplate>
<DataTemplate DataType="vm:LauncherPageSwitcher">
<v:LauncherPageSwitcher/>
</DataTemplate>
</ContentControl.DataTemplates> </ContentControl.DataTemplates>
</ContentControl> </ContentControl>
</Border> </Border>

View file

@ -133,8 +133,8 @@ namespace SourceGit.Views
return; return;
} }
// Ctrl+Shift+P opens preference dialog (macOS use hotkeys in system menu bar) // Ctrl+, opens preference dialog (macOS use hotkeys in system menu bar)
if (!OperatingSystem.IsMacOS() && e is { KeyModifiers: (KeyModifiers.Control | KeyModifiers.Shift), Key: Key.P }) if (!OperatingSystem.IsMacOS() && e is { KeyModifiers: KeyModifiers.Control, Key: Key.OemComma })
{ {
App.ShowWindow(new Preferences(), true); App.ShowWindow(new Preferences(), true);
e.Handled = true; e.Handled = true;
@ -149,7 +149,7 @@ namespace SourceGit.Views
} }
// Ctrl+Q quits the application (macOS use hotkeys in system menu bar) // Ctrl+Q quits the application (macOS use hotkeys in system menu bar)
if (!OperatingSystem.IsMacOS() && e.KeyModifiers == KeyModifiers.Control && e.Key == Key.Q) if (!OperatingSystem.IsMacOS() && e is { KeyModifiers: KeyModifiers.Control, Key: Key.Q })
{ {
App.Quit(0); App.Quit(0);
return; return;
@ -157,10 +157,18 @@ namespace SourceGit.Views
if (e.KeyModifiers.HasFlag(OperatingSystem.IsMacOS() ? KeyModifiers.Meta : KeyModifiers.Control)) if (e.KeyModifiers.HasFlag(OperatingSystem.IsMacOS() ? KeyModifiers.Meta : KeyModifiers.Control))
{ {
if (e.Key == Key.P) if (e.KeyModifiers.HasFlag(KeyModifiers.Shift) && e.Key == Key.P)
{ {
vm.OpenWorkspaceSwitcher(); vm.OpenWorkspaceSwitcher();
e.Handled = true; e.Handled = true;
return;
}
if (e.Key == Key.P)
{
vm.OpenTabSwitcher();
e.Handled = true;
return;
} }
if (e.Key == Key.W) if (e.Key == Key.W)
@ -257,7 +265,7 @@ namespace SourceGit.Views
else if (e.Key == Key.Escape) else if (e.Key == Key.Escape)
{ {
vm.ActivePage.CancelPopup(); vm.ActivePage.CancelPopup();
vm.CancelWorkspaceSwitcher(); vm.CancelSwitcher();
e.Handled = true; e.Handled = true;
return; return;
} }

View file

@ -3,19 +3,27 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:SourceGit.ViewModels" xmlns:vm="using:SourceGit.ViewModels"
xmlns:v="using:SourceGit.Views"
xmlns:c="using:SourceGit.Converters" xmlns:c="using:SourceGit.Converters"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.LauncherTabsSelector" x:Class="SourceGit.Views.LauncherPageSwitcher"
x:Name="ThisControl"> x:DataType="vm:LauncherPageSwitcher">
<Grid RowDefinitions="28,Auto"> <Grid RowDefinitions="28,Auto,Auto">
<TextBox Grid.Row="0" <TextBlock Grid.Row="0"
Text="{DynamicResource Text.Launcher.SwitchTab}"
FontWeight="Bold"
HorizontalAlignment="Center" VerticalAlignment="Top"/>
<TextBox Grid.Row="1"
Height="24" Height="24"
Margin="4,0" Margin="4,0"
BorderThickness="1" BorderThickness="1"
CornerRadius="12" CornerRadius="12"
Text="{Binding #ThisControl.SearchFilter, Mode=TwoWay}" Text="{Binding SearchFilter, Mode=TwoWay}"
KeyDown="OnSearchBoxKeyDown"
BorderBrush="{DynamicResource Brush.Border2}" BorderBrush="{DynamicResource Brush.Border2}"
VerticalContentAlignment="Center"> VerticalContentAlignment="Center"
v:AutoFocusBehaviour.IsEnabled="True">
<TextBox.InnerLeftContent> <TextBox.InnerLeftContent>
<Path Width="14" Height="14" <Path Width="14" Height="14"
Margin="6,0,0,0" Margin="6,0,0,0"
@ -27,8 +35,8 @@
<Button Classes="icon_button" <Button Classes="icon_button"
Width="16" Width="16"
Margin="0,0,6,0" Margin="0,0,6,0"
Click="OnClearSearchFilter" Command="{Binding ClearFilter}"
IsVisible="{Binding #ThisControl.SearchFilter, Converter={x:Static StringConverters.IsNotNullOrEmpty}}" IsVisible="{Binding SearchFilter, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
HorizontalAlignment="Right"> HorizontalAlignment="Right">
<Path Width="14" Height="14" <Path Width="14" Height="14"
Margin="0,1,0,0" Margin="0,1,0,0"
@ -38,19 +46,22 @@
</TextBox.InnerRightContent> </TextBox.InnerRightContent>
</TextBox> </TextBox>
<ListBox Grid.Row="1" <ListBox Grid.Row="2"
Width="200" x:Name="PagesListBox"
Width="300"
MaxHeight="400" MaxHeight="400"
Margin="0,4,0,0" Margin="0,8,0,0"
Background="Transparent" BorderThickness="0"
SelectionMode="Single" SelectionMode="Single"
Background="Transparent"
Focusable="True"
ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"
ItemsSource="{Binding #ThisControl.VisiblePages}" ItemsSource="{Binding VisiblePages, Mode=OneWay}"
SelectionChanged="OnPageSelectionChanged"> SelectedItem="{Binding SelectedPage, Mode=TwoWay}">
<ListBox.Styles> <ListBox.Styles>
<Style Selector="ListBoxItem"> <Style Selector="ListBoxItem">
<Setter Property="Padding" Value="0"/> <Setter Property="Padding" Value="8,0"/>
<Setter Property="MinHeight" Value="26"/> <Setter Property="MinHeight" Value="26"/>
<Setter Property="CornerRadius" Value="4"/> <Setter Property="CornerRadius" Value="4"/>
</Style> </Style>
@ -72,30 +83,28 @@
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate DataType="vm:LauncherPage"> <DataTemplate DataType="vm:LauncherPage">
<Grid ColumnDefinitions="Auto,*" VerticalAlignment="Center"> <Grid ColumnDefinitions="Auto,6,*" Background="Transparent" DoubleTapped="OnItemDoubleTapped">
<Path Grid.Column="0" <Path Grid.Column="0"
Width="12" Height="12" Margin="12,0" Width="12" Height="12"
Fill="{Binding Node.Bookmark, Converter={x:Static c:IntConverters.ToBookmarkBrush}}" Fill="{Binding Node.Bookmark, Converter={x:Static c:IntConverters.ToBookmarkBrush}}"
Data="{StaticResource Icons.Bookmark}" Data="{StaticResource Icons.Bookmark}"
IsVisible="{Binding Node.IsRepository}" IsVisible="{Binding Node.IsRepository}"
IsHitTestVisible="False"/> IsHitTestVisible="False"/>
<Path Grid.Column="0" <Path Grid.Column="0"
Width="12" Height="12" Margin="12,0" Width="12" Height="12"
Fill="{DynamicResource Brush.FG1}" Fill="{DynamicResource Brush.FG1}"
Data="{StaticResource Icons.Repositories}" Data="{StaticResource Icons.Repositories}"
IsVisible="{Binding !Node.IsRepository}" IsVisible="{Binding !Node.IsRepository}"
IsHitTestVisible="False"/> IsHitTestVisible="False"/>
<TextBlock Grid.Column="1" <TextBlock Grid.Column="2"
Classes="primary" Classes="primary"
VerticalAlignment="Center" VerticalAlignment="Center"
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Decrease}}"
Text="{Binding Node.Name}" Text="{Binding Node.Name}"
IsVisible="{Binding Node.IsRepository}" IsVisible="{Binding Node.IsRepository}"
IsHitTestVisible="False"/> IsHitTestVisible="False"/>
<TextBlock Grid.Column="1" <TextBlock Grid.Column="2"
Classes="primary" Classes="primary"
VerticalAlignment="Center" VerticalAlignment="Center"
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Decrease}}"
Text="{DynamicResource Text.PageTabBar.Welcome.Title}" Text="{DynamicResource Text.PageTabBar.Welcome.Title}"
IsVisible="{Binding !Node.IsRepository}" IsVisible="{Binding !Node.IsRepository}"
IsHitTestVisible="False"/> IsHitTestVisible="False"/>

View file

@ -0,0 +1,49 @@
using Avalonia.Controls;
using Avalonia.Input;
namespace SourceGit.Views
{
public partial class LauncherPageSwitcher : UserControl
{
public LauncherPageSwitcher()
{
InitializeComponent();
}
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
if (e.Key == Key.Enter && DataContext is ViewModels.LauncherPageSwitcher switcher)
{
switcher.Switch();
e.Handled = true;
}
}
private void OnItemDoubleTapped(object sender, TappedEventArgs e)
{
if (DataContext is ViewModels.LauncherPageSwitcher switcher)
{
switcher.Switch();
e.Handled = true;
}
}
private void OnSearchBoxKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Down && PagesListBox.ItemCount > 0)
{
PagesListBox.Focus(NavigationMethod.Directional);
if (PagesListBox.SelectedIndex < 0)
PagesListBox.SelectedIndex = 0;
else if (PagesListBox.SelectedIndex < PagesListBox.ItemCount)
PagesListBox.SelectedIndex++;
e.Handled = true;
}
}
}
}

View file

@ -40,7 +40,7 @@
</ListBox.ItemsPanel> </ListBox.ItemsPanel>
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type vm:LauncherPage}"> <DataTemplate DataType="vm:LauncherPage">
<Border Height="30" <Border Height="30"
Background="Transparent" Background="Transparent"
PointerPressed="OnPointerPressedTab" PointerPressed="OnPointerPressedTab"
@ -141,8 +141,106 @@
<Button x:Name="PageSelector" Classes="icon_button" Width="16" Height="16" Margin="8,0"> <Button x:Name="PageSelector" Classes="icon_button" Width="16" Height="16" Margin="8,0">
<Button.Flyout> <Button.Flyout>
<Flyout> <Flyout Opened="OnTabsDropdownOpened">
<v:LauncherTabsSelector Pages="{Binding Pages}" PageSelected="OnGotoSelectedPage"/> <Grid RowDefinitions="28,Auto" KeyDown="OnTabsDropdownKeyDown" LostFocus="OnTabsDropdownLostFocus">
<TextBox Grid.Row="0"
Height="24"
Margin="4,0"
BorderThickness="1"
CornerRadius="12"
Text="{Binding #ThisControl.SearchFilter, Mode=TwoWay}"
BorderBrush="{DynamicResource Brush.Border2}"
VerticalContentAlignment="Center"
KeyDown="OnTabsDropdownSearchBoxKeyDown"
v:AutoFocusBehaviour.IsEnabled="True">
<TextBox.InnerLeftContent>
<Path Width="14" Height="14"
Margin="6,0,0,0"
Fill="{DynamicResource Brush.FG2}"
Data="{StaticResource Icons.Search}"/>
</TextBox.InnerLeftContent>
<TextBox.InnerRightContent>
<Button Classes="icon_button"
Width="16"
Margin="0,0,6,0"
Click="OnClearSearchFilter"
IsVisible="{Binding #ThisControl.SearchFilter, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
HorizontalAlignment="Right">
<Path Width="14" Height="14"
Margin="0,1,0,0"
Fill="{DynamicResource Brush.FG1}"
Data="{StaticResource Icons.Clear}"/>
</Button>
</TextBox.InnerRightContent>
</TextBox>
<ListBox Grid.Row="1"
x:Name="TabsDropdownList"
Focusable="True"
Width="200"
MaxHeight="400"
Margin="0,4,0,0"
Background="Transparent"
SelectionMode="Single"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ItemsSource="{Binding #ThisControl.SelectablePages}"
SelectedItem="{Binding ActivePage, Mode=OneWay}">
<ListBox.Styles>
<Style Selector="ListBoxItem">
<Setter Property="Padding" Value="0"/>
<Setter Property="MinHeight" Value="26"/>
<Setter Property="CornerRadius" Value="4"/>
</Style>
<Style Selector="ListBox">
<Setter Property="FocusAdorner">
<FocusAdornerTemplate>
<Grid/>
</FocusAdornerTemplate>
</Setter>
</Style>
</ListBox.Styles>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate DataType="vm:LauncherPage">
<Grid ColumnDefinitions="Auto,*" Background="Transparent" DoubleTapped="OnTabsDropdownItemDoubleTapped">
<Path Grid.Column="0"
Width="12" Height="12" Margin="12,0"
Fill="{Binding Node.Bookmark, Converter={x:Static c:IntConverters.ToBookmarkBrush}}"
Data="{StaticResource Icons.Bookmark}"
IsVisible="{Binding Node.IsRepository}"
IsHitTestVisible="False"/>
<Path Grid.Column="0"
Width="12" Height="12" Margin="12,0"
Fill="{DynamicResource Brush.FG1}"
Data="{StaticResource Icons.Repositories}"
IsVisible="{Binding !Node.IsRepository}"
IsHitTestVisible="False"/>
<TextBlock Grid.Column="1"
Classes="primary"
VerticalAlignment="Center"
Text="{Binding Node.Name}"
IsVisible="{Binding Node.IsRepository}"
IsHitTestVisible="False"/>
<TextBlock Grid.Column="1"
Classes="primary"
VerticalAlignment="Center"
Text="{DynamicResource Text.PageTabBar.Welcome.Title}"
IsVisible="{Binding !Node.IsRepository}"
IsHitTestVisible="False"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Flyout> </Flyout>
</Button.Flyout> </Button.Flyout>
<Path Width="14" Height="14" Data="{StaticResource Icons.CircleDown}"/> <Path Width="14" Height="14" Data="{StaticResource Icons.CircleDown}"/>

View file

@ -1,6 +1,7 @@
using System; using System;
using Avalonia; using Avalonia;
using Avalonia.Collections;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Interactivity; using Avalonia.Interactivity;
@ -19,6 +20,20 @@ namespace SourceGit.Views
set => SetValue(IsScrollerVisibleProperty, value); set => SetValue(IsScrollerVisibleProperty, value);
} }
public static readonly StyledProperty<string> SearchFilterProperty =
AvaloniaProperty.Register<LauncherTabBar, string>(nameof(SearchFilter));
public string SearchFilter
{
get => GetValue(SearchFilterProperty);
set => SetValue(SearchFilterProperty, value);
}
public AvaloniaList<ViewModels.LauncherPage> SelectablePages
{
get;
} = [];
public LauncherTabBar() public LauncherTabBar()
{ {
InitializeComponent(); InitializeComponent();
@ -126,6 +141,14 @@ namespace SourceGit.Views
context.DrawGeometry(fill, stroke, geo); context.DrawGeometry(fill, stroke, geo);
} }
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == SearchFilterProperty)
UpdateSelectablePages();
}
private void ScrollTabs(object _, PointerWheelEventArgs e) private void ScrollTabs(object _, PointerWheelEventArgs e)
{ {
if (!e.KeyModifiers.HasFlag(KeyModifiers.Shift)) if (!e.KeyModifiers.HasFlag(KeyModifiers.Shift))
@ -248,13 +271,89 @@ namespace SourceGit.Views
e.Handled = true; e.Handled = true;
} }
private void OnGotoSelectedPage(object sender, LauncherTabSelectedEventArgs e) private void OnTabsDropdownOpened(object sender, EventArgs e)
{ {
if (DataContext is ViewModels.Launcher vm) UpdateSelectablePages();
vm.ActivePage = e.Page; }
PageSelector.Flyout?.Hide(); private void OnTabsDropdownKeyDown(object sender, KeyEventArgs e)
e.Handled = true; {
if (e.Key == Key.Escape)
{
PageSelector.Flyout?.Hide();
e.Handled = true;
}
else if (e.Key == Key.Enter)
{
if (TabsDropdownList.SelectedItem is ViewModels.LauncherPage page &&
DataContext is ViewModels.Launcher vm)
{
vm.ActivePage = page;
PageSelector.Flyout?.Hide();
e.Handled = true;
}
}
}
private void OnTabsDropdownSearchBoxKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Down && TabsDropdownList.ItemCount > 0)
{
TabsDropdownList.Focus(NavigationMethod.Directional);
if (TabsDropdownList.SelectedIndex < 0)
TabsDropdownList.SelectedIndex = 0;
else if (TabsDropdownList.SelectedIndex < TabsDropdownList.ItemCount)
TabsDropdownList.SelectedIndex++;
e.Handled = true;
}
}
private void OnTabsDropdownLostFocus(object sender, RoutedEventArgs e)
{
if (sender is Control { IsFocused: false, IsKeyboardFocusWithin: false })
PageSelector.Flyout?.Hide();
}
private void OnClearSearchFilter(object sender, RoutedEventArgs e)
{
SearchFilter = string.Empty;
}
private void OnTabsDropdownItemDoubleTapped(object sender, TappedEventArgs e)
{
if (sender is Control { DataContext: ViewModels.LauncherPage page } &&
DataContext is ViewModels.Launcher vm)
{
vm.ActivePage = page;
PageSelector.Flyout?.Hide();
e.Handled = true;
}
}
private void UpdateSelectablePages()
{
if (DataContext is not ViewModels.Launcher vm)
return;
SelectablePages.Clear();
var pages = vm.Pages;
var filter = SearchFilter?.Trim() ?? "";
if (string.IsNullOrEmpty(filter))
{
SelectablePages.AddRange(pages);
return;
}
foreach (var page in pages)
{
var node = page.Node;
if (node.Name.Contains(filter, StringComparison.OrdinalIgnoreCase) ||
(node.IsRepository && node.Id.Contains(filter, StringComparison.OrdinalIgnoreCase)))
SelectablePages.Add(page);
}
} }
private bool _pressedTab = false; private bool _pressedTab = false;

View file

@ -1,120 +0,0 @@
using System;
using Avalonia;
using Avalonia.Collections;
using Avalonia.Controls;
using Avalonia.Interactivity;
namespace SourceGit.Views
{
public class LauncherTabSelectedEventArgs : RoutedEventArgs
{
public ViewModels.LauncherPage Page { get; }
public LauncherTabSelectedEventArgs(ViewModels.LauncherPage page)
{
RoutedEvent = LauncherTabsSelector.PageSelectedEvent;
Page = page;
}
}
public partial class LauncherTabsSelector : UserControl
{
public static readonly StyledProperty<AvaloniaList<ViewModels.LauncherPage>> PagesProperty =
AvaloniaProperty.Register<LauncherTabsSelector, AvaloniaList<ViewModels.LauncherPage>>(nameof(Pages));
public AvaloniaList<ViewModels.LauncherPage> Pages
{
get => GetValue(PagesProperty);
set => SetValue(PagesProperty, value);
}
public static readonly StyledProperty<string> SearchFilterProperty =
AvaloniaProperty.Register<LauncherTabsSelector, string>(nameof(SearchFilter));
public string SearchFilter
{
get => GetValue(SearchFilterProperty);
set => SetValue(SearchFilterProperty, value);
}
public static readonly RoutedEvent<LauncherTabSelectedEventArgs> PageSelectedEvent =
RoutedEvent.Register<LauncherTabsSelector, LauncherTabSelectedEventArgs>(nameof(PageSelected), RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
public event EventHandler<LauncherTabSelectedEventArgs> PageSelected
{
add { AddHandler(PageSelectedEvent, value); }
remove { RemoveHandler(PageSelectedEvent, value); }
}
public AvaloniaList<ViewModels.LauncherPage> VisiblePages
{
get;
private set;
}
public LauncherTabsSelector()
{
VisiblePages = new AvaloniaList<ViewModels.LauncherPage>();
InitializeComponent();
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == PagesProperty || change.Property == SearchFilterProperty)
UpdateVisiblePages();
}
private void OnClearSearchFilter(object sender, RoutedEventArgs e)
{
SearchFilter = string.Empty;
}
private void OnPageSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (sender is ListBox { SelectedItem: ViewModels.LauncherPage page })
{
_isProcessingSelection = true;
RaiseEvent(new LauncherTabSelectedEventArgs(page));
_isProcessingSelection = false;
}
e.Handled = true;
}
private void UpdateVisiblePages()
{
if (_isProcessingSelection)
return;
VisiblePages.Clear();
if (Pages == null)
return;
var filter = SearchFilter?.Trim() ?? "";
if (string.IsNullOrEmpty(filter))
{
foreach (var p in Pages)
VisiblePages.Add(p);
return;
}
foreach (var page in Pages)
{
if (!page.Node.IsRepository)
continue;
if (page.Node.Name.Contains(filter, StringComparison.OrdinalIgnoreCase) ||
page.Node.Id.Contains(filter, StringComparison.OrdinalIgnoreCase))
VisiblePages.Add(page);
}
}
private bool _isProcessingSelection = false;
}
}

View file

@ -9,7 +9,7 @@
x:DataType="vm:WorkspaceSwitcher"> x:DataType="vm:WorkspaceSwitcher">
<Grid RowDefinitions="28,Auto,Auto"> <Grid RowDefinitions="28,Auto,Auto">
<TextBlock Grid.Row="0" <TextBlock Grid.Row="0"
Text="{DynamicResource Text.Repository.WorkspaceSwitcher}" Text="{DynamicResource Text.Launcher.SwitchWorkspace}"
FontWeight="Bold" FontWeight="Bold"
HorizontalAlignment="Center" VerticalAlignment="Top"/> HorizontalAlignment="Center" VerticalAlignment="Top"/>
@ -82,7 +82,7 @@
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate DataType="vm:Workspace"> <DataTemplate DataType="vm:Workspace">
<Grid ColumnDefinitions="Auto,*" VerticalAlignment="Center" Background="Transparent" DoubleTapped="OnItemDoubleTapped"> <Grid ColumnDefinitions="Auto,*" Background="Transparent" DoubleTapped="OnItemDoubleTapped">
<Path Grid.Column="0" <Path Grid.Column="0"
Width="12" Height="12" Width="12" Height="12"
Fill="{Binding Brush}" Fill="{Binding Brush}"