2017-09-13 18:37:44 +02:00
|
|
|
|
using System.Collections.ObjectModel;
|
2017-09-15 11:24:14 +02:00
|
|
|
|
using System.ComponentModel;
|
2017-09-12 18:20:32 +02:00
|
|
|
|
using System.Linq;
|
2017-09-22 18:48:09 +02:00
|
|
|
|
using ModernKeePassLibPCL;
|
2017-09-12 18:20:32 +02:00
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.ViewModels
|
|
|
|
|
{
|
2017-09-15 11:24:14 +02:00
|
|
|
|
public class GroupVm : INotifyPropertyChanged
|
2017-09-12 18:20:32 +02:00
|
|
|
|
{
|
2017-09-18 18:40:43 +02:00
|
|
|
|
private PwGroup _pwGroup;
|
|
|
|
|
|
2017-09-13 18:37:44 +02:00
|
|
|
|
public ObservableCollection<EntryVm> Entries { get; set; }
|
|
|
|
|
public ObservableCollection<GroupVm> Groups { get; set; }
|
2017-09-12 18:20:32 +02:00
|
|
|
|
public string Name { get; set; }
|
2017-09-13 18:37:44 +02:00
|
|
|
|
|
|
|
|
|
public string EntryCount {
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return $"{Entries?.Count} entries.";
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-15 15:58:51 +02:00
|
|
|
|
public string GroupCount
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return $"{Groups?.Count} groups.";
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-13 18:37:44 +02:00
|
|
|
|
|
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
|
|
|
|
|
2017-09-25 18:34:27 +02:00
|
|
|
|
public GroupVm(PwGroup pwGroup)
|
2017-09-13 18:37:44 +02:00
|
|
|
|
{
|
2017-09-25 18:34:27 +02:00
|
|
|
|
_pwGroup = pwGroup;
|
|
|
|
|
Name = pwGroup.Name;
|
|
|
|
|
Entries = new ObservableCollection<EntryVm>(pwGroup.Entries.Select(e => new EntryVm(e)));
|
|
|
|
|
//Entries.Insert(0, new EntryVm { Title = " + New entry" });
|
|
|
|
|
Groups = new ObservableCollection<GroupVm>(pwGroup.Groups.Select(g => new GroupVm(g)));
|
|
|
|
|
//Groups.Insert(0, new GroupVm { Name = " + New group" });
|
2017-09-13 18:37:44 +02:00
|
|
|
|
}
|
2017-09-15 11:24:14 +02:00
|
|
|
|
|
2017-09-25 18:34:27 +02:00
|
|
|
|
public void CreateNewGroup(string title)
|
2017-09-18 18:40:43 +02:00
|
|
|
|
{
|
2017-09-25 18:34:27 +02:00
|
|
|
|
var pwGroup = new PwGroup(true, true, title, PwIcon.Folder);
|
|
|
|
|
_pwGroup.AddGroup(pwGroup, true);
|
2017-09-18 18:40:43 +02:00
|
|
|
|
Groups.Add(new GroupVm(pwGroup));
|
|
|
|
|
NotifyPropertyChanged("Groups");
|
|
|
|
|
}
|
2017-09-25 18:34:27 +02:00
|
|
|
|
|
|
|
|
|
public void CreateNewEntry(string title)
|
|
|
|
|
{
|
|
|
|
|
var pwEntry = new PwEntry(true, true);
|
|
|
|
|
_pwGroup.AddEntry(pwEntry, true);
|
|
|
|
|
Entries.Add(new EntryVm(pwEntry));
|
|
|
|
|
NotifyPropertyChanged("Entries");
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-18 18:40:43 +02:00
|
|
|
|
|
2017-09-15 11:24:14 +02:00
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
|
|
|
|
|
|
public void NotifyPropertyChanged(string propertyName)
|
|
|
|
|
{
|
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
|
}
|
2017-09-12 18:20:32 +02:00
|
|
|
|
}
|
|
|
|
|
}
|