-
Notifications
You must be signed in to change notification settings - Fork 0
/
StatsSummaryWindow.cs
131 lines (104 loc) · 4 KB
/
StatsSummaryWindow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
KeeStats - A plugin for Keepass Password Manager
Copyright (C) 2014 Andrea Decorte
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using KeePassLib;
using KeePass.Forms;
namespace KeeStats
{
/// <summary>
/// Show the computed statistics in two datagridviews
/// </summary>
public partial class StatsSummaryWindow : Form
{
private PwDatabase _database = null;
public PwDatabase Database { get { return _database; } set { _database = value; } }
private PwGroup _group = null;
public PwGroup Group { get { return _group; } set
{ _group = value;
// add group name in window title
this.Text += " for group: ";
this.Text += _group.Name;
} }
private ImageList _icons = null;
public ImageList Icons { get { return _icons; } set { _icons = value; } }
public StatsSummaryWindow(List<StatItem> items, List<ExtendedStatItem> extended_items)
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
generalStatsView.DataSource = items;
generalStatsView.ReadOnly = true;
qualityStatsView.DataSource = extended_items;
qualityStatsView.ReadOnly = true;
// Disable if no items
generalStatsView.Enabled = items.Count != 0;
qualityStatsView.Enabled = extended_items.Count != 0;
// Hide item object column
qualityStatsView.Columns["Item"].Visible = false;
// Try to hide it on Mono (Visible properties not respected)
qualityStatsView.Columns["Item"].Width = 0;
qualityStatsView.Refresh();
qualityStatsView.CellClick += new DataGridViewCellEventHandler(qualityStatsView_CellClick);
recursiveSearch.Checked = true;
recursiveSearch.CheckedChanged += HandleCheckedChanged;
}
private void qualityStatsView_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex != qualityStatsView.Rows[e.RowIndex].Cells["Value"].ColumnIndex)
{
// only show if we're clicking on Value cell
return;
}
if (_database == null) {
// we need the database to show the edit window
return;
}
if (_icons == null) {
return;
}
PwEntry entry = qualityStatsView.Rows[e.RowIndex].Cells["Item"].Value as PwEntry;
if (entry == null) {
// For example a stat without an entry associated
return;
}
try {
PwEntryForm aForm = new PwEntryForm();
aForm.InitEx(entry, PwEditMode.ViewReadOnlyEntry, _database, _icons, false, false);
aForm.Show();
} catch (Exception ex) {
MessageBox.Show("Error while loading the edit window: " + ex.Message, "KeeStats", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
// TODO fix the Cancel button not working despite adding the event
}
void HandleCheckedChanged(object sender, EventArgs e)
{
CheckBox cb = sender as CheckBox;
List<StatItem> items = new List<StatItem>();
List<ExtendedStatItem> extended_items = new List<ExtendedStatItem>();
// Recompute stats
var result = StatComputer.ComputeStats(_group, ref items, ref extended_items, cb.Checked);
// Now update the data source so the view is updated
generalStatsView.DataSource = items;
qualityStatsView.DataSource = extended_items;
// Disable if no items
generalStatsView.Enabled = items.Count != 0;
qualityStatsView.Enabled = extended_items.Count != 0;
}
}
}