/// <summary> /// Recreate the custom icons list view. /// </summary> /// <returns>Index of the previous custom icon, if specified.</returns> private int RecreateCustomIconList(bool bSelectLastIcon) { m_lvCustomIcons.Items.Clear(); ImageList ilCustom = UIUtil.BuildImageList(m_pwDatabase.CustomIcons, 16, 16); m_lvCustomIcons.SmallImageList = ilCustom; int j = 0, iFoundCustom = -1; foreach (PwCustomIcon pwci in m_pwDatabase.CustomIcons) { ListViewItem lvi = m_lvCustomIcons.Items.Add(j.ToString(), j); lvi.Tag = pwci.Uuid; if (pwci.Uuid.Equals(m_pwDefaultCustomIcon)) { iFoundCustom = j; } ++j; } if (bSelectLastIcon && (m_lvCustomIcons.Items.Count > 0)) { m_lvCustomIcons.Items[m_lvCustomIcons.Items.Count - 1].Selected = true; m_lvCustomIcons.EnsureVisible(m_lvCustomIcons.Items.Count - 1); UIUtil.SetFocus(m_lvCustomIcons, this); } return(iFoundCustom); }
private int RecreateCustomIconList() { m_lvCustomIcons.Items.Clear(); ImageList ilCustom = UIUtil.BuildImageList(m_pwDatabase.CustomIcons, 16, 16); m_lvCustomIcons.SmallImageList = ilCustom; int j = 0, iFoundCustom = -1; foreach (PwCustomIcon pwci in m_pwDatabase.CustomIcons) { ListViewItem lvi = m_lvCustomIcons.Items.Add(j.ToString(), j); lvi.Tag = pwci.Uuid; if (pwci.Uuid.EqualsValue(m_pwDefaultCustomIcon)) { iFoundCustom = j; } ++j; } return(iFoundCustom); }
private void RecreateCustomIconList(PwUuid puSelect) { StringBuilder sb = new StringBuilder(); List <ListViewItem> lUnnamed = new List <ListViewItem>(); List <ListViewItem> lNamed = new List <ListViewItem>(); for (int i = 0; i < m_pd.CustomIcons.Count; ++i) { PwCustomIcon ci = m_pd.CustomIcons[i]; bool bMulti = (ci.Name == MultipleValuesEx.CueString); ListViewItem lvi = new ListViewItem(); if (ci.Name.Length == 0) { lvi.Text = lUnnamed.Count.ToString(); lUnnamed.Add(lvi); } else { lvi.Text = ci.Name; if (bMulti) { lUnnamed.Insert(0, lvi); } else { lNamed.Add(lvi); } } lvi.ImageIndex = i; lvi.Tag = ci; Image img = ci.GetImage(); if (bMulti) { lvi.ToolTipText = ci.Name; } else if (img != null) { if (sb.Length != 0) { sb.Remove(0, sb.Length); } if (ci.Name.Length != 0) { sb.AppendLine(ci.Name); } sb.Append(img.Width); sb.Append(" \u00D7 "); sb.Append(img.Height); sb.AppendLine(" px"); sb.Append(StrUtil.FormatDataSizeKB((ulong)ci.ImageDataPng.Length)); #if DEBUG if (ci.LastModificationTime.HasValue) { sb.AppendLine(); sb.Append("((( "); // Debug indicator sb.Append(TimeUtil.ToDisplayString(ci.LastModificationTime.Value)); sb.Append(" )))"); // Debug indicator } #endif lvi.ToolTipText = sb.ToString(); } } Comparison <ListViewItem> f = delegate(ListViewItem x, ListViewItem y) { string strX = (((x != null) ? x.Text : null) ?? string.Empty); string strY = (((y != null) ? y.Text : null) ?? string.Empty); return(StrUtil.CompareNaturally(strX, strY)); }; lNamed.Sort(f); List <ListViewItem> lAll = new List <ListViewItem>(lUnnamed.Count + lNamed.Count); lAll.AddRange(lUnnamed); lAll.AddRange(lNamed); ImageList ilCustom = UIUtil.BuildImageList(m_pd.CustomIcons, DpiUtil.ScaleIntX(16), DpiUtil.ScaleIntY(16)); m_lvCustomIcons.BeginUpdate(); m_lvCustomIcons.Items.Clear(); m_lvCustomIcons.SmallImageList = ilCustom; m_lvCustomIcons.Items.AddRange(lAll.ToArray()); m_lvCustomIcons.EndUpdate(); SelectCustomIcon(puSelect); // Doesn't always work before EndUpdate() }