Repository navigation
Expand file tree
/
Copy pathProjectNodeBase.cs
More file actions
146 lines (131 loc) · 3.88 KB
/
Copy pathProjectNodeBase.cs
File metadata and controls
146 lines (131 loc) · 3.88 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using System;
using System.Collections.Generic;
using System.ComponentModel;
using EnvDTE;
namespace NuGet.Dialog
{
public abstract class ProjectNodeBase : INotifyPropertyChanged
{
private bool _suppressNotifyParentOfIsSelectedChanged;
private FolderNode _parent;
private string _name;
private bool? _isSelected = false;
private bool _isEnabled = true;
protected ProjectNodeBase(string name)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
Name = name;
}
public event PropertyChangedEventHandler PropertyChanged = delegate { };
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Design",
"CA1024:UsePropertiesWhereAppropriate",
Justification = "The results need to be calculated dynamically.")]
public abstract IEnumerable<Project> GetSelectedProjects();
public FolderNode Parent
{
get
{
return _parent;
}
internal set
{
if (_parent != value)
{
_parent = value;
OnPropertyChanged("Parent");
}
}
}
public string Name
{
get
{
return _name;
}
private set
{
if (_name != value)
{
_name = value;
OnPropertyChanged("Name");
}
}
}
public bool IsEnabled
{
get
{
return _isEnabled;
}
set
{
if (_isEnabled != value)
{
_isEnabled = value;
OnEnabledChanged();
OnPropertyChanged("IsEnabled");
}
}
}
public bool? IsSelected
{
get
{
return _isSelected;
}
set
{
if (_isSelected != value)
{
_isSelected = value;
OnSelectedChanged();
OnPropertyChanged("IsSelected");
}
}
}
protected virtual void OnSelectedChanged()
{
if (_suppressNotifyParentOfIsSelectedChanged)
{
return;
}
if (Parent != null)
{
Parent.OnChildSelectedChanged();
}
}
private void OnEnabledChanged()
{
if (Parent != null)
{
Parent.OnChildEnabledChanged();
}
}
protected void OnPropertyChanged(string propertyName)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
internal void OnParentIsSelectedChange(bool? isSelected)
{
// When the parent folder is checked or unchecked by user,
// we want to apply the same state to all of its descending.
// But we don't want to notify this back to the parent,
// hence the suppression. Otherwise, we'll fall into an infinite loop.
// However, only do the above if this node is enabled.
if (IsEnabled)
{
_suppressNotifyParentOfIsSelectedChanged = true;
IsSelected = isSelected;
_suppressNotifyParentOfIsSelectedChanged = false;
}
}
public override string ToString()
{
return Name;
}
}
}