public static bool PerformGlobal(List<PwDatabase> vSources,
ImageList ilIcons)
{
Debug.Assert(vSources != null); if(vSources == null) return false;
if(KeePassLib.Native.NativeLib.IsUnix())
{
if(!NativeMethods.TryXDoTool(true))
{
MessageService.ShowWarning(KPRes.AutoTypeXDoToolRequiredGlobalVer);
return false;
}
}
IntPtr hWnd;
string strWindow;
try
{
// hWnd = NativeMethods.GetForegroundWindowHandle();
// strWindow = NativeMethods.GetWindowText(hWnd);
NativeMethods.GetForegroundWindowInfo(out hWnd, out strWindow, true);
}
catch(Exception) { Debug.Assert(false); hWnd = IntPtr.Zero; strWindow = null; }
if(string.IsNullOrEmpty(strWindow)) return false;
if(!IsValidAutoTypeWindow(hWnd, true)) return false;
PwObjectList<PwEntry> vList = new PwObjectList<PwEntry>();
DateTime dtNow = DateTime.Now;
EntryHandler eh = delegate(PwEntry pe)
{
// Ignore expired entries
if(pe.Expires && (pe.ExpiryTime < dtNow)) return true;
if(GetSequenceForWindow(pe, strWindow, true) != null)
vList.Add(pe);
return true;
};
foreach(PwDatabase pwSource in vSources)
{
if(pwSource.IsOpen == false) continue;
pwSource.RootGroup.TraverseTree(TraversalMethod.PreOrder, null, eh);
}
if(vList.UCount == 1)
AutoType.PerformInternal(vList.GetAt(0), strWindow);
else if(vList.UCount > 1)
{
EntryListForm elf = new EntryListForm();
elf.InitEx(KPRes.AutoTypeEntrySelection, KPRes.AutoTypeEntrySelectionDescShort,
KPRes.AutoTypeEntrySelectionDescLong,
Properties.Resources.B48x48_KGPG_Key2, ilIcons, vList);
elf.EnsureForeground = true;
if(elf.ShowDialog() == DialogResult.OK)
{
try { NativeMethods.EnsureForegroundWindow(hWnd); }
catch(Exception) { Debug.Assert(false); }
if(elf.SelectedEntry != null)
AutoType.PerformInternal(elf.SelectedEntry, strWindow);
}
UIUtil.DestroyForm(elf);
}
return true;
}