-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAppCmds.cpp
More file actions
235 lines (181 loc) · 5.88 KB
/
AppCmds.cpp
File metadata and controls
235 lines (181 loc) · 5.88 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
////////////////////////////////////////////////////////////////////////////////
//! \file AppCmds.cpp
//! \brief The AppCmds class definition.
//! \author Chris Oldwood
#include "Common.hpp"
#include "AppCmds.hpp"
#include "TheApp.hpp"
#include "AboutDlg.hpp"
#include "ProgressDlg.hpp"
#include "FileListDlg.hpp"
#include <WCL/BusyCursor.hpp>
#include "OptionsDlg.hpp"
////////////////////////////////////////////////////////////////////////////////
//! Constructor.
AppCmds::AppCmds(AppWnd& appWnd)
: CCmdControl(appWnd)
{
// Define the command table.
DEFINE_CMD_TABLE
// File menu.
CMD_ENTRY(ID_FILE_LIST, &AppCmds::onFileList, nullptr, -1)
CMD_ENTRY(ID_FILE_COMPARE, &AppCmds::onFileCompare, nullptr, -1)
CMD_ENTRY(ID_FILE_REFRESH, &AppCmds::onFileRefresh, nullptr, -1)
CMD_ENTRY(ID_FILE_EXIT, &AppCmds::onFileExit, nullptr, -1)
// Tools menu.
CMD_ENTRY(ID_TOOLS_OPTIONS, &AppCmds::onToolsOptions, nullptr, -1)
// Help menu.
CMD_ENTRY(ID_HELP_CONTENTS, &AppCmds::onHelpContents, nullptr, -1)
CMD_ENTRY(ID_HELP_ABOUT, &AppCmds::onHelpAbout, nullptr, -1)
END_CMD_TABLE
}
////////////////////////////////////////////////////////////////////////////////
//! Destructor.
AppCmds::~AppCmds()
{
}
////////////////////////////////////////////////////////////////////////////////
//! List the raw project settings.
void AppCmds::onFileList()
{
CBusyCursor busyCursor;
// Clear all existing data.
g_app.m_projects.clear();
g_app.m_settings.clear();
g_app.m_results.clear();
g_app.m_action = TheApp::LIST_SETTINGS;
// Generate the project settings data.
if (!doFindAndParseFiles(g_app.m_projects, g_app.m_settings))
return;
// Display the raw results.
listSettings(g_app.m_projects, g_app.m_settings, g_app.m_results);
g_app.m_appWnd.m_mainView.displayResults(g_app.m_results);
}
////////////////////////////////////////////////////////////////////////////////
//! Compare the files for differences.
void AppCmds::onFileCompare()
{
CBusyCursor busyCursor;
// Clear all existing data.
g_app.m_projects.clear();
g_app.m_settings.clear();
g_app.m_results.clear();
g_app.m_action = TheApp::COMPARE_SETTINGS;
// Generate the project settings data.
if (!doFindAndParseFiles(g_app.m_projects, g_app.m_settings))
return;
// Compare and display the results.
compareSettings(g_app.m_projects, g_app.m_settings, g_app.m_results);
g_app.m_appWnd.m_mainView.displayResults(g_app.m_results);
}
////////////////////////////////////////////////////////////////////////////////
//! Rescan the project files.
void AppCmds::onFileRefresh()
{
CBusyCursor busyCursor;
// Clear existing result data.
g_app.m_settings.clear();
g_app.m_results.clear();
// Generate the project settings data.
if (!doFindAndParseFiles(g_app.m_projects, g_app.m_settings))
return;
// Process the results according to the previous action.
if (g_app.m_action == TheApp::LIST_SETTINGS)
{
listSettings(g_app.m_projects, g_app.m_settings, g_app.m_results);
}
else // (g_app.m_action == TheApp::COMPARE_SETTINGS)
{
compareSettings(g_app.m_projects, g_app.m_settings, g_app.m_results);
}
g_app.m_appWnd.m_mainView.displayResults(g_app.m_results);
}
////////////////////////////////////////////////////////////////////////////////
//! Close the application.
void AppCmds::onFileExit()
{
g_app.m_appWnd.Close();
}
////////////////////////////////////////////////////////////////////////////////
//! Show the application settings dialog.
void AppCmds::onToolsOptions()
{
OptionsDlg options;
options.RunModal(g_app.m_appWnd);
}
////////////////////////////////////////////////////////////////////////////////
//! Show the HelpFile.
void AppCmds::onHelpContents()
{
CBusyCursor busyCursor;
::ShellExecute(nullptr, nullptr, CPath::ApplicationDir() / TXT("VCProjCompare.mht"), nullptr, nullptr, SW_SHOW);
}
////////////////////////////////////////////////////////////////////////////////
//! Show the about dialog.
void AppCmds::onHelpAbout()
{
AboutDlg dialog;
dialog.RunModal(g_app.m_appWnd);
}
////////////////////////////////////////////////////////////////////////////////
//! Find and parse the project files into an internal form.
bool AppCmds::doFindAndParseFiles(Projects& projects, ProjectSettings& settings)
{
AppDlg& view = g_app.m_appWnd.m_mainView;
// Initialise progress UI.
ProgressDlg progress(g_app.m_appWnd);
progress.updateProgressBar(0);
progress.setStatus(TXT("Searching for project files..."));
// Not doing a rescan?
if (projects.empty())
{
// Comparing all files?
if (view.isFolderScanSelected())
{
tstring folder = view.getPath1();
FileList files;
// Search folder for all project files.
if (!findProjectFiles(folder, files))
return false;
if (files.empty())
{
g_app.AlertMsg(TXT("No project files were found"));
return false;
}
// Allow user to edit the file list.
FileListDlg fileListDlg;
fileListDlg.m_files = files;
if (fileListDlg.RunModal(g_app.m_appWnd) != IDOK)
return false;
// Create project file list.
for (FileList::const_iterator it = fileListDlg.m_files.begin(); it != fileListDlg.m_files.end(); ++it)
projects.push_back(ProjectFile(*it));
// Remember the folder.
g_app.m_lastFolder = folder;
}
// Comparing just two specific files.
else
{
tstring file1 = view.getPath1();
tstring file2 = view.getPath2();
// Create project file list.
projects.push_back(ProjectFile(file1));
projects.push_back(ProjectFile(file2));
// Remember the files.
g_app.m_lastFile1 = file1;
g_app.m_lastFile2 = file2;
}
}
progress.updateProgressBar(2);
progress.setStatus(TXT("Reading project files..."));
// Load the project files.
if (!readProjectFiles(projects))
return false;
progress.updateProgressBar(4);
progress.setStatus(TXT("Parsing project files..."));
// Parse the project files.
if (!parseProjectFiles(projects, settings))
return false;
progress.updateProgressBar(5);
return true;
}