ux: remove workspace switcher popup and its hotkey binding (#1855)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2025-10-16 17:49:59 +08:00
parent 6d13ba66d1
commit 8a4a8be2a2
8 changed files with 2 additions and 274 deletions

View File

@@ -467,7 +467,6 @@
<x:String x:Key="Text.Hotkeys.Global.GotoPrevTab" xml:space="preserve">Go to previous tab</x:String>
<x:String x:Key="Text.Hotkeys.Global.NewTab" xml:space="preserve">Create new tab</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.SwitchTab" xml:space="preserve">Switch active tab</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>

View File

@@ -127,11 +127,6 @@ namespace SourceGit.ViewModels
_ignoreIndexChange = false;
}
public void OpenWorkspaceSwitcher()
{
Switcher = new WorkspaceSwitcher(this);
}
public void OpenTabSwitcher()
{
Switcher = new LauncherPageSwitcher(this);

View File

@@ -1,80 +0,0 @@
using System;
using System.Collections.Generic;
using CommunityToolkit.Mvvm.ComponentModel;
namespace SourceGit.ViewModels
{
public class WorkspaceSwitcher : ObservableObject, IDisposable
{
public List<Workspace> VisibleWorkspaces
{
get => _visibleWorkspaces;
private set => SetProperty(ref _visibleWorkspaces, value);
}
public string SearchFilter
{
get => _searchFilter;
set
{
if (SetProperty(ref _searchFilter, value))
UpdateVisibleWorkspaces();
}
}
public Workspace SelectedWorkspace
{
get => _selectedWorkspace;
set => SetProperty(ref _selectedWorkspace, value);
}
public WorkspaceSwitcher(Launcher launcher)
{
_launcher = launcher;
UpdateVisibleWorkspaces();
}
public void ClearFilter()
{
SearchFilter = string.Empty;
}
public void Switch()
{
_launcher.SwitchWorkspace(_selectedWorkspace);
_launcher.CancelSwitcher();
}
public void Dispose()
{
_visibleWorkspaces.Clear();
_selectedWorkspace = null;
_searchFilter = string.Empty;
}
private void UpdateVisibleWorkspaces()
{
var visible = new List<Workspace>();
if (string.IsNullOrEmpty(_searchFilter))
{
visible.AddRange(Preferences.Instance.Workspaces);
}
else
{
foreach (var workspace in Preferences.Instance.Workspaces)
{
if (workspace.Name.Contains(_searchFilter, StringComparison.OrdinalIgnoreCase))
visible.Add(workspace);
}
}
VisibleWorkspaces = visible;
SelectedWorkspace = visible.Count == 0 ? null : visible[0];
}
private Launcher _launcher = null;
private List<Workspace> _visibleWorkspaces = null;
private string _searchFilter = string.Empty;
private Workspace _selectedWorkspace = null;
}
}

View File

@@ -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" ColumnDefinitions="150,*">
<Grid RowDefinitions="20,20,20,20,20,20,20,20" ColumnDefinitions="150,*">
<TextBlock Grid.Row="0" Grid.Column="0" Classes="bold" Text="{OnPlatform Ctrl+\,, macOS=⌘+\,}"/>
<TextBlock Grid.Row="0" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.OpenPreferences}"/>
@@ -67,9 +67,6 @@
<TextBlock Grid.Row="6" Grid.Column="0" Classes="bold" Text="{OnPlatform Ctrl+Q, macOS=⌘+Q}"/>
<TextBlock Grid.Row="6" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Quit}" />
<TextBlock Grid.Row="7" Grid.Column="0" Classes="bold" Text="{OnPlatform Ctrl+Shift+P, macOS=⌘+⇧+P}"/>
<TextBlock Grid.Row="7" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.SwitchWorkspace}" />
<TextBlock Grid.Row="8" Grid.Column="0" Classes="bold" Text="{OnPlatform Ctrl+P, macOS=⌘+P}"/>
<TextBlock Grid.Row="8" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.SwitchTab}" />
</Grid>

