Ejemplo n.º 1
0
        public override void Terminate()
        {
            if (m_host == null)
            {
                return;
            }

            m_host.MainWindow.FileClosed -= this.OnFileClosed;

            ListView lv = (m_host.MainWindow.Controls.Find(
                               "m_lvEntries", true)[0] as ListView);

            if (lv == null)
            {
                Debug.Assert(false); return;
            }

            lv.DrawSubItem      -= Lv_DrawSubItem;
            lv.DrawItem         -= Lv_DrawItem;
            lv.DrawColumnHeader -= Lv_DrawColumnHeader;
            lv.OwnerDraw         = false;

            m_host.ColumnProviderPool.Remove(m_prov);
            m_prov = null;

            m_host = null;
        }
Ejemplo n.º 2
0
        public override bool Initialize(IPluginHost host)
        {
            Terminate();

            m_host = host;
            if (m_host == null)
            {
                Debug.Assert(false); return(false);
            }

            m_prov = new ColoredQualityColumnProvider();
            m_host.ColumnProviderPool.Add(m_prov);

            ListView lv = (m_host.MainWindow.Controls.Find(
                               "m_lvEntries", true)[0] as ListView);

            if (lv == null)
            {
                Debug.Assert(false); return(false);
            }

            // Custom draw the entry list so we can set background color.
            lv.OwnerDraw         = true;
            lv.DrawColumnHeader += Lv_DrawColumnHeader;
            lv.DrawItem         += Lv_DrawItem;
            lv.DrawSubItem      += Lv_DrawSubItem;

            m_host.MainWindow.FileClosed += this.OnFileClosed;

            return(true);
        }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
 private void OnFileClosed(object sender, FileClosedEventArgs e)
 {
     ColoredQualityColumnProvider.ClearCache();
 }