-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLinkCodeFiles.cs
More file actions
130 lines (112 loc) · 4.45 KB
/
Copy pathLinkCodeFiles.cs
File metadata and controls
130 lines (112 loc) · 4.45 KB
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using StatTag.Core.Models;
using StatTag.Models;
namespace StatTag
{
public sealed partial class LinkCodeFiles : Form
{
/// <summary>
/// The collection of actions that the user has indicated they wish to proceed with.
/// </summary>
public Dictionary<string, CodeFileAction> CodeFileUpdates { get; set; }
public Dictionary<string, List<Tag>> UnlinkedResults;
public List<string> UnlinkedAffectedCodeFiles { get; set; }
private readonly List<CodeFile> Files;
private const int ColMissingCodeFile = 0;
private const int ColActionToTake = 1;
private bool IsSelectingFile = false;
public LinkCodeFiles(Dictionary<string, List<Tag>> unlinkedResults, List<CodeFile> files)
{
InitializeComponent();
UnlinkedResults = unlinkedResults;
Files = files;
MinimumSize = Size;
CodeFileUpdates = new Dictionary<string, CodeFileAction>();
UIUtility.SetDialogTitle(this);
}
private void LinkCodeFiles_Load(object sender, EventArgs e)
{
foreach (var item in UnlinkedResults)
{
int row = dgvCodeFiles.Rows.Add(item.Key);
dgvCodeFiles.Rows[row].Tag = item;
}
UIUtility.BuildCodeFileActionColumn(Files, dgvCodeFiles, ColActionToTake, false);
}
private void cmdOK_Click(object sender, EventArgs e)
{
// Make sure we pick up any changes that the data grid view hasn't seen yet
dgvCodeFiles.EndEdit();
UnlinkedAffectedCodeFiles = new List<string>();
foreach (var row in dgvCodeFiles.Rows.OfType<DataGridViewRow>())
{
var fileCell = row.Cells[ColMissingCodeFile] as DataGridViewTextBoxCell;
var actionCell = row.Cells[ColActionToTake] as DataGridViewComboBoxCell;
if (actionCell == null || fileCell == null)
{
continue;
}
CodeFileUpdates.Add(fileCell.Value.ToString(), actionCell.Value as CodeFileAction);
if (!UnlinkedAffectedCodeFiles.Contains(fileCell.Value.ToString()))
{
UnlinkedAffectedCodeFiles.Add(fileCell.Value.ToString());
}
}
}
private void dgvCodeFiles_Leave(object sender, EventArgs e)
{
dgvCodeFiles.EndEdit();
}
private void dgvCodeFiles_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
if (dgvCodeFiles.IsCurrentCellDirty)
{
dgvCodeFiles.CommitEdit(DataGridViewDataErrorContexts.Commit);
dgvCodeFiles.EndEdit(DataGridViewDataErrorContexts.LeaveControl);
dgvCodeFiles.CurrentCell = dgvCodeFiles[0, 0];
}
}
private void dgvCodeFiles_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (IsSelectingFile)
{
return;
}
if (e.ColumnIndex != ColActionToTake || e.RowIndex < 0)
{
return;
}
var combo = dgvCodeFiles[e.ColumnIndex, e.RowIndex] as DataGridViewComboBoxCell;
if (combo == null)
{
return;
}
IsSelectingFile = true;
var value = combo.Value as CodeFileAction;
if (value != null && value.Action == Constants.CodeFileActionTask.SelectFile)
{
string fileName = UIUtility.GetOpenFileName(Constants.FileFilters.FormatForOpenFileDialog());
if (!string.IsNullOrWhiteSpace(fileName))
{
string package = CodeFile.GuessStatisticalPackage(fileName);
var action = UIUtility.AddOptionToBuildCodeFileActionColumn(
new CodeFile { FilePath = fileName, StatisticalPackage = package }, dgvCodeFiles, ColActionToTake);
combo.Value = action.Data;
}
else
{
combo.Value = null;
}
}
IsSelectingFile = false;
}
}
}