diff --git a/src/Converters/BranchTreeNodeConverters.cs b/src/Converters/BranchTreeNodeConverters.cs deleted file mode 100644 index 14f73fd7..00000000 --- a/src/Converters/BranchTreeNodeConverters.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System.Collections.Generic; - -using Avalonia; -using Avalonia.Controls; -using Avalonia.Data.Converters; - -namespace SourceGit.Converters -{ - public static class BranchTreeNodeConverters - { - public static readonly CornerRadius DEFAULT = new CornerRadius(4); - - public static readonly FuncMultiValueConverter ToCornerRadius = - new FuncMultiValueConverter(v => - { - if (v == null) - return DEFAULT; - - var array = new List(); - array.AddRange(v); - if (array.Count != 2) - return DEFAULT; - - var item = array[1] as TreeViewItem; - if (item == null || !item.IsSelected) - return DEFAULT; - - var prev = GetPrevTreeViewItem(item); - var next = GetNextTreeViewItem(item, true); - - double top = 4, bottom = 4; - if (prev != null && prev.IsSelected) - top = 0; - if (next != null && next.IsSelected) - bottom = 0; - - return new CornerRadius(top, bottom); - }); - - private static TreeViewItem GetPrevTreeViewItem(TreeViewItem item) - { - if (item.Parent is TreeView tree) - { - var idx = tree.IndexFromContainer(item); - if (idx == 0) - return null; - - var prev = tree.ContainerFromIndex(idx - 1) as TreeViewItem; - if (prev != null && prev.IsExpanded && prev.ItemCount > 0) - return prev.ContainerFromIndex(prev.ItemCount - 1) as TreeViewItem; - - return prev; - } - else if (item.Parent is TreeViewItem parentItem) - { - var idx = parentItem.IndexFromContainer(item); - if (idx == 0) - return parentItem; - - var prev = parentItem.ContainerFromIndex(idx - 1) as TreeViewItem; - if (prev != null && prev.IsExpanded && prev.ItemCount > 0) - return prev.ContainerFromIndex(prev.ItemCount - 1) as TreeViewItem; - - return prev; - } - else - { - return null; - } - } - - private static TreeViewItem GetNextTreeViewItem(TreeViewItem item, bool intoSelf = false) - { - if (intoSelf && item.IsExpanded && item.ItemCount > 0) - return item.ContainerFromIndex(0) as TreeViewItem; - - if (item.Parent is TreeView tree) - { - var idx = tree.IndexFromContainer(item); - if (idx == tree.ItemCount - 1) - return null; - - return tree.ContainerFromIndex(idx + 1) as TreeViewItem; - } - else if (item.Parent is TreeViewItem parentItem) - { - var idx = parentItem.IndexFromContainer(item); - if (idx == parentItem.ItemCount - 1) - return GetNextTreeViewItem(parentItem); - - return parentItem.ContainerFromIndex(idx + 1) as TreeViewItem; - } - else - { - return null; - } - } - } -} diff --git a/src/ViewModels/BranchTreeNode.cs b/src/ViewModels/BranchTreeNode.cs index b6b88b5d..194b1a26 100644 --- a/src/ViewModels/BranchTreeNode.cs +++ b/src/ViewModels/BranchTreeNode.cs @@ -1,8 +1,12 @@ using System; using System.Collections.Generic; using System.IO; + +using Avalonia; using Avalonia.Collections; +using CommunityToolkit.Mvvm.ComponentModel; + namespace SourceGit.ViewModels { public enum BranchTreeNodeType @@ -12,8 +16,10 @@ namespace SourceGit.ViewModels Branch, } - public class BranchTreeNode + public class BranchTreeNode : ObservableObject { + public const double DEFAULT_CORNER = 4.0; + public string Name { get; set; } public BranchTreeNodeType Type { get; set; } public object Backend { get; set; } @@ -51,6 +57,43 @@ namespace SourceGit.ViewModels get => IsBranch && (Backend as Models.Branch).IsCurrent; } + public bool IsSelected + { + get => _isSelected; + set => SetProperty(ref _isSelected, value); + } + + public CornerRadius CornerRadius + { + get => _cornerRadius; + set => SetProperty(ref _cornerRadius, value); + } + + public void UpdateCornerRadius(ref BranchTreeNode prev) + { + if (_isSelected && prev != null && prev.IsSelected) + { + var prevTop = prev.CornerRadius.TopLeft; + prev.CornerRadius = new CornerRadius(prevTop, 0); + CornerRadius = new CornerRadius(0, DEFAULT_CORNER); + } + else if (CornerRadius.TopLeft != DEFAULT_CORNER || + CornerRadius.BottomLeft != DEFAULT_CORNER) + { + CornerRadius = new CornerRadius(DEFAULT_CORNER); + } + + prev = this; + + if (!IsBranch && IsExpanded) + { + foreach (var child in Children) + child.UpdateCornerRadius(ref prev); + } + } + private bool _isSelected = false; + private CornerRadius _cornerRadius = new CornerRadius(DEFAULT_CORNER); + public class Builder { public List Locals => _locals; diff --git a/src/Views/DeleteMultipleBranches.axaml b/src/Views/DeleteMultipleBranches.axaml index ca0282ef..75f28674 100644 --- a/src/Views/DeleteMultipleBranches.axaml +++ b/src/Views/DeleteMultipleBranches.axaml @@ -14,75 +14,69 @@ Classes="bold" Text="{DynamicResource Text.DeleteMultiBranch}" /> - - - - - - + + + + - + - + - - + + - - - - - - - - + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/src/Views/Repository.axaml b/src/Views/Repository.axaml index 765210ae..9df2b540 100644 --- a/src/Views/Repository.axaml +++ b/src/Views/Repository.axaml @@ -208,14 +208,8 @@