Skip to content

Commit

Permalink
Don't show asterisks for empty fields
Browse files Browse the repository at this point in the history
If column data is hidden using asterisks, KeePass shows asterisks even for empty fields.
ColoredPassword now offers an option in the advanced settings to not show asterisks for empty fields.
This option is inactive by default.
  • Loading branch information
Rookiestyle committed May 11, 2024
1 parent 205098b commit 01f1b55
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 65 deletions.
6 changes: 5 additions & 1 deletion Translations/ColoredPassword.de.language.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Increment the TranslationVersion every time the translation file is updated
Also update the version.info file
-->
<TranslationVersion>7</TranslationVersion>
<TranslationVersion>8</TranslationVersion>
<item>
<key>Active</key>
<value>Aktiv</value>
Expand Down Expand Up @@ -49,4 +49,8 @@
<key>SyncColors</key>
<value>Synchronisiere Schriftfarben</value>
</item>
<item>
<key>DontShowAsterisks</key>
<value>Zeige keine * für leere Felder, auch wenn '{0}' aktiv ist</value>
</item>
</Translation>
4 changes: 4 additions & 0 deletions Translations/ColoredPassword.template.language.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@
<key>SyncColors</key>
<value>Snychronize font colors</value>
</item>
<item>
<key>DontShowAsterisks</key>
<value>Don't show asterisks for empty fields if '{0}' is active</value>
</item>
</Translation>
71 changes: 70 additions & 1 deletion src/ColoredPassword.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using KeePass.App.Configuration;
using KeePass.Plugins;
using KeePass.UI;
using KeePassLib;
using KeePassLib.Utility;

using PluginTools;
Expand Down Expand Up @@ -49,10 +50,76 @@ public override bool Initialize(IPluginHost host)

SinglePwDisplay.Enabled = ColorConfig.SinglePwDisplayActive;

m_host.MainWindow.UIStateUpdated += OnUIStateUpdated;

return true;
}

private void MainWindow_FormLoadPost(object sender, EventArgs e)
private void OnUIStateUpdated(object sender, EventArgs e)
{
if (!ColorConfig.DontShowAsteriskForEmptyFields) return;
Dictionary<int, CP_ColumnType> dHiddenColumns = new Dictionary<int, CP_ColumnType>();
for (int i = 0; i < KeePass.Program.Config.MainWindow.EntryListColumns.Count; i++)
{
var col = KeePass.Program.Config.MainWindow.EntryListColumns[i];
if (!col.HideWithAsterisks) continue;
dHiddenColumns[i] = new CP_ColumnType(col);
}

if (dHiddenColumns.Count == 0) return;

ListView lv = (ListView)Tools.GetControl("m_lvEntries");
if (lv == null)
{
PluginDebug.AddError("Could not find m_lvEntries", 0);
return;
}

try
{
lv.BeginUpdate();

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
}

foreach (var col in dHiddenColumns)
{
if (lvi.SubItems[col.Key].Text != PwDefs.HiddenPassword) continue;
if (col.Value.IsEmpty(li.Entry)) lvi.SubItems[col.Key].Text = string.Empty;
}
}
}
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();
}
}

private void MainWindow_FormLoadPost(object sender, EventArgs e)
{
m_host.MainWindow.FormLoadPost -= MainWindow_FormLoadPost;

Expand Down Expand Up @@ -396,6 +463,7 @@ private void OptionsForm_Shown(object sender, EventArgs e)
o.cbSyncColorsWithPrintForm.Checked = ColorConfig.SyncColorsWithPrintForm;
o.cbSinglePwDisplay.Checked = ColorConfig.SinglePwDisplayActive;
o.cbColorPwGen.Checked = ColorConfig.ColorPwGen;
o.cbDontShowAsterisk.Checked = ColorConfig.DontShowAsteriskForEmptyFields;
o.ctbExample.ColorText();
ColorConfig.Testmode = true;
}
Expand Down Expand Up @@ -425,6 +493,7 @@ private void OptionsClosed(object sender, Tools.OptionsFormsEventArgs e)
ColorConfig.SyncColorsWithPrintForm = o.cbSyncColorsWithPrintForm.Checked;
SinglePwDisplay.Enabled = ColorConfig.SinglePwDisplayActive = o.cbSinglePwDisplay.Checked;
ColorConfig.ColorPwGen = o.cbColorPwGen.Checked;
ColorConfig.DontShowAsteriskForEmptyFields = o.cbDontShowAsterisk.Checked;
ColorConfig.Write();
if (ColorConfig.Active) ColorPasswords(ColorConfig.Active);
}
Expand Down
Loading

0 comments on commit 01f1b55

Please sign in to comment.