mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-10-31 13:03:20 -07:00
refactor: there's no need to use AvaloniaList since we have replaced the TreeView with custom control
This commit is contained in:
parent
9bcadf3523
commit
4120331eda
3 changed files with 21 additions and 42 deletions
|
@ -4,8 +4,6 @@ using System.IO;
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using Avalonia.Collections;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace SourceGit.ViewModels
|
||||
|
@ -306,11 +304,11 @@ namespace SourceGit.ViewModels
|
|||
set => SetProperty(ref _externalMergeToolPath, value);
|
||||
}
|
||||
|
||||
public AvaloniaList<RepositoryNode> RepositoryNodes
|
||||
public List<RepositoryNode> RepositoryNodes
|
||||
{
|
||||
get => _repositoryNodes;
|
||||
set => SetProperty(ref _repositoryNodes, value);
|
||||
}
|
||||
get;
|
||||
set;
|
||||
} = [];
|
||||
|
||||
public List<string> OpenedTabs
|
||||
{
|
||||
|
@ -353,21 +351,15 @@ namespace SourceGit.ViewModels
|
|||
|
||||
public void AddNode(RepositoryNode node, RepositoryNode to = null)
|
||||
{
|
||||
var collection = to == null ? _repositoryNodes : to.SubNodes;
|
||||
var list = new List<RepositoryNode>();
|
||||
list.AddRange(collection);
|
||||
list.Add(node);
|
||||
list.Sort((l, r) =>
|
||||
var collection = to == null ? RepositoryNodes : to.SubNodes;
|
||||
collection.Add(node);
|
||||
collection.Sort((l, r) =>
|
||||
{
|
||||
if (l.IsRepository != r.IsRepository)
|
||||
return l.IsRepository ? 1 : -1;
|
||||
|
||||
return string.Compare(l.Name, r.Name, StringComparison.Ordinal);
|
||||
});
|
||||
|
||||
collection.Clear();
|
||||
foreach (var one in list)
|
||||
collection.Add(one);
|
||||
}
|
||||
|
||||
public RepositoryNode FindNode(string id)
|
||||
|
@ -400,7 +392,7 @@ namespace SourceGit.ViewModels
|
|||
|
||||
public void MoveNode(RepositoryNode node, RepositoryNode to = null)
|
||||
{
|
||||
if (to == null && _repositoryNodes.Contains(node))
|
||||
if (to == null && RepositoryNodes.Contains(node))
|
||||
return;
|
||||
if (to != null && to.SubNodes.Contains(node))
|
||||
return;
|
||||
|
@ -411,28 +403,19 @@ namespace SourceGit.ViewModels
|
|||
|
||||
public void RemoveNode(RepositoryNode node)
|
||||
{
|
||||
RemoveNodeRecursive(node, _repositoryNodes);
|
||||
RemoveNodeRecursive(node, RepositoryNodes);
|
||||
}
|
||||
|
||||
public void SortByRenamedNode(RepositoryNode node)
|
||||
{
|
||||
var container = FindNodeContainer(node, _repositoryNodes);
|
||||
if (container == null)
|
||||
return;
|
||||
|
||||
var list = new List<RepositoryNode>();
|
||||
list.AddRange(container);
|
||||
list.Sort((l, r) =>
|
||||
var container = FindNodeContainer(node, RepositoryNodes);
|
||||
container?.Sort((l, r) =>
|
||||
{
|
||||
if (l.IsRepository != r.IsRepository)
|
||||
return l.IsRepository ? 1 : -1;
|
||||
|
||||
return string.Compare(l.Name, r.Name, StringComparison.Ordinal);
|
||||
});
|
||||
|
||||
container.Clear();
|
||||
foreach (var one in list)
|
||||
container.Add(one);
|
||||
}
|
||||
|
||||
public void Save()
|
||||
|
@ -441,7 +424,7 @@ namespace SourceGit.ViewModels
|
|||
File.WriteAllText(_savePath, data);
|
||||
}
|
||||
|
||||
private RepositoryNode FindNodeRecursive(string id, AvaloniaList<RepositoryNode> collection)
|
||||
private RepositoryNode FindNodeRecursive(string id, List<RepositoryNode> collection)
|
||||
{
|
||||
foreach (var node in collection)
|
||||
{
|
||||
|
@ -456,7 +439,7 @@ namespace SourceGit.ViewModels
|
|||
return null;
|
||||
}
|
||||
|
||||
private AvaloniaList<RepositoryNode> FindNodeContainer(RepositoryNode node, AvaloniaList<RepositoryNode> collection)
|
||||
private List<RepositoryNode> FindNodeContainer(RepositoryNode node, List<RepositoryNode> collection)
|
||||
{
|
||||
foreach (var sub in collection)
|
||||
{
|
||||
|
@ -471,7 +454,7 @@ namespace SourceGit.ViewModels
|
|||
return null;
|
||||
}
|
||||
|
||||
private bool RemoveNodeRecursive(RepositoryNode node, AvaloniaList<RepositoryNode> collection)
|
||||
private bool RemoveNodeRecursive(RepositoryNode node, List<RepositoryNode> collection)
|
||||
{
|
||||
if (collection.Contains(node))
|
||||
{
|
||||
|
@ -525,7 +508,5 @@ namespace SourceGit.ViewModels
|
|||
|
||||
private int _externalMergeToolType = 0;
|
||||
private string _externalMergeToolPath = string.Empty;
|
||||
|
||||
private AvaloniaList<RepositoryNode> _repositoryNodes = new AvaloniaList<RepositoryNode>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
using Avalonia.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
|
@ -56,11 +55,11 @@ namespace SourceGit.ViewModels
|
|||
set;
|
||||
} = 0;
|
||||
|
||||
public AvaloniaList<RepositoryNode> SubNodes
|
||||
public List<RepositoryNode> SubNodes
|
||||
{
|
||||
get => _subNodes;
|
||||
set => SetProperty(ref _subNodes, value);
|
||||
}
|
||||
get;
|
||||
set;
|
||||
} = [];
|
||||
|
||||
public void Edit()
|
||||
{
|
||||
|
@ -100,6 +99,5 @@ namespace SourceGit.ViewModels
|
|||
private int _bookmark = 0;
|
||||
private bool _isExpanded = false;
|
||||
private bool _isVisible = true;
|
||||
private AvaloniaList<RepositoryNode> _subNodes = new AvaloniaList<RepositoryNode>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -242,7 +242,7 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
}
|
||||
|
||||
private void MakeTreeRows(List<RepositoryNode> rows, AvaloniaList<RepositoryNode> nodes, int depth = 0)
|
||||
private void MakeTreeRows(List<RepositoryNode> rows, List<RepositoryNode> nodes, int depth = 0)
|
||||
{
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue