mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-22 10:55:00 +00:00
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:
parent
36c2e083cc
commit
9614b995d8
17 changed files with 418 additions and 180 deletions
77
src/ViewModels/LauncherPageSwitcher.cs
Normal file
77
src/ViewModels/LauncherPageSwitcher.cs
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue