diff --git a/src/ViewModels/Preference.cs b/src/ViewModels/Preference.cs index 858cc2d8..63d6fcb1 100644 --- a/src/ViewModels/Preference.cs +++ b/src/ViewModels/Preference.cs @@ -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 RepositoryNodes + public List RepositoryNodes { - get => _repositoryNodes; - set => SetProperty(ref _repositoryNodes, value); - } + get; + set; + } = []; public List 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(); - 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(); - 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 collection) + private RepositoryNode FindNodeRecursive(string id, List collection) { foreach (var node in collection) { @@ -456,7 +439,7 @@ namespace SourceGit.ViewModels return null; } - private AvaloniaList FindNodeContainer(RepositoryNode node, AvaloniaList collection) + private List FindNodeContainer(RepositoryNode node, List collection) { foreach (var sub in collection) { @@ -471,7 +454,7 @@ namespace SourceGit.ViewModels return null; } - private bool RemoveNodeRecursive(RepositoryNode node, AvaloniaList collection) + private bool RemoveNodeRecursive(RepositoryNode node, List collection) { if (collection.Contains(node)) { @@ -525,7 +508,5 @@ namespace SourceGit.ViewModels private int _externalMergeToolType = 0; private string _externalMergeToolPath = string.Empty; - - private AvaloniaList _repositoryNodes = new AvaloniaList(); } } diff --git a/src/ViewModels/RepositoryNode.cs b/src/ViewModels/RepositoryNode.cs index fd33153b..3cc98c16 100644 --- a/src/ViewModels/RepositoryNode.cs +++ b/src/ViewModels/RepositoryNode.cs @@ -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 SubNodes + public List 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 _subNodes = new AvaloniaList(); } } diff --git a/src/ViewModels/Welcome.cs b/src/ViewModels/Welcome.cs index d675a73f..f1e1c921 100644 --- a/src/ViewModels/Welcome.cs +++ b/src/ViewModels/Welcome.cs @@ -242,7 +242,7 @@ namespace SourceGit.ViewModels } } - private void MakeTreeRows(List rows, AvaloniaList nodes, int depth = 0) + private void MakeTreeRows(List rows, List nodes, int depth = 0) { foreach (var node in nodes) {