mirror of
https://github.com/moparisthebest/keepass2android
synced 2025-01-31 07:00:27 -05:00
add missing items
This commit is contained in:
parent
7852083950
commit
f948e69061
79
src/Kp2aBusinessLogic/database/edit/DeleteMultipleItems.cs
Normal file
79
src/Kp2aBusinessLogic/database/edit/DeleteMultipleItems.cs
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Android.Content;
|
||||||
|
using KeePassLib;
|
||||||
|
using KeePassLib.Interfaces;
|
||||||
|
|
||||||
|
namespace keepass2android
|
||||||
|
{
|
||||||
|
public class DeleteMultipleItems : DeleteRunnable
|
||||||
|
{
|
||||||
|
private readonly List<IStructureItem> _elementsToDelete;
|
||||||
|
private readonly bool _canRecycle;
|
||||||
|
|
||||||
|
public DeleteMultipleItems(Context ctx, Database db, List<IStructureItem> elementsToDelete, OnFinish finish, IKp2aApp app)
|
||||||
|
: base(finish, app)
|
||||||
|
{
|
||||||
|
_elementsToDelete = elementsToDelete;
|
||||||
|
SetMembers(ctx, db);
|
||||||
|
|
||||||
|
//determine once. The property is queried for each delete operation, but might return false
|
||||||
|
//after one entry/group is deleted (and thus in recycle bin and thus can't be recycled anymore)
|
||||||
|
_canRecycle = DetermineCanRecycle();
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool DetermineCanRecycle()
|
||||||
|
{
|
||||||
|
Android.Util.Log.Debug("KP2A", "CanRecycle?");
|
||||||
|
if (!App.GetDb().DatabaseFormat.CanRecycle)
|
||||||
|
{
|
||||||
|
Android.Util.Log.Debug("KP2A", "CanRecycle? No because of DB format.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (_elementsToDelete.OfType<PwGroup>().Any(g => !CanRecycleGroup(g)))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_elementsToDelete.OfType<PwEntry>().Any(e => !CanRecycleGroup(e.ParentGroup)))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Android.Util.Log.Debug("KP2A", "CanRecycle? Yes.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanRecycle
|
||||||
|
{
|
||||||
|
get { return _canRecycle; }
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override UiStringKey QuestionsResourceId
|
||||||
|
{
|
||||||
|
get { return UiStringKey.AskDeletePermanentlyItems; }
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void PerformDelete(List<PwGroup> touchedGroups, List<PwGroup> permanentlyDeletedGroups)
|
||||||
|
{
|
||||||
|
foreach (var g in _elementsToDelete.OfType<PwGroup>())
|
||||||
|
{
|
||||||
|
Android.Util.Log.Debug("KP2A", "Deleting " + g.Name);
|
||||||
|
DoDeleteGroup(g, touchedGroups, permanentlyDeletedGroups);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var e in _elementsToDelete.OfType<PwEntry>())
|
||||||
|
{
|
||||||
|
Android.Util.Log.Debug("KP2A", "Deleting " + e.Strings.ReadSafe(PwDefs.TitleField));
|
||||||
|
DoDeleteEntry(e, touchedGroups);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override UiStringKey StatusMessage
|
||||||
|
{
|
||||||
|
get { return UiStringKey.DeletingItems; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
99
src/Kp2aBusinessLogic/database/edit/MoveElements.cs
Normal file
99
src/Kp2aBusinessLogic/database/edit/MoveElements.cs
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using Android.Content;
|
||||||
|
using KeePassLib;
|
||||||
|
using KeePassLib.Interfaces;
|
||||||
|
|
||||||
|
namespace keepass2android.database.edit
|
||||||
|
{
|
||||||
|
public class MoveElements: RunnableOnFinish
|
||||||
|
{
|
||||||
|
private readonly List<IStructureItem> _elementsToMove;
|
||||||
|
private readonly PwGroup _targetGroup;
|
||||||
|
private readonly Context _ctx;
|
||||||
|
private readonly IKp2aApp _app;
|
||||||
|
|
||||||
|
public MoveElements(List<IStructureItem> elementsToMove, PwGroup targetGroup, Context ctx, IKp2aApp app, OnFinish finish) : base(finish)
|
||||||
|
{
|
||||||
|
_elementsToMove = elementsToMove;
|
||||||
|
_targetGroup = targetGroup;
|
||||||
|
_ctx = ctx;
|
||||||
|
_app = app;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Run()
|
||||||
|
{
|
||||||
|
//check if we will run into problems. Then finish with error before we start doing anything.
|
||||||
|
foreach (var _elementToMove in _elementsToMove)
|
||||||
|
{
|
||||||
|
PwGroup pgParent = _elementToMove.ParentGroup;
|
||||||
|
if (pgParent != _targetGroup)
|
||||||
|
{
|
||||||
|
if (pgParent != null)
|
||||||
|
{
|
||||||
|
PwGroup group = _elementToMove as PwGroup;
|
||||||
|
if (group != null)
|
||||||
|
{
|
||||||
|
if ((_targetGroup == group) || (_targetGroup.IsContainedIn(group)))
|
||||||
|
{
|
||||||
|
Finish(false, _app.GetResourceString(UiStringKey.CannotMoveGroupHere));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var elementToMove in _elementsToMove)
|
||||||
|
{
|
||||||
|
|
||||||
|
_app.GetDb().Dirty.Add(elementToMove.ParentGroup);
|
||||||
|
|
||||||
|
PwGroup pgParent = elementToMove.ParentGroup;
|
||||||
|
if (pgParent != _targetGroup)
|
||||||
|
{
|
||||||
|
if (pgParent != null) // Remove from parent
|
||||||
|
{
|
||||||
|
PwEntry entry = elementToMove as PwEntry;
|
||||||
|
if (entry != null)
|
||||||
|
{
|
||||||
|
pgParent.Entries.Remove(entry);
|
||||||
|
_targetGroup.AddEntry(entry, true, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PwGroup group = (PwGroup)elementToMove;
|
||||||
|
if ((_targetGroup == group) || (_targetGroup.IsContainedIn(group)))
|
||||||
|
{
|
||||||
|
Finish(false, _app.GetResourceString(UiStringKey.CannotMoveGroupHere));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pgParent.Groups.Remove(group);
|
||||||
|
_targetGroup.AddGroup(group, true, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_onFinishToRun = new ActionOnFinish((success, message) =>
|
||||||
|
{
|
||||||
|
if (!success)
|
||||||
|
{ // Let's not bother recovering from a failure.
|
||||||
|
_app.LockDatabase(false);
|
||||||
|
}
|
||||||
|
}, OnFinishToRun);
|
||||||
|
|
||||||
|
// Save
|
||||||
|
SaveDb save = new SaveDb(_ctx, _app, OnFinishToRun, false);
|
||||||
|
save.SetStatusLogger(StatusLogger);
|
||||||
|
save.Run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user