2017-09-13 18:37:44 +02:00
|
|
|
|
using System.Collections.ObjectModel;
|
2017-09-12 18:20:32 +02:00
|
|
|
|
using System.Linq;
|
2017-10-03 18:38:31 +02:00
|
|
|
|
using Windows.UI.Text;
|
2017-09-29 18:08:20 +02:00
|
|
|
|
using Windows.UI.Xaml.Controls;
|
2017-10-03 16:06:49 +02:00
|
|
|
|
using ModernKeePass.Common;
|
2017-09-29 18:08:20 +02:00
|
|
|
|
using ModernKeePass.Mappings;
|
2017-09-26 15:38:58 +02:00
|
|
|
|
using ModernKeePassLib;
|
2017-09-12 18:20:32 +02:00
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.ViewModels
|
|
|
|
|
{
|
2017-10-03 16:06:49 +02:00
|
|
|
|
public class GroupVm : NotifyPropertyChangedBase
|
2017-09-12 18:20:32 +02:00
|
|
|
|
{
|
2017-10-02 18:40:54 +02:00
|
|
|
|
public GroupVm ParentGroup { get; }
|
|
|
|
|
public ObservableCollection<EntryVm> Entries { get; set; } = new ObservableCollection<EntryVm>();
|
|
|
|
|
public ObservableCollection<GroupVm> Groups { get; set; } = new ObservableCollection<GroupVm>();
|
2017-10-06 14:56:16 +02:00
|
|
|
|
|
2017-10-02 18:40:54 +02:00
|
|
|
|
public int EntryCount => Entries.Count - 1;
|
|
|
|
|
public int GroupCount => Groups.Count - 1;
|
2017-10-05 14:50:42 +02:00
|
|
|
|
public bool IsNotRoot => ParentGroup != null;
|
|
|
|
|
public FontWeight FontWeight => _pwGroup == null ? FontWeights.Bold : FontWeights.Normal;
|
2017-10-03 16:06:49 +02:00
|
|
|
|
|
2017-10-06 14:56:16 +02:00
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return _pwGroup == null ? "New group" : _pwGroup.Name; }
|
|
|
|
|
set { _pwGroup.Name = value; }
|
|
|
|
|
}
|
2017-09-29 18:08:20 +02:00
|
|
|
|
public Symbol IconSymbol
|
2017-09-15 15:58:51 +02:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-10-02 18:40:54 +02:00
|
|
|
|
if (_pwGroup == null) return Symbol.Add;
|
2017-09-29 18:08:20 +02:00
|
|
|
|
var result = PwIconToSegoeMapping.GetSymbolFromIcon(_pwGroup.IconId);
|
|
|
|
|
return result == Symbol.More ? Symbol.Folder : result;
|
2017-09-15 15:58:51 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-13 18:37:44 +02:00
|
|
|
|
|
2017-10-05 14:50:42 +02:00
|
|
|
|
public bool IsLeftPaneOpen
|
|
|
|
|
{
|
|
|
|
|
get { return _isLeftPaneOpen; }
|
|
|
|
|
set { SetProperty(ref _isLeftPaneOpen, value); }
|
|
|
|
|
}
|
2017-10-02 18:40:54 +02:00
|
|
|
|
|
2017-10-06 14:56:16 +02:00
|
|
|
|
public bool IsEditMode
|
|
|
|
|
{
|
|
|
|
|
get { return _isEditMode; }
|
|
|
|
|
set { SetProperty(ref _isEditMode, value); }
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-02 18:40:54 +02:00
|
|
|
|
private readonly PwGroup _pwGroup;
|
2017-10-05 14:50:42 +02:00
|
|
|
|
private bool _isLeftPaneOpen;
|
2017-10-06 14:56:16 +02:00
|
|
|
|
private bool _isEditMode;
|
2017-10-05 14:50:42 +02:00
|
|
|
|
|
2017-10-02 18:40:54 +02:00
|
|
|
|
public GroupVm() {}
|
2017-09-14 18:33:29 +02:00
|
|
|
|
|
2017-10-02 18:40:54 +02:00
|
|
|
|
public GroupVm(PwGroup pwGroup, GroupVm parent)
|
2017-09-13 18:37:44 +02:00
|
|
|
|
{
|
2017-09-25 18:34:27 +02:00
|
|
|
|
_pwGroup = pwGroup;
|
2017-10-02 18:40:54 +02:00
|
|
|
|
ParentGroup = parent;
|
|
|
|
|
Entries = new ObservableCollection<EntryVm>(pwGroup.Entries.Select(e => new EntryVm(e, this)));
|
|
|
|
|
Entries.Insert(0, new EntryVm ());
|
|
|
|
|
//Entries.Add(new EntryVm { Title = " New entry" });
|
|
|
|
|
Groups = new ObservableCollection<GroupVm>(pwGroup.Groups.Select(g => new GroupVm(g, this)));
|
2017-09-25 18:34:27 +02:00
|
|
|
|
//Groups.Insert(0, new GroupVm { Name = " + New group" });
|
2017-10-02 18:40:54 +02:00
|
|
|
|
Groups.Insert(0, new GroupVm ());
|
2017-09-13 18:37:44 +02:00
|
|
|
|
}
|
2017-09-15 11:24:14 +02:00
|
|
|
|
|
2017-10-02 18:40:54 +02:00
|
|
|
|
public void CreateNewGroup()
|
2017-09-18 18:40:43 +02:00
|
|
|
|
{
|
2017-10-02 18:40:54 +02:00
|
|
|
|
var pwGroup = new PwGroup(true, true, "New group", PwIcon.Folder);
|
2017-09-25 18:34:27 +02:00
|
|
|
|
_pwGroup.AddGroup(pwGroup, true);
|
2017-10-02 18:40:54 +02:00
|
|
|
|
Groups.Add(new GroupVm(pwGroup, this));
|
2017-09-18 18:40:43 +02:00
|
|
|
|
}
|
2017-09-25 18:34:27 +02:00
|
|
|
|
|
2017-10-02 18:40:54 +02:00
|
|
|
|
public void CreateNewEntry()
|
2017-09-25 18:34:27 +02:00
|
|
|
|
{
|
|
|
|
|
var pwEntry = new PwEntry(true, true);
|
|
|
|
|
_pwGroup.AddEntry(pwEntry, true);
|
2017-10-02 18:40:54 +02:00
|
|
|
|
Entries.Add(new EntryVm(pwEntry, this));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveGroup()
|
|
|
|
|
{
|
|
|
|
|
_pwGroup.ParentGroup.Groups.Remove(_pwGroup);
|
|
|
|
|
ParentGroup.Groups.Remove(this);
|
2017-09-25 18:34:27 +02:00
|
|
|
|
}
|
2017-09-27 18:01:21 +02:00
|
|
|
|
|
2017-10-02 18:40:54 +02:00
|
|
|
|
public void RemoveEntry(EntryVm entry)
|
|
|
|
|
{
|
|
|
|
|
_pwGroup.Entries.Remove(entry.Entry);
|
|
|
|
|
Entries.Remove(entry);
|
|
|
|
|
}
|
2017-09-12 18:20:32 +02:00
|
|
|
|
}
|
|
|
|
|
}
|