Files
modernkeepass/ModernKeePass/ViewModels/GroupVm.cs

65 lines
1.7 KiB
C#
Raw Normal View History

using System.Collections.ObjectModel;
2017-09-15 11:24:14 +02:00
using System.ComponentModel;
using System.Linq;
using ModernKeePassLibPCL;
namespace ModernKeePass.ViewModels
{
2017-09-15 11:24:14 +02:00
public class GroupVm : INotifyPropertyChanged
{
private PwGroup _pwGroup;
public ObservableCollection<EntryVm> Entries { get; set; }
public ObservableCollection<GroupVm> Groups { get; set; }
public string Name { get; set; }
public string EntryCount {
get
{
return $"{Entries?.Count} entries.";
}
}
public string GroupCount
{
get
{
return $"{Groups?.Count} groups.";
}
}
2017-09-15 11:24:14 +02:00
public GroupVm()
{
Name = "GroupName";
Entries = new ObservableCollection<EntryVm>();
Groups = new ObservableCollection<GroupVm>();
}
2017-09-14 18:33:29 +02:00
public GroupVm(PwGroup group)
{
_pwGroup = group;
Name = group.Name;
Entries = new ObservableCollection<EntryVm>(group.Entries.Select(e => new EntryVm(e)));
Groups = new ObservableCollection<GroupVm>(group.Groups.Select(g => new GroupVm(g)));
}
2017-09-15 11:24:14 +02:00
public void AddGroup(string title)
{
var pwGroup = new PwGroup
{
Name = title
};
Groups.Add(new GroupVm(pwGroup));
NotifyPropertyChanged("Groups");
this._pwGroup.Groups.Add(pwGroup);
}
2017-09-15 11:24:14 +02:00
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}