A simple widget to visualise a set of example source files.
More...
#include <ExampleSourceViewer.h>
|
| ExampleSourceViewer (const std::string &deployPath, const std::string &examplesRoot, const std::string &examplesType) |
| Constructor. More...
|
|
|
void | cppTraverseDir (Wt::WStandardItem *parent, const boost::filesystem::path &path) |
|
void | javaTraverseDir (Wt::WStandardItem *parent, const boost::filesystem::path &path) |
|
void | javaTraversePackages (Wt::WStandardItem *parent, const boost::filesystem::path &srcPath, const std::string packageName) |
|
void | showFile () |
| Displayed the currently selected file. More...
|
|
void | handlePathChange () |
|
void | setExample (const std::string &exampleDir, const std::string &example) |
|
A simple widget to visualise a set of example source files.
Definition at line 21 of file ExampleSourceViewer.h.
◆ ExampleSourceViewer()
ExampleSourceViewer::ExampleSourceViewer |
( |
const std::string & |
deployPath, |
|
|
const std::string & |
examplesRoot, |
|
|
const std::string & |
examplesType |
|
) |
| |
◆ cppTraverseDir()
void ExampleSourceViewer::cppTraverseDir |
( |
Wt::WStandardItem * |
parent, |
|
|
const boost::filesystem::path & |
path |
|
) |
| |
|
private |
Definition at line 194 of file ExampleSourceViewer.C.
197 static const char *supportedFiles[] = {
198 ".C",
".cpp",
".h",
".css",
".xml",
".png",
".gif",
".csv",
".ico", 0
203 parent->appendRow(dir);
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());
249 classItem->setFlags(classItem->flags() | ItemIsXHTMLText);
255 (*it_companion).string());
256 classItem->appendRow(header);
257 classItem->appendRow(cpp);
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++)
278 parent->appendRow(classes[i]);
280 for (
unsigned int i = 0; i < files.size(); i++)
281 parent->appendRow(files[i]);
283 for (
unsigned int i = 0; i < dirs.size(); i++)
285 }
catch (fs::filesystem_error& e) {
286 std::cerr << e.what() << std::endl;
◆ handlePathChange()
void ExampleSourceViewer::handlePathChange |
( |
| ) |
|
|
private |
Definition at line 84 of file ExampleSourceViewer.C.
86 WApplication *app = wApp;
89 std::string example = app->internalPathNextPart(
deployPath_);
91 if (example.find(
"..") != std::string::npos
92 || example.find(
'/') != std::string::npos
93 || example.find(
'\\') != std::string::npos) {
94 app->setInternalPathValid(
false);
◆ javaTraverseDir()
void ExampleSourceViewer::javaTraverseDir |
( |
Wt::WStandardItem * |
parent, |
|
|
const boost::filesystem::path & |
path |
|
) |
| |
|
private |
Definition at line 324 of file ExampleSourceViewer.C.
329 parent->appendRow(dir);
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)) {
341 parent->appendRow(dir);
353 for (
unsigned int i = 0; i < dirs.size(); i++)
356 for (
unsigned int i = 0; i < files.size(); i++) {
359 parent->appendRow(file);
◆ javaTraversePackages()
void ExampleSourceViewer::javaTraversePackages |
( |
Wt::WStandardItem * |
parent, |
|
|
const boost::filesystem::path & |
srcPath, |
|
|
const std::string |
packageName |
|
) |
| |
|
private |
Definition at line 290 of file ExampleSourceViewer.C.
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,
"");
302 parent->appendRow(packageItem);
307 packageItem->appendRow(file);
311 for (fs::directory_iterator i(srcPath); i != end_itr; ++i) {
313 if (fs::is_directory(p)) {
314 std::string pn = packageName;
◆ setExample()
void ExampleSourceViewer::setExample |
( |
const std::string & |
exampleDir, |
|
|
const std::string & |
example |
|
) |
| |
|
private |
Definition at line 101 of file ExampleSourceViewer.C.
108 exists = fs::exists(exampleDir);
109 }
catch (std::exception&) {
113 WApplication::instance()->setInternalPathValid(
false);
114 addWidget(
new WText(
"No such example: " + exampleDir));
118 model_ =
new WStandardItemModel(0, 1,
this);
125 WApplication::instance()->setTitle(tr(
"srcview.title." + example));
127 new WText(tr(
"srcview.title." +
examplesType_ +
"." + example));
128 title->setInternalPathEncoding(
true);
149 WStandardItem *w =
model_->item(0);
152 if (w->rowCount() > 0)
160 WVBoxLayout *topLayout =
new WVBoxLayout();
161 topLayout->addWidget(title);
163 WHBoxLayout *gitLayout =
new WHBoxLayout();
166 topLayout->addLayout(gitLayout, 1);
167 gitLayout->setResizable(0);
175 setLayout(topLayout);
176 setStyleClass(
"maindiv");
◆ showFile()
void ExampleSourceViewer::showFile |
( |
| ) |
|
|
private |
◆ deployPath_
std::string ExampleSourceViewer::deployPath_ |
|
private |
◆ examplesRoot_
std::string ExampleSourceViewer::examplesRoot_ |
|
private |
◆ examplesType_
std::string ExampleSourceViewer::examplesType_ |
|
private |
◆ exampleView_
Wt::WTreeView* ExampleSourceViewer::exampleView_ |
|
private |
◆ model_
Wt::WStandardItemModel* ExampleSourceViewer::model_ |
|
private |
◆ sourceView_
The documentation for this class was generated from the following files: