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);
125 WApplication::instance()->setTitle(
tr(
"srcview.title." + example));
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++) {
static const int FileNameRole
Wt::WStandardItemModel * model_
static std::string stem(const fs::path &p)
WStandardItem * item(int row, int column=0) const
WFlags< ItemFlag > flags() const
WStandardItem which stores a file.
void showFile()
Displayed the currently selected file.
void setExample(const std::string &exampleDir, const std::string &example)
bool isExpanded(const WModelIndex &index) const
void addLayout(std::unique_ptr< WLayout > layout, int stretch, WFlags< AlignmentFlag > alignment)
void addWidget(std::unique_ptr< WWidget > widget, int stretch, WFlags< AlignmentFlag > alignment)
bool internalPathMatches(const std::string &path) const
static const int FilePathRole
virtual void resize(const WLength &width, const WLength &height) override
void setSelectionMode(SelectionMode mode)
Wt::WTreeView * exampleView_
void setInternalPathValid(bool valid)
WStandardItem * child(int row, int column=0) const
std::shared_ptr< WAbstractItemModel > model() const
virtual void setAlternatingRowColors(bool enable) override
std::string examplesRoot_
virtual void setHeaderHeight(const WLength &height) override
static const int ContentsRole
Signal & selectionChanged()
virtual void setModel(const std::shared_ptr< WAbstractItemModel > &model) override
ExampleSourceViewer(const std::string &deployPath, const std::string &examplesRoot, const std::string &examplesType)
Constructor.
WModelIndexSet selectedIndexes() const
void javaTraverseDir(Wt::WStandardItem *parent, const boost::filesystem::path &path)
std::string examplesType_
void appendRow(std::vector< std::unique_ptr< WStandardItem > > items)
void setInternalPathEncoding(bool enabled)
void javaTraversePackages(Wt::WStandardItem *parent, const boost::filesystem::path &srcPath, const std::string packageName)
void setResizable(int index, bool enabled=true, const WLength &initialSize=WLength::Auto)
void expandToDepth(int depth)
View class for source code.
void cppTraverseDir(Wt::WStandardItem *parent, const boost::filesystem::path &path)
static std::string filename(const fs::path &p)
void select(const WModelIndex &index, SelectionFlag option=SelectionFlag::Select)
void setExpanded(const WModelIndex &, bool expanded)
bool setIndex(const Wt::WModelIndex &index)
Sets the model index.
static bool comparePaths(const fs::path &p1, const fs::path &p2)
std::string internalPathNextPart(const std::string &path) const
void setSortingEnabled(bool enabled)
void setFlags(WFlags< ItemFlag > flags)
virtual Wt::Signals::connection connect(WObject *target, WObject::Method method) override
fs::path parent_path(const fs::path &p)
static fs::path getCompanion(const fs::path &path)
WStandardItem * invisibleRootItem() const
WModelIndex index() const