fix: branch tree not restore last IsExpanded nodes. See issue #20

* Binding IsExpanded property of TreeViewItem with Models.BranchTreeNode
* Current local branch should never be collapsed
This commit is contained in:
leo 2024-03-09 20:58:00 +08:00
parent ef26f5b41c
commit 213f04a57b
2 changed files with 13 additions and 2 deletions

View file

@ -114,7 +114,7 @@ namespace SourceGit.Models {
lastFolder = new BranchTreeNode() {
Name = subs[i],
Type = BranchTreeNodeType.Folder,
IsExpanded = _expanded.Contains(path),
IsExpanded = branch.IsCurrent || _expanded.Contains(path),
};
roots.Add(lastFolder);
_maps.Add(path, lastFolder);
@ -122,7 +122,7 @@ namespace SourceGit.Models {
var folder = new BranchTreeNode() {
Name = subs[i],
Type = BranchTreeNodeType.Folder,
IsExpanded = _expanded.Contains(path),
IsExpanded = branch.IsCurrent || _expanded.Contains(path),
};
_maps.Add(path, folder);
lastFolder.Children.Add(folder);

View file

@ -161,6 +161,11 @@
ScrollViewer.VerticalScrollBarVisibility="Auto"
LostFocus="OnLocalBranchTreeLostFocus"
SelectionChanged="OnLocalBranchTreeSelectionChanged">
<TreeView.Styles>
<Style Selector="TreeViewItem" x:DataType="m:BranchTreeNode">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
</Style>
</TreeView.Styles>
<TreeView.ItemTemplate>
<TreeDataTemplate ItemsSource="{Binding Children}" x:DataType="{x:Type m:BranchTreeNode}">
<Grid Height="24" ColumnDefinitions="Auto,*,Auto,Auto" Background="Transparent" ContextRequested="OnLocalBranchContextMenuRequested" DoubleTapped="OnDoubleTappedLocalBranchNode">
@ -208,6 +213,12 @@
ScrollViewer.VerticalScrollBarVisibility="Auto"
LostFocus="OnRemoteBranchTreeLostFocus"
SelectionChanged="OnRemoteBranchTreeSelectionChanged">
<TreeView.Styles>
<Style Selector="TreeViewItem" x:DataType="m:BranchTreeNode">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
</Style>
</TreeView.Styles>
<TreeView.ItemTemplate>
<TreeDataTemplate ItemsSource="{Binding Children}" x:DataType="{x:Type m:BranchTreeNode}">
<Grid Height="24" ColumnDefinitions="Auto,*,Auto" Background="Transparent" ContextRequested="OnRemoteBranchContextMenuRequested">