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-10-17 18:46:05 +02:00
|
|
|
|
using Windows.UI.Xaml;
|
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-10-17 18:46:05 +02:00
|
|
|
|
using ModernKeePass.Interfaces;
|
2017-09-29 18:08:20 +02:00
|
|
|
|
using ModernKeePass.Mappings;
|
2017-09-26 15:38:58 +02:00
|
|
|
|
using ModernKeePassLib;
|
2017-10-17 18:46:05 +02:00
|
|
|
|
using System;
|
2017-09-12 18:20:32 +02:00
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.ViewModels
|
|
|
|
|
{
|
2017-10-17 18:46:05 +02:00
|
|
|
|
public class GroupVm : NotifyPropertyChangedBase, IPwEntity
|
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>();
|
2017-10-06 16:21:12 -04:00
|
|
|
|
|
2017-10-02 18:40:54 +02:00
|
|
|
|
public ObservableCollection<GroupVm> Groups { get; set; } = new ObservableCollection<GroupVm>();
|
2017-10-06 14:56:16 +02:00
|
|
|
|
|
2017-10-06 16:21:12 -04:00
|
|
|
|
public int EntryCount => Entries.Count() - 1;
|
2017-10-02 18:40:54 +02:00
|
|
|
|
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-17 18:46:05 +02:00
|
|
|
|
public string Id => _pwGroup.Uuid.ToHexString();
|
2017-10-06 16:21:12 -04:00
|
|
|
|
|
|
|
|
|
public IOrderedEnumerable<IGrouping<char, EntryVm>> EntriesZoomedOut
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return from e in Entries
|
|
|
|
|
where e.Entry != null
|
2017-10-17 18:46:05 +02:00
|
|
|
|
group e by e.Name.FirstOrDefault() into grp
|
2017-10-06 16:21:12 -04:00
|
|
|
|
orderby grp.Key
|
|
|
|
|
select grp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-06 14:56:16 +02:00
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return _pwGroup == null ? "New group" : _pwGroup.Name; }
|
|
|
|
|
set { _pwGroup.Name = value; }
|
|
|
|
|
}
|
2017-10-06 16:21:12 -04:00
|
|
|
|
|
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;
|
2017-10-17 18:46:05 +02:00
|
|
|
|
Entries = new ObservableCollection<EntryVm>(pwGroup.Entries.Select(e => new EntryVm(e, this)).OrderBy(e => e.Name));
|
2017-10-02 18:40:54 +02:00
|
|
|
|
Entries.Insert(0, new EntryVm ());
|
2017-10-06 16:21:12 -04:00
|
|
|
|
Groups = new ObservableCollection<GroupVm>(pwGroup.Groups.Select(g => new GroupVm(g, this)).OrderBy(g => g.Name));
|
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-13 15:46:41 +02:00
|
|
|
|
public GroupVm CreateNewGroup()
|
2017-09-18 18:40:43 +02:00
|
|
|
|
{
|
2017-10-13 15:46:41 +02:00
|
|
|
|
var pwGroup = new PwGroup(true, true, string.Empty, PwIcon.Folder);
|
2017-09-25 18:34:27 +02:00
|
|
|
|
_pwGroup.AddGroup(pwGroup, true);
|
2017-10-13 15:46:41 +02:00
|
|
|
|
var newGroup = new GroupVm(pwGroup, this) {IsEditMode = true};
|
|
|
|
|
Groups.Add(newGroup);
|
|
|
|
|
return newGroup;
|
2017-09-18 18:40:43 +02:00
|
|
|
|
}
|
2017-09-25 18:34:27 +02:00
|
|
|
|
|
2017-10-13 15:46:41 +02:00
|
|
|
|
public EntryVm CreateNewEntry()
|
2017-09-25 18:34:27 +02:00
|
|
|
|
{
|
|
|
|
|
var pwEntry = new PwEntry(true, true);
|
|
|
|
|
_pwGroup.AddEntry(pwEntry, true);
|
2017-10-13 15:46:41 +02:00
|
|
|
|
var newEntry = new EntryVm(pwEntry, this) {IsEditMode = true};
|
|
|
|
|
Entries.Add(newEntry);
|
|
|
|
|
return newEntry;
|
2017-10-02 18:40:54 +02:00
|
|
|
|
}
|
2017-09-27 18:01:21 +02:00
|
|
|
|
|
2017-10-17 18:46:05 +02:00
|
|
|
|
public void MarkForDelete()
|
|
|
|
|
{
|
|
|
|
|
var app = (App)Application.Current;
|
2017-10-18 10:32:51 +02:00
|
|
|
|
app.PendingDeleteEntities.Add(Id, this);
|
2017-10-17 18:46:05 +02:00
|
|
|
|
ParentGroup.Groups.Remove(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CommitDelete()
|
|
|
|
|
{
|
|
|
|
|
_pwGroup.ParentGroup.Groups.Remove(_pwGroup);
|
|
|
|
|
}
|
2017-10-18 10:32:51 +02:00
|
|
|
|
public void UndoDelete()
|
|
|
|
|
{
|
|
|
|
|
ParentGroup.Groups.Add(this);
|
|
|
|
|
}
|
2017-09-12 18:20:32 +02:00
|
|
|
|
}
|
|
|
|
|
}
|