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) {
102 const std::string& example)
108 exists = fs::exists(exampleDir);
109 }
catch (std::exception&) {
113 WApplication::instance()->setInternalPathValid(
false);
114 addWidget(
new WText(
"No such example: " + exampleDir));
125 WApplication::instance()->setTitle(tr(
"srcview.title." + example));
128 title->setInternalPathEncoding(
true);
175 setLayout(topLayout);
184 std::string ext = fs::extension(path);
188 else if (ext ==
".C" || ext ==
".cpp")
195 const fs::path& path)
197 static const char *supportedFiles[] = {
198 ".C",
".cpp",
".h",
".css",
".xml",
".png",
".gif",
".csv",
".ico", 0
206 std::set<fs::path> paths;
208 fs::directory_iterator end_itr;
209 for (fs::directory_iterator i(path); i != end_itr; ++i)
212 std::vector<FileItem*> classes, files;
213 std::vector<fs::path> dirs;
215 while (!paths.empty()) {
216 fs::path p = *paths.begin();
220 if (fs::is_symlink(p))
224 if (fs::is_regular(p)) {
225 std::string ext = fs::extension(p);
226 bool supported =
false;
227 for (
const char **s = supportedFiles; *s != 0; ++s)
239 if (!companion.empty()) {
240 std::set<fs::path>::iterator it_companion = paths.find(companion);
242 if (it_companion != paths.end()) {
243 std::string className =
stem(p);
244 escapeText(className);
245 std::string label =
"<i>class</i> " + className;
248 new FileItem(
"/icons/cppclass.png", label, std::string());
255 (*it_companion).string());
259 classes.push_back(classItem);
260 paths.erase(it_companion);
264 files.push_back(file);
266 }
else if (fs::is_directory(p)) {
271 files.push_back(file);
277 for (
unsigned int i = 0; i < classes.size(); i++)
280 for (
unsigned int i = 0; i < files.size(); i++)
283 for (
unsigned int i = 0; i < dirs.size(); i++)
285 }
catch (fs::filesystem_error& e) {
286 std::cerr << e.what() << std::endl;
291 const fs::path& srcPath,
292 const std::string packageName)
294 fs::directory_iterator end_itr;
297 for (fs::directory_iterator i(srcPath); i != end_itr; ++i) {
299 if (fs::is_regular(p)) {
301 packageItem =
new FileItem(
"/icons/package.png", packageName,
"");
311 for (fs::directory_iterator i(srcPath); i != end_itr; ++i) {
313 if (fs::is_directory(p)) {
314 std::string pn = packageName;
325 const fs::path& path)
332 std::vector<fs::path> files, dirs;
334 fs::directory_iterator end_itr;
335 for (fs::directory_iterator i(path); i != end_itr; ++i) {
337 if (fs::is_directory(p)) {
353 for (
unsigned int i = 0; i < dirs.size(); i++)
356 for (
unsigned int i = 0; i < files.size(); i++) {