This repository has been archived by the owner on Nov 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIssuesForm.cs
259 lines (235 loc) · 9.38 KB
/
IssuesForm.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/**
*
* TortoiseMantis Copyright 2010 Andreas Stieger <[email protected]>
*
* This file is part of TortoiseMantis.
*
* TortoiseMantis 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 3 of the License, or
* (at your option) any later version.
*
* TortoiseMantis 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, see <http://www.gnu.org/licenses/>.
*
**/
using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TortoiseMantis.MantisConnectReference;
namespace TortoiseMantis
{
internal partial class IssuesForm : Form, IIssuesDisplay
{
private IssueHeaderData[] issueHeaders;
private IssueHeaderData selectedIssue;
private String myAccountID;
private ConnectionSettings cs;
private String searchString;
private IssuesListColumnSorter issuesListColumnSorter;
private IDictionary<string, string> userNameMapping;
private IDictionary<string, string> statusMapping;
private IDictionary<string, Color> statusColorMapping;
public IssuesForm(Plugin plugin, ConnectionSettings cs)
{
InitializeComponent();
issuesListColumnSorter = new IssuesListColumnSorter();
issuesList.ListViewItemSorter = (IComparer)issuesListColumnSorter;
this.Text += String.Format(" v{0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version);
issueHeaders = null;
selectedIssue = null;
myAccountID = null;
userNameMapping = new Dictionary<string, string>();
statusMapping = new Dictionary<string, string>();
this.cs = cs;
searchString = String.Empty;
plugin.StatusUpdated += new Plugin.StatusUpdatedHandler(plugin_StatusUpdated);
InitializeStatusColorMapping();
}
void plugin_StatusUpdated(string status)
{
statusLabel.Text = status;
progressBar.PerformStep();
}
private void IssuesForm_Load(object sender, EventArgs e)
{
progressBar.Value = progressBar.Minimum;
statusLabel.Text = "connecting...";
}
public void SetStatusMappings(ObjectRef[] statusEnum)
{
statusMapping.Clear();
IEnumerator e = statusEnum.GetEnumerator();
while (e.MoveNext())
{
ObjectRef status = (ObjectRef)e.Current;
statusMapping.Add(status.id, status.name);
}
ListIssues();
}
public void SetAccountData(AccountData[] accountData)
{
userNameMapping.Clear();
IEnumerator e = accountData.GetEnumerator();
while (e.MoveNext())
{
AccountData account = (AccountData)e.Current;
userNameMapping.Add(account.id, account.name);
if (account.name == cs.Username)
{
this.myAccountID = account.id;
}
}
ListIssues();
}
public void SetIssueHeaderData(IssueHeaderData[] issueHeaders)
{
this.issueHeaders = issueHeaders;
ListIssues();
}
private void ListIssues()
{
if (issueHeaders == null)
{
return;
}
bool showThisIssue;
issuesList.BeginUpdate();
issuesList.Items.Clear();
IEnumerator issueHeadersEnumerator = issueHeaders.GetEnumerator();
while (issueHeadersEnumerator.MoveNext())
{
IssueHeaderData issueHeaderData = (IssueHeaderData)issueHeadersEnumerator.Current;
showThisIssue = true;
if (this.radioButtonMyIssues.Checked)
{
if ((myAccountID != null) && (issueHeaderData.handler != myAccountID))
{
showThisIssue = false;
}
}
if (searchString != String.Empty)
{
showThisIssue &=
(
issueHeaderData.summary.Contains(searchString) ||
issueHeaderData.id.Contains(searchString)
);
}
if (showThisIssue)
{
ListViewItem item = new ListViewItem(issueHeaderData.id);
//item.UseItemStyleForSubItems = false; // allow coloring of just status
String owner = issueHeaderData.handler;
String statusString = GetStatusString(issueHeaderData.status);
if (owner != null && !this.radioButtonMyIssues.Checked)
{
statusString += String.Format(" ({0})", GetUserName(issueHeaderData.handler));
}
ListViewItem.ListViewSubItem status = item.SubItems.Add(statusString);
item.BackColor = getStatusColor(GetStatusString(issueHeaderData.status));
item.SubItems.Add(issueHeaderData.summary);
item.Tag = issueHeaderData;
issuesList.Items.Add(item);
}
}
// if the filter found one item, select it
if (issuesList.Items.Count == 1)
{
issuesList.Items[0].Selected = true;
}
issuesList.Sort();
issuesList.EndUpdate();
progressBar.Value = progressBar.Maximum;
statusLabel.Text = String.Format("showing {0} of {1} issues", issuesList.Items.Count, issueHeaders.Length);
}
public IssueHeaderData GetSelectedIssue()
{
return selectedIssue;
}
private String GetUserName(string userid)
{
if (userNameMapping.ContainsKey(userid))
return userNameMapping[userid];
return "unknown";
}
private String GetStatusString(string statusCode)
{
if (statusMapping.ContainsKey(statusCode))
return statusMapping[statusCode];
return "unknown";
}
private void InitializeStatusColorMapping()
{
statusColorMapping = new Dictionary<string, Color>();
statusColorMapping.Add("new", Color.FromArgb(0xfc, 0xbd, 0xbd));
statusColorMapping.Add("feedback", Color.FromArgb(0xe3, 0xb7, 0xeb));
statusColorMapping.Add("acknowledged", Color.FromArgb(0xff, 0xcd, 0x85));
statusColorMapping.Add("confirmed", Color.FromArgb(0xff, 0xf4, 0x94));
statusColorMapping.Add("assigned", Color.FromArgb(0xc2, 0xdf, 0xff));
statusColorMapping.Add("resolved", Color.FromArgb(0xd2, 0xf5, 0xb0));
statusColorMapping.Add("closed", Color.FromArgb(0xc9, 0xcc, 0xc4));
}
private Color getStatusColor(string status)
{
if (statusColorMapping.ContainsKey(status))
return statusColorMapping[status];
return Color.White;
}
private void buttonOK_Click(object sender, EventArgs e)
{
if (issuesList.SelectedItems.Count == 1)
{
selectedIssue = (IssueHeaderData)issuesList.SelectedItems[0].Tag;
}
}
private void filterRadio_Changed(object sender, EventArgs e)
{
ListIssues();
}
private void textBoxSearch_TextChanged(object sender, EventArgs e)
{
searchString = textBoxSearch.Text;
ListIssues();
}
private void issuesList_SelectedIndexChanged(object sender, EventArgs e)
{
buttonOK.Enabled = (issuesList.SelectedItems.Count > 0);
}
private void issuesList_DoubleClick(object sender, EventArgs e)
{
buttonOK.PerformClick();
}
private void issuesList_ColumnClick(object sender, ColumnClickEventArgs e)
{
if (e.Column == issuesListColumnSorter.SortColumn)
{
if (issuesListColumnSorter.SortOrder == SortOrder.Ascending)
{
issuesListColumnSorter.SortOrder = SortOrder.Descending;
}
else
{
issuesListColumnSorter.SortOrder = SortOrder.Ascending;
}
}
else
{
issuesListColumnSorter.SortColumn = e.Column;
issuesListColumnSorter.SortOrder = SortOrder.Ascending;
}
issuesList.Sort();
}
}
}