Skip to content

Commit

Permalink
Make column widths in search window match column widths in entrylist
Browse files Browse the repository at this point in the history
Closes #17
  • Loading branch information
Rookiestyle committed Jan 21, 2023
1 parent 6896e89 commit 28ae0d3
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 230 deletions.
20 changes: 14 additions & 6 deletions Translations/GlobalSearch.de.language.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Translation>
<TranslationVersion>3</TranslationVersion>
<!--
Increment the TranslationVersion every time the translation file is updated
Also update the version.info file
-->
<TranslationVersion>4</TranslationVersion>
<item>
<key>Description</key>
<value>Bitte wähle aus, welche Suchfunktionen {0} erweitern soll.
Expand All @@ -18,14 +22,14 @@ Bei Auswahl eines Eintrags
Wenn '{1}' nur Einträge aus genau einer Datenbank findet, dann wird diese Datenbank aktiviert und die Ergebnisse werden wie gewohnt angezeigt.</value>
</item>
<item>
<key>OptionsCaption</key>
<value>Suchfunktionen erweitern</value>
<key>OptionsCaption</key>
<value>Suchfunktionen erweitern</value>
</item>
<item>
<key>Search</key>
<value>Suche in allen geöffneten Datenbanken</value>
</item>
<item>
<item>
<key>MultiDBSearchInfoSearchFormActive</key>
<value>Info, wenn '{0}' Einträge mehrerer Datenbanken enthält</value>
</item>
Expand All @@ -49,11 +53,11 @@ Um diese Meldung zu deaktivieren, wähle {0} oder besuche die Pluginoptionen.</v
</item>
<item>
<key>ErrorNoActivation</key>
<value>{0} kann nicht aktiviert werden.
<value>{0} kann nicht aktiviert werden.

Nicht alle erforderlichen Objekte gefunden.</value>
</item>
<item>
<item>
<key>PWDisplayMode</key>
<value>Passwortanzeige</value>
</item>
Expand All @@ -69,4 +73,8 @@ Nicht alle erforderlichen Objekte gefunden.</value>
<key>PWDisplayModeEntryView</key>
<value>Wie Eintragsliste</value>
</item>
<item>
<key>UseEntryListColumnWidths</key>
<value>Spaltenbreite wie Eintragsliste</value>
</item>
</Translation>
4 changes: 4 additions & 0 deletions Translations/GlobalSearch.template.language.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,8 @@ Could not find required objects</value>
<key>PWDisplayModeEntryView</key>
<value>Like Entry List</value>
</item>
<item>
<key>UseEntryListColumnWidths</key>
<value>Column widths like Entry List</value>
</item>
</Translation>
4 changes: 2 additions & 2 deletions src/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ public static Point SearchResultLocation
}

public static bool UseEntryListColumnWidths
{
{
get { return CustomConfig.GetBool(ConfigUseEntryListColumnWidths, true); }
set { CustomConfig.SetBool(ConfigUseEntryListColumnWidths, value); }
}
}

