Skip to content

Commit 8ac9f83

Browse files
committed
feature: supports to collapse/expand the left-sidebar of repository page (#2368)
Signed-off-by: leo <longshuang@msn.cn>
1 parent e9d7d56 commit 8ac9f83

8 files changed

Lines changed: 143 additions & 10 deletions

File tree

src/Resources/Icons.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@
126126
<StreamGeometry x:Key="Icons.ScrollToTop">M155 143h715v81H155V143zm358 94 358 369H662l1 278H363V605H155l358-369z</StreamGeometry>
127127
<StreamGeometry x:Key="Icons.Search">M702 677 590 565a148 148 0 10-25 27L676 703zm-346-200a115 115 0 11115 115A115 115 0 01355 478z</StreamGeometry>
128128
<StreamGeometry x:Key="Icons.Settings">M928 500a21 21 0 00-19-20L858 472a11 11 0 01-9-9c-1-6-2-13-3-19a11 11 0 015-12l46-25a21 21 0 0010-26l-8-22a21 21 0 00-24-13l-51 10a11 11 0 01-12-6c-3-6-6-11-10-17a11 11 0 011-13l34-39a21 21 0 001-28l-15-18a20 20 0 00-27-4l-45 27a11 11 0 01-13-1c-5-4-10-9-15-12a11 11 0 01-3-12l19-49a21 21 0 00-9-26l-20-12a21 21 0 00-27 6L650 193a9 9 0 01-11 3c-1-1-12-5-20-7a11 11 0 01-7-10l1-52a21 21 0 00-17-22l-23-4a21 21 0 00-24 14L532 164a11 11 0 01-11 7h-20a11 11 0 01-11-7l-17-49a21 21 0 00-24-15l-23 4a21 21 0 00-17 22l1 52a11 11 0 01-8 11c-5 2-15 6-19 7c-4 1-8 0-12-4l-33-40A21 21 0 00313 146l-20 12A21 21 0 00285 184l19 49a11 11 0 01-3 12c-5 4-10 8-15 12a11 11 0 01-13 1L228 231a21 21 0 00-27 4L186 253a21 21 0 001 28L221 320a11 11 0 011 13c-3 5-7 11-10 17a11 11 0 01-12 6l-51-10a21 21 0 00-24 13l-8 22a21 21 0 0010 26l46 25a11 11 0 015 12l0 3c-1 6-2 11-3 16a11 11 0 01-9 9l-51 8A21 21 0 0096 500v23A21 21 0 00114 544l51 8a11 11 0 019 9c1 6 2 13 3 19a11 11 0 01-5 12l-46 25a21 21 0 00-10 26l8 22a21 21 0 0024 13l51-10a11 11 0 0112 6c3 6 6 11 10 17a11 11 0 01-1 13l-34 39a21 21 0 00-1 28l15 18a20 20 0 0027 4l45-27a11 11 0 0113 1c5 4 10 9 15 12a11 11 0 013 12l-19 49a21 21 0 009 26l20 12a21 21 0 0027-6L374 832c3-3 7-5 10-4c7 3 12 5 20 7a11 11 0 018 10l-1 52a21 21 0 0017 22l23 4a21 21 0 0024-14l17-50a11 11 0 0111-7h20a11 11 0 0111 7l17 49a21 21 0 0020 15a19 19 0 004 0l23-4a21 21 0 0017-22l-1-52a11 11 0 018-10c8-3 13-5 18-7l1 0c6-2 9 0 11 3l34 41A21 21 0 00710 878l20-12a21 21 0 009-26l-18-49a11 11 0 013-12c5-4 10-8 15-12a11 11 0 0113-1l45 27a21 21 0 0027-4l15-18a21 21 0 00-1-28l-34-39a11 11 0 01-1-13c3-5 7-11 10-17a11 11 0 0112-6l51 10a21 21 0 0024-13l8-22a21 21 0 00-10-26l-46-25a11 11 0 01-5-12l0-3c1-6 2-11 3-16a11 11 0 019-9l51-8a21 21 0 0018-21v-23zm-565 188a32 32 0 01-51 5a270 270 0 011-363a32 32 0 0151 6l91 161a32 32 0 010 31zM512 782a270 270 0 01-57-6a32 32 0 01-20-47l92-160a32 32 0 0127-16h184a32 32 0 0130 41c-35 109-137 188-257 188zm15-328L436 294a32 32 0 0121-47a268 268 0 0155-6c120 0 222 79 257 188a32 32 0 01-30 41h-184a32 32 0 01-28-16z</StreamGeometry>
129+
<StreamGeometry x:Key="Icons.Sidebar.Collapsed">M864 277a117 117 0 00-117-117h-469A117 117 0 00160 277v469a117 117 0 00117 117h469a117 117 0 00117-117v-469zm64 469a181 181 0 01-181 181h-469a181 181 0 01-181-181v-469A181 181 0 01277 96h469a181 181 0 01181 181v469zM256 320a64 64 0 11128 0v384a64 64 0 01-128 0v-384z</StreamGeometry>
130+
<StreamGeometry x:Key="Icons.Sidebar.Expanded">M858 213a47 47 0 00-47-47H422v691h388a47 47 0 0047-47V213zm77 597a124 124 0 01-124 124H213A124 124 0 0190 811V213c0-68 55-124 124-124h597c68 0 124 55 124 124v597z</StreamGeometry>
129131
<StreamGeometry x:Key="Icons.Skip">M622 718v137q0 9-7 16t-16 7H462q-9 0-16-7t-7-16v-137q0-9 7-16t16-7h137q9 0 16 7t7 16zm181-343q0 31-9 58t-20 44-31 34-33 25-35 20q-23 13-39 37t-16 38q0 10-7 19t-16 9H459q-9 0-15-11T439 626v-26q0-47 37-89T558 449q34-15 48-32t14-43q0-24-27-42T532 313q-37 0-62 17-20 14-61 66-7 9-18 9-7 0-14-5L283 329q-7-6-9-14t3-16q91-152 265-152 46 0 92 18t83 47 61 73 23 91z</StreamGeometry>
130132
<StreamGeometry x:Key="Icons.SoftwareUpdate">M900 287c40 69 60 144 60 225s-20 156-60 225c-40 69-94 123-163 163-69 40-144 60-225 60s-156-20-225-60c-69-40-123-94-163-163C84 668 64 593 64 512s20-156 60-225 94-123 163-163c69-40 144-60 225-60s156 20 225 60 123 94 163 163zM762 512c0-9-3-16-9-22L578 315l-44-44c-6-6-13-9-22-9s-16 3-22 9l-44 44-176 176c-6 6-9 13-9 22s3 16 9 22l44 44c6 6 13 9 22 9s16-3 22-9l92-92v269c0 9 3 16 9 22 6 6 13 9 22 9h62c8 0 16-3 22-9 6-6 9-13 9-22V486l92 92c6 6 13 9 22 9 8 0 16-3 22-9l44-44c6-6 9-13 9-22z</StreamGeometry>
131133
<StreamGeometry x:Key="Icons.SquashIntoParent">M512 939C465 939 427 900 427 853 427 806 465 768 512 768 559 768 597 806 597 853 597 900 559 939 512 939M555 85 555 555 747 363 807 423 512 719 217 423 277 363 469 555 469 85 555 85Z</StreamGeometry>

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,7 @@
854854
<x:String x:Key="Text.Repository.Tags.OrderByName" xml:space="preserve">By Name</x:String>
855855
<x:String x:Key="Text.Repository.Tags.Sort" xml:space="preserve">Sort</x:String>
856856
<x:String x:Key="Text.Repository.Terminal" xml:space="preserve">Open in Terminal</x:String>
857+
<x:String x:Key="Text.Repository.ToggleSidebar" xml:space="preserve">Toggle sidebar</x:String>
857858
<x:String x:Key="Text.Repository.ViewLogs" xml:space="preserve">View Logs</x:String>
858859
<x:String x:Key="Text.Repository.Visit" xml:space="preserve">Visit '{0}' in Browser</x:String>
859860
<x:String x:Key="Text.Repository.Worktrees" xml:space="preserve">WORKTREES</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,7 @@
858858
<x:String x:Key="Text.Repository.Tags.OrderByName" xml:space="preserve">按名称</x:String>
859859
<x:String x:Key="Text.Repository.Tags.Sort" xml:space="preserve">排序</x:String>
860860
<x:String x:Key="Text.Repository.Terminal" xml:space="preserve">在终端中打开</x:String>
861+
<x:String x:Key="Text.Repository.ToggleSidebar" xml:space="preserve">收起或展开侧边栏</x:String>
861862
<x:String x:Key="Text.Repository.ViewLogs" xml:space="preserve">查看命令日志</x:String>
862863
<x:String x:Key="Text.Repository.Visit" xml:space="preserve">访问远程仓库 '{0}'</x:String>
863864
<x:String x:Key="Text.Repository.Worktrees" xml:space="preserve">工作树列表</x:String>

src/Resources/Styles.axaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,37 @@
12781278
<Setter Property="Data" Value="M 0 4 L 8 4 L 4 8 Z" />
12791279
</Style>
12801280
</Style>
1281+
1282+
<Style Selector="ToggleButton.sidebar_expander">
1283+
<Setter Property="Background" Value="Transparent"/>
1284+
<Setter Property="Template">
1285+
<ControlTemplate>
1286+
<Border Background="Transparent"
1287+
Width="{TemplateBinding Width}"
1288+
Height="{TemplateBinding Height}"
1289+
HorizontalAlignment="Left"
1290+
VerticalAlignment="Center">
1291+
<Path x:Name="ChevronPath"
1292+
Width="14" Height="14"
1293+
Margin="0,1,0,0"
1294+
Data="{StaticResource Icons.Sidebar.Expanded}"
1295+
Fill="{DynamicResource Brush.FG1}"
1296+
HorizontalAlignment="Center"
1297+
VerticalAlignment="Center"/>
1298+
</Border>
1299+
</ControlTemplate>
1300+
</Setter>
1301+
1302+
<Style Selector="^:checked /template/ Path#ChevronPath">
1303+
<Setter Property="Data" Value="{StaticResource Icons.Sidebar.Collapsed}" />
1304+
</Style>
1305+
<Style Selector="^ Path">
1306+
<Setter Property="Opacity" Value="0.8"/>
1307+
</Style>
1308+
<Style Selector="^:pointerover Path">
1309+
<Setter Property="Opacity" Value="1"/>
1310+
</Style>
1311+
</Style>
12811312

12821313
<Style Selector="ToggleButton.folder">
12831314
<Setter Property="Margin" Value="0" />

src/ViewModels/LayoutInfo.cs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Avalonia.Controls;
1+
using System.Text.Json.Serialization;
2+
using Avalonia.Controls;
23
using CommunityToolkit.Mvvm.ComponentModel;
34

45
namespace SourceGit.ViewModels
@@ -35,10 +36,43 @@ public WindowState LauncherWindowState
3536
set;
3637
} = WindowState.Normal;
3738

