-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAppDlg.cpp
More file actions
280 lines (222 loc) · 8.35 KB
/
AppDlg.cpp
File metadata and controls
280 lines (222 loc) · 8.35 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
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
////////////////////////////////////////////////////////////////////////////////
//! \file AppDlg.cpp
//! \brief The AppDlg class definition.
//! \author Chris Oldwood
#include "Common.hpp"
#include "AppDlg.hpp"
#include <WCL/Path.hpp>
#include "TheApp.hpp"
#include <WCL/ScreenDC.hpp>
////////////////////////////////////////////////////////////////////////////////
//! Constructor.
AppDlg::AppDlg()
: CMainDlg(IDD_MAIN)
{
DEFINE_CTRL_TABLE
CTRL(IDC_FOLDER, &m_folderButton)
CTRL(IDC_FILES, &m_filesButton)
CTRL(IDC_LABEL_1, &m_path1Label)
CTRL(IDC_PATH_1, &m_path1Editor)
CTRL(IDC_LABEL_2, &m_path2Label)
CTRL(IDC_PATH_2, &m_path2Editor)
CTRL(IDC_RESULTS, &m_resultsView)
END_CTRL_TABLE
DEFINE_GRAVITY_TABLE
CTRLGRAV(IDC_FOLDER, LEFT_EDGE, TOP_EDGE, LEFT_EDGE, TOP_EDGE)
CTRLGRAV(IDC_FILES, LEFT_EDGE, TOP_EDGE, LEFT_EDGE, TOP_EDGE)
CTRLGRAV(IDC_LABEL_1, LEFT_EDGE, TOP_EDGE, LEFT_EDGE, TOP_EDGE)
CTRLGRAV(IDC_PATH_1, LEFT_EDGE, TOP_EDGE, RIGHT_EDGE, TOP_EDGE)
CTRLGRAV(IDC_BROWSE_1, RIGHT_EDGE, TOP_EDGE, RIGHT_EDGE, TOP_EDGE)
CTRLGRAV(IDC_LABEL_2, LEFT_EDGE, TOP_EDGE, LEFT_EDGE, TOP_EDGE)
CTRLGRAV(IDC_PATH_2, LEFT_EDGE, TOP_EDGE, RIGHT_EDGE, TOP_EDGE)
CTRLGRAV(IDC_BROWSE_2, RIGHT_EDGE, TOP_EDGE, RIGHT_EDGE, TOP_EDGE)
CTRLGRAV(IDC_HEADING, LEFT_EDGE, TOP_EDGE, RIGHT_EDGE, TOP_EDGE)
CTRLGRAV(IDC_RESULTS, LEFT_EDGE, TOP_EDGE, RIGHT_EDGE, BOTTOM_EDGE)
END_GRAVITY_TABLE
DEFINE_CTRLMSG_TABLE
CMD_CTRLMSG(IDC_FOLDER, BN_CLICKED, &AppDlg::onFolderComparison)
CMD_CTRLMSG(IDC_FILES, BN_CLICKED, &AppDlg::onFileComparison)
CMD_CTRLMSG(IDC_BROWSE_1, BN_CLICKED, &AppDlg::onBrowsePath1)
CMD_CTRLMSG(IDC_BROWSE_2, BN_CLICKED, &AppDlg::onBrowsePath2)
NFY_CTRLMSG(IDC_RESULTS, NM_RCLICK, &AppDlg::onRightClickResult)
END_CTRLMSG_TABLE
}
////////////////////////////////////////////////////////////////////////////////
//! Destructor.
AppDlg::~AppDlg()
{
}
////////////////////////////////////////////////////////////////////////////////
//! Query if the user wants to scan folders.
bool AppDlg::isFolderScanSelected() const
{
return m_folderButton.IsChecked();
}
////////////////////////////////////////////////////////////////////////////////
//! Get the 1st path.
tstring AppDlg::getPath1() const
{
return tstring(m_path1Editor.Text());
}
////////////////////////////////////////////////////////////////////////////////
//! Get the 2nd path.
tstring AppDlg::getPath2() const
{
return tstring(m_path2Editor.Text());
}
////////////////////////////////////////////////////////////////////////////////
//! Handle dialog creation.
void AppDlg::OnInitDialog()
{
// m_resultsFont.Create(CLogFont(TXT("Lucida Console"), -CScreenDC().PointSizeToPixels(8)));
// Initialise controls.
m_folderButton.Check(true);
m_filesButton.Check(false);
onFolderComparison();
// m_resultsView.Font(m_resultsFont);
m_resultsView.ImageList(LVSIL_SMALL, IDB_RESICONS, 16, RGB(255, 0, 255));
m_resultsView.InsertColumn(TOOL, TXT("Tool"), m_resultsView.StringWidth(20), LVCFMT_LEFT);
m_resultsView.InsertColumn(SETTING, TXT("Setting"), m_resultsView.StringWidth(25), LVCFMT_LEFT);
m_resultsView.InsertColumn(BUILD, TXT("Build"), m_resultsView.StringWidth(15), LVCFMT_LEFT);
m_resultsView.InsertColumn(PROJECT, TXT("Project"), m_resultsView.StringWidth(25), LVCFMT_LEFT);
m_resultsView.InsertColumn(PATH, TXT("Path"), m_resultsView.StringWidth(25), LVCFMT_LEFT);
m_resultsView.InsertColumn(VALUE, TXT("Value"), m_resultsView.StringWidth(30), LVCFMT_LEFT);
m_resultsView.FullRowSelect(true);
}
////////////////////////////////////////////////////////////////////////////////
//! Browse for the 1st path.
void AppDlg::onBrowsePath1()
{
if (m_folderButton.IsChecked())
browseForFolder(m_path1Editor);
else
browseForFile(m_path1Editor);
}
////////////////////////////////////////////////////////////////////////////////
//! Browse for the 2nd path.
void AppDlg::onBrowsePath2()
{
browseForFile(m_path2Editor);
}
////////////////////////////////////////////////////////////////////////////////
//! Switch to comparing files in a folder.
void AppDlg::onFolderComparison()
{
// Manually fix-up the other radio button.
m_filesButton.Check(false);
// Set the control labels.
m_path1Label.Text(TXT("F&older:"));
m_path2Label.Text(TXT("N/A:"));
// Initialise the paths.
m_path1Editor.Text(g_app.m_lastFolder);
m_path2Editor.Text(TXT(""));
// Disable the second path controls.
Control(IDC_LABEL_2).Enable(false);
Control(IDC_PATH_2).Enable(false);
Control(IDC_BROWSE_2).Enable(false);
}
////////////////////////////////////////////////////////////////////////////////
//! Switch to comparing specifc files.
void AppDlg::onFileComparison()
{
// Manually fix-up the other radio button.
m_folderButton.Check(false);
// Set the control labels.
m_path1Label.Text(TXT("File &1:"));
m_path2Label.Text(TXT("File &2:"));
// Initialise the paths.
m_path1Editor.Text(g_app.m_lastFile1);
m_path2Editor.Text(g_app.m_lastFile2);
// Enable the second path controls.
Control(IDC_LABEL_2).Enable(true);
Control(IDC_PATH_2).Enable(true);
Control(IDC_BROWSE_2).Enable(true);
}
////////////////////////////////////////////////////////////////////////////////
//! Show a context menu for the selected result.
LRESULT AppDlg::onRightClickResult(NMHDR& /*event*/)
{
// Only show menu, if a selection.
if (m_resultsView.IsSelection())
{
ToolSetting toolSetting;
// Get the selected setting.
size_t selection = m_resultsView.Selection();
toolSetting.m_tool = m_resultsView.ItemText(selection, 0);
toolSetting.m_setting = m_resultsView.ItemText(selection, 1);
// Check setting status.
bool projectDep = (g_app.m_projectDepList.find(toolSetting) != g_app.m_projectDepList.end());
bool buildDep = (g_app.m_buildDepList.find(toolSetting) != g_app.m_buildDepList.end());
CPopupMenu menu(IDR_CONTEXT);
// Enable/Disable relevant commands.
menu.EnableCmd(ID_CONTEXT_PROJECT,!projectDep && !buildDep);
menu.EnableCmd(ID_CONTEXT_BUILD, !projectDep && !buildDep);
// Show context menu.
const MSG& msg = g_app.m_MainThread.CurrentMsg();
uint cmd = menu.TrackMenu(m_resultsView, msg.pt);
// Add to ignored settings list?
if (cmd == ID_CONTEXT_PROJECT)
{
g_app.m_projectDepList.insert(toolSetting);
g_app.m_modified |= TheApp::PROJECT_LIST;
}
// Add to build dependent settings list?
else if (cmd == ID_CONTEXT_BUILD)
{
g_app.m_buildDepList.insert(toolSetting);
g_app.m_modified |= TheApp::BUILDDEP_LIST;
}
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
//! Browse for a folder path.
void AppDlg::browseForFolder(CEditBox& pathEditor)
{
// Use the current path as a default.
CPath initialFolder = pathEditor.Text();
// Use the application folder, if no default.
if (initialFolder.Empty())
initialFolder = CPath::ApplicationDir();
CPath path;
// Query the user.
if (path.SelectDir(*this, TXT("Select the root folder of the .vcproj files"), initialFolder))
pathEditor.Text(path);
}
////////////////////////////////////////////////////////////////////////////////
//! Browse for a file path.
void AppDlg::browseForFile(CEditBox& pathEditor)
{
static tchar s_exts[] = { TXT("Project Files (*.vcproj)\0*.vcproj\0")
TXT("All Files (*.*)\0*.*\0")
TXT("\0\0") };
// Use the current path as a default.
CPath initialFolder = pathEditor.Text();
if (initialFolder.Exists() && !initialFolder.IsFolder())
initialFolder = initialFolder.Directory();
// Use the application folder, if no default.
if (initialFolder.Empty())
initialFolder = CPath::ApplicationDir();
CPath path;
// Query the user.
if (path.Select(*this, CPath::SelectFile, s_exts, TXT("vcproj"), initialFolder))
pathEditor.Text(path);
}
////////////////////////////////////////////////////////////////////////////////
//! Display the results list.
void AppDlg::displayResults(Table& results)
{
m_resultsView.DeleteAllItems();
// Load the table rows.
for (size_t i = 0; i < results.size(); ++i)
{
RowPtr row = results[i];
ASSERT(row->size() == NUM_COLUMNS);
m_resultsView.InsertItem(i, row->at(TOOL));
m_resultsView.ItemText (i, SETTING, row->at(SETTING));
m_resultsView.ItemText (i, BUILD, row->at(BUILD));
m_resultsView.ItemText (i, PROJECT, row->at(PROJECT));
m_resultsView.ItemText (i, PATH, row->at(PATH));
m_resultsView.ItemText (i, VALUE, row->at(VALUE));
}
}