Skip to content

Commit 0c8179b

Browse files
committed
enhance: add a opened tabs selector popup (#958)
Signed-off-by: leo <[email protected]>
1 parent e757e63 commit 0c8179b

File tree

5 files changed

+249
-2
lines changed

5 files changed

+249
-2
lines changed

src/Resources/Icons.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<StreamGeometry x:Key="Icons.Check">M512 597m-1 0a1 1 0 103 0a1 1 0 10-3 0ZM810 393 732 315 448 600 293 444 214 522l156 156 78 78 362-362z</StreamGeometry>
1111
<StreamGeometry x:Key="Icons.Changes">M747 467c29 0 56 4 82 12v-363c0-47-38-84-84-84H125c-47 0-84 38-84 84v707c0 47 38 84 84 84h375a287 287 0 01-43-152c0-160 129-289 289-289zm-531-250h438c19 0 34 15 34 34s-15 34-34 34H216c-19 0-34-15-34-34s15-34 34-34zm0 179h263c19 0 34 15 34 34s-15 34-34 34H216c-19 0-34-15-34-34s15-34 34-34zm131 247h-131c-19 0-34-15-34-34s15-34 34-34h131c19 0 34 15 34 34s-15 34-34 34zM747 521c-130 0-236 106-236 236S617 992 747 992s236-106 236-236S877 521 747 521zm11 386v-65h-130c-12 0-22-10-22-22s10-22 22-22h260l-130 108zm108-192H606l130-108v65h130c12 0 22 10 22 22s-10 22-22 22z</StreamGeometry>
1212
<StreamGeometry x:Key="Icons.CherryPick">M529 511c115 0 212 79 239 185h224a62 62 0 017 123l-7 0-224 0a247 247 0 01-479 0H65a62 62 0 01-7-123l7-0h224a247 247 0 01239-185zm0 124a124 124 0 100 247 124 124 0 000-247zm0-618c32 0 58 24 61 55l0 7V206c89 11 165 45 225 103a74 74 0 0122 45l0 9v87a62 62 0 01-123 7l-0-7v-65l-6-4c-43-33-97-51-163-53l-17-0c-74 0-133 18-180 54l-6 4v65a62 62 0 01-55 61l-7 0a62 62 0 01-61-55l-0-7V362c0-20 8-39 23-53 60-58 135-92 224-103V79c0-34 28-62 62-62z</StreamGeometry>
13+
<StreamGeometry x:Key="Icons.CircleDown">M512 926c-229 0-414-186-414-414S283 98 512 98s414 186 414 414-186 414-414 414zm0-73c189 0 341-153 341-341S701 171 512 171 171 323 171 512s153 341 341 341zm-6-192L284 439l52-52 171 171 171-171L728 439l-222 222z</StreamGeometry>
1314
<StreamGeometry x:Key="Icons.Clear">M512 57c251 0 455 204 455 455S763 967 512 967 57 763 57 512 261 57 512 57zm181 274c-11-11-29-11-40 0L512 472 371 331c-11-11-29-11-40 0-11 11-11 29 0 40L471 512 331 653c-11 11-11 29 0 40 11 11 29 11 40 0l141-141 141 141c11 11 29 11 40 0 11-11 11-29 0-40L552 512l141-141c11-11 11-29 0-40z</StreamGeometry>
1415
<StreamGeometry x:Key="Icons.Clean">M797 829a49 49 0 1049 49 49 49 0 00-49-49zm147-114A49 49 0 10992 764a49 49 0 00-49-49zM928 861a49 49 0 1049 49A49 49 0 00928 861zm-5-586L992 205 851 64l-71 71a67 67 0 00-94 0l235 235a67 67 0 000-94zm-853 128a32 32 0 00-32 50 1291 1291 0 0075 112L288 552c20 0 25 21 8 37l-93 86a1282 1282 0 00120 114l100-32c19-6 28 15 14 34l-40 55c26 19 53 36 82 53a89 89 0 00115-20 1391 1391 0 00256-485l-188-188s-306 224-595 198z</StreamGeometry>
1516
<StreamGeometry x:Key="Icons.Clone">M1280 704c0 141-115 256-256 256H288C129 960 0 831 0 672c0-126 80-232 192-272A327 327 0 01192 384c0-177 143-320 320-320 119 0 222 64 277 160C820 204 857 192 896 192c106 0 192 86 192 192 0 24-5 48-13 69C1192 477 1280 580 1280 704zm-493-128H656V352c0-18-14-32-32-32h-96c-18 0-32 14-32 32v224h-131c-29 0-43 34-23 55l211 211c12 12 33 12 45 0l211-211c20-20 6-55-23-55z</StreamGeometry>

src/Views/LauncherTabBar.axaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:vm="using:SourceGit.ViewModels"
66
xmlns:c="using:SourceGit.Converters"
7+
xmlns:v="using:SourceGit.Views"
78
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
89
x:Class="SourceGit.Views.LauncherTabBar"
910
x:DataType="vm:Launcher"
1011
x:Name="ThisControl">
11-
<Grid ColumnDefinitions="Auto,*,Auto,Auto">
12+
<Grid ColumnDefinitions="Auto,*,Auto">
1213
<RepeatButton Grid.Column="0"
1314
Classes="icon_button"
1415
Width="18" Height="30"
@@ -123,7 +124,16 @@
123124
<Path Width="8" Height="14" Stretch="Fill" Data="{StaticResource Icons.TriangleRight}"/>
124125
</RepeatButton>
125126

126-
<Button Classes="icon_button" Width="16" Height="16" Margin="8,0" Command="{Binding AddNewTab}">
127+
<Button x:Name="PageSelector" Classes="icon_button" Width="16" Height="16" Margin="8,0">
128+
<Button.Flyout>
129+
<Flyout>
130+
<v:LauncherTabsSelector Pages="{Binding Pages}" PageSelected="OnGotoSelectedPage"/>
131+
</Flyout>
132+
</Button.Flyout>
133+
<Path Width="14" Height="14" Data="{StaticResource Icons.CircleDown}"/>
134+
</Button>
135+
136+
<Button Classes="icon_button" Width="16" Height="16" Command="{Binding AddNewTab}">
127137
<ToolTip.Tip>
128138
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
129139
<TextBlock Text="{DynamicResource Text.PageTabBar.New}" VerticalAlignment="Center"/>

src/Views/LauncherTabBar.axaml.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,15 @@ private void OnCloseTab(object sender, RoutedEventArgs e)
248248
e.Handled = true;
249249
}
250250

