Skip to content

Commit

Permalink
Add some finishing touches
Browse files Browse the repository at this point in the history
* Changed save file dialog filter options
* Added some comments
* Added some cleanup if the plugin needs to be unloaded
  • Loading branch information
arbrown committed Jul 26, 2016
1 parent 4599b68 commit 5a13a89
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
21 changes: 19 additions & 2 deletions KPUsage/KPUsagePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ public override bool Initialize(IPluginHost host)
return true;
}

public override void Terminate()
{

// Clean up menu items
exportUsageMenuItem.Click -= ExportUsageMenuItem_Click;
var menu = this.host.MainWindow.ToolsMenu.DropDownItems;
menu.Remove(sep);
menu.Remove(exportUsageMenuItem);
}

private void ExportUsageMenuItem_Click(object sender, EventArgs e)
{
if (!this.host.Database.IsOpen)
Expand All @@ -40,16 +50,22 @@ private void ExportUsageMenuItem_Click(object sender, EventArgs e)
return;
}

var sfDialog = new SaveFileDialog();
var sfDialog = new SaveFileDialog()
{
AddExtension = true,
DefaultExt = "csv",
Filter = "Comma-Separated Values (*.csv)|*.csv",
};

if (sfDialog.ShowDialog() == DialogResult.OK)
{
var dic = new Dictionary<ulong, List<PwEntry>>();

// Traverse all entries
this.host.Database.RootGroup.TraverseTree(TraversalMethod.PreOrder, null,
(PwEntry en) =>
{

// Add entry to multi-dictionary by usage count
if (!dic.ContainsKey(en.UsageCount))
{
var tempList = new List<PwEntry>();
Expand All @@ -61,6 +77,7 @@ private void ExportUsageMenuItem_Click(object sender, EventArgs e)
return true;
});

// Write out every entry, unsorted
using (var file = new StreamWriter(sfDialog.FileName, false))
{
file.WriteLine("Name, Usage Count");
Expand Down
2 changes: 1 addition & 1 deletion KPUsage/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[assembly: AssemblyTitle("KPUsage")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("KeePass Plugin")]
[assembly: AssemblyCopyright("Copyright © Drew Brown 2016")]
[assembly: AssemblyTrademark("")]
Expand Down

0 comments on commit 5a13a89

Please sign in to comment.