11 #include <Wt/WApplication>
12 #include <Wt/WContainerWidget>
13 #include <Wt/WEnvironment>
14 #include <Wt/WLineEdit>
15 #include <Wt/WGridLayout>
16 #include <Wt/WHBoxLayout>
17 #include <Wt/WPushButton>
20 #include <Wt/WTreeView>
21 #include <Wt/WVBoxLayout>
22 #include <Wt/WViewWidget>
24 #include <boost/filesystem/operations.hpp>
25 #include <boost/filesystem/exception.hpp>
26 #include <boost/filesystem/convenience.hpp>
27 #include <boost/algorithm/string.hpp>
33 namespace fs = boost::filesystem;
38 #if BOOST_FILESYSTEM_VERSION < 3
39 return p.empty() ? std::string() : *--p.end();
41 return p.empty() ? std::string() : (*--p.end()).
string();
46 static std::string
stem(
const fs::path& p)
49 std::size_t pos = fn.find(
'.');
50 if (pos == std::string::npos)
53 return fn.substr(0, pos);
61 std::string path = p.string();
63 return path.substr(0, path.length() - fn.length() - 1);
72 const std::string& examplesRoot,
73 const std::string& examplesType)
74 : deployPath_(deployPath),
75 examplesRoot_(examplesRoot),
76 examplesType_(examplesType)
78 wApp->internalPathChanged().connect
91 if (example.find(
"..") != std::string::npos
92 || example.find(
'/') != std::string::npos
93 || example.find(
'\\') != std::string::npos)
101 const std::string& example)
107 exists = fs::exists(exampleDir);
108 }
catch (std::exception&) {
123 WApplication::instance()->setTitle(
tr(
"srcview.title." + example));
182 std::string ext = fs::extension(path);
186 else if (ext ==
".C" || ext ==
".cpp")
193 const fs::path& path)
195 static const char *supportedFiles[] = {
196 ".C",
".cpp",
".h",
".css",
".xml",
".png",
".gif",
".csv",
".ico", 0
204 std::set<fs::path> paths;
206 fs::directory_iterator end_itr;
207 for (fs::directory_iterator i(path); i != end_itr; ++i)
210 std::vector<FileItem*> classes, files;
211 std::vector<fs::path> dirs;
213 while (!paths.empty()) {
214 fs::path p = *paths.begin();
218 if (fs::is_symlink(p))
222 if (fs::is_regular(p)) {
223 std::string ext = fs::extension(p);
224 bool supported =
false;
225 for (
const char **s = supportedFiles; *s != 0; ++s)
237 if (!companion.empty()) {
238 std::set<fs::path>::iterator it_companion = paths.find(companion);
240 if (it_companion != paths.end()) {
241 std::string className =
stem(p);
243 std::string label =
"<i>class</i> " + className;
246 new FileItem(
"/icons/cppclass.png", label, std::string());
253 (*it_companion).string());
257 classes.push_back(classItem);
258 paths.erase(it_companion);
262 files.push_back(file);
264 }
else if (fs::is_directory(p)) {
269 files.push_back(file);
275 for (
unsigned int i = 0; i < classes.size(); i++)
278 for (
unsigned int i = 0; i < files.size(); i++)
281 for (
unsigned int i = 0; i < dirs.size(); i++)
283 }
catch (fs::filesystem_error& e) {
284 std::cerr << e.what() << std::endl;
289 const fs::path& srcPath,
290 const std::string packageName)
292 fs::directory_iterator end_itr;
295 for (fs::directory_iterator i(srcPath); i != end_itr; ++i) {
297 if (fs::is_regular(p)) {
299 packageItem =
new FileItem(
"/icons/package.png", packageName,
"");
309 for (fs::directory_iterator i(srcPath); i != end_itr; ++i) {
311 if (fs::is_directory(p)) {
312 std::string pn = packageName;
323 const fs::path& path)
330 std::vector<fs::path> files, dirs;
332 fs::directory_iterator end_itr;
333 for (fs::directory_iterator i(path); i != end_itr; ++i) {
335 if (fs::is_directory(p)) {
351 for (
unsigned int i = 0; i < dirs.size(); i++)
354 for (
unsigned int i = 0; i < files.size(); i++) {