feature: remember the state of repository sidebar (#823)

This commit is contained in:
leo 2024-12-18 15:33:09 +08:00
parent 7526def448
commit 5ec8279d38
No known key found for this signature in database
4 changed files with 112 additions and 37 deletions

View file

@ -90,31 +90,31 @@ namespace SourceGit.Models
{ {
get; get;
set; set;
} = new AvaloniaList<Filter>(); } = [];
public AvaloniaList<CommitTemplate> CommitTemplates public AvaloniaList<CommitTemplate> CommitTemplates
{ {
get; get;
set; set;
} = new AvaloniaList<CommitTemplate>(); } = [];
public AvaloniaList<string> CommitMessages public AvaloniaList<string> CommitMessages
{ {
get; get;
set; set;
} = new AvaloniaList<string>(); } = [];
public AvaloniaList<IssueTrackerRule> IssueTrackerRules public AvaloniaList<IssueTrackerRule> IssueTrackerRules
{ {
get; get;
set; set;
} = new AvaloniaList<IssueTrackerRule>(); } = [];
public AvaloniaList<CustomAction> CustomActions public AvaloniaList<CustomAction> CustomActions
{ {
get; get;
set; set;
} = new AvaloniaList<CustomAction>(); } = [];
public bool EnableAutoFetch public bool EnableAutoFetch
{ {
@ -158,6 +158,42 @@ namespace SourceGit.Models
set; set;
} = "---"; } = "---";
public bool IsLocalBranchesExpandedInSideBar
{
get;
set;
} = true;
public bool IsRemotesExpandedInSideBar
{
get;
set;
} = false;
public bool IsTagsExpandedInSideBar
{
get;
set;
} = false;
public bool IsSubmodulesExpandedInSideBar
{
get;
set;
} = false;
public bool IsWorktreeExpandedInSideBar
{
get;
set;
} = false;
public List<string> ExpandedBranchNodesInSideBar
{
get;
set;
} = [];
public Dictionary<string, FilterMode> CollectHistoriesFilters() public Dictionary<string, FilterMode> CollectHistoriesFilters()
{ {
var map = new Dictionary<string, FilterMode>(); var map = new Dictionary<string, FilterMode>();

View file

@ -59,6 +59,12 @@ namespace SourceGit.ViewModels
public List<BranchTreeNode> Locals => _locals; public List<BranchTreeNode> Locals => _locals;
public List<BranchTreeNode> Remotes => _remotes; public List<BranchTreeNode> Remotes => _remotes;
public void SetExpandedNodes(List<string> expanded)
{
foreach (var node in expanded)
_expanded.Add(node);
}
public void Run(List<Models.Branch> branches, List<Models.Remote> remotes, bool bForceExpanded) public void Run(List<Models.Branch> branches, List<Models.Remote> remotes, bool bForceExpanded)
{ {
var folders = new Dictionary<string, BranchTreeNode>(); var folders = new Dictionary<string, BranchTreeNode>();
@ -97,20 +103,6 @@ namespace SourceGit.ViewModels
SortNodes(_remotes); SortNodes(_remotes);
} }
public void CollectExpandedNodes(List<BranchTreeNode> nodes)
{
foreach (var node in nodes)
{
if (node.Backend is Models.Branch)
continue;
if (node.IsExpanded)
_expanded.Add(node.Path);
CollectExpandedNodes(node.Children);
}
}
private void MakeBranchNode(Models.Branch branch, List<BranchTreeNode> roots, Dictionary<string, BranchTreeNode> folders, string prefix, bool bForceExpanded) private void MakeBranchNode(Models.Branch branch, List<BranchTreeNode> roots, Dictionary<string, BranchTreeNode> folders, string prefix, bool bForceExpanded)
{ {
var fullpath = $"{prefix}/{branch.Name}"; var fullpath = $"{prefix}/{branch.Name}";

View file

@ -322,32 +322,67 @@ namespace SourceGit.ViewModels
public bool IsLocalBranchGroupExpanded public bool IsLocalBranchGroupExpanded
{ {
get => _isLocalBranchGroupExpanded; get => _settings.IsLocalBranchesExpandedInSideBar;
set => SetProperty(ref _isLocalBranchGroupExpanded, value); set
{
if (value != _settings.IsLocalBranchesExpandedInSideBar)
{
_settings.IsLocalBranchesExpandedInSideBar = value;
OnPropertyChanged();
}
}
} }
public bool IsRemoteGroupExpanded public bool IsRemoteGroupExpanded
{ {
get => _isRemoteGroupExpanded; get => _settings.IsRemotesExpandedInSideBar;
set => SetProperty(ref _isRemoteGroupExpanded, value); set
{
if (value != _settings.IsRemotesExpandedInSideBar)
{
_settings.IsRemotesExpandedInSideBar = value;
OnPropertyChanged();
}
}
} }
public bool IsTagGroupExpanded public bool IsTagGroupExpanded
{ {
get => _isTagGroupExpanded; get => _settings.IsTagsExpandedInSideBar;
set => SetProperty(ref _isTagGroupExpanded, value); set
{
if (value != _settings.IsTagsExpandedInSideBar)
{
_settings.IsTagsExpandedInSideBar = value;
OnPropertyChanged();
}
}
} }
public bool IsSubmoduleGroupExpanded public bool IsSubmoduleGroupExpanded
{ {
get => _isSubmoduleGroupExpanded; get => _settings.IsSubmodulesExpandedInSideBar;
set => SetProperty(ref _isSubmoduleGroupExpanded, value); set
{
if (value != _settings.IsSubmodulesExpandedInSideBar)
{
_settings.IsSubmodulesExpandedInSideBar = value;
OnPropertyChanged();
}
}
} }
public bool IsWorktreeGroupExpanded public bool IsWorktreeGroupExpanded
{ {
get => _isWorktreeGroupExpanded; get => _settings.IsWorktreeExpandedInSideBar;
set => SetProperty(ref _isWorktreeGroupExpanded, value); set
{
if (value != _settings.IsWorktreeExpandedInSideBar)
{
_settings.IsWorktreeExpandedInSideBar = value;
OnPropertyChanged();
}
}
} }
public InProgressContext InProgressContext public InProgressContext InProgressContext
@ -700,6 +735,22 @@ namespace SourceGit.ViewModels
Task.Run(RefreshCommits); Task.Run(RefreshCommits);
} }
public void UpdateBranchNodeIsExpanded(BranchTreeNode node)
{
if (_settings == null || !string.IsNullOrWhiteSpace(_filter))
return;
if (node.IsExpanded)
{
if (!_settings.ExpandedBranchNodesInSideBar.Contains(node.Path))
_settings.ExpandedBranchNodesInSideBar.Add(node.Path);
}
else
{
_settings.ExpandedBranchNodesInSideBar.Remove(node.Path);
}
}
public void SetTagFilterMode(Models.Tag tag, Models.FilterMode mode) public void SetTagFilterMode(Models.Tag tag, Models.FilterMode mode)
{ {
var changed = _settings.UpdateHistoriesFilter(tag.Name, Models.FilterType.Tag, mode); var changed = _settings.UpdateHistoriesFilter(tag.Name, Models.FilterType.Tag, mode);
@ -2014,8 +2065,7 @@ namespace SourceGit.ViewModels
var builder = new BranchTreeNode.Builder(); var builder = new BranchTreeNode.Builder();
if (string.IsNullOrEmpty(_filter)) if (string.IsNullOrEmpty(_filter))
{ {
builder.CollectExpandedNodes(_localBranchTrees); builder.SetExpandedNodes(_settings.ExpandedBranchNodesInSideBar);
builder.CollectExpandedNodes(_remoteBranchTrees);
builder.Run(branches, remotes, false); builder.Run(branches, remotes, false);
} }
else else
@ -2237,12 +2287,6 @@ namespace SourceGit.ViewModels
private List<Models.Commit> _searchedCommits = new List<Models.Commit>(); private List<Models.Commit> _searchedCommits = new List<Models.Commit>();
private List<string> _revisionFiles = new List<string>(); private List<string> _revisionFiles = new List<string>();
private bool _isLocalBranchGroupExpanded = true;
private bool _isRemoteGroupExpanded = false;
private bool _isTagGroupExpanded = false;
private bool _isSubmoduleGroupExpanded = false;
private bool _isWorktreeGroupExpanded = false;
private string _filter = string.Empty; private string _filter = string.Empty;
private List<Models.Remote> _remotes = new List<Models.Remote>(); private List<Models.Remote> _remotes = new List<Models.Remote>();
private List<Models.Branch> _branches = new List<Models.Branch>(); private List<Models.Branch> _branches = new List<Models.Branch>();

View file

@ -275,6 +275,9 @@ namespace SourceGit.Views
rows.RemoveRange(idx + 1, removeCount); rows.RemoveRange(idx + 1, removeCount);
} }
var repo = DataContext as ViewModels.Repository;
repo?.UpdateBranchNodeIsExpanded(node);
RaiseEvent(new RoutedEventArgs(RowsChangedEvent)); RaiseEvent(new RoutedEventArgs(RowsChangedEvent));
_disableSelectionChangingEvent = false; _disableSelectionChangingEvent = false;
} }