View File

@@ -118,7 +118,7 @@
</ContentControl.DataTemplates>
</ContentControl>
<!-- Workspace/Pages Switcher -->
<!-- Pages Switcher -->
<Border Grid.Row="0" Grid.RowSpan="2"
Background="Transparent"
IsVisible="{Binding Switcher, Converter={x:Static ObjectConverters.IsNotNull}}"
@@ -127,10 +127,6 @@
<Border Background="{DynamicResource Brush.Popup}" CornerRadius="8">
<ContentControl Margin="16,10,16,12" Content="{Binding Switcher}">
<ContentControl.DataTemplates>
<DataTemplate DataType="vm:WorkspaceSwitcher">
<v:WorkspaceSwitcher/>
</DataTemplate>
<DataTemplate DataType="vm:LauncherPageSwitcher">
<v:LauncherPageSwitcher/>
</DataTemplate>

View File

@@ -174,13 +174,6 @@ namespace SourceGit.Views
if (e.KeyModifiers.HasFlag(OperatingSystem.IsMacOS() ? KeyModifiers.Meta : KeyModifiers.Control))
{
if (e.KeyModifiers.HasFlag(KeyModifiers.Shift) && e.Key == Key.P)
{
vm.OpenWorkspaceSwitcher();
e.Handled = true;
return;
}
if (e.Key == Key.P)
{
vm.OpenTabSwitcher();
@@ -329,7 +322,6 @@ namespace SourceGit.Views
var workspaces = new MenuItem();
workspaces.Header = groupHeader;
workspaces.Tag = OperatingSystem.IsMacOS() ? "⌘+⇧+P" : "Ctrl+Shift+P";
workspaces.IsEnabled = false;
menu.Items.Add(workspaces);

View File

@@ -1,109 +0,0 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:v="using:SourceGit.Views"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.WorkspaceSwitcher"
x:DataType="vm:WorkspaceSwitcher">
<Grid RowDefinitions="Auto,Auto,Auto">
<TextBlock Grid.Row="0"
Text="{DynamicResource Text.Launcher.Workspaces}"
FontWeight="Bold"
HorizontalAlignment="Center"/>
<TextBox Grid.Row="1"
Height="24"
Margin="4,8,4,0"
BorderThickness="1"
CornerRadius="12"
Text="{Binding SearchFilter, Mode=TwoWay}"
KeyDown="OnSearchBoxKeyDown"
BorderBrush="{DynamicResource Brush.Border2}"
VerticalContentAlignment="Center"
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"
Command="{Binding ClearFilter}"
IsVisible="{Binding 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="2"
x:Name="WorkspaceListBox"
Width="300"
MaxHeight="400"
Margin="4,8,4,0"
BorderThickness="0"
SelectionMode="Single"
Background="Transparent"
Focusable="True"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ItemsSource="{Binding VisibleWorkspaces, Mode=OneWay}"
SelectedItem="{Binding SelectedWorkspace, Mode=TwoWay}">
<ListBox.Styles>
<Style Selector="ListBoxItem">
<Setter Property="Padding" Value="8,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:Workspace">
<Grid ColumnDefinitions="Auto,*" Background="Transparent" Tapped="OnItemTapped">
<Path Grid.Column="0"
Width="12" Height="12"
Fill="{Binding Brush}"
Data="{StaticResource Icons.Workspace}"
IsVisible="{Binding !IsActive}"
IsHitTestVisible="False"/>
<Path Grid.Column="0"
Width="12" Height="12"
Fill="{Binding Brush}"
Data="{StaticResource Icons.Check}"
IsVisible="{Binding IsActive}"
IsHitTestVisible="False"/>
<TextBlock Grid.Column="1"
Margin="8,0,0,0"
VerticalAlignment="Center"
Text="{Binding Name}"
IsHitTestVisible="False"
TextTrimming="CharacterEllipsis"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</UserControl>

View File

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