Auto create new recycle bin if needed

Entries now also make use of the recycle bin
New path indication below groups and entries title
Password generator now has custom characters back (working thanks to lib 2.37)
This commit is contained in:
2017-10-31 12:14:26 +01:00
committed by BONNEVILLE Geoffroy
parent 699452667c
commit d32f312d60
8 changed files with 504 additions and 58 deletions

View File

@@ -1,12 +1,13 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using System.Text;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using ModernKeePass.Interfaces;
using ModernKeePass.Mappings;
using ModernKeePassLib;
using ModernKeePassLib.Cryptography.PasswordGenerator;
using ModernKeePassLib.Security;
using System;
using Windows.UI.Xaml;
using ModernKeePassLib.Cryptography;
namespace ModernKeePass.ViewModels
@@ -32,6 +33,7 @@ namespace ModernKeePass.ViewModels
public bool SpecialPatternSelected { get; set; }
public bool BracketsPatternSelected { get; set; }
public string CustomChars { get; set; } = string.Empty;
public PwUuid IdUuid => _pwEntry?.Uuid;
public string Name
{
@@ -122,9 +124,20 @@ namespace ModernKeePass.ViewModels
}
}
public string Path
{
get
{
var path = new StringBuilder(ParentGroup.Path);
path.Append($" > {ParentGroup.Name}");
return path.ToString();
}
}
public event PropertyChangedEventHandler PropertyChanged;
private readonly PwEntry _pwEntry;
private readonly App _app = (App)Application.Current;
private bool _isEditMode;
private bool _isRevealPassword;
@@ -139,8 +152,7 @@ namespace ModernKeePass.ViewModels
_pwEntry = entry;
ParentGroup = parent;
}
public void GeneratePassword()
{
var pwProfile = new PwProfile()
@@ -182,24 +194,27 @@ namespace ModernKeePass.ViewModels
public void MarkForDelete()
{
var app = (App)Application.Current;
app.PendingDeleteEntities.Add(Id, this);
_app.PendingDeleteEntities.Add(Id, this);
ParentGroup.Entries.Remove(this);
if (_app.Database.RecycleBinEnabled && !ParentGroup.IsSelected) _app.Database.RecycleBin.Entries.Add(this);
}
public void CommitDelete()
{
_pwEntry.ParentGroup.Entries.Remove(_pwEntry);
if (_app.Database.RecycleBinEnabled && !ParentGroup.IsSelected) _app.Database.RecycleBin.AddPwEntry(_pwEntry);
else _app.Database.AddDeletedItem(IdUuid);
}
public void UndoDelete()
{
ParentGroup.Entries.Add(this);
if (_app.Database.RecycleBinEnabled && !ParentGroup.IsSelected) _app.Database.RecycleBin.Entries.Remove(this);
}
public void Save()
{
var app = (App)Application.Current;
app.Database.Save();
_app.Database.Save();
}
}
}

View File

@@ -1,5 +1,6 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Windows.UI.Text;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
@@ -31,8 +32,13 @@ namespace ModernKeePass.ViewModels
get { return _app.Database.RecycleBinEnabled && _app.Database.RecycleBin.Id == Id; }
set
{
// TODO: if _pwGroup is null, create a new group
if (value && _pwGroup != null) _app.Database.RecycleBin = this;
else if (value && _pwGroup == null)
{
var recycleBin = _app.Database.RootGroup.AddNewGroup("Recycle bin");
recycleBin.IsSelected = true;
recycleBin.IconSymbol = Symbol.Delete;
}
}
}
@@ -56,6 +62,7 @@ namespace ModernKeePass.ViewModels
var result = PwIconToSegoeMapping.GetSymbolFromIcon(_pwGroup.IconId);
return result == Symbol.More ? Symbol.Folder : result;
}
set { _pwGroup.IconId = PwIconToSegoeMapping.GetIconFromSymbol(value); }
}
public bool IsEditMode
@@ -64,6 +71,17 @@ namespace ModernKeePass.ViewModels
set { SetProperty(ref _isEditMode, value); }
}
public string Path
{
get
{
if (ParentGroup == null) return string.Empty;
var path = new StringBuilder(ParentGroup.Path);
path.Append($" > {ParentGroup.Name}");
return path.ToString();
}
}
private readonly PwGroup _pwGroup;
private readonly App _app = (App)Application.Current;
private bool _isEditMode;
@@ -82,16 +100,16 @@ namespace ModernKeePass.ViewModels
Groups.Insert(0, new GroupVm ());
}
public GroupVm CreateNewGroup()
public GroupVm AddNewGroup(string name = "")
{
var pwGroup = new PwGroup(true, true, string.Empty, PwIcon.Folder);
var pwGroup = new PwGroup(true, true, name, PwIcon.Folder);
_pwGroup.AddGroup(pwGroup, true);
var newGroup = new GroupVm(pwGroup, this) {IsEditMode = true};
var newGroup = new GroupVm(pwGroup, this) {Name = name, IsEditMode = string.IsNullOrEmpty(name)};
Groups.Add(newGroup);
return newGroup;
}
public EntryVm CreateNewEntry()
public EntryVm AddNewEntry()
{
var pwEntry = new PwEntry(true, true);
_pwGroup.AddEntry(pwEntry, true);
@@ -99,6 +117,11 @@ namespace ModernKeePass.ViewModels
Entries.Add(newEntry);
return newEntry;
}
public void AddPwEntry(PwEntry entry)
{
_pwGroup.AddEntry(entry, true);
}
public void MarkForDelete()
{
@@ -111,6 +134,7 @@ namespace ModernKeePass.ViewModels
{
_pwGroup.ParentGroup.Groups.Remove(_pwGroup);
if (_app.Database.RecycleBinEnabled && !IsSelected) _app.Database.RecycleBin._pwGroup.AddGroup(_pwGroup, true);
else _app.Database.AddDeletedItem(IdUuid);
}
public void UndoDelete()