199{
200 static const char *supportedFiles[] = {
201 ".C", ".cpp", ".h", ".css", ".xml", ".png", ".gif", ".csv", ".ico", 0
202 };
203
204 auto dir = std::make_unique<FileItem>("/icons/yellow-folder-open.png",
206 "");
208 parent->appendRow(std::move(dir));
209 parent = dirPtr;
210 try {
211 std::set<fs::path> paths;
212
213 fs::directory_iterator end_itr;
214 for (fs::directory_iterator i(path); i != end_itr; ++i)
215 paths.insert(*i);
216
217 std::vector<std::unique_ptr<FileItem>> classes, files;
218 std::vector<fs::path> dirs;
219
220 while (!paths.empty()) {
221 fs::path p = *paths.begin();
222 paths.erase(p);
223
224
225 if (fs::is_symlink(p))
226 continue;
227
228
229 if (fs::is_regular(p)) {
230 std::string ext = fs::extension(p);
231 bool supported = false;
232 for (const char **s = supportedFiles; *s != 0; ++s)
233 if (*s == ext) {
234 supported = true;
235 break;
236 }
237
238 if (!supported)
239 continue;
240 }
241
242
244 if (!companion.empty()) {
245 std::set<fs::path>::iterator it_companion = paths.find(companion);
246
247 if (it_companion != paths.end()) {
248 std::string className =
stem(p);
249 escapeText(className);
250 std::string label = "<i>class</i> " + className;
251
252 std::unique_ptr<FileItem> classItem =
253 std::make_unique<FileItem>("/icons/cppclass.png", label, std::string());
254 classItem->setFlags(classItem->flags() | ItemFlag::XHTMLText);
255
256 auto header
257 = std::make_unique<FileItem>(
"/icons/document.png",
filename(p),
258 p.string());
259 auto cpp
260 = std::make_unique<FileItem>("/icons/document.png",
262 (*it_companion).string());
263 classItem->appendRow(std::move(header));
264 classItem->appendRow(std::move(cpp));
265
266 classes.push_back(std::move(classItem));
267 paths.erase(it_companion);
268 } else {
269 auto file
270 = std::make_unique<FileItem>(
"/icons/document.png",
filename(p),
271 p.string());
272 files.push_back(std::move(file));
273 }
274 } else if (fs::is_directory(p)) {
275 dirs.push_back(p);
276 } else {
277 auto file
278 = std::make_unique<FileItem>(
"/icons/document.png",
filename(p),
279 p.string());
280 files.push_back(std::move(file));
281 }
282 }
283
285
286 for (unsigned int i = 0; i < classes.size(); i++)
287 parent->appendRow(std::move(classes[i]));
288
289 for (unsigned int i = 0; i < files.size(); i++)
290 parent->appendRow(std::move(files[i]));
291
292 for (unsigned int i = 0; i < dirs.size(); i++)
294 } catch (fs::filesystem_error& e) {
295 std::cerr << e.what() << std::endl;
296 }
297}
static fs::path getCompanion(const fs::path &path)
static std::string stem(const fs::path &p)
static std::string filename(const fs::path &p)
static bool comparePaths(const fs::path &p1, const fs::path &p2)
void cppTraverseDir(WStandardItem *parent, const boost::filesystem::path &path)
WStandardItem which stores a file.