public static void DeleteSelectedItems <T>(ListView lv, PwObjectList <T> vInternalList) where T : class, IDeepCloneable <T> { if (lv == null) { throw new ArgumentNullException("lv"); } if (vInternalList == null) { throw new ArgumentNullException("vInternalList"); } ListView.SelectedIndexCollection lvsic = lv.SelectedIndices; int nSelectedCount = lvsic.Count; for (int i = 0; i < nSelectedCount; ++i) { int nIndex = lvsic[nSelectedCount - i - 1]; if (vInternalList.Remove(lv.Items[nIndex].Tag as T)) { lv.Items.RemoveAt(nIndex); } else { Debug.Assert(false); } } }
private void OnTrayOpening(object sender, EventArgs e) { PluginDebug.AddInfo("Tray setup: Start", 0); m_TrayMenu.DropDownItems.Clear(); List <PwDatabase> lDB = m_host.MainWindow.DocumentManager.GetOpenDatabases(); SearchParameters sp = new SearchParameters(); sp.ExcludeExpired = !Program.Config.Integration.AutoTypeExpiredCanMatch; //exclude expired entries only if they can not match sp.SearchInStringNames = true; Dictionary <string, PwObjectList <PwEntry> > dEntries = new Dictionary <string, PwObjectList <PwEntry> >(); foreach (PwDatabase db in lDB) { string dbName = UrlUtil.GetFileName(db.IOConnectionInfo.Path); if (!string.IsNullOrEmpty(db.Name)) { dbName = db.Name + " (" + dbName + ")"; } PwObjectList <PwEntry> entries = new PwObjectList <PwEntry>(); if (Config.UseDBForOTPSeeds(db)) { sp.SearchString = OTPDAO.OTPHandler_DB.DBNAME; } else { sp.SearchString = Config.OTPFIELD; // Config.SEED + " " + Config.SETTINGS; } db.RootGroup.SearchEntries(sp, entries); PluginDebug.AddInfo("Tray setup: Check database", 0, "DB: " + dbName, "Entries: " + entries.UCount.ToString()); if ((entries == null) || (entries.UCount == 0)) { continue; } //Ignore deleted entries PwGroup pgRecycle = db.RecycleBinEnabled ? db.RootGroup.FindGroup(db.RecycleBinUuid, true) : null; if (pgRecycle != null) { for (int i = (int)entries.UCount - 1; i >= 0; i--) { PwEntry pe = entries.GetAt((uint)i); if (pe.IsContainedIn(pgRecycle)) { entries.Remove(pe); } } } entries.Sort(SortEntries); dEntries.Add(dbName, entries); } foreach (var kvp in dEntries) { ToolStripMenuItem parent = null; //If entries of only one DB are found don't include the DB as additional menu level if (dEntries.Count == 1) { parent = m_TrayMenu; } else { parent = new ToolStripMenuItem(kvp.Key); m_TrayMenu.DropDownItems.Add(parent); } foreach (PwEntry pe in kvp.Value) { ToolStripMenuItem entry = new ToolStripMenuItem(); string[] text = GetTrayText(pe); PluginDebug.AddInfo("Tray setup: Add entry", 0, "Uuid: " + text[2]); // Do NOT add username and entry title to debugfile if (text[0] == string.Empty) { entry.Text = StrUtil.EncodeMenuText(string.Format(PluginTranslate.User, text[1])); } else if (text[1] == string.Empty) { entry.Text = StrUtil.EncodeMenuText(text[0]); } else { entry.Text = StrUtil.EncodeMenuText(text[0] + " (" + text[1] + ")"); } entry.Name = "KPOTP_" + pe.Uuid.ToString(); entry.Click += OnOTPTray; entry.Tag = pe; parent.DropDownItems.Add(entry); } } m_TrayMenu.Enabled = dEntries.Count > 0; m_TrayMenu.Text = m_TrayMenu.Enabled ? PluginTranslate.OTPCopyTrayEntries : PluginTranslate.OTPCopyTrayNoEntries; }