mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 23:50:18 -04:00
Recycle bin restore function (actually implemented a move functionality, for later)
This commit is contained in:
@@ -14,7 +14,9 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class EntryVm : INotifyPropertyChanged, IPwEntity
|
||||
{
|
||||
public GroupVm ParentGroup { get; }
|
||||
public GroupVm ParentGroup { get; private set; }
|
||||
|
||||
public GroupVm PreviousGroup { get; private set; }
|
||||
|
||||
public System.Drawing.Color? BackgroundColor => _pwEntry?.BackgroundColor;
|
||||
public System.Drawing.Color? ForegroundColor => _pwEntry?.ForegroundColor;
|
||||
@@ -194,22 +196,34 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
public void MarkForDelete()
|
||||
{
|
||||
_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);
|
||||
Move(_app.Database.RecycleBinEnabled && !ParentGroup.IsSelected ? _app.Database.RecycleBin : null);
|
||||
}
|
||||
|
||||
public void UndoDelete()
|
||||
{
|
||||
Move(PreviousGroup);
|
||||
}
|
||||
|
||||
public void Move(GroupVm destination)
|
||||
{
|
||||
PreviousGroup = ParentGroup;
|
||||
PreviousGroup.Entries.Remove(this);
|
||||
PreviousGroup.RemovePwEntry(_pwEntry);
|
||||
if (destination == null)
|
||||
{
|
||||
_app.Database.AddDeletedItem(IdUuid);
|
||||
return;
|
||||
}
|
||||
ParentGroup = destination;
|
||||
ParentGroup.Entries.Add(this);
|
||||
if (_app.Database.RecycleBinEnabled && !ParentGroup.IsSelected) _app.Database.RecycleBin.Entries.Remove(this);
|
||||
ParentGroup.AddPwEntry(_pwEntry);
|
||||
}
|
||||
|
||||
public void CommitDelete()
|
||||
{
|
||||
_pwEntry.ParentGroup.Entries.Remove(_pwEntry);
|
||||
if (_app.Database.RecycleBinEnabled && !PreviousGroup.IsSelected) _app.Database.RecycleBin.AddPwEntry(_pwEntry);
|
||||
else _app.Database.AddDeletedItem(IdUuid);
|
||||
}
|
||||
|
||||
public void Save()
|
||||
|
@@ -13,7 +13,8 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class GroupVm : NotifyPropertyChangedBase, IPwEntity, ISelectableModel
|
||||
{
|
||||
public GroupVm ParentGroup { get; }
|
||||
public GroupVm ParentGroup { get; private set; }
|
||||
public GroupVm PreviousGroup { get; private set; }
|
||||
public ObservableCollection<EntryVm> Entries { get; set; } = new ObservableCollection<EntryVm>();
|
||||
|
||||
public ObservableCollection<GroupVm> Groups { get; set; } = new ObservableCollection<GroupVm>();
|
||||
@@ -24,6 +25,8 @@ namespace ModernKeePass.ViewModels
|
||||
public PwUuid IdUuid => _pwGroup?.Uuid;
|
||||
public string Id => IdUuid?.ToHexString();
|
||||
public bool IsNotRoot => ParentGroup != null;
|
||||
|
||||
public bool ShowRestore => IsNotRoot && ParentGroup.IsSelected;
|
||||
/// <summary>
|
||||
/// Is the Group the database Recycle Bin?
|
||||
/// </summary>
|
||||
@@ -122,27 +125,45 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
_pwGroup.AddEntry(entry, true);
|
||||
}
|
||||
|
||||
|
||||
public void RemovePwEntry(PwEntry entry)
|
||||
{
|
||||
_pwGroup.Entries.Remove(entry);
|
||||
}
|
||||
|
||||
public void MarkForDelete()
|
||||
{
|
||||
_app.PendingDeleteEntities.Add(Id, this);
|
||||
ParentGroup.Groups.Remove(this);
|
||||
if (_app.Database.RecycleBinEnabled && !IsSelected) _app.Database.RecycleBin.Groups.Add(this);
|
||||
Move(_app.Database.RecycleBinEnabled && !IsSelected ? _app.Database.RecycleBin : null);
|
||||
}
|
||||
|
||||
|
||||
public void UndoDelete()
|
||||
{
|
||||
Move(PreviousGroup);
|
||||
}
|
||||
|
||||
public void Move(GroupVm destination)
|
||||
{
|
||||
PreviousGroup = ParentGroup;
|
||||
PreviousGroup.Groups.Remove(this);
|
||||
PreviousGroup._pwGroup.Groups.Remove(_pwGroup);
|
||||
if (destination == null)
|
||||
{
|
||||
_app.Database.AddDeletedItem(IdUuid);
|
||||
return;
|
||||
}
|
||||
ParentGroup = destination;
|
||||
ParentGroup.Groups.Add(this);
|
||||
ParentGroup._pwGroup.AddGroup(_pwGroup, true);
|
||||
}
|
||||
|
||||
public void CommitDelete()
|
||||
{
|
||||
_pwGroup.ParentGroup.Groups.Remove(_pwGroup);
|
||||
if (_app.Database.RecycleBinEnabled && !IsSelected) _app.Database.RecycleBin._pwGroup.AddGroup(_pwGroup, true);
|
||||
if (_app.Database.RecycleBinEnabled && !PreviousGroup.IsSelected) _app.Database.RecycleBin._pwGroup.AddGroup(_pwGroup, true);
|
||||
else _app.Database.AddDeletedItem(IdUuid);
|
||||
}
|
||||
|
||||
public void UndoDelete()
|
||||
{
|
||||
ParentGroup.Groups.Add(this);
|
||||
if (_app.Database.RecycleBinEnabled && !IsSelected) _app.Database.RecycleBin.Groups.Remove(this);
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
_app.Database.Save();
|
||||
|
Reference in New Issue
Block a user