251+
private void OnGotoSelectedPage(object sender, LauncherTabSelectedEventArgs e)
252+
{
253+
if (DataContext is ViewModels.Launcher vm)
254+
vm.ActivePage = e.Page;
255+
256+
PageSelector.Flyout?.Hide();
257+
e.Handled = true;
258+
}
259+
251260
private bool _pressedTab = false;
252261
private Point _pressedTabPosition = new Point();
253262
private bool _startDragTab = false;
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<UserControl xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:vm="using:SourceGit.ViewModels"
6+
xmlns:c="using:SourceGit.Converters"
7+
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
8+
x:Class="SourceGit.Views.LauncherTabsSelector"
9+
x:Name="ThisControl">
10+
<Grid RowDefinitions="28,Auto">
11+
<TextBox Grid.Row="0"
12+
Height="24"
13+
Margin="4,0"
14+
BorderThickness="1"
15+
CornerRadius="12"
16+
Text="{Binding #ThisControl.SearchFilter, Mode=TwoWay}"
17+
BorderBrush="{DynamicResource Brush.Border2}"
18+
VerticalContentAlignment="Center">
19+
<TextBox.InnerLeftContent>
20+
<Path Width="14" Height="14"
21+
Margin="6,0,0,0"
22+
Fill="{DynamicResource Brush.FG2}"
23+
Data="{StaticResource Icons.Search}"/>
24+
</TextBox.InnerLeftContent>
25+
26+
<TextBox.InnerRightContent>
27+
<Button Classes="icon_button"
28+
Width="16"
29+
Margin="0,0,6,0"
30+
Click="OnClearSearchFilter"
31+
IsVisible="{Binding #ThisControl.SearchFilter, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
32+
HorizontalAlignment="Right">
33+
<Path Width="14" Height="14"
34+
Margin="0,1,0,0"
35+
Fill="{DynamicResource Brush.FG1}"
36+
Data="{StaticResource Icons.Clear}"/>
37+
</Button>
38+
</TextBox.InnerRightContent>
39+
</TextBox>
40+
41+
<ListBox Grid.Row="1"
42+
Width="200"
43+
MaxHeight="400"
44+
Margin="0,4,0,0"
45+
Background="Transparent"
46+
SelectionMode="Single"
47+
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
48+
ScrollViewer.VerticalScrollBarVisibility="Auto"
49+
ItemsSource="{Binding #ThisControl.VisiblePages}"
50+
SelectionChanged="OnPageSelectionChanged">
51+
<ListBox.Styles>
52+
<Style Selector="ListBoxItem">
53+
<Setter Property="Padding" Value="0"/>
54+
<Setter Property="MinHeight" Value="26"/>
55+
<Setter Property="CornerRadius" Value="4"/>
56+
</Style>
57+
58+
<Style Selector="ListBox">
59+
<Setter Property="FocusAdorner">
60+
<FocusAdornerTemplate>
61+
<Grid/>
62+
</FocusAdornerTemplate>
63+
</Setter>
64+
</Style>
65+
</ListBox.Styles>
66+
67+
<ListBox.ItemsPanel>
68+
<ItemsPanelTemplate>
69+
<StackPanel Orientation="Vertical"/>
70+
</ItemsPanelTemplate>
71+
</ListBox.ItemsPanel>
72+
73+
<ListBox.ItemTemplate>
74+
<DataTemplate DataType="vm:LauncherPage">
75+
<Grid ColumnDefinitions="Auto,*" VerticalAlignment="Center">
76+
<Path Grid.Column="0"
77+
Width="12" Height="12" Margin="12,0"
78+
Fill="{Binding Node.Bookmark, Converter={x:Static c:IntConverters.ToBookmarkBrush}}"
79+
Data="{StaticResource Icons.Bookmark}"
80+
IsVisible="{Binding Node.IsRepository}"
81+
IsHitTestVisible="False"/>
82+
<Path Grid.Column="0"
83+
Width="12" Height="12" Margin="12,0"
84+
Fill="{DynamicResource Brush.FG1}"
85+
Data="{StaticResource Icons.Repositories}"
86+
IsVisible="{Binding !Node.IsRepository}"
87+
IsHitTestVisible="False"/>
88+
<TextBlock Grid.Column="1"
89+
Classes="primary"
90+
VerticalAlignment="Center"
91+
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Decrease}}"
92+
Text="{Binding Node.Name}"
93+
IsVisible="{Binding Node.IsRepository}"
94+
IsHitTestVisible="False"/>
95+
<TextBlock Grid.Column="1"
96+
Classes="primary"
97+
VerticalAlignment="Center"
98+
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Decrease}}"
99+
Text="{DynamicResource Text.PageTabBar.Welcome.Title}"
100+
IsVisible="{Binding !Node.IsRepository}"
101+
IsHitTestVisible="False"/>
102+
</Grid>
103+
</DataTemplate>
104+
</ListBox.ItemTemplate>
105+
</ListBox>
106+
</Grid>
107+
</UserControl>
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
using System;
2+
3+
using Avalonia;
4+
using Avalonia.Collections;
5+
using Avalonia.Controls;
6+
using Avalonia.Interactivity;
7+
8+
namespace SourceGit.Views
9+
{
10+
public class LauncherTabSelectedEventArgs : RoutedEventArgs
11+
{
12+
public ViewModels.LauncherPage Page { get; }
13+
14+
public LauncherTabSelectedEventArgs(ViewModels.LauncherPage page)
15+
{
16+
RoutedEvent = LauncherTabsSelector.PageSelectedEvent;
17+
Page = page;
18+
}
19+
}
20+
21+
public partial class LauncherTabsSelector : UserControl
22+
{
23+
public static readonly StyledProperty<AvaloniaList<ViewModels.LauncherPage>> PagesProperty =
24+
AvaloniaProperty.Register<LauncherTabsSelector, AvaloniaList<ViewModels.LauncherPage>>(nameof(Pages));
25+
26+
public AvaloniaList<ViewModels.LauncherPage> Pages
27+
{
28+
get => GetValue(PagesProperty);
29+
set => SetValue(PagesProperty, value);
30+
}
31+
32+
public static readonly StyledProperty<string> SearchFilterProperty =
33+
AvaloniaProperty.Register<LauncherTabsSelector, string>(nameof(SearchFilter));
34+
35+
public string SearchFilter
36+
{
37+
get => GetValue(SearchFilterProperty);
38+
set => SetValue(SearchFilterProperty, value);
39+
}
40+
41+
public static readonly RoutedEvent<LauncherTabSelectedEventArgs> PageSelectedEvent =
42+
RoutedEvent.Register<ChangeCollectionView, LauncherTabSelectedEventArgs>(nameof(PageSelected), RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
43+
44+
public event EventHandler<LauncherTabSelectedEventArgs> PageSelected
45+
{
46+
add { AddHandler(PageSelectedEvent, value); }
47+
remove { RemoveHandler(PageSelectedEvent, value); }
48+
}
49+
50+
public AvaloniaList<ViewModels.LauncherPage> VisiblePages
51+
{
52+
get;
53+
private set;
54+
}
55+
56+
public LauncherTabsSelector()
57+
{
58+
VisiblePages = new AvaloniaList<ViewModels.LauncherPage>();
59+
InitializeComponent();
60+
}
61+
62+
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
63+
{
64+
base.OnPropertyChanged(change);
65+
66+
if (change.Property == PagesProperty || change.Property == SearchFilterProperty)
67+
UpdateVisiblePages();
68+
}
69+
70+
private void OnClearSearchFilter(object sender, RoutedEventArgs e)
71+
{
72+
SearchFilter = string.Empty;
73+
}
74+
75+
private void OnPageSelectionChanged(object sender, SelectionChangedEventArgs e)
76+
{
77+
if (sender is ListBox { SelectedItem : ViewModels.LauncherPage page })
78+
{
79+
_isProcessingSelection = true;
80+
RaiseEvent(new LauncherTabSelectedEventArgs(page));
81+
_isProcessingSelection = false;
82+
}
83+
84+
e.Handled = true;
85+
}
86+
87+
private void UpdateVisiblePages()
88+
{
89+
if (_isProcessingSelection)
90+
return;
91+
92+
VisiblePages.Clear();
93+
94+
if (Pages == null)
95+
return;
96+
97+
var filter = SearchFilter?.Trim() ?? "";
98+
if (string.IsNullOrEmpty(filter))
99+
{
100+
foreach (var p in Pages)
101+
VisiblePages.Add(p);
102+
103+
return;
104+
}
105+
106+
foreach (var page in Pages)
107+
{
108+
if (!page.Node.IsRepository)
109+
continue;
110+
111+
if (page.Node.Name.Contains(filter, StringComparison.OrdinalIgnoreCase) ||
112+
page.Node.Id.Contains(filter, StringComparison.OrdinalIgnoreCase))
113+
VisiblePages.Add(page);
114+
}
115+
}
116+
117+
private bool _isProcessingSelection = false;
118+
}
119+
}
120+

0 commit comments

Comments
 (0)