예제 #1
0
		/// <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);
		}
예제 #2
0
		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);
		}
예제 #3
0
        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));
        }
예제 #4
0
        private ListViewItem AddEntryToList(PwEntry pe, ListViewStateEx lvse)
        {
            if((pe == null) || (lvse == null)) return null;

            ListViewItem lvi = new ListViewItem();
            lvi.Tag = pe;

            if(pe.Expires && (pe.ExpiryTime <= m_dtCachedNow))
            {
                lvi.ImageIndex = (int)PwIcon.Expired;
                lvi.Font = m_fontExpired;
            }
            else if(pe.CustomIconUuid == PwUuid.Zero)
                lvi.ImageIndex = (int)pe.IconId;
            else
                lvi.ImageIndex = (int)PwIcon.Count +
                    m_docMgr.ActiveDatabase.GetCustomIconIndex(pe.CustomIconUuid);

            if(m_bEntryGrouping)
            {
                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;
            if(!pe.BackgroundColor.IsEmpty)
                lvi.BackColor = pe.BackgroundColor;

            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
            {
                if(lvse.ColumnWidths[(int)AppDefs.ColumnId.Title] > 0)
                {
                    if(m_viewHideFields.ProtectTitle) lvi.Text = PwDefs.HiddenPassword;
                    else lvi.Text = pe.Strings.ReadSafe(PwDefs.TitleField);
                }
            }

            m_lvEntries.Items.Add(lvi);

            if(lvse.ColumnWidths[(int)AppDefs.ColumnId.UserName] > 0)
            {
                if(m_viewHideFields.ProtectUserName) lvi.SubItems.Add(PwDefs.HiddenPassword);
                else lvi.SubItems.Add(pe.Strings.ReadSafe(PwDefs.UserNameField));
            }
            else lvi.SubItems.Add(string.Empty);

            if(lvse.ColumnWidths[(int)AppDefs.ColumnId.Password] > 0)
            {
                if(m_viewHideFields.ProtectPassword) lvi.SubItems.Add(PwDefs.HiddenPassword);
                else lvi.SubItems.Add(pe.Strings.ReadSafe(PwDefs.PasswordField));
            }
            else lvi.SubItems.Add(string.Empty);

            if(lvse.ColumnWidths[(int)AppDefs.ColumnId.Url] > 0)
            {
                if(m_viewHideFields.ProtectUrl) lvi.SubItems.Add(PwDefs.HiddenPassword);
                else lvi.SubItems.Add(pe.Strings.ReadSafe(PwDefs.UrlField));
            }
            else lvi.SubItems.Add(string.Empty);

            if(lvse.ColumnWidths[(int)AppDefs.ColumnId.Notes] > 0)
            {
                if(m_viewHideFields.ProtectNotes) lvi.SubItems.Add(PwDefs.HiddenPassword);
                else
                {
                    string strNotesData = pe.Strings.ReadSafe(PwDefs.NotesField);
                    string strNotesNoR = strNotesData.Replace("\r", string.Empty);
                    lvi.SubItems.Add(strNotesNoR.Replace("\n", " "));
                }
            }
            else lvi.SubItems.Add(string.Empty);

            if(lvse.ColumnWidths[(int)AppDefs.ColumnId.CreationTime] > 0)
                lvi.SubItems.Add(TimeUtil.ToDisplayString(pe.CreationTime));
            else lvi.SubItems.Add(string.Empty);

            if(lvse.ColumnWidths[(int)AppDefs.ColumnId.LastAccessTime] > 0)
                lvi.SubItems.Add(TimeUtil.ToDisplayString(pe.LastAccessTime));
            else lvi.SubItems.Add(string.Empty);

            if(lvse.ColumnWidths[(int)AppDefs.ColumnId.LastModificationTime] > 0)
                lvi.SubItems.Add(TimeUtil.ToDisplayString(pe.LastModificationTime));
            else lvi.SubItems.Add(string.Empty);

            if(lvse.ColumnWidths[(int)AppDefs.ColumnId.ExpiryTime] > 0)
            {
                if(pe.Expires) lvi.SubItems.Add(TimeUtil.ToDisplayString(pe.ExpiryTime));
                else lvi.SubItems.Add(m_strNeverExpiresText);
            }
            else lvi.SubItems.Add(string.Empty);

            if(lvse.ColumnWidths[(int)AppDefs.ColumnId.Uuid] > 0)
                lvi.SubItems.Add(pe.Uuid.ToHexString());
            else lvi.SubItems.Add(string.Empty);

            if(lvse.ColumnWidths[(int)AppDefs.ColumnId.Attachment] > 0)
                lvi.SubItems.Add(pe.Binaries.UCount.ToString());
            else lvi.SubItems.Add(string.Empty);

            return lvi;
        }
예제 #5
0
        /// <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();
        }
예제 #6
0
        /// <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();
        }
예제 #7
0
		/// <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();
		}
예제 #8
0
		/// <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);
		}
예제 #9
0
		private ListViewItem AddEntryToList(PwEntry pe, ListViewStateEx lvse)
		{
			if((pe == null) || (lvse == null)) return null;

			ListViewItem lvi = new ListViewItem();
			lvi.Tag = pe;

			if(pe.Expires && (pe.ExpiryTime <= m_dtCachedNow))
			{
				lvi.ImageIndex = (int)PwIcon.Expired;
				if(m_fontExpired != null) lvi.Font = m_fontExpired;
			}
			else if(pe.CustomIconUuid.EqualsValue(PwUuid.Zero))
				lvi.ImageIndex = (int)pe.IconId;
			else
				lvi.ImageIndex = (int)PwIcon.Count +
					m_docMgr.ActiveDatabase.GetCustomIconIndex(pe.CustomIconUuid);

			if(m_bEntryGrouping)
			{
				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;

			if(!pe.BackgroundColor.IsEmpty)
				lvi.BackColor = pe.BackgroundColor;
			// else if(Program.Config.MainWindow.EntryListAlternatingBgColors &&
			//	((m_lvEntries.Items.Count & 1) == 1))
			//	lvi.BackColor = m_clrAlternateItemBgColor;

			// 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);

			for(int iColumn = 1; iColumn < m_lvEntries.Columns.Count; ++iColumn)
				lvi.SubItems.Add(GetEntryFieldEx(pe, iColumn, true));

			m_lvEntries.Items.Add(lvi);
			return lvi;
		}