Skip to content

Commit

Permalink
Improve KeeTheme integration
Browse files Browse the repository at this point in the history
If KeeTheme is installed AND active, the background color for password display will not be changed

Closes #10
  • Loading branch information
Rookiestyle committed Sep 8, 2021
1 parent 54fdfe2 commit a01a6e4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 22 deletions.
47 changes: 35 additions & 12 deletions src/ColoredSecureTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ private void M_text_ParentChanged(object sender, EventArgs e)

private void ColoredSecureTextBox_SizeChanged(object sender, EventArgs e)
{
if (!m_bKeeTheme) m_text.Size = Size;
m_text.Size = Size;
}

private void ColoredSecureTextBox_LocationChanged(object sender, EventArgs e)
{
if (!m_bKeeTheme) m_text.Location = Location;
AdjustLocation();
}

private void UpdateEnabledState(object sender, EventArgs e)
Expand Down Expand Up @@ -142,18 +142,13 @@ protected override void OnParentChanged(EventArgs e)
Parent.SuspendLayout();
Parent.Controls.Add(m_text);
m_text.Parent = Parent;
foreach (Control c in Parent.Controls)
{
if (c.TabIndex > TabIndex)
c.TabIndex++;
}
m_text.TabStop = true;
m_text.TabIndex = TabIndex + 1;
m_text.TabIndex = TabIndex;
Parent.ResumeLayout();
Parent.PerformLayout();
}

public override void EnableProtection(bool bEnable)
public override void EnableProtection(bool bEnable)
{
PluginDebug.AddInfo(Name + " Protect password display: " + bEnable.ToString());
m_text.TextChanged -= ColorTextChanged;
Expand All @@ -170,6 +165,7 @@ public override void EnableProtection(bool bEnable)
Focus();
Select(m_text.SelectionStart, m_text.SelectionLength);
m_text.Visible = false;
m_text.TabStop = false;
if (m_bKeeTheme) m_text.Parent.Visible = false;
}
else
Expand All @@ -179,12 +175,14 @@ public override void EnableProtection(bool bEnable)
//ColorConfig.BackColorDefault = BackColor;
m_text.RightToLeft = RightToLeft;
m_text.Size = Size;
if (!m_bKeeTheme) m_text.Location = Location;
AdjustLocation();
m_text.Font = Font;
m_text.Visible = true;
m_text.TabStop = true;
if (m_bKeeTheme) m_text.Parent.Visible = true;
m_text.Text = Text;
m_text.ReadOnly = ReadOnly;
Visible = false;
TabStop = false;
if (!m_bReadOnlySaved)
{
Expand All @@ -206,6 +204,17 @@ public override void EnableProtection(bool bEnable)
}
}

private void AdjustLocation()
{
//If KeeTheme is active, the ColoredTextBox is contained in
//a RichTextBoxDecorator

//Change the location of the RichTextBoxDecorator if KeeTheme is active
//Change the location of the ColoredTextBox otherwise
if (m_bKeeTheme) m_text.Parent.Location = Location;
else m_text.Location = Location;
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
Expand All @@ -227,8 +236,22 @@ private Form GetForm(Control c)

public class ColorTextBox : RichTextBox
{
public bool ColorBackground = true;
protected override void Dispose(bool disposing)
private bool m_bColorBackground = true;
private bool? m_bKeeTheme = null;
public bool ColorBackground
{
get { return GetColorBackground(); }
set { m_bColorBackground = value; }
}

private bool GetColorBackground()
{
if (!m_bKeeTheme.HasValue && Parent != null) m_bKeeTheme= Parent.GetType().FullName.Contains("KeeTheme");
if (!m_bKeeTheme.HasValue) return m_bColorBackground;
return !m_bKeeTheme.Value && m_bColorBackground;
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing && (ContextMenuStrip != null) && !ContextMenuStrip.IsDisposed)
Expand Down
8 changes: 2 additions & 6 deletions src/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,8 @@ public Options()
cbColorEntryViewKeepBackgroundColor.Text = PluginTranslate.ColorEntryViewKeepBackgroundColor;
cbSinglePwDisplay.Text = PluginTranslate.SinglePwDisplay;
cbColorPwGen.Text = PluginTranslate.ColorPwGenDisplay;
try
{
var f = KeePass.Program.Translation.Forms.Find(x => x.FullName == "KeePass.Forms.PwGeneratorForm");
gPasswordGenerator.Text = f.Window.Text;
}
catch { }
var f = KeePass.Program.Translation.Forms.Find(x => x.FullName == "KeePass.Forms.PwGeneratorForm");
if (f != null && f.Window != null) gPasswordGenerator.Text = f.Window.Text;
}

private void OnColorSelect(object sender, EventArgs e)
Expand Down
6 changes: 3 additions & 3 deletions src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("rookiestyle")]
[assembly: AssemblyProduct("KeePass Plugin")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyCopyright("Copyright © 2020-2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.11.5")]
[assembly: AssemblyFileVersion("0.11.5")]
[assembly: AssemblyVersion("0.12")]
[assembly: AssemblyFileVersion("0.12")]
2 changes: 1 addition & 1 deletion version.info
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
:
ColoredPassword:0.11.5
ColoredPassword:0.12
ColoredPassword!de:5
ColoredPassword!pl:2
ColoredPassword!pt:1
Expand Down

0 comments on commit a01a6e4

Please sign in to comment.