mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
New Database settings page
Implements Recycle Bin (new group creation still needs to be implemented) Code refactoring
This commit is contained in:
@@ -7,11 +7,10 @@ using ModernKeePass.Common;
|
||||
using ModernKeePass.Interfaces;
|
||||
using ModernKeePass.Mappings;
|
||||
using ModernKeePassLib;
|
||||
using System;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class GroupVm : NotifyPropertyChangedBase, IPwEntity
|
||||
public class GroupVm : NotifyPropertyChangedBase, IPwEntity, ISelectableModel
|
||||
{
|
||||
public GroupVm ParentGroup { get; }
|
||||
public ObservableCollection<EntryVm> Entries { get; set; } = new ObservableCollection<EntryVm>();
|
||||
@@ -19,26 +18,33 @@ namespace ModernKeePass.ViewModels
|
||||
public ObservableCollection<GroupVm> Groups { get; set; } = new ObservableCollection<GroupVm>();
|
||||
|
||||
public int EntryCount => Entries.Count() - 1;
|
||||
public int GroupCount => Groups.Count - 1;
|
||||
public bool IsNotRoot => ParentGroup != null;
|
||||
public FontWeight FontWeight => _pwGroup == null ? FontWeights.Bold : FontWeights.Normal;
|
||||
public string Id => _pwGroup.Uuid.ToHexString();
|
||||
|
||||
public IOrderedEnumerable<IGrouping<char, EntryVm>> EntriesZoomedOut
|
||||
public int GroupCount => Groups.Count - 1;
|
||||
public PwUuid IdUuid => _pwGroup?.Uuid;
|
||||
public string Id => IdUuid?.ToHexString();
|
||||
public bool IsNotRoot => ParentGroup != null;
|
||||
/// <summary>
|
||||
/// Is the Group the database Recycle Bin?
|
||||
/// </summary>
|
||||
public bool IsSelected
|
||||
{
|
||||
get
|
||||
get { return _app.Database.RecycleBinEnabled && _app.Database.RecycleBin.Id == Id; }
|
||||
set
|
||||
{
|
||||
return from e in Entries
|
||||
where e.Entry != null
|
||||
group e by e.Name.FirstOrDefault() into grp
|
||||
orderby grp.Key
|
||||
select grp;
|
||||
// TODO: if _pwGroup is null, create a new group
|
||||
if (value && _pwGroup != null) _app.Database.RecycleBin = this;
|
||||
}
|
||||
}
|
||||
|
||||
public IOrderedEnumerable<IGrouping<char, EntryVm>> EntriesZoomedOut => from e in Entries
|
||||
where !e.IsFirstItem
|
||||
group e by e.Name.FirstOrDefault() into grp
|
||||
orderby grp.Key
|
||||
select grp;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return _pwGroup == null ? "New group" : _pwGroup.Name; }
|
||||
get { return _pwGroup == null ? "< New group >" : _pwGroup.Name; }
|
||||
set { _pwGroup.Name = value; }
|
||||
}
|
||||
|
||||
@@ -59,18 +65,20 @@ namespace ModernKeePass.ViewModels
|
||||
}
|
||||
|
||||
private readonly PwGroup _pwGroup;
|
||||
private bool _isLeftPaneOpen;
|
||||
private readonly App _app = (App)Application.Current;
|
||||
private bool _isEditMode;
|
||||
|
||||
public GroupVm() {}
|
||||
|
||||
public GroupVm(PwGroup pwGroup, GroupVm parent)
|
||||
public GroupVm(PwGroup pwGroup, GroupVm parent, PwUuid recycleBinId = null)
|
||||
{
|
||||
_pwGroup = pwGroup;
|
||||
ParentGroup = parent;
|
||||
|
||||
if (recycleBinId != null && _pwGroup.Uuid.Equals(recycleBinId)) _app.Database.RecycleBin = this;
|
||||
Entries = new ObservableCollection<EntryVm>(pwGroup.Entries.Select(e => new EntryVm(e, this)).OrderBy(e => e.Name));
|
||||
Entries.Insert(0, new EntryVm ());
|
||||
Groups = new ObservableCollection<GroupVm>(pwGroup.Groups.Select(g => new GroupVm(g, this)).OrderBy(g => g.Name));
|
||||
Groups = new ObservableCollection<GroupVm>(pwGroup.Groups.Select(g => new GroupVm(g, this, recycleBinId)).OrderBy(g => g.Name));
|
||||
Groups.Insert(0, new GroupVm ());
|
||||
}
|
||||
|
||||
@@ -94,24 +102,31 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
public void MarkForDelete()
|
||||
{
|
||||
var app = (App)Application.Current;
|
||||
app.PendingDeleteEntities.Add(Id, this);
|
||||
_app.PendingDeleteEntities.Add(Id, this);
|
||||
ParentGroup.Groups.Remove(this);
|
||||
if (_app.Database.RecycleBinEnabled && !IsSelected) _app.Database.RecycleBin.Groups.Add(this);
|
||||
}
|
||||
|
||||
public void CommitDelete()
|
||||
{
|
||||
_pwGroup.ParentGroup.Groups.Remove(_pwGroup);
|
||||
if (_app.Database.RecycleBinEnabled && !IsSelected) _app.Database.RecycleBin._pwGroup.AddGroup(_pwGroup, true);
|
||||
}
|
||||
|
||||
public void UndoDelete()
|
||||
{
|
||||
ParentGroup.Groups.Add(this);
|
||||
if (_app.Database.RecycleBinEnabled && !IsSelected) _app.Database.RecycleBin.Groups.Remove(this);
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
var app = (App)Application.Current;
|
||||
app.Database.Save();
|
||||
_app.Database.Save();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user