mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-05 11:05: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
|
@ -45,8 +45,8 @@
|
|||
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,*">
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Classes="primary bold" Text="{OnPlatform Ctrl+Shift+P, macOS=⌘+\,}"/>
|
||||
<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+\,, macOS=⌘+\,}"/>
|
||||
<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}"/>
|
||||
|
@ -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="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="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="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="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>
|
||||
|
||||
<TextBlock Text="{DynamicResource Text.Hotkeys.Repo}"
|
||||
|
|
|
@ -106,14 +106,18 @@
|
|||
<!-- Workspace Switcher -->
|
||||
<Border Grid.Row="1"
|
||||
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 Background="{DynamicResource Brush.Popup}" CornerRadius="8">
|
||||
<ContentControl Margin="16" Content="{Binding WorkspaceSwitcher}">
|
||||
<ContentControl Margin="16" Content="{Binding Switcher}">
|
||||
<ContentControl.DataTemplates>
|
||||
<DataTemplate DataType="vm:WorkspaceSwitcher">
|
||||
<v:WorkspaceSwitcher/>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="vm:LauncherPageSwitcher">
|
||||
<v:LauncherPageSwitcher/>
|
||||
</DataTemplate>
|
||||
</ContentControl.DataTemplates>
|
||||
</ContentControl>
|
||||
</Border>
|
||||
|
|
|
@ -133,8 +133,8 @@ namespace SourceGit.Views
|
|||
return;
|
||||
}
|
||||
|
||||
// Ctrl+Shift+P opens preference dialog (macOS use hotkeys in system menu bar)
|
||||
if (!OperatingSystem.IsMacOS() && e is { KeyModifiers: (KeyModifiers.Control | KeyModifiers.Shift), Key: Key.P })
|
||||
// Ctrl+, opens preference dialog (macOS use hotkeys in system menu bar)
|
||||
if (!OperatingSystem.IsMacOS() && e is { KeyModifiers: KeyModifiers.Control, Key: Key.OemComma })
|
||||
{
|
||||
App.ShowWindow(new Preferences(), true);
|
||||
e.Handled = true;
|
||||
|
@ -149,7 +149,7 @@ namespace SourceGit.Views
|
|||
}
|
||||
|
||||
// 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);
|
||||
return;
|
||||
|
@ -157,10 +157,18 @@ namespace SourceGit.Views
|
|||
|
||||
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();
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.Key == Key.P)
|
||||
{
|
||||
vm.OpenTabSwitcher();
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.Key == Key.W)
|
||||
|
@ -257,7 +265,7 @@ namespace SourceGit.Views
|
|||
else if (e.Key == Key.Escape)
|
||||
{
|
||||
vm.ActivePage.CancelPopup();
|
||||
vm.CancelWorkspaceSwitcher();
|
||||
vm.CancelSwitcher();
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -3,19 +3,27 @@
|
|||
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"
|
||||
xmlns:c="using:SourceGit.Converters"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="SourceGit.Views.LauncherTabsSelector"
|
||||
x:Name="ThisControl">
|
||||
<Grid RowDefinitions="28,Auto">
|
||||
<TextBox Grid.Row="0"
|
||||
x:Class="SourceGit.Views.LauncherPageSwitcher"
|
||||
x:DataType="vm:LauncherPageSwitcher">
|
||||
<Grid RowDefinitions="28,Auto,Auto">
|
||||
<TextBlock Grid.Row="0"
|
||||
Text="{DynamicResource Text.Launcher.SwitchTab}"
|
||||
FontWeight="Bold"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Top"/>
|
||||
|
||||
<TextBox Grid.Row="1"
|
||||
Height="24"
|
||||
Margin="4,0"
|
||||
BorderThickness="1"
|
||||
CornerRadius="12"
|
||||
Text="{Binding #ThisControl.SearchFilter, Mode=TwoWay}"
|
||||
Text="{Binding SearchFilter, Mode=TwoWay}"
|
||||
KeyDown="OnSearchBoxKeyDown"
|
||||
BorderBrush="{DynamicResource Brush.Border2}"
|
||||
VerticalContentAlignment="Center">
|
||||
VerticalContentAlignment="Center"
|
||||
v:AutoFocusBehaviour.IsEnabled="True">
|
||||
<TextBox.InnerLeftContent>
|
||||
<Path Width="14" Height="14"
|
||||
Margin="6,0,0,0"
|
||||
|
@ -27,8 +35,8 @@
|
|||
<Button Classes="icon_button"
|
||||
Width="16"
|
||||
Margin="0,0,6,0"
|
||||
Click="OnClearSearchFilter"
|
||||
IsVisible="{Binding #ThisControl.SearchFilter, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
|
||||
Command="{Binding ClearFilter}"
|
||||
IsVisible="{Binding SearchFilter, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
|
||||
HorizontalAlignment="Right">
|
||||
<Path Width="14" Height="14"
|
||||
Margin="0,1,0,0"
|
||||
|
@ -38,19 +46,22 @@
|
|||
</TextBox.InnerRightContent>
|
||||
</TextBox>
|
||||
|
||||
<ListBox Grid.Row="1"
|
||||
Width="200"
|
||||
<ListBox Grid.Row="2"
|
||||
x:Name="PagesListBox"
|
||||
Width="300"
|
||||
MaxHeight="400"
|
||||
Margin="0,4,0,0"
|
||||
Background="Transparent"
|
||||
Margin="0,8,0,0"
|
||||
BorderThickness="0"
|
||||
SelectionMode="Single"
|
||||
Background="Transparent"
|
||||
Focusable="True"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||
ItemsSource="{Binding #ThisControl.VisiblePages}"
|
||||
SelectionChanged="OnPageSelectionChanged">
|
||||
ItemsSource="{Binding VisiblePages, Mode=OneWay}"
|
||||
SelectedItem="{Binding SelectedPage, Mode=TwoWay}">
|
||||
<ListBox.Styles>
|
||||
<Style Selector="ListBoxItem">
|
||||
<Setter Property="Padding" Value="0"/>
|
||||
<Setter Property="Padding" Value="8,0"/>
|
||||
<Setter Property="MinHeight" Value="26"/>
|
||||
<Setter Property="CornerRadius" Value="4"/>
|
||||
</Style>
|
||||
|
@ -72,30 +83,28 @@
|
|||
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate DataType="vm:LauncherPage">
|
||||
<Grid ColumnDefinitions="Auto,*" VerticalAlignment="Center">
|
||||
<Grid ColumnDefinitions="Auto,6,*" Background="Transparent" DoubleTapped="OnItemDoubleTapped">
|
||||
<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}}"
|
||||
Data="{StaticResource Icons.Bookmark}"
|
||||
IsVisible="{Binding Node.IsRepository}"
|
||||
IsHitTestVisible="False"/>
|
||||
<Path Grid.Column="0"
|
||||
Width="12" Height="12" Margin="12,0"
|
||||
Width="12" Height="12"
|
||||
Fill="{DynamicResource Brush.FG1}"
|
||||
Data="{StaticResource Icons.Repositories}"
|
||||
IsVisible="{Binding !Node.IsRepository}"
|
||||
IsHitTestVisible="False"/>
|
||||
<TextBlock Grid.Column="1"
|
||||
<TextBlock Grid.Column="2"
|
||||
Classes="primary"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Decrease}}"
|
||||
Text="{Binding Node.Name}"
|
||||
IsVisible="{Binding Node.IsRepository}"
|
||||
IsHitTestVisible="False"/>
|
||||
<TextBlock Grid.Column="1"
|
||||
<TextBlock Grid.Column="2"
|
||||
Classes="primary"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Decrease}}"
|
||||
Text="{DynamicResource Text.PageTabBar.Welcome.Title}"
|
||||
IsVisible="{Binding !Node.IsRepository}"
|
||||
IsHitTestVisible="False"/>
|
49
src/Views/LauncherPageSwitcher.axaml.cs
Normal file
49
src/Views/LauncherPageSwitcher.axaml.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@
|
|||
</ListBox.ItemsPanel>
|
||||
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type vm:LauncherPage}">
|
||||
<DataTemplate DataType="vm:LauncherPage">
|
||||
<Border Height="30"
|
||||
Background="Transparent"
|
||||
PointerPressed="OnPointerPressedTab"
|
||||
|
@ -141,8 +141,106 @@
|
|||
|
||||
<Button x:Name="PageSelector" Classes="icon_button" Width="16" Height="16" Margin="8,0">
|
||||
<Button.Flyout>
|
||||
<Flyout>
|
||||
<v:LauncherTabsSelector Pages="{Binding Pages}" PageSelected="OnGotoSelectedPage"/>
|
||||
<Flyout Opened="OnTabsDropdownOpened">
|
||||
<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>
|
||||
</Button.Flyout>
|
||||
<Path Width="14" Height="14" Data="{StaticResource Icons.CircleDown}"/>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
|
||||
using Avalonia;
|
||||
using Avalonia.Collections;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
|
@ -18,6 +19,20 @@ namespace SourceGit.Views
|
|||
get => GetValue(IsScrollerVisibleProperty);
|
||||
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()
|
||||
{
|
||||
|
@ -125,7 +140,15 @@ namespace SourceGit.Views
|
|||
var stroke = new Pen(this.FindResource("Brush.Border0") as IBrush);
|
||||
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)
|
||||
{
|
||||
if (!e.KeyModifiers.HasFlag(KeyModifiers.Shift))
|
||||
|
@ -247,16 +270,92 @@ namespace SourceGit.Views
|
|||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnGotoSelectedPage(object sender, LauncherTabSelectedEventArgs e)
|
||||
|
||||
private void OnTabsDropdownOpened(object sender, EventArgs e)
|
||||
{
|
||||
if (DataContext is ViewModels.Launcher vm)
|
||||
vm.ActivePage = e.Page;
|
||||
UpdateSelectablePages();
|
||||
}
|
||||
|
||||
private void OnTabsDropdownKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
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);
|
||||
|
||||
PageSelector.Flyout?.Hide();
|
||||
e.Handled = true;
|
||||
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 Point _pressedTabPosition = new Point();
|
||||
private bool _startDragTab = false;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
x:DataType="vm:WorkspaceSwitcher">
|
||||
<Grid RowDefinitions="28,Auto,Auto">
|
||||
<TextBlock Grid.Row="0"
|
||||
Text="{DynamicResource Text.Repository.WorkspaceSwitcher}"
|
||||
Text="{DynamicResource Text.Launcher.SwitchWorkspace}"
|
||||
FontWeight="Bold"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Top"/>
|
||||
|
||||
|
@ -82,7 +82,7 @@
|
|||
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate DataType="vm:Workspace">
|
||||
<Grid ColumnDefinitions="Auto,*" VerticalAlignment="Center" Background="Transparent" DoubleTapped="OnItemDoubleTapped">
|
||||
<Grid ColumnDefinitions="Auto,*" Background="Transparent" DoubleTapped="OnItemDoubleTapped">
|
||||
<Path Grid.Column="0"
|
||||
Width="12" Height="12"
|
||||
Fill="{Binding Brush}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue