-
Notifications
You must be signed in to change notification settings - Fork 204
/
Copy pathMoveRepositoryNode.cs
69 lines (60 loc) · 1.71 KB
/
MoveRepositoryNode.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace SourceGit.ViewModels
{
public class MoveRepositoryNode : Popup
{
public RepositoryNode Target
{
get;
} = null;
public List<RepositoryNode> Rows
{
get;
} = [];
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(Preferences.Instance.RepositoryNodes, 1);
}
public override Task<bool> Sure()
{
if (_selected != null)
{
var node = Preferences.Instance.FindNode(_selected.Id);
Preferences.Instance.MoveNode(Target, node, true);
Welcome.Instance.Refresh();
}
return null;
}
private void MakeRows(List<RepositoryNode> 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;
}
}