Repository navigation
Expand file tree
/
Copy pathChangeSelection.cs
More file actions
82 lines (70 loc) · 2.32 KB
/
Copy pathChangeSelection.cs
File metadata and controls
82 lines (70 loc) · 2.32 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
using System.Collections;
using System.Collections.Generic;
namespace SourceGit.ViewModels
{
public class ChangeSelection
{
public List<Models.Change> Changes { get; }
public bool IsSingleFolder { get; }
public string SingleFolderPath { get; }
public bool HasFolder { get; }
public int Count => Changes.Count;
public ChangeSelection(IList selected)
{
var changes = new List<Models.Change>();
IsSingleFolder = false;
SingleFolderPath = null;
HasFolder = false;
if (selected is { Count: > 0 })
{
foreach (var item in selected)
{
if (item is Models.Change c)
{
changes.Add(c);
}
else if (item is ChangeTreeNode node)
{
CollectChangesInNode(changes, node);
if (node.IsFolder && !HasFolder)
HasFolder = true;
}
}
if (selected.Count == 1 && selected[0] is ChangeTreeNode { IsFolder: true } folder)
{
IsSingleFolder = true;
SingleFolderPath = folder.FullPath;
}
}
Changes = changes;
}
public bool IsChanged(ChangeSelection other)
{
if (other == null ||
IsSingleFolder != other.IsSingleFolder ||
SingleFolderPath != other.SingleFolderPath ||
HasFolder != other.HasFolder ||
Changes.Count != other.Changes.Count)
return true;
foreach (var c in other.Changes)
{
if (!Changes.Contains(c))
return true;
}
return false;
}
private static void CollectChangesInNode(List<Models.Change> outs, ChangeTreeNode node)
{
if (node.IsFolder)
{
foreach (var child in node.Children)
CollectChangesInNode(outs, child);
}
else
{
if (!outs.Contains(node.Change))
outs.Add(node.Change);
}
}
}
}