using System; using System.Collections.Generic; using System.Threading.Tasks; namespace SourceGit.ViewModels { public class MoveRepositoryNode : Popup { public RepositoryNode Target { get; private set; } = null; public List Rows { get; private set; } = []; public RepositoryNode Selected { get => _selected; set => SetProperty(ref _selected, value); } public MoveRepositoryNode(RepositoryNode target) { Target = target; Rows.Add(new RepositoryNode() { Name = "ROOT", Depth = 0, Id = Guid.NewGuid().ToString() }); MakeRows(Preference.Instance.RepositoryNodes, 1); View = new Views.MoveRepositoryNode() { DataContext = this }; } public override Task Sure() { if (_selected != null) { var node = Preference.Instance.FindNode(_selected.Id); Preference.Instance.MoveNode(Target, node, true); Welcome.Instance.Refresh(); } return null; } private void MakeRows(List collection, int depth) { foreach (var node in collection) { if (node.IsRepository || node.Id == Target.Id) continue; var dump = new RepositoryNode() { Name = node.Name, Depth = depth, Id = node.Id }; Rows.Add(dump); MakeRows(node.SubNodes, depth + 1); } } private RepositoryNode _selected = null; } }