mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 23:50:18 -04:00
ModernKeePassLib custom PCL version
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -194,13 +194,6 @@ namespace ModernKeePassLib.Collections
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Add(AutoTypeAssociation a)
|
||||
{
|
||||
Debug.Assert(a != null); if(a == null) throw new ArgumentNullException("a");
|
||||
|
||||
m_lWindowAssocs.Add(a);
|
||||
}
|
||||
|
||||
public AutoTypeAssociation GetAt(int iIndex)
|
||||
{
|
||||
if((iIndex < 0) || (iIndex >= m_lWindowAssocs.Count))
|
||||
@@ -209,6 +202,22 @@ namespace ModernKeePassLib.Collections
|
||||
return m_lWindowAssocs[iIndex];
|
||||
}
|
||||
|
||||
public void Add(AutoTypeAssociation a)
|
||||
{
|
||||
if(a == null) { Debug.Assert(false); throw new ArgumentNullException("a"); }
|
||||
|
||||
m_lWindowAssocs.Add(a);
|
||||
}
|
||||
|
||||
public void Insert(int iIndex, AutoTypeAssociation a)
|
||||
{
|
||||
if((iIndex < 0) || (iIndex > m_lWindowAssocs.Count))
|
||||
throw new ArgumentOutOfRangeException("iIndex");
|
||||
if(a == null) { Debug.Assert(false); throw new ArgumentNullException("a"); }
|
||||
|
||||
m_lWindowAssocs.Insert(iIndex, a);
|
||||
}
|
||||
|
||||
public void RemoveAt(int iIndex)
|
||||
{
|
||||
if((iIndex < 0) || (iIndex >= m_lWindowAssocs.Count))
|
||||
@@ -216,5 +225,20 @@ namespace ModernKeePassLib.Collections
|
||||
|
||||
m_lWindowAssocs.RemoveAt(iIndex);
|
||||
}
|
||||
|
||||
// public void Sort()
|
||||
// {
|
||||
// m_lWindowAssocs.Sort(AutoTypeConfig.AssocCompareFn);
|
||||
// }
|
||||
|
||||
// private static int AssocCompareFn(AutoTypeAssociation x,
|
||||
// AutoTypeAssociation y)
|
||||
// {
|
||||
// if(x == null) { Debug.Assert(false); return ((y == null) ? 0 : -1); }
|
||||
// if(y == null) { Debug.Assert(false); return 1; }
|
||||
// int cn = x.WindowName.CompareTo(y.WindowName);
|
||||
// if(cn != 0) return cn;
|
||||
// return x.Sequence.CompareTo(y.Sequence);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -28,7 +28,7 @@ using ModernKeePassLib.Security;
|
||||
using ModernKeePassLib.Utility;
|
||||
|
||||
#if KeePassLibSD
|
||||
using ModernKeePassLibSD;
|
||||
using KeePassLibSD;
|
||||
#endif
|
||||
|
||||
namespace ModernKeePassLib.Collections
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -28,7 +28,7 @@ using ModernKeePassLib.Security;
|
||||
using ModernKeePassLib.Utility;
|
||||
|
||||
#if KeePassLibSD
|
||||
using ModernKeePassLibSD;
|
||||
using KeePassLibSD;
|
||||
#endif
|
||||
|
||||
namespace ModernKeePassLib.Collections
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -133,6 +133,14 @@ namespace ModernKeePassLib.Collections
|
||||
}
|
||||
}
|
||||
|
||||
public void Insert(uint uIndex, T pwObject)
|
||||
{
|
||||
Debug.Assert(pwObject != null);
|
||||
if(pwObject == null) throw new ArgumentNullException("pwObject");
|
||||
|
||||
m_vObjects.Insert((int)uIndex, pwObject);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get an object of the list.
|
||||
/// </summary>
|
||||
@@ -225,7 +233,7 @@ namespace ModernKeePassLib.Collections
|
||||
if(nCount <= 1) return;
|
||||
|
||||
int nIndex = m_vObjects.IndexOf(tObject);
|
||||
Debug.Assert(nIndex >= 0);
|
||||
if(nIndex < 0) { Debug.Assert(false); return; }
|
||||
|
||||
if(bUp && (nIndex > 0)) // No assert for top item
|
||||
{
|
||||
@@ -241,6 +249,68 @@ namespace ModernKeePassLib.Collections
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveOne(T[] vObjects, bool bUp)
|
||||
{
|
||||
Debug.Assert(vObjects != null);
|
||||
if(vObjects == null) throw new ArgumentNullException("vObjects");
|
||||
|
||||
List<int> lIndices = new List<int>();
|
||||
foreach(T t in vObjects)
|
||||
{
|
||||
if(t == null) { Debug.Assert(false); continue; }
|
||||
|
||||
int p = IndexOf(t);
|
||||
if(p >= 0) lIndices.Add(p);
|
||||
else { Debug.Assert(false); }
|
||||
}
|
||||
|
||||
MoveOne(lIndices.ToArray(), bUp);
|
||||
}
|
||||
|
||||
public void MoveOne(int[] vIndices, bool bUp)
|
||||
{
|
||||
Debug.Assert(vIndices != null);
|
||||
if(vIndices == null) throw new ArgumentNullException("vIndices");
|
||||
|
||||
int n = m_vObjects.Count;
|
||||
if(n <= 1) return; // No moving possible
|
||||
|
||||
int m = vIndices.Length;
|
||||
if(m == 0) return; // Nothing to move
|
||||
|
||||
int[] v = new int[m];
|
||||
Array.Copy(vIndices, v, m);
|
||||
Array.Sort<int>(v);
|
||||
|
||||
if((bUp && (v[0] <= 0)) || (!bUp && (v[m - 1] >= (n - 1))))
|
||||
return; // Moving as a block is not possible
|
||||
|
||||
int iStart = (bUp ? 0 : (m - 1));
|
||||
int iExcl = (bUp ? m : -1);
|
||||
int iStep = (bUp ? 1 : -1);
|
||||
|
||||
for(int i = iStart; i != iExcl; i += iStep)
|
||||
{
|
||||
int p = v[i];
|
||||
if((p < 0) || (p >= n)) { Debug.Assert(false); continue; }
|
||||
|
||||
T t = m_vObjects[p];
|
||||
|
||||
if(bUp)
|
||||
{
|
||||
Debug.Assert(p > 0);
|
||||
m_vObjects.RemoveAt(p);
|
||||
m_vObjects.Insert(p - 1, t);
|
||||
}
|
||||
else // Down
|
||||
{
|
||||
Debug.Assert(p < (n - 1));
|
||||
m_vObjects.RemoveAt(p);
|
||||
m_vObjects.Insert(p + 1, t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move some of the objects in this list to the top/bottom.
|
||||
/// </summary>
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -26,15 +26,15 @@ using ModernKeePassLib.Delegates;
|
||||
using ModernKeePassLib.Interfaces;
|
||||
|
||||
#if KeePassLibSD
|
||||
using ModernKeePassLibSD;
|
||||
using KeePassLibSD;
|
||||
#endif
|
||||
|
||||
namespace ModernKeePassLib.Collections
|
||||
{
|
||||
public sealed class PwObjectPool
|
||||
{
|
||||
private SortedDictionary<PwUuidComparable, IStructureItem> m_dict =
|
||||
new SortedDictionary<PwUuidComparable, IStructureItem>();
|
||||
private SortedDictionary<PwUuid, IStructureItem> m_dict =
|
||||
new SortedDictionary<PwUuid, IStructureItem>();
|
||||
|
||||
public static PwObjectPool FromGroupRecursive(PwGroup pgRoot, bool bEntries)
|
||||
{
|
||||
@@ -42,16 +42,16 @@ namespace ModernKeePassLib.Collections
|
||||
|
||||
PwObjectPool p = new PwObjectPool();
|
||||
|
||||
if(!bEntries) p.m_dict[new PwUuidComparable(pgRoot.Uuid)] = pgRoot;
|
||||
if(!bEntries) p.m_dict[pgRoot.Uuid] = pgRoot;
|
||||
GroupHandler gh = delegate(PwGroup pg)
|
||||
{
|
||||
p.m_dict[new PwUuidComparable(pg.Uuid)] = pg;
|
||||
p.m_dict[pg.Uuid] = pg;
|
||||
return true;
|
||||
};
|
||||
|
||||
EntryHandler eh = delegate(PwEntry pe)
|
||||
{
|
||||
p.m_dict[new PwUuidComparable(pe.Uuid)] = pe;
|
||||
p.m_dict[pe.Uuid] = pe;
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -63,13 +63,13 @@ namespace ModernKeePassLib.Collections
|
||||
public IStructureItem Get(PwUuid pwUuid)
|
||||
{
|
||||
IStructureItem pItem;
|
||||
m_dict.TryGetValue(new PwUuidComparable(pwUuid), out pItem);
|
||||
m_dict.TryGetValue(pwUuid, out pItem);
|
||||
return pItem;
|
||||
}
|
||||
|
||||
public bool ContainsOnlyType(Type t)
|
||||
{
|
||||
foreach(KeyValuePair<PwUuidComparable, IStructureItem> kvp in m_dict)
|
||||
foreach(KeyValuePair<PwUuid, IStructureItem> kvp in m_dict)
|
||||
{
|
||||
if(kvp.Value.GetType() != t) return false;
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
KeePass Password Safe - The Open-Source Password Manager
|
||||
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -26,7 +26,7 @@ using System.Diagnostics;
|
||||
using ModernKeePassLib.Interfaces;
|
||||
|
||||
#if KeePassLibSD
|
||||
using ModernKeePassLibSD;
|
||||
using KeePassLibSD;
|
||||
#endif
|
||||
|
||||
namespace ModernKeePassLib.Collections
|
||||
|
Reference in New Issue
Block a user