39+
public bool RepositorySidebarCollapsed
40+
{
41+
get => _repositorySidebarCollapsed;
42+
set
43+
{
44+
if (SetProperty(ref _repositorySidebarCollapsed, value))
45+
{
46+
OnPropertyChanged(nameof(RepositorySidebarMinWidth));
47+
OnPropertyChanged(nameof(RepositorySidebarDisplayWidth));
48+
}
49+
}
50+
}
51+
3852
public GridLength RepositorySidebarWidth
3953
{
40-
get => _repositorySidebarWidth;
41-
set => SetProperty(ref _repositorySidebarWidth, value);
54+
get;
55+
set;
56+
}
57+
58+
[JsonIgnore]
59+
public double RepositorySidebarMinWidth
60+
{
61+
get => _repositorySidebarCollapsed ? 48 : 200;
62+
}
63+
64+
[JsonIgnore]
65+
public GridLength RepositorySidebarDisplayWidth
66+
{
67+
get => _repositorySidebarCollapsed ? new GridLength(48, GridUnitType.Pixel) : RepositorySidebarWidth;
68+
set
69+
{
70+
if (!_repositorySidebarCollapsed)
71+
{
72+
RepositorySidebarWidth = value;
73+
OnPropertyChanged();
74+
}
75+
}
4276
}
4377

