/// <summary> /// Start Image Editing /// </summary> /// <param name="Item">ListViewItem to edit</param> private void StartImageEditing(ListViewItem item) { IconPickerForm ipf = new IconPickerForm(); PwListItem pli = (((ListViewItem)item).Tag as PwListItem); if (pli == null) { Debug.Assert(false); return; } PwEntry pe = pli.Entry; ipf.InitEx(m_host.MainWindow.ClientIcons, (uint)PwIcon.Count, m_host.Database, (uint)pe.IconId, pe.CustomIconUuid); if (ipf.ShowDialog() == DialogResult.OK) { if (ipf.ChosenCustomIconUuid != PwUuid.Zero) { pe.CustomIconUuid = ipf.ChosenCustomIconUuid; } else { pe.IconId = (PwIcon)ipf.ChosenIconId; pe.CustomIconUuid = PwUuid.Zero; } //m_host.MainWindow.RefreshEntriesList(); //Util.UpdateSaveIcon(); } }
private void populateExpiringEntries(PwObjectList <PwEntry> pwObjectList) { if (pwObjectList.Count() > 0) { foreach (PwEntry pe in pwObjectList) { if (pe.Strings.Exists(PasswordChangeReminderExt._EntryStringKey)) { PwListItem pli = new PwListItem(pe); int iRemindIn = Convert.ToInt32(pe.Strings.Get(PasswordChangeReminderExt._EntryStringKey).ReadString().ToString()); int iPwAge = Tools.calculateAge(pe); int iChangeIn = iRemindIn - iPwAge; ListViewItem lvi = lvExpiringPasswords.Items.Add(pe.Strings.ReadSafe(PwDefs.TitleField)); lvi.UseItemStyleForSubItems = false; if (iChangeIn > m_config.pcrPasswordsFormTentativeState) { lvi.SubItems.Add(iChangeIn + " " + Properties.strings.pcr_days).BackColor = m_config.pcrPasswordsFormGreatColor; lvi.Group = lvExpiringPasswords.Groups[1]; lvi.BackColor = m_config.pcrPasswordsFormGreatColor; } else if (iChangeIn > m_config.pcrPasswordsFormCriticalState) { lvi.SubItems.Add(iChangeIn + " " + Properties.strings.pcr_days).BackColor = m_config.pcrPasswordsFormTentativeColor; lvi.Group = lvExpiringPasswords.Groups[1]; lvi.BackColor = m_config.pcrPasswordsFormTentativeColor; lvExpiringPasswords.ShowGroups = true; } else { lvi.SubItems.Add(Properties.strings.pcr_today + " (" + iChangeIn + Properties.strings.pcr_days + ")").BackColor = m_config.pcrPasswordsFormCriticalColor; lvi.Group = lvExpiringPasswords.Groups[0]; lvi.BackColor = m_config.pcrPasswordsFormCriticalColor; lvExpiringPasswords.ShowGroups = true; } lvi.SubItems.Add(iPwAge + " " + Properties.strings.pcr_days).BackColor = Color.LightGray; lvi.SubItems.Add(iRemindIn + " " + Properties.strings.pcr_days).BackColor = Color.LightGray; lvi.ToolTipText = Properties.strings.pcr_created + ": " + pe.CreationTime + "\r\n" + Properties.strings.pcr_last_modified + ": " + pe.LastModificationTime; lvi.Tag = pli; if (pe.CustomIconUuid.Equals(PwUuid.Zero)) { lvi.ImageIndex = (int)pe.IconId; } else { lvi.ImageIndex = (int)PwIcon.Count + pdb.GetCustomIconIndex(pe.CustomIconUuid); } } } } else { lvExpiringPasswords.Items.Add(Properties.strings.pcr_nothing + "..."); } }
private void Lv_DrawItem(object sender, DrawListViewItemEventArgs e) { if (_highlightsOn) { ListViewItem lvi = e.Item; PwListItem li = (lvi.Tag as PwListItem); if (li == null) { Debug.Assert(false); return; } PwEntry pe = li.Entry; if (pe == null) { Debug.Assert(false); return; } ProtectedString pStr = pe.Strings.Get(PwDefs.PasswordField); if (pStr == null) { Debug.Assert(false); return; } string pw = pStr.ReadString(); if (pw.IndexOf('{') >= 0) { //It is a reference to another entry. PwDatabase pd = null; try { pd = _host.MainWindow.DocumentManager.SafeFindContainerOf(pe); } catch (Exception) { Debug.Assert(false); } SprContext context = new SprContext(pe, pd, (SprCompileFlags.Deref | SprCompileFlags.TextTransforms), false, false); pw = SprEngine.Compile(pw, context); } uint bits = QualityEstimation.EstimatePasswordBits(pw.ToCharArray()); foreach (KeyValuePair <uint, Color> kvp in QualityDelimiter) { if (bits <= kvp.Key) { lvi.BackColor = kvp.Value; break; } } } e.DrawDefault = true; }
public void StartEditing(ListViewItem Item, int SubItem, bool ContinueEdit) { if (Item != null) { PwListItem pli = (((ListViewItem)Item).Tag as PwListItem); if (pli == null) { Debug.Assert(false); return; } PwEntry pe = pli.Entry; StartEditing(pe, Item, SubItem, ContinueEdit); } }
private bool SaveEntryStatus(ListViewItem Item, PwIcon icon, string text) { PwListItem pli = (((ListViewItem)Item).Tag as PwListItem); if (pli == null) { Debug.Assert(false); return(false); } PwEntry pe = pli.Entry; pe = m_host.Database.RootGroup.FindEntry(pe.Uuid, true); var protString = pe.Strings.Get(PwDefs.PasswordField); if (protString != null && !protString.IsEmpty) { return(false); } PwEntry peInit = pe.CloneDeep(); pe.CreateBackup(null); pe.Touch(true, false); // Touch *after* backup pe.IconId = icon; Item.ImageIndex = (int)icon; pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(false, text)); Item.SubItems[getSubitemOfField(KeePass.App.Configuration.AceColumnType.UserName)].Text = text; PwCompareOptions cmpOpt = (PwCompareOptions.IgnoreLastMod | PwCompareOptions.IgnoreLastAccess | PwCompareOptions.IgnoreLastBackup); if (pe.EqualsEntry(peInit, cmpOpt, MemProtCmpMode.None)) { pe.LastModificationTime = peInit.LastModificationTime; pe.History.Remove(pe.History.GetAt(pe.History.UCount - 1)); // Undo backup return(false); } else { return(true); } }
private void Lv_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { ListViewItem lvi = e.Item; // Only color if currently looking at "Quality" column. if (e.Header.Text == Globals.COLUMN_NAME) { PwListItem li = (lvi.Tag as PwListItem); if (li == null) { Debug.Assert(false); return; } PwEntry pe = li.Entry; if (pe == null) { Debug.Assert(false); return; } ProtectedString pStr = pe.Strings.Get(PwDefs.PasswordField); if (pStr == null) { Debug.Assert(false); return; } string strPw = pStr.ReadString(); uint uCacheEst = ColoredQualityColumnProvider.loadQualityFromCache(strPw); foreach (KeyValuePair <uint, Color> kvp in QualityDelimiter) { // Evaluate which color to display for current password based on // strength of password. if (uCacheEst <= kvp.Key) { e.SubItem.BackColor = kvp.Value; break; } } } else { // Keep the color the same if it isn't currently the "Quality" column. e.SubItem.BackColor = lvi.BackColor; } e.DrawDefault = true; }
//Dereference placeholders in URL fields private void DerefStrings(PCAInitData pcadata, PwEntry pe) { if (m_miSprCompileFn == null) { return; } if (pcadata.URL.Contains("{")) { PwListItem pli = new PwListItem(pe); pcadata.URL = (string)m_miSprCompileFn.Invoke(null, new object[] { pcadata.URL, pli }); } if (pcadata.URL2.Contains("{")) { PwListItem pli = new PwListItem(pe); pcadata.URL2 = (string)m_miSprCompileFn.Invoke(null, new object[] { pcadata.URL2, pli }); } }
public override string GetCellData(string strColumnName, PwEntry pe) { if (pe.Strings.Exists(PasswordChangeReminderExt._EntryStringKey)) { PwListItem pli = new PwListItem(pe); int iRemindIn = Convert.ToInt32(pe.Strings.Get(PasswordChangeReminderExt._EntryStringKey).ReadString().ToString()); int iPwAge = Tools.calculateAge(pe); int iChangeIn = iRemindIn - iPwAge; if (iChangeIn <= 0) { return(Properties.strings.pcr_today + " (" + iChangeIn.ToString() + " " + Properties.strings.pcr_days + ")"); } return(iChangeIn.ToString() + " days"); } return(string.Empty); }
private void lvExpiringPasswordsItem_onDoubleClick(object sender, MouseEventArgs e) { ListViewHitTestInfo lvHit = lvExpiringPasswords.HitTest(e.Location); ListViewItem lvi = lvHit.Item; PwListItem pli = (lvi.Tag as PwListItem); PwEntry pe = pli.Entry; if (pe == null || pdb == null || il_icons == null) { return; // Do not assert } pe.CreationTime = DateTime.Parse("20.12.2019"); pe.LastModificationTime = DateTime.Parse("20.12.2019"); this.Close(); PwDatabase pwDb = pdb; PwEntryForm pForm = new PwEntryForm(); pForm.InitEx(pe, PwEditMode.EditExistingEntry, pwDb, il_icons, false, false); DialogResult dr = pForm.ShowDialog(); bool bMod = ((dr == DialogResult.OK) && pForm.HasModifiedEntry); UIUtil.DestroyForm(pForm); bool bUpdImg = pwDb.UINeedsIconUpdate; PwObjectList <PwEntry> pwEntries = new PwObjectList <PwEntry>(); pwEntries.Add(pe); MainForm mf = Program.MainForm; mf.SelectEntries(pwEntries, true, true); mf.RefreshEntriesList(); mf.UpdateUI(false, null, bUpdImg, null, false, null, bMod); if (Program.Config.Application.AutoSaveAfterEntryEdit && bMod) { mf.SaveDatabase(pwDb, null); } }
private string DerefString(string text, PwEntry pe) { if (m_miSprCompileFn == null) { return(text); } if (!KeePass.Program.Config.MainWindow.EntryListShowDerefData) { return(text); } if (KeePass.Program.Config.MainWindow.EntryListShowDerefDataAsync) { return(text); } if (!text.Contains("{")) { return(text); } PwListItem pli = new PwListItem(pe); return((string)m_miSprCompileFn.Invoke(null, new object[] { text, pli })); }
// Adapted from KeePass because it is private internal static ListViewItem GuiFindEntry(PwUuid puSearch) { Debug.Assert(puSearch != null); if (puSearch == null) { return(null); } foreach (ListViewItem lvi in m_lvEntries.Items) { PwListItem pli = (((ListViewItem)lvi).Tag as PwListItem); if (pli == null) { Debug.Assert(false); return(null); } if (pli.Entry.Uuid.EqualsValue(puSearch)) { return(lvi); } } return(null); }
private void checkOnStartup_onFileOpened(object sender, EventArgs e) { if (m_host != null && m_host.Database != null && m_host.Database.IsOpen && m_config != null && m_config.checkOnStartup) { foreach (PwEntry pe in Tools.GetExpiringPasswords(m_host)) { if (pe.Strings.Exists(PasswordChangeReminderExt._EntryStringKey)) { PwListItem pli = new PwListItem(pe); int iRemindIn = Convert.ToInt32(pe.Strings.Get(PasswordChangeReminderExt._EntryStringKey).ReadString().ToString()); int iPwAge = Tools.calculateAge(pe); int iChangeIn = iRemindIn - iPwAge; if (iChangeIn <= 0) { PCRPasswordsForm ep = new PCRPasswordsForm(m_host); ep.InitEx(Tools.GetExpiringPasswords(m_host), m_host.Database, m_host.MainWindow.ClientIcons, m_config); ep.ShowDialog(); break; } } } } }
/// <summary> /// Internal method to updated columns /// </summary> /// <param name="lColumns">List containing column indices that correspond to KeePass.Program.Config.MainWindow.EntryListColumns</param> private void Update() { if (m_dColumns.Count == 0) { return; } for (int i = 0; i < m_lvEntries.Items.Count; i++) { PwListItem pli = m_lvEntries.Items[i].Tag as PwListItem; if ((pli == null) || (pli.Entry == null)) { continue; } foreach (var c in m_dColumns) { int col = KeePass.Program.Config.MainWindow.EntryListColumns.IndexOf(c.Value); if (col < 0) { continue; } m_lvEntries.Items[i].SubItems[col].Text = KeePassLib.Utility.StrUtil.MultiToSingleLine(m_cp.GetCellData(c.Key, pli.Entry)); } } }
/// <summary> /// Accept or discard current value of cell editor control /// </summary> /// <param name="AcceptChanges">Use the _editingControl's Text as new SubItem text or discard changes?</param> private void EndEditing(bool AcceptChanges, bool ContinueEdit) { mutEdit.WaitOne(); //if (_editingControl == null) //{ // mutEdit.ReleaseMutex(); // return; //} ListViewItem Item = _editItem; int SubItem = _editSubItem; PaddedTextBox c = _editingControl; PwListItem pli = (((ListViewItem)Item).Tag as PwListItem); if (pli == null) { Debug.Assert(false); return; } PwEntry pe = pli.Entry; if (AcceptChanges == true) { // Check if item and textbox contain different text if (Util.GetEntryFieldEx(pe, SubItem, false) != c.Text) { // Save changes //MAYBE save only if editing is stopped or another item will be edited next //if (ContinueEdit == false) AcceptChanges = Util.SaveEntry(m_host.Database, Item, SubItem, c.Text); //TODO TEST maybe it wont flickr if we set visible false later // Avoid flickering // Set item text manually before calling RefreshEntriesList // If Item is protected if (!_editItem.SubItems[_editSubItem].Text.Equals(PwDefs.HiddenPassword)) { // Updating the listview item _editItem.SubItems[_editSubItem].Text = Util.GetEntryFieldEx(pe, SubItem, true); } } else { // No changes detected AcceptChanges = false; } } else { // Cancel // Nothing todo // AcceptChanges is false } //TODO Should be part of the textbox and inlineedit should be notified by event c.Leave -= new EventHandler(_editControl_Leave); c.LostFocus -= new EventHandler(_editControl_LostFocus); c.KeyPress -= new KeyPressEventHandler(_editControl_KeyPress); if (ContinueEdit == false) { _editingControl = null; _editItem = null; _editSubItem = -1; c.Visible = false; //Util.SelectEntry((PwEntry)Item.Tag, true); //m_lvEntries.Update(); m_lvEntries.Select(); m_lvEntries.HideSelection = false; m_lvEntries.Focus(); if (AcceptChanges == true) { // The number of visible entries has not changed, so we can call RefreshEntriesList Util.UpdateSaveState(); m_host.MainWindow.EnsureVisibleEntry(pe.Uuid); //TEST m_host.MainWindow.RefreshEntriesList(); } } // Add/Resume UIStateUpdated Event Handler //m_evMainWindow.Resume("OnPwListCustomColumnUpdate"); //m_host.MainWindow.UIStateUpdated += new EventHandler(OnPwListCustomColumnUpdate); mutEdit.ReleaseMutex(); }
// Ported from KeePass Mainform_functions SetListEntry internal static ListViewItem InsertListEntryOLD(PwEntry pe, int iIndex) { // Adapted variables DateTime m_dtCachedNow = DateTime.Now; Font m_fontExpired = FontUtil.CreateFont(m_lvEntries.Font, FontStyle.Strikeout); bool m_bEntryGrouping = m_lvEntries.ShowGroups; bool m_bShowTanIndices = Program.Config.MainWindow.TanView.ShowIndices; bool bSubEntries = Program.Config.MainWindow.ShowEntriesOfSubGroups; ListViewGroup m_lvgLastEntryGroup = null; foreach (ListViewGroup lvg in m_lvEntries.Groups) { if ((lvg.Tag as PwGroup) == pe.ParentGroup) { m_lvgLastEntryGroup = lvg; } } PwGroup pg = (Program.MainForm.GetSelectedGroup()); PwObjectList <PwEntry> pwlSource = ((pg != null) ? pg.GetEntries(bSubEntries) : new PwObjectList <PwEntry>()); bool m_bOnlyTans = ListContainsOnlyTans(pwlSource); ListViewItem lviTarget = null; Color m_clrAlternateItemBgColor = UIUtil.GetAlternateColor(m_lvEntries.BackColor); if (pe == null) { Debug.Assert(false); return(null); } ListViewItem lvi = (lviTarget ?? new ListViewItem()); PwListItem pli = new PwListItem(pe); lvi.Tag = pli; //lvi.BeginUpdate(); if (pe.Expires && (pe.ExpiryTime <= m_dtCachedNow)) { lvi.ImageIndex = (int)PwIcon.Expired; if (m_fontExpired != null) { lvi.Font = m_fontExpired; } } else // Not expired { // Reset font, if item was expired previously (i.e. has expired font) if ((lviTarget != null) && (lvi.ImageIndex == (int)PwIcon.Expired)) { lvi.Font = m_lvEntries.Font; } if (pe.CustomIconUuid.EqualsValue(PwUuid.Zero)) { lvi.ImageIndex = (int)pe.IconId; } else { lvi.ImageIndex = (int)PwIcon.Count + m_host.MainWindow.DocumentManager.ActiveDatabase.GetCustomIconIndex(pe.CustomIconUuid); } } if (m_bEntryGrouping && (lviTarget == null)) { PwGroup pgContainer = pe.ParentGroup; PwGroup pgLast = ((m_lvgLastEntryGroup != null) ? (PwGroup)m_lvgLastEntryGroup.Tag : null); Debug.Assert(pgContainer != null); if (pgContainer != null) { if (pgContainer != pgLast) { m_lvgLastEntryGroup = new ListViewGroup( pgContainer.GetFullPath()); m_lvgLastEntryGroup.Tag = pgContainer; m_lvEntries.Groups.Add(m_lvgLastEntryGroup); } lvi.Group = m_lvgLastEntryGroup; } } if (!pe.ForegroundColor.IsEmpty) { lvi.ForeColor = pe.ForegroundColor; } else if (lviTarget != null) { lvi.ForeColor = m_lvEntries.ForeColor; } else { Debug.Assert(UIUtil.ColorsEqual(lvi.ForeColor, m_lvEntries.ForeColor)); } if (!pe.BackgroundColor.IsEmpty) { lvi.BackColor = pe.BackgroundColor; } // else if(Program.Config.MainWindow.EntryListAlternatingBgColors && // ((m_lvEntries.Items.Count & 1) == 1)) // lvi.BackColor = m_clrAlternateItemBgColor; else if (lviTarget != null) { lvi.BackColor = m_lvEntries.BackColor; } else { Debug.Assert(UIUtil.ColorsEqual(lvi.BackColor, m_lvEntries.BackColor)); } // m_bOnlyTans &= PwDefs.IsTanEntry(pe); if (m_bShowTanIndices && m_bOnlyTans) { string strIndex = pe.Strings.ReadSafe(PwDefs.TanIndexField); if (strIndex.Length > 0) { lvi.Text = strIndex; } else { lvi.Text = PwDefs.TanTitle; } } else { lvi.Text = GetEntryFieldEx(pe, 0, true); } int nColumns = m_lvEntries.Columns.Count; if (lviTarget == null) { for (int iColumn = 1; iColumn < nColumns; ++iColumn) { lvi.SubItems.Add(GetEntryFieldEx(pe, iColumn, true)); } } else { int nSubItems = lvi.SubItems.Count; for (int iColumn = 1; iColumn < nColumns; ++iColumn) { string strSub = GetEntryFieldEx(pe, iColumn, true); if (iColumn < nSubItems) { lvi.SubItems[iColumn].Text = strSub; } else { lvi.SubItems.Add(strSub); } } Debug.Assert(lvi.SubItems.Count == nColumns); } //if (lviTarget == null) m_lvEntries.Items.Add(lvi); if (lviTarget == null) { m_lvEntries.Items.Insert(iIndex, lvi); } UIUtil.SetAlternatingBgColors(m_lvEntries, m_clrAlternateItemBgColor, Program.Config.MainWindow.EntryListAlternatingBgColors); //lvi.EndUpdate(); return(lvi); }
/* * // Get all user defined strings * internal static Dictionary<string, string> GetDictEntriesUserStrings(PwGroup pwg) * { * Dictionary<string, string> strd = new Dictionary<string, string>(); * //SortedDictionary<string, string> strd = new SortedDictionary<string, string>(); * * // Add all known pwentry strings * foreach (PwEntry pe in pwg.GetEntries(true)) * { * foreach (KeyValuePair<string, ProtectedString> pstr in pe.Strings) * { * if (!strd.ContainsKey(pstr.Key)) * { * if (!PwDefs.IsStandardField(pstr.Key)) * { * strd.Add(pstr.Key, pstr.Value.ReadString()); * } * } * } * } * * return strd; * }*/ // Ported from KeePass Entry Dialog SaveEntry() and UpdateEntryStrings(...) internal static bool SaveEntry(PwDatabase pwStorage, ListViewItem Item, int SubItem, string Text) { PwListItem pli = (((ListViewItem)Item).Tag as PwListItem); if (pli == null) { Debug.Assert(false); return(false); } PwEntry pe = pli.Entry; pe = pwStorage.RootGroup.FindEntry(pe.Uuid, true); PwEntry peInit = pe.CloneDeep(); pe.CreateBackup(null); pe.Touch(true, false); // Touch *after* backup int colID = SubItem; AceColumn col = GetAceColumn(colID); AceColumnType colType = col.Type; switch (colType) { case AceColumnType.Title: //if(PwDefs.IsTanEntry(pe)) //TODO tan list TanTitle ??? pe.Strings.Set(PwDefs.TanTitle, new ProtectedString(false, Text)); //else pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pwStorage.MemoryProtection.ProtectTitle, Text)); break; case AceColumnType.UserName: pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(pwStorage.MemoryProtection.ProtectUserName, Text)); break; case AceColumnType.Password: //byte[] pb = Text.ToUtf8(); //pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pwStorage.MemoryProtection.ProtectPassword, pb)); //MemUtil.ZeroByteArray(pb); pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pwStorage.MemoryProtection.ProtectPassword, Text)); break; case AceColumnType.Url: pe.Strings.Set(PwDefs.UrlField, new ProtectedString(pwStorage.MemoryProtection.ProtectUrl, Text)); break; case AceColumnType.Notes: pe.Strings.Set(PwDefs.NotesField, new ProtectedString(pwStorage.MemoryProtection.ProtectNotes, Text)); break; case AceColumnType.OverrideUrl: pe.OverrideUrl = Text; break; case AceColumnType.Tags: List <string> vNewTags = StrUtil.StringToTags(Text); pe.Tags.Clear(); foreach (string strTag in vNewTags) { pe.AddTag(strTag); } break; case AceColumnType.CustomString: pe.Strings.Set(col.CustomName, new ProtectedString(pe.Strings.GetSafe(col.CustomName).IsProtected, Text)); break; default: // Nothing todo break; } PwCompareOptions cmpOpt = (PwCompareOptions.IgnoreLastMod | PwCompareOptions.IgnoreLastAccess | PwCompareOptions.IgnoreLastBackup); if (pe.EqualsEntry(peInit, cmpOpt, MemProtCmpMode.None)) { pe.LastModificationTime = peInit.LastModificationTime; pe.History.Remove(pe.History.GetAt(pe.History.UCount - 1)); // Undo backup return(false); } else { return(true); } }
private void OnMouseUp(object sender, MouseEventArgs e) { // Only if left double click was detected if (m_bDoubleClick) { m_bDoubleClick = false; if (m_lvEntries.Items.Count > 0) { // Horizontal click position was inside the item area ListViewItem open = null; // FindNearestItem is supported only when the ListView is in SMALLICON or LARGEICON view. // Check right bound of the list item area // We can't check the bottom bound directly because the items are unsorted //if (m_lvEntries.Items[0].Bounds.Right > e.X) { //TODO only with one for loop ?????? //use ListView.Groups ? // We have to find the first item below the click position foreach (ListViewItem item in m_lvEntries.Items) { // Check vertical click position if (item.Bounds.Bottom >= e.Y) { if (item.Bounds.Top <= e.Y) { // Item match open = null; break; } // Found item below the click position // Group header double click detected if ((open == null) || (item.Bounds.Top < open.Bounds.Top)) { // Found first item or // Found item which is nearer to the group header open = item; } // We have to go through all items because the items are not sorted } } if (open != null) { // Open list group PwListItem pli = (((ListViewItem)open).Tag as PwListItem); if (pli == null) { Debug.Assert(false); return; } PwGroup pg = pli.Entry.ParentGroup; OpenGroup(pg); return; } } } } }
////////////////////////////////////////////////////////////// // Sub Plugin functionality private void OnMouseDown(object sender, MouseEventArgs e) { // Only allow left mouse button and double clicks if ((e.Button == MouseButtons.Left) && (e.Clicks == 2)) { ListViewItem add = null; ListViewItem above = null; //TODO only with one for loop and one listviewitem ?????? //use ListView.Groups ? if (m_lvEntries.Items.Count > 0) { // Check right bound of the list item area // We can't check the bottom bound directly because the items are unsorted if (m_lvEntries.Items[0].Bounds.Right < e.X) { // Horizontal click position was beside the item area // We have to find the matching item or first item below the click position or the last item in the list bool belowlast = true; foreach (ListViewItem item in m_lvEntries.Items) { // Check vertical click position if (item.Bounds.Bottom >= e.Y) { belowlast = false; if (item.Bounds.Top <= e.Y) { // Item match add = item; break; } // Found item below the click position // Group header double click detected if ((add == null) || (item.Bounds.Top < add.Bounds.Top)) { // Found first item or // Found item which is nearer to the group header //add = item; } // We have to go through all items because the items are not sorted } else { // Item is above the click position // Found item below the click position // Group header double click detected if ((above == null) || (item.Bounds.Top > above.Bounds.Top)) { // Found first item or // Found item which is nearer to the group header above = item; } // We have to go through all items because the items are not sorted } } if (add == null) { if (belowlast) { add = above; } } } else { // Horizontal click position was inside the item area // Check if the click position is below the item area foreach (ListViewItem item in m_lvEntries.Items) { // Check vertical click position if (item.Bounds.Bottom >= e.Y) { // There are items below the click position // Group Header was clicked add = null; break; } else { // Item is above the click position // Found item below the click position if ((add == null) || (item.Bounds.Top > add.Bounds.Top)) { // Found first item or // Found item which is nearer to the group header add = item; } // We have to go through all items because the items are not sorted } } } } else { // No item in listview PwGroup pg = Program.MainForm.GetSelectedGroup(); AddEntry(pg, 0); return; } if (add != null) { // Empty area double click detected PwListItem pli = (((ListViewItem)add).Tag as PwListItem); if (pli == null) { Debug.Assert(false); return; } PwGroup pg = pli.Entry.ParentGroup; int iIndex = m_lvEntries.Items.IndexOf(add); AddEntry(pg, iIndex); } } }
private ListViewItem GetPreviousItemFor(ListViewItem Item) { bool m_bEntryGrouping = m_lvEntries.ShowGroups; ListViewItem prevItem = null; if (m_lvEntries.Items.Count > 0) { if (m_lvEntries.Groups.Count > 0) { // Grouping is enabled // Within the group the items are not in display order, // but the order can be derived from the item indices PwListItem pli = (((ListViewItem)Item).Tag as PwListItem); PwGroup pg = pli.Entry.ParentGroup; foreach (ListViewGroup lvg in m_lvEntries.Groups) { if ((lvg.Tag as PwGroup) == pli.Entry.ParentGroup) { List <ListViewItem> lItems = new List <ListViewItem>(); foreach (ListViewItem lviEnum in lvg.Items) { lItems.Add(lviEnum); } lItems.Sort(Util.LviCompareByIndex); int previdx = lItems.IndexOf(Item) - 1; if (previdx >= 0) { // Previous item is within the group prevItem = lItems[previdx]; break; } else { // Previous item is in previous group int prevgrp = m_lvEntries.Groups.IndexOf(lvg) - 1; if (prevgrp >= 0) { // Go to last item in previous group lItems = new List <ListViewItem>(); foreach (ListViewItem lviEnum in m_lvEntries.Groups[prevgrp].Items) { lItems.Add(lviEnum); } lItems.Sort(Util.LviCompareByIndex); prevItem = lItems[lItems.Count - 1]; } else { // Go to last item in last group lItems = new List <ListViewItem>(); foreach (ListViewItem lviEnum in m_lvEntries.Groups[m_lvEntries.Groups.Count - 1].Items) { lItems.Add(lviEnum); } lItems.Sort(Util.LviCompareByIndex); prevItem = lItems[lItems.Count - 1]; } } } } } else { // Grouping is disabled // All items in list are in their correct order int idx = m_lvEntries.Items.IndexOf(Item); int cnt = m_lvEntries.Items.Count; prevItem = m_lvEntries.Items[(idx - 1 + cnt) % cnt]; } } return(prevItem); }
private void OnUIStateUpdated(object sender, EventArgs e) { if (!Config.AlreadyExpiredActive && !Config.SoonExpiredActive) { return; } if ((m_host == null) || (m_host.Database == null) || !m_host.Database.IsOpen) { PluginDebug.AddInfo("No active database or database is not opened, nothing to do", 0); return; } ListView lv = (ListView)Tools.GetControl("m_lvEntries"); if (lv == null) { PluginDebug.AddError("Could not find m_lvEntries", 0); return; } DateTime dtSoon = DateTime.Now.AddDays(Program.Config.Application.ExpirySoonDays); bool canHideExpired = true; int hidden = 0; PwGroup recycle = null; if (Config.HideExpired && Config.AlreadyExpiredActive) { canHideExpired = HidingAllowed(sender); recycle = m_host.Database.RecycleBinEnabled ? m_host.Database.RootGroup.FindGroup(m_host.Database.RecycleBinUuid, true) : null; } else { PluginDebug.AddInfo("Hiding of expired entries", 0, "Active: " + false.ToString()); } if (!canHideExpired && !Config.AlreadyExpiredActive && !Config.SoonExpiredActive) { return; } try { lv.BeginUpdate(); //don't use foreach and change the number of items... (thanks to darkdragon) //foreach (ListViewItem lvi in lv.Items) for (int i = lv.Items.Count - 1; i >= 0; i--) { ListViewItem lvi = null; PwListItem li = null; try { //This can throw if multiple concurrent changes are in progress //Can happen when e. g. doing Edit Entries (quick) - Expire npw lvi = lv.Items[i]; li = (lvi.Tag as PwListItem); } catch { } if (li == null) { continue; } if (li.Entry == null) { PluginDebug.AddError("List entry does not contain valid PwEntry", 0, lvi.Text); continue; //should never happen but on the other side... you never know } ExpiryStatus expiry = EntryExpiry(li.Entry, dtSoon); if ((expiry == ExpiryStatus.Expired) && Config.AlreadyExpiredActive) { if (Config.HideExpired && canHideExpired) { if (!li.Entry.IsContainedIn(recycle)) { try { //This can throw if multiple concurrent changes are in progress //Can happen when e. g. doing Edit Entries (quick) - Expire npw lv.Items.Remove(lvi); } catch { } hidden++; PluginDebug.AddInfo("Hidden entry: " + li.Entry.Uuid.ToHexString(), 0, "Removed from list"); } else { PluginDebug.AddInfo("Hidden entry: " + li.Entry.Uuid.ToHexString(), 0, "Not removed from list, contained in recycle bin"); } } else { lvi.ImageIndex = Config.AlreadyExpiredIcon; lvi.BackColor = Config.AlreadyExpiredColor; if (!lvi.UseItemStyleForSubItems) { for (int j = 0; j < lvi.SubItems.Count; j++) { lvi.SubItems[i].BackColor = lvi.BackColor; } } } } else if (Config.SoonExpiredActive && (expiry == ExpiryStatus.ExpiringSoon)) { lvi.ImageIndex = Config.SoonExpiredIcon; lvi.BackColor = Config.SoonExpiredColor; if (!lvi.UseItemStyleForSubItems) { for (int j = 0; j < lvi.SubItems.Count; j++) { lvi.SubItems[i].BackColor = lvi.BackColor; } } } } if (hidden > 0) { UIUtil.SetAlternatingBgColors(lv, UIUtil.GetAlternateColor(lv.BackColor), Program.Config.MainWindow.EntryListAlternatingBgColors); m_host.MainWindow.SetStatusEx(string.Format(PluginTranslate.HiddenExpired, hidden)); } } catch (Exception ex) { bool bDM = PluginDebug.DebugMode; PluginDebug.DebugMode = true; PluginDebug.AddError("Exception during OnUIStateUpdate", -1, ex.Message, ex.Source, ex.StackTrace); PluginDebug.DebugMode = bDM; } finally { if (lv != null) { lv.EndUpdate(); } } }
/// <summary> /// Find Next ListView Item /// </summary> /// <param name="Item">Item to find next for</param> /// <returns>Item</returns> private ListViewItem GetNextItemFor(ListViewItem Item) { bool m_bEntryGrouping = m_lvEntries.ShowGroups; ListViewItem nextItem = null; if (m_lvEntries.Items.Count > 0) { if (m_lvEntries.Groups.Count > 0) { // Grouping is enabled // Within the group the items are not in display order, // but the order can be derived from the item indices PwListItem pli = (((ListViewItem)Item).Tag as PwListItem); PwGroup pg = pli.Entry.ParentGroup; foreach (ListViewGroup lvg in m_lvEntries.Groups) { if ((lvg.Tag as PwGroup) == pli.Entry.ParentGroup) { List <ListViewItem> lItems = new List <ListViewItem>(); foreach (ListViewItem lviEnum in lvg.Items) { lItems.Add(lviEnum); } lItems.Sort(Util.LviCompareByIndex); int nextidx = lItems.IndexOf(Item) + 1; if (nextidx < lItems.Count) { // Next item is within the group nextItem = lItems[nextidx]; break; } else { // Next item is in next group int nextgrp = m_lvEntries.Groups.IndexOf(lvg) + 1; if (nextgrp < m_lvEntries.Groups.Count) { // Go to first item in next group lItems = new List <ListViewItem>(); foreach (ListViewItem lviEnum in m_lvEntries.Groups[nextgrp].Items) { lItems.Add(lviEnum); } lItems.Sort(Util.LviCompareByIndex); nextItem = lItems[0]; } else { // Go to first item in first group lItems = new List <ListViewItem>(); foreach (ListViewItem lviEnum in m_lvEntries.Groups[0].Items) { lItems.Add(lviEnum); } lItems.Sort(Util.LviCompareByIndex); nextItem = lItems[0]; } } } } } else { // Grouping is disabled // All items in list are in their correct order int idx = m_lvEntries.Items.IndexOf(Item); int cnt = m_lvEntries.Items.Count; nextItem = m_lvEntries.Items[(idx + 1) % cnt]; } } return(nextItem); }