/// <summary> /// Update the entries list. This function completely rebuilds the entries /// list. You must call this function after you've made any changes to /// the entries of the currently selected group. Note that if you only /// made small changes (like editing an existing entry), the /// <c>RefreshEntriesList</c> function could be a better choice, as it only /// updates currently listed items and doesn't rebuild the whole list as /// <c>UpdateEntryList</c>. /// </summary> /// <param name="pgSelected">Group whose entries should be shown. If this /// parameter is <c>null</c>, the entries of the currently selected group /// (groups view) are displayed, otherwise the entries of the <c>pgSelected</c> /// group are displayed.</param> private void UpdateEntryList(PwGroup pgSelected, bool bOnlyUpdateCurrentlyShown) { NotifyUserActivity(); UpdateImageLists(false); PwEntry peTop = GetTopEntry(), peFocused = GetSelectedEntry(false); PwEntry[] vSelected = GetSelectedEntries(); int iScrollY = NativeMethods.GetScrollPosY(m_lvEntries.Handle); bool bSubEntries = Program.Config.MainWindow.ShowEntriesOfSubGroups; PwGroup pg = (pgSelected ?? GetSelectedGroup()); if(bOnlyUpdateCurrentlyShown) { Debug.Assert(pgSelected == null); pg = GetCurrentEntries(); } PwObjectList<PwEntry> pwlSource = ((pg != null) ? pg.GetEntries(bSubEntries) : new PwObjectList<PwEntry>()); m_bOnlyTans = ListContainsOnlyTans(pwlSource); m_asyncListUpdate.CancelPendingUpdatesAsync(); m_lvEntries.BeginUpdate(); lock(m_asyncListUpdate.ListEditSyncObject) { m_lvEntries.Items.Clear(); } m_lvEntries.Groups.Clear(); m_lvgLastEntryGroup = null; // m_bEntryGrouping = (((pg != null) ? pg.IsVirtual : false) || bSubEntries); m_bEntryGrouping = bSubEntries; if(pg != null) { PwDatabase pd = m_docMgr.ActiveDatabase; if(bOnlyUpdateCurrentlyShown && !m_lvEntries.ShowGroups && EntryUtil.EntriesHaveSameParent(pwlSource) && pd.IsOpen) { // Just reorder, don't enable grouping EntryUtil.ReorderEntriesAsInDatabase(pwlSource, pd); peTop = null; // Don't scroll to previous top item } else m_bEntryGrouping |= pg.IsVirtual; } int iLg = Program.Config.MainWindow.ListGrouping; if((iLg & (int)AceListGrouping.Primary) == (int)AceListGrouping.On) m_bEntryGrouping = true; else if((iLg & (int)AceListGrouping.Primary) == (int)AceListGrouping.Off) m_bEntryGrouping = false; m_lvEntries.ShowGroups = m_bEntryGrouping; int nTopIndex = -1; ListViewItem lviFocused = null; m_dtCachedNow = DateTime.Now; ListViewStateEx lvseCachedState = new ListViewStateEx(m_lvEntries); if(pg != null) { foreach(PwEntry pe in pwlSource) { ListViewItem lvi = SetListEntry(pe, null); if(vSelected != null) { if(Array.IndexOf(vSelected, pe) >= 0) lvi.Selected = true; } if(pe == peTop) nTopIndex = m_lvEntries.Items.Count - 1; if(pe == peFocused) lviFocused = lvi; } } Debug.Assert(lvseCachedState.CompareTo(m_lvEntries)); UIUtil.SetAlternatingBgColors(m_lvEntries, m_clrAlternateItemBgColor, Program.Config.MainWindow.EntryListAlternatingBgColors); Debug.Assert(m_bEntryGrouping == m_lvEntries.ShowGroups); if(UIUtil.GetGroupsEnabled(m_lvEntries)) { // Test nTopIndex to ensure we're not scrolling an unrelated list if((nTopIndex >= 0) && (iScrollY > 0)) NativeMethods.Scroll(m_lvEntries, 0, iScrollY); } else { Debug.Assert((nTopIndex != 0) || (UIUtil.GetTopVisibleItem( m_lvEntries) == 0)); // No scrolling required for item 0 if(nTopIndex > 0) UIUtil.SetTopVisibleItem(m_lvEntries, nTopIndex, false); } if(lviFocused != null) UIUtil.SetFocusedItem(m_lvEntries, lviFocused, false); View view = m_lvEntries.View; if(m_bSimpleTanView) { if(m_lvEntries.Items.Count == 0) m_lvEntries.View = View.Details; else if(m_bOnlyTans && (view != View.List)) { // SortPasswordList(false, 0, false); m_lvEntries.View = View.List; } else if(!m_bOnlyTans && (view != View.Details)) m_lvEntries.View = View.Details; } else // m_bSimpleTanView == false { if(view != View.Details) m_lvEntries.View = View.Details; } m_lvEntries.EndUpdate(); // Resize columns *after* EndUpdate, otherwise sizing problem // caused by the scrollbar if(Program.Config.MainWindow.EntryListAutoResizeColumns && (m_lvEntries.View == View.Details)) UIUtil.ResizeColumns(m_lvEntries, true); }
private void AddEntriesToList(PwObjectList<PwEntry> vEntries) { if(vEntries == null) { Debug.Assert(false); return; } m_bEntryGrouping = m_lvEntries.ShowGroups; ListViewStateEx lvseCachedState = new ListViewStateEx(m_lvEntries); foreach(PwEntry pe in vEntries) { if(pe == null) { Debug.Assert(false); continue; } if(m_bEntryGrouping) { PwGroup pg = pe.ParentGroup; foreach(ListViewGroup lvg in m_lvEntries.Groups) { PwGroup pgList = (lvg.Tag as PwGroup); Debug.Assert(pgList != null); if((pgList != null) && (pg == pgList)) { m_lvgLastEntryGroup = lvg; break; } } } SetListEntry(pe, null); } Debug.Assert(lvseCachedState.CompareTo(m_lvEntries)); UIUtil.SetAlternatingBgColors(m_lvEntries, m_clrAlternateItemBgColor, Program.Config.MainWindow.EntryListAlternatingBgColors); }
private void AddEntriesToList(PwObjectList<PwEntry> vEntries) { if(vEntries == null) { Debug.Assert(false); return; } m_bEntryGrouping = m_lvEntries.ShowGroups; ListViewStateEx lvseCachedState = new ListViewStateEx(m_lvEntries); foreach(PwEntry pe in vEntries) { if(pe == null) { Debug.Assert(false); continue; } if(m_bEntryGrouping) { PwGroup pg = pe.ParentGroup; foreach(ListViewGroup lvg in m_lvEntries.Groups) { PwGroup pgList = lvg.Tag as PwGroup; Debug.Assert(pgList != null); if((pgList != null) && (pg == pgList)) { m_lvgLastEntryGroup = lvg; break; } } } AddEntryToList(pe, lvseCachedState); } Debug.Assert(lvseCachedState.CompareTo(m_lvEntries)); }
/// <summary> /// Refresh the entries list. All currently displayed entries are updated. /// If you made changes to the list that change the number of visible entries /// (like adding or removing an entry), you must use the <c>UpdatePasswordList</c> /// function instead. /// </summary> public void RefreshEntriesList() { int nItemCount = m_lvEntries.Items.Count; if(nItemCount <= 0) return; PwEntry peTop = GetTopEntry(); PwEntry peFocused = GetSelectedEntry(false); UpdateImageLists(); PwEntry[] vSelected = GetSelectedEntries(); if(vSelected == null) vSelected = new PwEntry[0]; PwEntry[] vList = new PwEntry[nItemCount]; for(int iEnum = 0; iEnum < nItemCount; ++iEnum) vList[iEnum] = (PwEntry)m_lvEntries.Items[iEnum].Tag; m_lvEntries.BeginUpdate(); m_lvEntries.Items.Clear(); m_lvEntries.Groups.Clear(); m_lvgLastEntryGroup = null; int nTopIndex = -1; ListViewItem lviFocused = null; m_dtCachedNow = DateTime.Now; ListViewStateEx lvseCachedState = new ListViewStateEx(m_lvEntries); for(int iAdd = 0; iAdd < nItemCount; ++iAdd) { PwEntry pe = vList[iAdd]; ListViewItem lvi = AddEntryToList(pe, lvseCachedState); if(pe == peTop) nTopIndex = iAdd; if(pe == peFocused) lviFocused = lvi; if(Array.IndexOf(vSelected, pe) >= 0) lvi.Selected = true; } Debug.Assert(lvseCachedState.CompareTo(m_lvEntries)); if(nTopIndex >= 0) { m_lvEntries.EnsureVisible(m_lvEntries.Items.Count - 1); m_lvEntries.EnsureVisible(nTopIndex); } if(lviFocused != null) m_lvEntries.FocusedItem = lviFocused; m_lvEntries.EndUpdate(); }
/// <summary> /// Update the entries list. This function completely rebuilds the entries /// list. You must call this function after you've made any changes to /// the entries of the currently selected group. Note that if you only /// made small changes (like editing an existing entry), the /// <c>RefreshEntriesList</c> function could be a better choice, as it only /// updates currently listed items and doesn't rebuild the whole list as /// <c>UpdateEntriesList</c>. /// </summary> /// <param name="pgSelected">Group whose entries should be shown. If this /// parameter is <c>null</c>, the entries of the currently selected group /// (groups view) are displayed, otherwise the entries of the <c>pgSelected</c> /// group are displayed.</param> private void UpdateEntryList(PwGroup pgSelected, bool bOnlyUpdateCurrentlyShown) { NotifyUserActivity(); UpdateImageLists(); PwEntry peTop = GetTopEntry(), peFocused = GetSelectedEntry(false); PwEntry[] vSelected = GetSelectedEntries(); bool bSubEntries = Program.Config.MainWindow.ShowEntriesOfSubGroups; PwGroup pg = (pgSelected ?? GetSelectedGroup()); if(bOnlyUpdateCurrentlyShown) { Debug.Assert(pgSelected == null); pg = GetCurrentEntries(); } PwObjectList<PwEntry> pwlSource = ((pg != null) ? pg.GetEntries(bSubEntries) : new PwObjectList<PwEntry>()); m_lvEntries.BeginUpdate(); m_lvEntries.Items.Clear(); m_bOnlyTans = true; m_lvEntries.Groups.Clear(); m_lvgLastEntryGroup = null; m_bEntryGrouping = (((pg != null) ? pg.IsVirtual : false) || bSubEntries); m_lvEntries.ShowGroups = m_bEntryGrouping; int nTopIndex = -1; ListViewItem lviFocused = null; m_dtCachedNow = DateTime.Now; ListViewStateEx lvseCachedState = new ListViewStateEx(m_lvEntries); if(pg != null) { foreach(PwEntry pe in pwlSource) { ListViewItem lvi = AddEntryToList(pe, lvseCachedState); if(vSelected != null) { if(Array.IndexOf(vSelected, pe) >= 0) lvi.Selected = true; } if(pe == peTop) nTopIndex = m_lvEntries.Items.Count - 1; if(pe == peFocused) lviFocused = lvi; } } Debug.Assert(lvseCachedState.CompareTo(m_lvEntries)); if(nTopIndex >= 0) { m_lvEntries.EnsureVisible(m_lvEntries.Items.Count - 1); m_lvEntries.EnsureVisible(nTopIndex); } if(lviFocused != null) m_lvEntries.FocusedItem = lviFocused; View view = m_lvEntries.View; if(m_bSimpleTanView) { if(m_lvEntries.Items.Count == 0) m_lvEntries.View = View.Details; else if(m_bOnlyTans && (view != View.List)) { // SortPasswordList(false, 0, false); m_lvEntries.View = View.List; } else if(!m_bOnlyTans && (view != View.Details)) m_lvEntries.View = View.Details; } else // m_bSimpleTANView == false { if(view != View.Details) m_lvEntries.View = View.Details; } m_lvEntries.EndUpdate(); }
/// <summary> /// Refresh the entries list. All currently displayed entries are updated. /// If you made changes to the list that change the number of visible entries /// (like adding or removing an entry), you must use the <c>UpdatePasswordList</c> /// function instead. /// </summary> public void RefreshEntriesList() { int nItemCount = m_lvEntries.Items.Count; if(nItemCount <= 0) return; PwEntry peTop = GetTopEntry(); PwEntry peFocused = GetSelectedEntry(false); int iScrollY = NativeMethods.GetScrollPosY(m_lvEntries.Handle); UpdateImageLists(); // Important PwEntry[] vSelected = GetSelectedEntries(); if(vSelected == null) vSelected = new PwEntry[0]; PwEntry[] vList = new PwEntry[nItemCount]; for(int iEnum = 0; iEnum < nItemCount; ++iEnum) vList[iEnum] = (PwEntry)m_lvEntries.Items[iEnum].Tag; m_lvEntries.BeginUpdate(); m_lvEntries.Items.Clear(); m_lvEntries.Groups.Clear(); m_lvgLastEntryGroup = null; int nTopIndex = -1; ListViewItem lviFocused = null; m_dtCachedNow = DateTime.Now; ListViewStateEx lvseCachedState = new ListViewStateEx(m_lvEntries); for(int iAdd = 0; iAdd < nItemCount; ++iAdd) { PwEntry pe = vList[iAdd]; ListViewItem lvi = AddEntryToList(pe, lvseCachedState); if(pe == peTop) nTopIndex = iAdd; if(pe == peFocused) lviFocused = lvi; if(Array.IndexOf(vSelected, pe) >= 0) lvi.Selected = true; } Debug.Assert(lvseCachedState.CompareTo(m_lvEntries)); UIUtil.SetAlternatingBgColors(m_lvEntries, m_clrAlternateItemBgColor, Program.Config.MainWindow.EntryListAlternatingBgColors); Debug.Assert(m_bEntryGrouping == m_lvEntries.ShowGroups); if(m_lvEntries.ShowGroups) { // Test nTopIndex to ensure we're not scrolling an unrelated list if((nTopIndex >= 0) && (iScrollY > 0)) NativeMethods.Scroll(m_lvEntries, 0, iScrollY); } else { if(nTopIndex >= 0) { m_lvEntries.EnsureVisible(m_lvEntries.Items.Count - 1); m_lvEntries.EnsureVisible(nTopIndex); } } if(lviFocused != null) m_lvEntries.FocusedItem = lviFocused; m_lvEntries.EndUpdate(); }
/// <summary> /// Update the entries list. This function completely rebuilds the entries /// list. You must call this function after you've made any changes to /// the entries of the currently selected group. Note that if you only /// made small changes (like editing an existing entry), the /// <c>RefreshEntriesList</c> function could be a better choice, as it only /// updates currently listed items and doesn't rebuild the whole list as /// <c>UpdateEntriesList</c>. /// </summary> /// <param name="pgSelected">Group whose entries should be shown. If this /// parameter is <c>null</c>, the entries of the currently selected group /// (groups view) are displayed, otherwise the entries of the <c>pgSelected</c> /// group are displayed.</param> private void UpdateEntryList(PwGroup pgSelected, bool bOnlyUpdateCurrentlyShown) { NotifyUserActivity(); UpdateImageLists(); PwEntry peTop = GetTopEntry(), peFocused = GetSelectedEntry(false); PwEntry[] vSelected = GetSelectedEntries(); int iScrollY = NativeMethods.GetScrollPosY(m_lvEntries.Handle); bool bSubEntries = Program.Config.MainWindow.ShowEntriesOfSubGroups; PwGroup pg = (pgSelected ?? GetSelectedGroup()); if(bOnlyUpdateCurrentlyShown) { Debug.Assert(pgSelected == null); pg = GetCurrentEntries(); } PwObjectList<PwEntry> pwlSource = ((pg != null) ? pg.GetEntries(bSubEntries) : new PwObjectList<PwEntry>()); m_bOnlyTans = ListContainsOnlyTans(pwlSource); m_lvEntries.BeginUpdate(); m_lvEntries.Items.Clear(); m_lvEntries.Groups.Clear(); m_lvgLastEntryGroup = null; // m_bEntryGrouping = (((pg != null) ? pg.IsVirtual : false) || bSubEntries); m_bEntryGrouping = bSubEntries; if(pg != null) { if(bOnlyUpdateCurrentlyShown && !m_lvEntries.ShowGroups && EntryUtil.EntriesHaveSameParent(pwlSource)) { // Just reorder, don't enable grouping EntryUtil.ReorderEntriesAsInDatabase(pwlSource, m_docMgr.ActiveDatabase); peTop = null; // Don't scroll to previous top item } else m_bEntryGrouping |= pg.IsVirtual; } m_lvEntries.ShowGroups = m_bEntryGrouping; int nTopIndex = -1; ListViewItem lviFocused = null; m_dtCachedNow = DateTime.Now; ListViewStateEx lvseCachedState = new ListViewStateEx(m_lvEntries); if(pg != null) { foreach(PwEntry pe in pwlSource) { ListViewItem lvi = AddEntryToList(pe, lvseCachedState); if(vSelected != null) { if(Array.IndexOf(vSelected, pe) >= 0) lvi.Selected = true; } if(pe == peTop) nTopIndex = m_lvEntries.Items.Count - 1; if(pe == peFocused) lviFocused = lvi; } } Debug.Assert(lvseCachedState.CompareTo(m_lvEntries)); UIUtil.SetAlternatingBgColors(m_lvEntries, m_clrAlternateItemBgColor, Program.Config.MainWindow.EntryListAlternatingBgColors); Debug.Assert(m_bEntryGrouping == m_lvEntries.ShowGroups); if(m_lvEntries.ShowGroups) { // Test nTopIndex to ensure we're not scrolling an unrelated list if((nTopIndex >= 0) && (iScrollY > 0)) NativeMethods.Scroll(m_lvEntries, 0, iScrollY); } else { if(nTopIndex >= 0) { m_lvEntries.EnsureVisible(m_lvEntries.Items.Count - 1); m_lvEntries.EnsureVisible(nTopIndex); } } if(lviFocused != null) m_lvEntries.FocusedItem = lviFocused; View view = m_lvEntries.View; if(m_bSimpleTanView) { if(m_lvEntries.Items.Count == 0) m_lvEntries.View = View.Details; else if(m_bOnlyTans && (view != View.List)) { // SortPasswordList(false, 0, false); m_lvEntries.View = View.List; } else if(!m_bOnlyTans && (view != View.Details)) m_lvEntries.View = View.Details; } else // m_bSimpleTanView == false { if(view != View.Details) m_lvEntries.View = View.Details; } m_lvEntries.EndUpdate(); if(Program.Config.MainWindow.EntryListAutoResizeColumns && (m_lvEntries.View == View.Details)) UIUtil.ResizeColumns(m_lvEntries, true); }