public static bool HookActive(string menuName)
{
Expand Down
46 changes: 14 additions & 32 deletions src/GlobalSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,9 @@ private void OnSearchExecute(object sender, EventArgs e)
string sSubTitle = iCount == 1 ? KPRes.SearchEntriesFound1 : KPRes.SearchEntriesFound;
sSubTitle = sSubTitle.Replace("{PARAM}", iCount.ToString());
ResizableListViewForm dlg = new ResizableListViewForm(KPRes.Search, sSubTitle);
dlg.RememberColumnWidths = !Config.UseEntryListColumnWidths;
dlg.InitEx(KPRes.Search, sSubTitle, null, null, l, il, InitListView);
m_bUsedEntryViewColumnWidths = false;
ShowMultiDBInfo(true);
PluginDebug.AddInfo("Multi-DB results: Show", 0);
if (dlg.ShowDialog(m_host.MainWindow) != DialogResult.OK)
Expand Down Expand Up @@ -722,17 +724,13 @@ private void InitListView(ListView lv)
int wf = w / iDisplayIndices.Length;
iDisplayIndices[0] = 0;
int di = Math.Min(UIUtil.GetSmallIconSize().Width, wf);
var iOldLVWidth = lv.ClientSize.Width;
var iNewLVWidth = 0;
for (int i = 0; i < lv.Columns.Count; i++)
{
iDisplayIndices[i + 1] = lv.Columns[i].DisplayIndex + 1;
if (!m_bUsedEntryViewColumnWidths) lv.Columns[i].Width = (i == lv.Columns.Count - 1) ? wf - di : wf;
iNewLVWidth += lv.Columns[i].Width;
}
lv.Columns.Insert(0, KPRes.Database, wf + di);

this damn thing interferes...
if (ResizableListViewForm.ColumnsWidth.Count == lv.Columns.Count && !m_bUsedEntryViewColumnWidths)
{
for (int i = 0; i < lv.Columns.Count; i++) lv.Columns[i].Width = ResizableListViewForm.ColumnsWidth[i];
Expand Down Expand Up @@ -803,18 +801,7 @@ private void OnShowOptions(object sender, EventArgs e)
private void Tools_OptionsFormShown(object sender, Tools.OptionsFormsEventArgs e)
{
Options o = new Options();
o.cbSearchForm.Checked = Config.SearchForm;
o.cbSearchDupPw.Checked = o.cbSearchDupPw.Enabled && Config.HookSearchDupPw;
o.cbSearchPwPairs.Checked = o.cbSearchPwPairs.Enabled && Config.HookSearchPwPairs;
o.cbSearchPwCluster.Checked = o.cbSearchPwCluster.Enabled && Config.HookSearchPwCluster;
o.cbSearchPwQuality.Checked = o.cbSearchPwQuality.Enabled && Config.HookPwQuality;
o.cbSearchLarge.Checked = o.cbSearchLarge.Enabled && Config.HookLargeEntries;
o.cbSearchLastMod.Checked = o.cbSearchLastMod.Enabled && Config.HookLastMod;
o.cbSearchAllExpired.Checked = o.cbSearchAllExpired.Enabled && Config.HookAllExpired;
o.cbMultiDBSearchInfoSearchFormActive.Checked = Config.ShowMultiDBInfoSearchForm;
o.cbMultiDBSearchInfoSingleSearchActive.Checked = Config.ShowMultiDBInfoSingleSearch;
o.cbUseEntryListColumnWidths.Checked = Config.UseEntryListColumnWidths;
o.SetPwDisplayMode(Config.PasswordDisplay);
o.InitEx();
Tools.AddPluginToOptionsForm(this, o);
}

Expand All @@ -824,18 +811,7 @@ private void Tools_OptionsFormClosed(object sender, Tools.OptionsFormsEventArgs
bool bShown = false;
Options o = (Options)Tools.GetPluginFromOptions(this, out bShown);
if (!bShown) return;
Config.SearchForm = o.cbSearchForm.Checked;
if (o.cbSearchDupPw.Enabled) Config.HookSearchDupPw = o.cbSearchDupPw.Checked;
if (o.cbSearchPwPairs.Enabled) Config.HookSearchPwPairs = o.cbSearchPwPairs.Checked;
if (o.cbSearchPwCluster.Enabled) Config.HookSearchPwCluster = o.cbSearchPwCluster.Checked;
if (o.cbSearchPwQuality.Enabled) Config.HookPwQuality = o.cbSearchPwQuality.Checked;
if (o.cbSearchLarge.Enabled) Config.HookLargeEntries = o.cbSearchLarge.Checked;
if (o.cbSearchLastMod.Enabled) Config.HookLastMod = o.cbSearchLastMod.Checked;
if (o.cbSearchAllExpired.Enabled) Config.HookAllExpired = o.cbSearchAllExpired.Checked;
Config.ShowMultiDBInfoSearchForm = o.cbMultiDBSearchInfoSearchFormActive.Checked;
Config.ShowMultiDBInfoSingleSearch = o.cbMultiDBSearchInfoSingleSearchActive.Checked;
Config.UseEntryListColumnWidths = o.cbUseEntryListColumnWidths.Checked;
Config.PasswordDisplay = o.GetPwDisplayMode();
o.UpdateConfig();
Activate();
}
#endregion
Expand Down Expand Up @@ -968,22 +944,28 @@ private void ResizableListViewForm_Activated(object sender, EventArgs e)
Size = sSize;
}

public bool RememberColumnWidths = true;

private void ResizableListViewForm_FormClosed(object sender, FormClosedEventArgs e)
{
Config.SearchResultSize = Size;
Config.SearchResultLocation = Location;
ColumnsWidth.Clear();
if (RememberColumnWidths) ColumnsWidth.Clear();
ListView lvMain = Tools.GetControl("m_lvMain", this) as ListView;
if (lvMain == null)
{
PluginDebug.AddError("GlobalSearch - Make resizable", 0, "Saved size & position", "Saved 0 column widths", "Could not get m_lvMain");
return;
}
foreach (ColumnHeader c in lvMain.Columns)
if (RememberColumnWidths)
{
ColumnsWidth.Add(c.Width);
foreach (ColumnHeader c in lvMain.Columns)
{
ColumnsWidth.Add(c.Width);
}
PluginDebug.AddInfo("GlobalSearch - Make resizable", 0, "Saved size & position", "Saved 0 column widths");
}
PluginDebug.AddInfo("GlobalSearch - Make resizable", 0, "Saved size & position", "Saved " + lvMain.Columns.Count.ToString() + " column widths");
else PluginDebug.AddInfo("GlobalSearch - Make resizable", 0, "Saved size & position", "Saved " + lvMain.Columns.Count.ToString() + " column widths");
}

private void ResizableListViewForm_Resize(object sender, EventArgs e)
Expand Down
5 changes: 0 additions & 5 deletions src/GlobalSearch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@
<Name>KeePass</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Options.resx">
<DependentUpon>Options.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="BeforeBuild" Condition=" '$(Configuration)' == 'Debug' ">
<Exec Command="..\translationcopy.cmd $(Configuration)" />
Expand Down
101 changes: 79 additions & 22 deletions src/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ namespace GlobalSearch
///
public partial class Options : UserControl
{
private TreeNode tvnSearchForm { get { return tvHookedSearches.Nodes.Find("tvnSearchForm", true)[0]; } }
private TreeNode tvnUseEntryListColummnWidth { get { return tvHookedSearches.Nodes.Find("tvnUseEntryListColummnWidth", true)[0]; } }
private TreeNode tvnLastMod { get { return tvHookedSearches.Nodes.Find("tvnLastMod", true)[0]; } }
private TreeNode tvnLargeEntries { get { return tvHookedSearches.Nodes.Find("tvnLargeEntries", true)[0]; } }
private TreeNode tvnDupPw { get { return tvHookedSearches.Nodes.Find("tvnDupPw", true)[0]; } }
private TreeNode tvnSimPwPairs { get { return tvHookedSearches.Nodes.Find("tvnSimPwPairs", true)[0]; } }
private TreeNode tvnSimPwCluster { get { return tvHookedSearches.Nodes.Find("tvnSimPwCluster", true)[0]; } }
private TreeNode tvnPwQuality { get { return tvHookedSearches.Nodes.Find("tvnPwQuality", true)[0]; } }
private TreeNode tvnExpired { get { return tvHookedSearches.Nodes.Find("tvnExpired", true)[0]; } }

public Options()
{
//
Expand All @@ -31,24 +41,22 @@ public Options()
Text = PluginTranslate.PluginName;
tpOptions.Text = PluginTranslate.OptionsCaption;
tpHelp.Text = KeePass.Resources.KPRes.Description;
AdjustCheckBox(cbSearchForm, SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchForm));
cbUseEntryListColumnWidths.Text = PluginTranslate.UseEntryListColumnWidths;

AdjustCheckBox(cbSearchLastMod, SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchLastMod));
AdjustCheckBox(cbSearchLarge, SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchLargeEntries));
AdjustCheckBox(cbSearchDupPw, SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchDupPw));
AdjustCheckBox(cbSearchPwPairs, SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchPasswordPairs));
AdjustCheckBox(cbSearchPwCluster, SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchPasswordClusters));
AdjustCheckBox(cbSearchPwQuality, SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchPasswordQuality));
AdjustCheckBox(cbSearchPwQuality, SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchPasswordQuality));

