mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2025-01-11 23:57:21 -08:00
enhance: keep repository tree sorted by name
This commit is contained in:
parent
15456f0dee
commit
207e82b391
2 changed files with 45 additions and 2 deletions
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace SourceGit.ViewModels
|
namespace SourceGit.ViewModels
|
||||||
|
@ -50,8 +49,13 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
public override Task<bool> Sure()
|
public override Task<bool> Sure()
|
||||||
{
|
{
|
||||||
|
bool needSort = _node.Name != _name;
|
||||||
_node.Name = _name;
|
_node.Name = _name;
|
||||||
_node.Bookmark = _bookmark;
|
_node.Bookmark = _bookmark;
|
||||||
|
|
||||||
|
if (needSort)
|
||||||
|
Preference.SortByRenamedNode(_node);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -362,6 +362,30 @@ namespace SourceGit.ViewModels
|
||||||
RemoveNodeRecursive(node, _instance._repositoryNodes);
|
RemoveNodeRecursive(node, _instance._repositoryNodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void SortByRenamedNode(RepositoryNode node)
|
||||||
|
{
|
||||||
|
var container = FindNodeContainer(node, _instance._repositoryNodes);
|
||||||
|
if (container == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var list = new List<RepositoryNode>();
|
||||||
|
list.AddRange(container);
|
||||||
|
list.Sort((l, r) =>
|
||||||
|
{
|
||||||
|
if (l.IsRepository != r.IsRepository)
|
||||||
|
{
|
||||||
|
return l.IsRepository ? 1 : -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return l.Name.CompareTo(r.Name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
container.Clear();
|
||||||
|
foreach (var one in list) container.Add(one);
|
||||||
|
}
|
||||||
|
|
||||||
public static Repository FindRepository(string path)
|
public static Repository FindRepository(string path)
|
||||||
{
|
{
|
||||||
foreach (var repo in _instance.Repositories)
|
foreach (var repo in _instance.Repositories)
|
||||||
|
@ -417,6 +441,21 @@ namespace SourceGit.ViewModels
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static AvaloniaList<RepositoryNode> FindNodeContainer(RepositoryNode node, AvaloniaList<RepositoryNode> collection)
|
||||||
|
{
|
||||||
|
foreach (var sub in collection)
|
||||||
|
{
|
||||||
|
if (node == sub)
|
||||||
|
return collection;
|
||||||
|
|
||||||
|
var subCollection = FindNodeContainer(node, sub.SubNodes);
|
||||||
|
if (subCollection != null)
|
||||||
|
return subCollection;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private static bool RemoveNodeRecursive(RepositoryNode node, AvaloniaList<RepositoryNode> collection)
|
private static bool RemoveNodeRecursive(RepositoryNode node, AvaloniaList<RepositoryNode> collection)
|
||||||
{
|
{
|
||||||
if (collection.Contains(node))
|
if (collection.Contains(node))
|
||||||
|
|
Loading…
Reference in a new issue