ux: more flex layout for left siderbar groups

This commit is contained in:
leo 2024-07-04 17:59:32 +08:00
parent 3ce580b682
commit 8faa8c7378
No known key found for this signature in database
4 changed files with 480 additions and 394 deletions

View file

@ -24,7 +24,6 @@ namespace SourceGit.ViewModels
public string Name { get; set; }
public BranchTreeNodeType Type { get; set; }
public object Backend { get; set; }
public bool IsExpanded { get; set; }
public bool IsFiltered { get; set; }
public List<BranchTreeNode> Children { get; set; } = new List<BranchTreeNode>();
@ -69,6 +68,12 @@ namespace SourceGit.ViewModels
set => SetProperty(ref _isSelected, value);
}
public bool IsExpanded
{
get => _isExpanded;
set => SetProperty(ref _isExpanded, value);
}
public string Tooltip
{
get
@ -108,7 +113,9 @@ namespace SourceGit.ViewModels
child.UpdateCornerRadius(ref prev);
}
}
private bool _isSelected = false;
private bool _isExpanded = false;
private CornerRadius _cornerRadius = new CornerRadius(DEFAULT_CORNER);
public class Builder

View file

@ -271,6 +271,18 @@ namespace SourceGit.ViewModels
set => SetProperty(ref _searchedCommits, value);
}
public bool IsLocalBranchGroupExpanded
{
get => _isLocalBranchGroupExpanded;
set => SetProperty(ref _isLocalBranchGroupExpanded, value);
}
public bool IsRemoteGroupExpanded
{
get => _isRemoteGroupExpanded;
set => SetProperty(ref _isRemoteGroupExpanded, value);
}
public bool IsTagGroupExpanded
{
get => _isTagGroupExpanded;
@ -355,14 +367,7 @@ namespace SourceGit.ViewModels
_histories = null;
_workingCopy = null;
_stashesPage = null;
_isSearching = false;
_searchCommitFilter = string.Empty;
_isTagGroupExpanded = false;
_isSubmoduleGroupExpanded = false;
_inProgressContext = null;
_hasUnsolvedConflicts = false;
_remotes.Clear();
_branches.Clear();
@ -1941,6 +1946,8 @@ namespace SourceGit.ViewModels
private string _searchCommitFilter = string.Empty;
private List<Models.Commit> _searchedCommits = new List<Models.Commit>();
private bool _isLocalBranchGroupExpanded = true;
private bool _isRemoteGroupExpanded = false;
private bool _isTagGroupExpanded = false;
private bool _isSubmoduleGroupExpanded = false;
private bool _isWorktreeGroupExpanded = false;

View file

@ -119,7 +119,7 @@
</Grid>
<!-- Dashboard -->
<Grid Grid.Row="1" Margin="0,0,0,8" RowDefinitions="Auto,Auto,28,Auto,28,*,28,Auto,28,Auto,28,Auto" IsVisible="{Binding !IsSearching}">
<Grid Grid.Row="1" Margin="0,0,0,8" RowDefinitions="Auto,Auto,*" IsVisible="{Binding !IsSearching}">
<!-- Page Switcher for Right Panel -->
<Border Grid.Row="0" Margin="8,0,4,0" BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}" CornerRadius="6">
<Border CornerRadius="6" ClipToBounds="True">
@ -231,14 +231,17 @@
</TextBox.InnerRightContent>
</TextBox>
<Grid Grid.Row="2" RowDefinitions="28,Auto,28,Auto,28,Auto,28,Auto,28,Auto" LayoutUpdated="OnDashboardLayoutUpdated">
<!-- Local Branches -->
<TextBlock Grid.Row="2" Classes="group_header_label" Text="{DynamicResource Text.Repository.LocalBranches}"/>
<TreeView Grid.Row="3"
<ToggleButton Grid.Row="0" Classes="group_expander" IsChecked="{Binding IsLocalBranchGroupExpanded, Mode=TwoWay}">
<TextBlock Classes="group_header_label" Margin="0" Text="{DynamicResource Text.Repository.LocalBranches}"/>
</ToggleButton>
<TreeView Grid.Row="1"
x:Name="localBranchTree"
MaxHeight="400"
Margin="8,0,4,0"
SelectionMode="Multiple"
ItemsSource="{Binding LocalBranchTrees}"
IsVisible="{Binding IsLocalBranchGroupExpanded}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ContextRequested="OnLocalBranchContextMenuRequested"
@ -305,17 +308,20 @@
</TreeView>
<!-- Remotes -->
<Grid Grid.Row="4" ColumnDefinitions="*,Auto">
<TextBlock Grid.Column="0" Classes="group_header_label" Text="{DynamicResource Text.Repository.Remotes}"/>
<ToggleButton Grid.Row="2" Classes="group_expander" IsChecked="{Binding IsRemoteGroupExpanded, Mode=TwoWay}">
<Grid ColumnDefinitions="*,Auto">
<TextBlock Grid.Column="0" Classes="group_header_label" Margin="0" Text="{DynamicResource Text.Repository.Remotes}"/>
<Button Grid.Column="1" Classes="icon_button" Width="14" Margin="8,0" Command="{Binding AddRemote}" ToolTip.Tip="{DynamicResource Text.Repository.Remotes.Add}">
<Path Width="12" Height="12" Data="{StaticResource Icons.Remote.Add}"/>
</Button>
</Grid>
<TreeView Grid.Row="5"
</ToggleButton>
<TreeView Grid.Row="3"
x:Name="remoteBranchTree"
Margin="8,0,4,0"
SelectionMode="Multiple"
ItemsSource="{Binding RemoteBranchTrees}"
IsVisible="{Binding IsRemoteGroupExpanded}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ContextRequested="OnRemoteBranchContextMenuRequested"
@ -369,7 +375,7 @@
</TreeView>
<!-- Tags -->
<ToggleButton Grid.Row="6" Classes="group_expander" IsChecked="{Binding IsTagGroupExpanded, Mode=TwoWay}">
<ToggleButton Grid.Row="4" Classes="group_expander" IsChecked="{Binding IsTagGroupExpanded, Mode=TwoWay}">
<Grid ColumnDefinitions="Auto,*,Auto">
<TextBlock Grid.Column="0" Classes="group_header_label" Margin="0" Text="{DynamicResource Text.Repository.Tags}"/>
<TextBlock Grid.Column="1" Text="{Binding Tags, Converter={x:Static c:ListConverters.ToCount}}" Foreground="{DynamicResource Brush.FG2}" FontWeight="Bold"/>
@ -378,7 +384,7 @@
</Button>
</Grid>
</ToggleButton>
<DataGrid Grid.Row="7"
<DataGrid Grid.Row="5"
x:Name="tagsList"
Margin="8,0,4,0"
Background="Transparent"
@ -395,8 +401,7 @@
VerticalScrollBarVisibility="Auto"
IsVisible="{Binding IsTagGroupExpanded, Mode=OneWay}"
SelectionChanged="OnTagDataGridSelectionChanged"
ContextRequested="OnTagContextRequested"
PropertyChanged="OnTagPropertyChanged">
ContextRequested="OnTagContextRequested">
<DataGrid.Styles>
<Style Selector="DataGridRow">
<Setter Property="CornerRadius" Value="4" />
@ -458,7 +463,7 @@
</DataGrid>
<!-- Submodules -->
<ToggleButton Grid.Row="8" Classes="group_expander" IsChecked="{Binding IsSubmoduleGroupExpanded, Mode=TwoWay}">
<ToggleButton Grid.Row="6" Classes="group_expander" IsChecked="{Binding IsSubmoduleGroupExpanded, Mode=TwoWay}">
<Grid ColumnDefinitions="Auto,*,Auto,Auto">
<TextBlock Grid.Column="0" Classes="group_header_label" Margin="0" Text="{DynamicResource Text.Repository.Submodules}"/>
<TextBlock Grid.Column="1" Text="{Binding Submodules, Converter={x:Static c:ListConverters.ToCount}}" Foreground="{DynamicResource Brush.FG2}" FontWeight="Bold"/>
@ -481,7 +486,8 @@
</Button>
</Grid>
</ToggleButton>
<DataGrid Grid.Row="9"
<DataGrid Grid.Row="7"
x:Name="submoduleList"
MaxHeight="200"
Margin="8,0,4,0"
Background="Transparent"
@ -539,7 +545,7 @@
</DataGrid>
<!-- Worktrees -->
<ToggleButton Grid.Row="10" Classes="group_expander" IsChecked="{Binding IsWorktreeGroupExpanded, Mode=TwoWay}">
<ToggleButton Grid.Row="8" Classes="group_expander" IsChecked="{Binding IsWorktreeGroupExpanded, Mode=TwoWay}">
<Grid ColumnDefinitions="Auto,*,Auto,Auto">
<TextBlock Grid.Column="0" Classes="group_header_label" Margin="0" Text="{DynamicResource Text.Repository.Worktrees}"/>
<TextBlock Grid.Column="1" Text="{Binding Worktrees, Converter={x:Static c:ListConverters.ToCount}}" Foreground="{DynamicResource Brush.FG2}" FontWeight="Bold"/>
@ -562,8 +568,8 @@
</Button>
</Grid>
</ToggleButton>
<DataGrid Grid.Row="11"
MaxHeight="200"
<DataGrid Grid.Row="9"
x:Name="worktreeList"
Margin="8,0,4,0"
Background="Transparent"
ItemsSource="{Binding Worktrees}"
@ -628,6 +634,7 @@
</DataGrid.Columns>
</DataGrid>
</Grid>
</Grid>
<!-- Commit Search Panel -->
<Grid Grid.Row="1" RowDefinitions="Auto,32,*" Margin="8,0,4,8" IsVisible="{Binding IsSearching}" PropertyChanged="OnSearchCommitPanelPropertyChanged">