FindInfo fiExpired = SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchExpired);
cbSearchAllExpired.Enabled = fiExpired.StandardMethod != null;
cbSearchAllExpired.Text = KeePass.Resources.KPRes.ExpiredEntries;

cbMultiDBSearchInfoSearchFormActive.Text = string.Format(PluginTranslate.MultiDBSearchInfoSearchFormActive, cbSearchForm.Text);
AdjustNode(tvnSearchForm, SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchForm));

tvnUseEntryListColummnWidth.Text = PluginTranslate.UseEntryListColumnWidths;

AdjustNode(tvnLastMod, SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchLastMod));
AdjustNode(tvnLargeEntries, SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchLargeEntries));
AdjustNode(tvnDupPw, SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchDupPw));
AdjustNode(tvnSimPwPairs, SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchPasswordPairs));
AdjustNode(tvnSimPwCluster, SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchPasswordClusters));
AdjustNode(tvnPwQuality, SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchPasswordQuality));
AdjustNode(tvnExpired, SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchExpired));
tvnExpired.Text = KeePass.Resources.KPRes.ExpiredEntries;

cbMultiDBSearchInfoSearchFormActive.Text = string.Format(PluginTranslate.MultiDBSearchInfoSearchFormActive, tvnSearchForm.Text);
cbMultiDBSearchInfoSingleSearchActive.Text = PluginTranslate.MultiDBSearchInfoSingleSearchActive;
string sDesc = string.Format(PluginTranslate.Description, PluginTranslate.PluginName, cbSearchForm.Text);
string sDesc = string.Format(PluginTranslate.Description, PluginTranslate.PluginName, tvnSearchForm.Text);
tbDesc.Lines = sDesc.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);

