Skip to content

Commit

Permalink
Fixed KeeResize compatibility, closes #24 and #25 (#38)
Browse files Browse the repository at this point in the history
* Fixed KeeResize compatibility, closes #25 and #25 by @h-a-s-h
  • Loading branch information
mitchcapper authored May 10, 2018
1 parent caf9729 commit 00cfa75
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 19 deletions.
30 changes: 15 additions & 15 deletions EntryTemplateManager.ChildViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ private void OnPwGenClick(object sender, EventArgs e) {
}
private void OnPwGenOpen(object sender, EventArgs e) {
PwGeneratorForm pgf = new PwGeneratorForm();
ProtectedString ps = new ProtectedString(true, current_password_field.ToUtf8());
ProtectedString ps = new ProtectedString(true, current_password_field.ToUtf8());
bool bAtLeastOneChar = (ps.Length > 0);
PwProfile opt = PwProfile.DeriveFromPassword(ps);
PwProfile opt = PwProfile.DeriveFromPassword(ps);

pgf.InitEx(bAtLeastOneChar ? opt : null, true, false);
if (pgf.ShowDialog() == DialogResult.OK) {
Expand All @@ -71,15 +71,15 @@ private void OnPwGenOpen(object sender, EventArgs e) {
PwGenerator.Generate(out psNew, pgf.SelectedProfile, pbEntropy,
Program.PwGeneratorPool);

current_password_field.SetPassword(psNew.ReadUtf8());
current_password_confirm_field.SetPassword(psNew.ReadUtf8());
current_password_field.SetPassword(psNew.ReadUtf8());
current_password_confirm_field.SetPassword(psNew.ReadUtf8());
}

}
private void OnProfilesDynamicMenuClick(object sender, DynamicMenuEventArgs e) {
PwProfile pwp = null;
if (e.ItemName == DeriveFromPrevious) {
pwp = PwProfile.DeriveFromPassword(new ProtectedString(true, current_password_field.ToUtf8()));
pwp = PwProfile.DeriveFromPassword(new ProtectedString(true, current_password_field.ToUtf8()));
}
else {
foreach (PwProfile pwgo in Program.Config.PasswordGenerator.UserProfiles) {
Expand All @@ -94,8 +94,8 @@ private void OnProfilesDynamicMenuClick(object sender, DynamicMenuEventArgs e) {
ProtectedString psNew;

PwGenerator.Generate(out psNew, pwp, null, m_host.PwGeneratorPool);
current_password_field.SetPassword(psNew.ReadUtf8());
current_password_confirm_field.SetPassword(psNew.ReadUtf8());
current_password_field.SetPassword(psNew.ReadUtf8());
current_password_confirm_field.SetPassword(psNew.ReadUtf8());

}
else { Debug.Assert(false); }
Expand All @@ -118,9 +118,9 @@ private void init_pwgen_button() {
m_dynGenProfiles.MenuClick += OnProfilesDynamicMenuClick;

m_ctxPwGen.Items.AddRange(new ToolStripItem[] {
m_ctxPwGenOpen,
m_ctxPwGenSep0,
m_ctxPwGenProfiles});
m_ctxPwGenOpen,
m_ctxPwGenSep0,
m_ctxPwGenProfiles});
m_ctxPwGen.Name = "m_ctxPwGen";
m_ctxPwGen.Size = new Size(209, 54);
//
Expand Down Expand Up @@ -193,7 +193,7 @@ private bool InitializeChildView(TabPage page, String uuid) {
List<EntryTemplate> cur = parse_entry(par_template.Strings);
const int LABEL_WIDTH = 130;
const int LEFT_CONTROL_OFFSET = LABEL_WIDTH + 5;
int CONTROL_WIDTH = TAB_WIDTH - LABEL_WIDTH - 55;
int CONTROL_WIDTH = page.ClientSize.Width - LABEL_WIDTH - 55;
foreach (EntryTemplate t in cur) {
Label label = new Label();
label.Text = t.title + ":";
Expand Down Expand Up @@ -347,7 +347,7 @@ void btn_popout_Click(object sender, EventArgs e) {
ProtectedString psValue = form.EntryStrings.Get(t.fieldName);
Debug.Assert(psValue != null);
EditStringForm esf = new EditStringForm();
esf.InitEx(form.EntryStrings, t.fieldName, psValue, m_host.Database);
esf.InitEx(form.EntryStrings, t.fieldName, psValue, m_host.Database);
if (esf.ShowDialog() == DialogResult.OK)
form.UpdateEntryStrings(false, true);

Expand Down Expand Up @@ -376,7 +376,7 @@ private void find_override_url_control(Form form) {

new_override_url_control = get_control_from_form(form, "m_cmbOverrideUrl") as ImageComboBoxEx;
if (new_override_url_control == null)//older keepass
override_url_control = get_control_from_form(form, "m_tbOverrideUrl") as TextBox;
override_url_control = get_control_from_form(form, "m_tbOverrideUrl") as TextBox;
}
private int LinesFromOption(String val){
if (String.IsNullOrEmpty(val))
Expand Down Expand Up @@ -418,7 +418,7 @@ private void save_child_vals() {
}
else if (t.type == "Protected Inline") {
SecureEdit sedit = et_to_secure_edit[t];
str = new ProtectedString(true,sedit.ToUtf8());
str = new ProtectedString(true,sedit.ToUtf8());
}
else
continue;
Expand Down Expand Up @@ -500,7 +500,7 @@ private void init_child_vals() {
}
else if (t.type == "Protected Inline") {
SecureEdit sedit = et_to_secure_edit[t];
sedit.SetPassword(str.ReadUtf8());
sedit.SetPassword(str.ReadUtf8());
}
else if (t.type == "Listbox"){
ComboBox combobox = (ComboBox) pair.Value;
Expand Down
46 changes: 42 additions & 4 deletions KPEntryTemplates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,50 @@ void GlobalWindowManager_WindowAdded(object sender, GwmWindowEventArgs e) {
if (form == null)
return;
form.Shown += form_Shown;
form.Resize += form_Resize;
}

void form_Shown(object sender, EventArgs e) {
PwEntryForm form = sender as PwEntryForm;
new EntryTemplateManager(m_host, form);
}
void form_Shown(object sender, EventArgs e)
{
PwEntryForm form = sender as PwEntryForm;
new EntryTemplateManager(m_host, form);
}

void form_Resize(object sender, EventArgs e)
{
// on form resize, change edits and bottom button widths;
// also reposition right side buttons

PwEntryForm form = sender as PwEntryForm;

TabControl tabControl = null;
foreach (Control c in form.Controls) {
if (c is TabControl) {
tabControl = c as TabControl;
break;
}
}
if (tabControl == null) return;

TabPage tmplPage = tabControl.TabPages[0];
if (tmplPage.Text != "Template") return;

foreach (Control c in tmplPage.Controls) {
if (!(c is Label)) {
if (c is CheckBox) {
c.Left = tmplPage.Width - ((c.Width + 55) / 2);
} else if (c is Button) {
if ((c as Button).Text == "Remove As Template Child") {
c.Width = tmplPage.Width - c.Left - 55;
} else {
c.Left = tmplPage.Width - ((c.Width + 55) / 2);
}
} else {
c.Width = tmplPage.Width - c.Left - 55;
}
}
}
}

void EntryTemplates_EntryCreating(object sender, TemplateEntryEventArgs e) {
EntryTemplateManager.InitChildEntry(e.TemplateEntry, e.Entry);
Expand Down

0 comments on commit 00cfa75

Please sign in to comment.