From 9844043c7f6ce373f8e41af190938ec47bc663c6 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 20 Aug 2024 16:53:59 +0800 Subject: [PATCH] ux: use ListBox with VirtualizingStackPanel instead of DataGrid since height of DataGridRow is not equal with the RowHeight value --- src/Resources/Styles.axaml | 52 ++++++++++ src/Views/BranchTree.axaml | 156 ++++++++++++----------------- src/Views/Repository.axaml | 181 +++++++++------------------------- src/Views/Repository.axaml.cs | 14 +-- src/Views/TagsView.axaml | 30 ++---- src/Views/TagsView.axaml.cs | 1 + 6 files changed, 180 insertions(+), 254 deletions(-) diff --git a/src/Resources/Styles.axaml b/src/Resources/Styles.axaml index 3874060a..d3204fae 100644 --- a/src/Resources/Styles.axaml +++ b/src/Resources/Styles.axaml @@ -706,6 +706,58 @@ + + + + + + + + + - + + + - - - - - + + - - - - - + + - - + + - - - - - + + - - + + - - - - - - - - - - - - + + + + + + + diff --git a/src/Views/Repository.axaml b/src/Views/Repository.axaml index 82396bc9..22ec2d07 100644 --- a/src/Views/Repository.axaml +++ b/src/Views/Repository.axaml @@ -240,70 +240,31 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + @@ -329,74 +290,30 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/src/Views/Repository.axaml.cs b/src/Views/Repository.axaml.cs index a83d24bd..6c3c80ea 100644 --- a/src/Views/Repository.axaml.cs +++ b/src/Views/Repository.axaml.cs @@ -200,7 +200,7 @@ namespace SourceGit.Views private void OnSubmoduleContextRequested(object sender, ContextRequestedEventArgs e) { - if (sender is DataGrid { SelectedItem: Models.Submodule submodule } grid && DataContext is ViewModels.Repository repo) + if (sender is ListBox { SelectedItem: Models.Submodule submodule } grid && DataContext is ViewModels.Repository repo) { var menu = repo.CreateContextMenuForSubmodule(submodule.Path); grid.OpenContextMenu(menu); @@ -211,7 +211,7 @@ namespace SourceGit.Views private void OnDoubleTappedSubmodule(object sender, TappedEventArgs e) { - if (sender is DataGrid { SelectedItem: Models.Submodule submodule } && DataContext is ViewModels.Repository repo) + if (sender is ListBox { SelectedItem: Models.Submodule submodule } && DataContext is ViewModels.Repository repo) { repo.OpenSubmodule(submodule.Path); } @@ -221,7 +221,7 @@ namespace SourceGit.Views private void OnWorktreeContextRequested(object sender, ContextRequestedEventArgs e) { - if (sender is DataGrid { SelectedItem: Models.Worktree worktree } grid && DataContext is ViewModels.Repository repo) + if (sender is ListBox { SelectedItem: Models.Worktree worktree } grid && DataContext is ViewModels.Repository repo) { var menu = repo.CreateContextMenuForWorktree(worktree); grid.OpenContextMenu(menu); @@ -232,7 +232,7 @@ namespace SourceGit.Views private void OnDoubleTappedWorktree(object sender, TappedEventArgs e) { - if (sender is DataGrid { SelectedItem: Models.Worktree worktree } && DataContext is ViewModels.Repository repo) + if (sender is ListBox { SelectedItem: Models.Worktree worktree } && DataContext is ViewModels.Repository repo) { repo.OpenWorktree(worktree); } @@ -242,7 +242,7 @@ namespace SourceGit.Views private void OnLeftSidebarDataGridPropertyChanged(object _, AvaloniaPropertyChangedEventArgs e) { - if (e.Property == DataGrid.ItemsSourceProperty || e.Property == DataGrid.IsVisibleProperty) + if (e.Property == ListBox.ItemsSourceProperty || e.Property == ListBox.IsVisibleProperty) UpdateLeftSidebarLayout(); } @@ -266,8 +266,8 @@ namespace SourceGit.Views var remoteBranchRows = vm.IsRemoteGroupExpanded ? RemoteBranchTree.Rows.Count : 0; var desiredBranches = (localBranchRows + remoteBranchRows) * 24.0; var desiredTag = vm.IsTagGroupExpanded ? 24.0 * TagsList.Rows : 0; - var desiredSubmodule = vm.IsSubmoduleGroupExpanded ? SubmoduleList.RowHeight * vm.Submodules.Count : 0; - var desiredWorktree = vm.IsWorktreeGroupExpanded ? WorktreeList.RowHeight * vm.Worktrees.Count : 0; + var desiredSubmodule = vm.IsSubmoduleGroupExpanded ? 24.0 * vm.Submodules.Count : 0; + var desiredWorktree = vm.IsWorktreeGroupExpanded ? 24.0 * vm.Worktrees.Count : 0; var desiredOthers = desiredTag + desiredSubmodule + desiredWorktree; var hasOverflow = (desiredBranches + desiredOthers > leftHeight); diff --git a/src/Views/TagsView.axaml b/src/Views/TagsView.axaml index bcbbe358..4bafa55b 100644 --- a/src/Views/TagsView.axaml +++ b/src/Views/TagsView.axaml @@ -7,31 +7,12 @@ xmlns:vm="using:SourceGit.ViewModels" xmlns:c="using:SourceGit.Converters" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" - x:Class="SourceGit.Views.TagsView"> - - - - - - + x:Class="SourceGit.Views.TagsView"> - @@ -70,7 +51,8 @@ - diff --git a/src/Views/TagsView.axaml.cs b/src/Views/TagsView.axaml.cs index 23d31ab4..9bb20aca 100644 --- a/src/Views/TagsView.axaml.cs +++ b/src/Views/TagsView.axaml.cs @@ -282,6 +282,7 @@ namespace SourceGit.Views var tags = Tags; if (tags == null || tags.Count == 0) { + Rows = 0; Content = null; return; }