gSearches.Text = KeePass.Resources.KPRes.SearchingOp;
Expand All @@ -58,25 +66,74 @@ public Options()
rbPWDisplayEntryList.Text = PluginTranslate.PWDisplayModeEntryView;
}

private void AdjustCheckBox(CheckBox cbBox, FindInfo fiInfo)
private void SetDisabled(TreeNode t)
{
t.NodeFont = new Font(t.NodeFont == null ? t.TreeView.Font : t.NodeFont, FontStyle.Strikeout);
}

private bool IsEnabled(TreeNode t)
{
return t.NodeFont == null || !t.NodeFont.Strikeout;
}

public void InitEx()
{
cbBox.Text = fiInfo.OptionsText.Replace("&", string.Empty);
cbBox.Enabled = fiInfo.StandardMethod != null || (fiInfo.Name == SearchHelp.SearchForm);
tvnSearchForm.Checked = Config.SearchForm;
tvnUseEntryListColummnWidth.Checked = Config.UseEntryListColumnWidths;
tvnDupPw.Checked = IsEnabled(tvnDupPw) && Config.HookSearchDupPw;
tvnSimPwPairs.Checked = IsEnabled(tvnSimPwPairs) && Config.HookSearchPwPairs;
tvnSimPwCluster.Checked = IsEnabled(tvnSimPwCluster) && Config.HookSearchPwCluster;
tvnPwQuality.Checked = IsEnabled(tvnPwQuality) && Config.HookPwQuality;
tvnLargeEntries.Checked = IsEnabled(tvnLargeEntries) && Config.HookLargeEntries;
tvnLastMod.Checked = IsEnabled(tvnLastMod) && Config.HookLastMod;
tvnExpired.Checked = IsEnabled(tvnExpired) && Config.HookAllExpired;
cbMultiDBSearchInfoSearchFormActive.Checked = Config.ShowMultiDBInfoSearchForm;
cbMultiDBSearchInfoSingleSearchActive.Checked = Config.ShowMultiDBInfoSingleSearch;
SetPwDisplayMode(Config.PasswordDisplay);
}

public void SetPwDisplayMode(Config.PasswordDisplayMode m)
public void UpdateConfig()
{
Config.SearchForm = tvnSearchForm.Checked;
Config.UseEntryListColumnWidths = tvnUseEntryListColummnWidth.Checked;
if (IsEnabled(tvnDupPw)) Config.HookSearchDupPw = tvnDupPw.Checked;
if (IsEnabled(tvnSimPwPairs)) Config.HookSearchPwPairs = tvnSimPwPairs.Checked;
if (IsEnabled(tvnSimPwCluster)) Config.HookSearchPwCluster = tvnSimPwCluster.Checked;
if (IsEnabled(tvnPwQuality)) Config.HookPwQuality = tvnPwQuality.Checked;
if (IsEnabled(tvnLargeEntries)) Config.HookLargeEntries = tvnLargeEntries.Checked;
if (IsEnabled(tvnLastMod)) Config.HookLastMod = tvnLastMod.Checked;
if (IsEnabled(tvnExpired)) Config.HookAllExpired = tvnExpired.Checked;
Config.ShowMultiDBInfoSearchForm = cbMultiDBSearchInfoSearchFormActive.Checked;
Config.ShowMultiDBInfoSingleSearch = cbMultiDBSearchInfoSingleSearchActive.Checked;
Config.PasswordDisplay = GetPwDisplayMode();
}

private void AdjustNode(TreeNode t, FindInfo fiInfo)
{
t.Text = fiInfo.OptionsText.Replace("&", string.Empty);
if (fiInfo.StandardMethod != null || (fiInfo.Name == SearchHelp.SearchForm)) return;
SetDisabled(t);
}

private void SetPwDisplayMode(Config.PasswordDisplayMode m)
{
rbPWDisplayAlways.Checked = true;
if (m == Config.PasswordDisplayMode.Never) rbPWDisplayNever.Checked = true;
if (m == Config.PasswordDisplayMode.EntryviewBased) rbPWDisplayEntryList.Checked = true;
}

public Config.PasswordDisplayMode GetPwDisplayMode()
private Config.PasswordDisplayMode GetPwDisplayMode()
{
if (rbPWDisplayNever.Checked) return Config.PasswordDisplayMode.Never;
if (rbPWDisplayEntryList.Checked) return Config.PasswordDisplayMode.EntryviewBased;
return Config.PasswordDisplayMode.Always;
}

private void tvHookedSearches_BeforeChecked(object sender, TreeViewCancelEventArgs e)
{
if (IsEnabled(e.Node)) return;
e.Cancel = true;
}
}
}

Expand Down
Loading

0 comments on commit 28ae0d3

Please sign in to comment.