View file

@ -7,6 +7,7 @@ using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.VisualTree;
using AvaloniaEdit.Utils;
namespace SourceGit.Views
{
@ -280,18 +281,6 @@ namespace SourceGit.Views
e.Handled = true;
}
private void OnTagPropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)
{
if (e.Property == DataGrid.ItemsSourceProperty && DataContext is ViewModels.Repository vm)
{
if (vm.VisibleTags == null)
return;
var desiredHeight = tagsList.RowHeight * vm.VisibleTags.Count;
tagsList.Height = Math.Min(200, desiredHeight);
}
}
private void OnToggleFilter(object sender, RoutedEventArgs e)
{
if (sender is ToggleButton toggle)
@ -379,5 +368,81 @@ namespace SourceGit.Views
outs.Add(b);
}
}
private void OnDashboardLayoutUpdated(object sender, EventArgs e)
{
var vm = DataContext as ViewModels.Repository;
if (vm == null || vm.Settings == null)
return;
var grid = sender as Grid;
if (grid == null)
return;
var leftHeight = grid.Bounds.Height - 28.0 * 5;
if (vm.IsTagGroupExpanded)
{
var desiredHeight = Math.Min(200.0, tagsList.RowHeight * vm.VisibleTags.Count);
leftHeight -= desiredHeight;
if (!tagsList.Height.IsClose(desiredHeight))
tagsList.Height = desiredHeight;
}
if (vm.IsSubmoduleGroupExpanded)
{
var desiredHeight = Math.Min(200.0, submoduleList.RowHeight * vm.Submodules.Count);
leftHeight -= desiredHeight;
if (!submoduleList.Height.IsClose(desiredHeight))
submoduleList.Height = desiredHeight;
}
if (vm.IsWorktreeGroupExpanded)
{
var desiredHeight = Math.Min(200.0, worktreeList.RowHeight * vm.Worktrees.Count);
leftHeight -= desiredHeight;
if (!worktreeList.Height.IsClose(desiredHeight))
worktreeList.Height = desiredHeight;
}
var desiredLocalBranchHeight = GetTreeRowsCount(vm.LocalBranchTrees) * 24;
var desiredRemoteHeight = GetTreeRowsCount(vm.RemoteBranchTrees) * 24;
if (!vm.IsRemoteGroupExpanded)
{
if (vm.IsLocalBranchGroupExpanded)
{
var localBranchHeight = Math.Min(leftHeight, desiredLocalBranchHeight);
localBranchTree.Height = localBranchHeight;
}
}
else
{
if (vm.IsLocalBranchGroupExpanded)
{
var localBranchHeight = Math.Min(leftHeight * 0.5, desiredLocalBranchHeight);
if (!localBranchTree.Height.IsClose(localBranchHeight))
localBranchTree.Height = localBranchHeight;
leftHeight -= localBranchHeight;
}
var remoteHeight = Math.Min(leftHeight, desiredRemoteHeight);
if (!remoteBranchTree.Height.IsClose(remoteHeight))
remoteBranchTree.Height = remoteHeight;
}
}
private int GetTreeRowsCount(List<ViewModels.BranchTreeNode> nodes)
{
int count = nodes.Count;
foreach (var node in nodes)
{
if (!node.IsBranch && node.IsExpanded)
count += GetTreeRowsCount(node.Children);
}
return count;
}
}
}