4478
public GridLength WorkingCopyLeftWidth
@@ -65,7 +99,7 @@ public GridLength CommitDetailFilesLeftWidth
6599
set => SetProperty(ref _commitDetailFilesLeftWidth, value);
66100
}
67101

68-
private GridLength _repositorySidebarWidth = new GridLength(250, GridUnitType.Pixel);
102+
private bool _repositorySidebarCollapsed = false;
69103
private GridLength _workingCopyLeftWidth = new GridLength(300, GridUnitType.Pixel);
70104
private GridLength _stashesLeftWidth = new GridLength(300, GridUnitType.Pixel);
71105
private GridLength _commitDetailChangesLeftWidth = new GridLength(256, GridUnitType.Pixel);

src/Views/Repository.axaml

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
x:DataType="vm:Repository">
1212
<Grid>
1313
<Grid.ColumnDefinitions>
14-
<ColumnDefinition Width="{Binding Source={x:Static vm:Preferences.Instance}, Path=Layout.RepositorySidebarWidth, Mode=TwoWay}" MinWidth="200"/>
14+
<ColumnDefinition Width="{Binding Source={x:Static vm:Preferences.Instance}, Path=Layout.RepositorySidebarDisplayWidth, Mode=TwoWay}"
15+
MinWidth="{Binding Source={x:Static vm:Preferences.Instance}, Path=Layout.RepositorySidebarMinWidth, Mode=OneWay}"/>
1516
<ColumnDefinition Width="3"/>
1617
<ColumnDefinition Width="*" MinWidth="200"/>
1718
</Grid.ColumnDefinitions>
1819

