Skip to content

Commit cf67fd9

Browse files
authored
Merge pull request #39 from mitchcapper/239_support
KP 2.39 support, rich textbox support, better password confirmation support, redid high dpi support and resize support completely.
2 parents 00cfa75 + 1eb55b7 commit cf67fd9

File tree

8 files changed

+294
-220
lines changed

8 files changed

+294
-220
lines changed

EntryTemplateManager.ChildViewer.cs

Lines changed: 192 additions & 121 deletions
Large diffs are not rendered by default.

EntryTemplateManager.TemplateEditor.cs

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Drawing;
44
using System.Windows.Forms;
5+
using KeePass.UI;
56
using KeePassLib;
67

78
namespace KPEntryTemplates {
@@ -23,6 +24,7 @@ private void InitializeGridView(TabPage page) {
2324
return;
2425
}
2526

27+
page.HorizontalScroll.Enabled = false;
2628
page.SuspendLayout();
2729
dataGridView = new DataGridView();
2830
colTitle = new DataGridViewTextBoxColumn();
@@ -44,15 +46,18 @@ private void InitializeGridView(TabPage page) {
4446
dataGridView.DefaultValuesNeeded += dataGridView_DefaultValuesNeeded;
4547
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
4648
dataGridView.Columns.AddRange(new DataGridViewColumn[] {
47-
colTitle,
49+
colTitle,
4850
colField,
49-
colFieldName,
50-
colType,
51+
colFieldName,
52+
colType,
5153
colOpt,colOptionValue});
5254
dataGridView.Location = new Point(0, 0);
5355
dataGridView.Name = "dataGridView";
54-
dataGridView.Size = new System.Drawing.Size(TAB_WIDTH, TAB_HEIGHT);
55-
dataGridView.TabIndex = 0;
56+
dataGridView.TabIndex = 0;
57+
SetBaseSizes(page);
58+
var template = new EntryTemplate(null, null, "DataGridView", 0, null);//used just for the conrol sizing
59+
SetControlSizing(template, dataGridView);
60+
dataGridView.ScrollBars = ScrollBars.None;
5661
dataGridView.DragDrop += dataGridView_DragDrop;
5762
dataGridView.DragOver += dataGridView_DragOver;
5863
dataGridView.MouseDown += dataGridView_MouseDown;
@@ -77,17 +82,17 @@ private void InitializeGridView(TabPage page) {
7782
//
7883
colField.HeaderText = "Field";
7984
colField.Items.AddRange(new object[] {
80-
"Custom",
81-
"Title",
82-
"Username",
83-
"Password",
85+
"Custom",
86+
"Title",
87+
"Username",
88+
"Password",
8489
"Password Confirmation",
8590
"URL",
8691
"Notes",
8792
"Override URL",
8893
"Expiry Date"});
8994
colField.Name = "colField";
90-
colField.Width = 105;
95+
colField.Width = DpiUtil.ScaleIntX(105);
9196
colField.DropDownWidth = 180;
9297

9398

@@ -98,56 +103,59 @@ private void InitializeGridView(TabPage page) {
98103
colFieldName.HeaderText = "Field Name";
99104
colFieldName.Name = "colFieldName";
100105
colFieldName.SortMode = DataGridViewColumnSortMode.NotSortable;
101-
colFieldName.Width = 75;
106+
colFieldName.Width = DpiUtil.ScaleIntX(75);
102107
//
103108
// colType
104109
//
105110
colType.HeaderText = "Type";
106111
colType.Name = "colType";
107-
colType.Width = 100;
112+
colType.Width = DpiUtil.ScaleIntX(100);
108113
colType.Items.AddRange(new object[] {
109-
"Inline",
114+
"Inline",
110115
"Inline URL",
111-
"Popout",
112-
"Protected Inline",
113-
"Protected Popout",
116+
"Popout",
117+
"Protected Inline",
118+
"Protected Popout",
114119
"Date",
115120
"Time",
116121
"Date Time",
117122
"Checkbox",
118123
"Divider",
119-
"Listbox"
124+
"Listbox",
125+
"RichTextbox"
120126
});
121127
colType.DropDownWidth = 150;
122-
colOpt.HeaderText = "Opt";
128+
colOpt.HeaderText = "Npt";
123129
colOpt.Name = "colOpt";
124-
colOpt.Width = 40;
130+
colOpt.Width = DpiUtil.ScaleIntX(40);
125131
colOpt.UseColumnTextForButtonValue = true;
126132
colOpt.Text = "Opt";
127133
colOpt.ToolTipText = "Option";
128134
colOptionValue.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
129135
colOptionValue.Visible = false;
130136
colOptionValue.Name = "colOptionValue";
131137
colOptionValue.Width = 0;
132-
133-
138+
139+
134140
page.Controls.Add(dataGridView);
135141
remove_as_template_button = new Button();
136142
remove_as_template_button.Text = "Remove As Template";
137-
remove_as_template_button.Width = TAB_WIDTH - 140 - 45;
138-
remove_as_template_button.Left = 115;
143+
remove_as_template_button.Height = BUTTON_HEIGHT;
144+
remove_as_template_button.Width = PAGE_WIDTH - DpiUtil.ScaleIntX(140) - DpiUtil.ScaleIntX(45);
145+
remove_as_template_button.Left = DpiUtil.ScaleIntX(85);
139146
//remove_as_template_button.Height = 28;
140147
remove_as_template_button.UseVisualStyleBackColor = true;
141-
dataGridView.Size = new Size(TAB_WIDTH, TAB_HEIGHT - remove_as_template_button.Height - 10); //have to set its size before setting the buttons size
142-
remove_as_template_button.Top = dataGridView.Height + 5;
148+
149+
dataGridView.Tag = template;
150+
151+
remove_as_template_button.Tag = template;
143152
remove_as_template_button.Click += remove_as_template_button_Click;
153+
SetControlSizing(template, remove_as_template_button);
144154
page.Controls.Add(remove_as_template_button);
145-
form.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
146-
form.AutoScaleMode = AutoScaleMode.Font;
147155
page.ResumeLayout();
148-
156+
149157
}
150-
private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e){
158+
private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e) {
151159
if (e.ColumnIndex != dataGridView.Columns["colOpt"].Index)
152160
return;
153161
DataGridViewRow row = dataGridView.Rows[e.RowIndex];
@@ -157,14 +165,15 @@ private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e){
157165
String msg = "";
158166
switch (type) {
159167
case "Inline":
168+
case "RichTextbox"://CustomRichTextBoxEx
160169
case "Protected Inline":
161170
msg = "How many lines to show for the textbox(1-100)?";
162171
break;
163172
case "Listbox":
164173
msg = "Listbox Items, seperate with each with a comma";
165174
break;
166175
}
167-
String ret = OptionsForm.GetOption(msg, (string) row.Cells["colOptionValue"].Value);
176+
String ret = OptionsForm.GetOption(msg, (string)row.Cells["colOptionValue"].Value);
168177
if (ret != null)
169178
row.Cells["colOptionValue"].Value = ret;
170179
}
@@ -190,7 +199,7 @@ void dataGridView_EditingControlShowing(object sender, DataGridViewEditingContro
190199
else if (cell.OwningColumn.Name == "colType") {
191200
box.SelectedIndexChanged += col_type_box_SelectedIndexChanged;
192201
}
193-
if (box != null){
202+
if (box != null) {
194203
box.DropDown += box_DropDown;
195204
box.SelectedIndexChanged += box_SelectedIndexChanged;
196205
}
@@ -204,19 +213,20 @@ void box_SelectedIndexChanged(object sender, EventArgs e) {
204213
void box_DropDown(object sender, EventArgs e) {
205214
((DataGridViewComboBoxEditingControl)sender).BackColor = Color.White;
206215
}
207-
private void SetRowOptionEnabled(DataGridViewRow row, String type){
216+
private void SetRowOptionEnabled(DataGridViewRow row, String type) {
208217
bool opt_enabled = false;
209218
switch (type) {
210219
case "Inline":
211220
case "Protected Inline":
221+
case "RichTextbox":
212222
case "Listbox":
213223
opt_enabled = true;
214224
break;
215225
}
216226

217227
(row.Cells["colOpt"] as DataGridViewDisableButtonCell).Enabled = opt_enabled;
218228
}
219-
private void col_type_box_SelectedIndexChanged(object sender, EventArgs e){
229+
private void col_type_box_SelectedIndexChanged(object sender, EventArgs e) {
220230
DataGridViewCell cell = dataGridView.CurrentCell;
221231
String type = cell.EditedFormattedValue.ToString();
222232
SetRowOptionEnabled(cell.OwningRow, type);
@@ -260,7 +270,7 @@ void col_field_box_SelectedIndexChanged(object sender, EventArgs e) {
260270
break;
261271
case "Notes":
262272
fieldName = PwDefs.NotesField;
263-
type = conf.ProtectNotes ? "Protected Inline" : "Inline";
273+
type = conf.ProtectNotes ? "Protected Inline" : "RichTextbox";
264274
break;
265275
default:
266276
type = "";
@@ -274,13 +284,13 @@ void col_field_box_SelectedIndexChanged(object sender, EventArgs e) {
274284
return;
275285
}
276286
row.Cells["colType"].ReadOnly = row.Cells["colFieldName"].ReadOnly = read_only;
277-
if (type != ""){
287+
if (type != "") {
278288
row.Cells["colType"].Value = type;
279289
SetRowOptionEnabled(row, type);
280290
}
281291
if (fieldName != "")
282292
row.Cells["colFieldName"].Value = fieldName;
283-
293+
284294

285295
}
286296

@@ -293,7 +303,7 @@ void dataGridView_SelectionChanged(object sender, EventArgs e) {
293303
to_del = null;
294304

295305
}
296-
private void RemoveToDel(){
306+
private void RemoveToDel() {
297307
if (to_del != null) {
298308
if (dataGridView.Rows.Contains(to_del))
299309
dataGridView.Rows.Remove(to_del);
@@ -369,8 +379,7 @@ void dataGridView_RowValidating(object sender, DataGridViewCellCancelEventArgs e
369379
if (res != DialogResult.Retry) {
370380
dataGridView.CancelEdit();
371381
to_del = row;
372-
}
373-
else {
382+
} else {
374383
e.Cancel = true;
375384
row.ErrorText = old_row_err;
376385
}
@@ -448,8 +457,7 @@ private void init_data_table() {
448457
row.Cells["colOptionValue"].Value = t.options;
449458
}
450459

451-
}
452-
catch (Exception e) {
460+
} catch (Exception e) {
453461
MessageBox.Show(e.Message);
454462
}
455463
}
@@ -481,8 +489,7 @@ private void dataGridView_MouseDown(object sender, MouseEventArgs e) {
481489
Size dragSize = SystemInformation.DragSize;
482490
dragBoxFromMouseDown = new Rectangle(new Point(e.X - (dragSize.Width / 2), e.Y - (dragSize.Height / 2)),
483491
dragSize);
484-
}
485-
else
492+
} else
486493
dragBoxFromMouseDown = Rectangle.Empty;
487494
}
488495

EntryTemplateManager.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
using KeePassLib.Utility;
1111
using KeePass.UI;
1212
using KeePass.Resources;
13+
using System.Threading.Tasks;
1314

1415
namespace KPEntryTemplates {
1516
partial class EntryTemplateManager {
16-
private const int TAB_WIDTH = 465;
17-
private const int TAB_HEIGHT = 350;
1817

1918
private PwEntryForm form;
2019
private IPluginHost m_host;
@@ -43,7 +42,7 @@ public EntryTemplateManager(IPluginHost host, PwEntryForm form) {
4342
form.EntrySaving += form_EntrySaving;
4443
our_page.UseVisualStyleBackColor = true;
4544
form_tab_control.TabPages.Insert(0, our_page);
46-
if (entry_is_child || entry_is_template)
45+
if (entry_is_child || entry_is_template && !KeePassLib.Native.NativeLib.IsUnix())
4746
form_tab_control.SelectTab(0);
4847
}
4948

@@ -102,8 +101,7 @@ private void child_view_show() {
102101
entry_is_child = false;
103102
buttons_show();
104103
return;
105-
}
106-
104+
}
107105
init_child_vals();
108106
}
109107
public static bool entry_is_in_template_group(IPluginHost m_host, PwGroup group) {

KPEntryTemplates.cs

Lines changed: 34 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
4+
using System.Threading.Tasks;
45
using System.Windows.Forms;
56
using KeePass.Forms;
67
using KeePass.Plugins;
8+
using KeePass.Resources;
79
using KeePass.UI;
810
using KeePass.Util;
911
using KeePassLib;
@@ -48,50 +50,38 @@ void GlobalWindowManager_WindowAdded(object sender, GwmWindowEventArgs e) {
4850
if (form == null)
4951
return;
5052
form.Shown += form_Shown;
51-
form.Resize += form_Resize;
53+
form.Resize += form_Resize;
5254
}
5355

54-
void form_Shown(object sender, EventArgs e)
55-
{
56-
PwEntryForm form = sender as PwEntryForm;
57-
new EntryTemplateManager(m_host, form);
58-
}
59-
60-
void form_Resize(object sender, EventArgs e)
61-
{
62-
// on form resize, change edits and bottom button widths;
63-
// also reposition right side buttons
64-
65-
PwEntryForm form = sender as PwEntryForm;
66-
67-
TabControl tabControl = null;
68-
foreach (Control c in form.Controls) {
69-
if (c is TabControl) {
70-
tabControl = c as TabControl;
71-
break;
72-
}
73-
}
74-
if (tabControl == null) return;
75-
76-
TabPage tmplPage = tabControl.TabPages[0];
77-
if (tmplPage.Text != "Template") return;
78-
79-
foreach (Control c in tmplPage.Controls) {
80-
if (!(c is Label)) {
81-
if (c is CheckBox) {
82-
c.Left = tmplPage.Width - ((c.Width + 55) / 2);
83-
} else if (c is Button) {
84-
if ((c as Button).Text == "Remove As Template Child") {
85-
c.Width = tmplPage.Width - c.Left - 55;
86-
} else {
87-
c.Left = tmplPage.Width - ((c.Width + 55) / 2);
88-
}
89-
} else {
90-
c.Width = tmplPage.Width - c.Left - 55;
91-
}
92-
}
93-
}
94-
}
56+
private void form_Shown(object sender, EventArgs e) {
57+
PwEntryForm form = sender as PwEntryForm;
58+
new EntryTemplateManager(m_host, form);
59+
//form_Resize(sender, e);
60+
61+
}
62+
63+
void form_Resize(object sender, EventArgs e) {
64+
65+
66+
PwEntryForm form = sender as PwEntryForm;
67+
68+
TabControl tabControl = null;
69+
foreach (Control c in form.Controls) {
70+
if (c is TabControl) {
71+
tabControl = c as TabControl;
72+
break;
73+
}
74+
}
75+
if (tabControl == null) return;
76+
77+
TabPage tmplPage = tabControl.TabPages[0];
78+
if (tmplPage.Text != "Template")
79+
return;
80+
EntryTemplateManager.SetBaseSizes(tmplPage);
81+
foreach (Control c in tmplPage.Controls)
82+
EntryTemplateManager.UpdateControlSize(c);
83+
84+
}
9585

9686
void EntryTemplates_EntryCreating(object sender, TemplateEntryEventArgs e) {
9787
EntryTemplateManager.InitChildEntry(e.TemplateEntry, e.Entry);
@@ -115,7 +105,7 @@ void m_tsmi_set_template_parent_Click(object sender, EventArgs e) {
115105
return;
116106
PwEntry[] entries = m_host.MainWindow.GetSelectedEntries();
117107
foreach (PwEntry entry in entries) {
118-
EntryTemplateManager.set_entry_template_parent(m_host.Database,entry, parent);
108+
EntryTemplateManager.set_entry_template_parent(m_host.Database, entry, parent);
119109
}
120110
m_host.MainWindow.UpdateUI(false, null, false, m_host.MainWindow.GetSelectedGroup(), false, null, true);
121111
}
@@ -137,7 +127,7 @@ void EntryContextMenu_Opening(object sender, System.ComponentModel.CancelEventAr
137127
}
138128
public override string UpdateUrl {
139129
get {
140-
return "http://mitchcapper.com/keepass_versions.txt?KPET";
130+
return "http://mitchcapper.com/keepass_versions.txt?KPET&KPV=" + PwDefs.VersionString;
141131
}
142132
}
143133
public override void Terminate() {

0 commit comments

Comments
 (0)