forked from miroiu/nodify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BlackboardViewModel.cs
47 lines (40 loc) · 1.73 KB
/
BlackboardViewModel.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
using System.Linq;
namespace Nodify.StateMachine
{
public class BlackboardViewModel : ObservableObject
{
private NodifyObservableCollection<BlackboardKeyViewModel> _keys = new NodifyObservableCollection<BlackboardKeyViewModel>();
public NodifyObservableCollection<BlackboardKeyViewModel> Keys
{
get => _keys;
set => SetProperty(ref _keys, value);
}
private NodifyObservableCollection<BlackboardItemReferenceViewModel> _actions = new NodifyObservableCollection<BlackboardItemReferenceViewModel>();
public NodifyObservableCollection<BlackboardItemReferenceViewModel> Actions
{
get => _actions;
set => SetProperty(ref _actions, value);
}
private NodifyObservableCollection<BlackboardItemReferenceViewModel> _conditions = new NodifyObservableCollection<BlackboardItemReferenceViewModel>();
public NodifyObservableCollection<BlackboardItemReferenceViewModel> Conditions
{
get => _conditions;
set => SetProperty(ref _conditions, value);
}
public INodifyCommand AddKeyCommand { get; }
public INodifyCommand RemoveKeyCommand { get; }
public BlackboardViewModel()
{
AddKeyCommand = new DelegateCommand(() => Keys.Add(new BlackboardKeyViewModel
{
Name = "New Key "
}));
RemoveKeyCommand = new DelegateCommand<BlackboardKeyViewModel>(key => Keys.Remove(key));
Keys.WhenAdded(key =>
{
var existingKeyNames = Keys.Where(k => k != key).Select(k => k.Name).ToList();
key.Name = existingKeyNames.GetUnique(key.Name);
});
}
}
}