1920
<!-- Left Panel -->
20-
<Grid Grid.Column="0" RowDefinitions="Auto,*">
21+
<Grid Grid.Column="0"
22+
RowDefinitions="Auto,*"
23+
IsVisible="{Binding Source={x:Static vm:Preferences.Instance}, Path=Layout.RepositorySidebarCollapsed, Mode=OneWay, Converter={x:Static BoolConverters.Not}}">
2124
<!-- Page Switcher for Left Contents (Dashboard or CommitSearch) -->
2225
<StackPanel Grid.Row="0" Margin="0,6" Height="24" HorizontalAlignment="Center" Orientation="Horizontal">
2326
<RadioButton Classes="switch_button"
@@ -706,14 +709,65 @@
706709
</Grid>
707710
</Grid>
708711

712+
<!-- Left Collapsed Sidebar -->
713+
<Grid Grid.Column="0"
714+
IsVisible="{Binding Source={x:Static vm:Preferences.Instance}, Path=Layout.RepositorySidebarCollapsed, Mode=OneWay}">
715+
<ListBox Background="Transparent" SelectedIndex="{Binding SelectedViewIndex, Mode=TwoWay}" SelectionMode="AlwaysSelected">
716+
<ListBox.Styles>
717+
<Style Selector="Path.icon">
718+
<Setter Property="Width" Value="16"/>
719+
<Setter Property="Height" Value="16"/>
720+
<Setter Property="Fill" Value="{DynamicResource Brush.FG1}"/>
721+
<Setter Property="HorizontalAlignment" Value="Center"/>
722+
<Setter Property="VerticalAlignment" Value="Center"/>
723+
</Style>
724+
<Style Selector="ListBoxItem">
725+
<Setter Property="Height" Value="42"/>
726+
<Setter Property="Margin" Value="0"/>
727+
<Setter Property="Padding" Value="0"/>
728+
<Setter Property="BorderThickness" Value="0"/>
729+
<Setter Property="CornerRadius" Value="0"/>
730+
</Style>
731+
<Style Selector="ListBoxItem:pointerover /template/ ContentPresenter#PART_ContentPresenter, ListBoxItem:selected /template/ ContentPresenter#PART_ContentPresenter">
732+
<Setter Property="Background" Value="Transparent"/>
733+
</Style>
734+
<Style Selector="ListBoxItem:selected">
735+
<Setter Property="BorderBrush" Value="{DynamicResource Brush.FG1}"/>
736+
</Style>
737+
<Style Selector="ListBoxItem:selected Path.icon">
738+
<Setter Property="Fill" Value="{DynamicResource Brush.Accent}"/>
739+
</Style>
740+
</ListBox.Styles>
741+
742+
<ListBox.ItemsPanel>
743+
<ItemsPanelTemplate>
744+
<StackPanel Orientation="Vertical"/>
745+
</ItemsPanelTemplate>
746+
</ListBox.ItemsPanel>
747+
748+
<ListBoxItem>
749+
<Path Classes="icon" Data="{StaticResource Icons.Histories}"/>
750+
</ListBoxItem>
751+
752+
<ListBoxItem IsVisible="{Binding !IsBare}">
753+
<Path Classes="icon" Margin="2,0,0,0" Data="{StaticResource Icons.Changes}"/>
754+
</ListBoxItem>
755+
756+
<ListBoxItem IsVisible="{Binding !IsBare}">
757+
<Path Classes="icon" Data="{StaticResource Icons.Stashes}"/>
758+
</ListBoxItem>
759+
</ListBox>
760+
</Grid>
761+
709762
<!-- Splitter -->
710763
<GridSplitter Grid.Column="1"
711764
MinWidth="1"
712765
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
713766
Background="Transparent"
714767
BorderThickness="0,0,1,0"
715768
BorderBrush="{DynamicResource Brush.Border0}"
716-
Focusable="False"/>
769+
Focusable="False"
770+
IsEnabled="{Binding Source={x:Static vm:Preferences.Instance}, Path=Layout.RepositorySidebarCollapsed, Mode=OneWay, Converter={x:Static BoolConverters.Not}}"/>
717771

