From 8faa8c7378da88add3da7e929da7b40432b7bb50 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 4 Jul 2024 17:59:32 +0800 Subject: [PATCH] ux: more flex layout for left siderbar groups --- src/ViewModels/BranchTreeNode.cs | 9 +- src/ViewModels/Repository.cs | 21 +- src/Views/Repository.axaml | 755 ++++++++++++++++--------------- src/Views/Repository.axaml.cs | 89 +++- 4 files changed, 480 insertions(+), 394 deletions(-) diff --git a/src/ViewModels/BranchTreeNode.cs b/src/ViewModels/BranchTreeNode.cs index 11486c20..f4044476 100644 --- a/src/ViewModels/BranchTreeNode.cs +++ b/src/ViewModels/BranchTreeNode.cs @@ -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 Children { get; set; } = new List(); @@ -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 diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index cdd2371a..55962b73 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -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 _searchedCommits = new List(); + private bool _isLocalBranchGroupExpanded = true; + private bool _isRemoteGroupExpanded = false; private bool _isTagGroupExpanded = false; private bool _isSubmoduleGroupExpanded = false; private bool _isWorktreeGroupExpanded = false; diff --git a/src/Views/Repository.axaml b/src/Views/Repository.axaml index 0a3a9478..a18f8b3c 100644 --- a/src/Views/Repository.axaml +++ b/src/Views/Repository.axaml @@ -119,7 +119,7 @@ - + @@ -231,402 +231,409 @@ - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - - - - - - - - - - + + + + + + + + + + - + + + + + - + + + + + + - - + - - - - - - - - + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - + - + + + + + - + + + + + + + + - - + + + + + + + - - - - - - - - + + + + + + + + + - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Views/Repository.axaml.cs b/src/Views/Repository.axaml.cs index 43e9a4a6..a7ba1a33 100644 --- a/src/Views/Repository.axaml.cs +++ b/src/Views/Repository.axaml.cs @@ -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 nodes) + { + int count = nodes.Count; + + foreach (var node in nodes) + { + if (!node.IsBranch && node.IsExpanded) + count += GetTreeRowsCount(node.Children); + } + + return count; + } } }