718772
<!-- Right -->
719773
<Grid Grid.Column="2" RowDefinitions="Auto,Auto,Auto,*">

src/Views/Repository.axaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ private void OnLeftSidebarSizeChanged(object _, SizeChangedEventArgs e)
186186

187187
private void UpdateLeftSidebarLayout()
188188
{
189-
var vm = DataContext as ViewModels.Repository;
190-
if (vm?.Settings == null)
189+
if (!IsLoaded)
191190
return;
192191

193-
if (!IsLoaded)
192+
if (DataContext is not ViewModels.Repository { UIStates: { } } vm ||
193+
ViewModels.Preferences.Instance.Layout.RepositorySidebarCollapsed)
194194
return;
195195

196196
var leftHeight = LeftSidebarGroups.Bounds.Height - 28.0 * 5 - 4;

src/Views/RepositoryToolbar.axaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
x:DataType="vm:Repository">
1010
<Grid ColumnDefinitions="*,Auto,0,*">
1111
<StackPanel Grid.Column="0" Orientation="Horizontal" Margin="4,0,0,0">
12+
<ToggleButton Classes="sidebar_expander"
13+
Width="32"
14+
IsChecked="{Binding Source={x:Static vm:Preferences.Instance}, Path=Layout.RepositorySidebarCollapsed, Mode=TwoWay}"
15+
ToolTip.Tip="{DynamicResource Text.Repository.ToggleSidebar}"/>
16+
17+
<Rectangle Width="1" Height="16"
18+
Margin="4,0"
19+
VerticalAlignment="Center"
20+
Fill="{DynamicResource Brush.Border2}"/>
21+
1222
<Button Classes="icon_button" Width="32" Click="OpenWithExternalTools" ToolTip.Tip="{DynamicResource Text.Repository.OpenWithExternalTools}">
1323
<Path Width="14" Height="14" Data="{StaticResource Icons.OpenWith}"/>
1424
</Button>

0 commit comments

Comments
 (0)