A simple widget to visualise a set of example source files. More...
#include <ExampleSourceViewer.h>

Public Member Functions | |
| ExampleSourceViewer (const std::string &deployPath, const std::string &examplesRoot, const std::string &examplesType) | |
| Constructor. | |
Private Member Functions | |
| 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. | |
| void | handlePathChange () |
| void | setExample (const std::string &exampleDir, const std::string &example) |
Private Attributes | |
| Wt::WTreeView * | exampleView_ |
| SourceView * | sourceView_ |
| std::string | deployPath_ |
| std::string | examplesRoot_ |
| std::string | examplesType_ |
| Wt::WStandardItemModel * | model_ |
A simple widget to visualise a set of example source files.
Definition at line 21 of file ExampleSourceViewer.h.
| ExampleSourceViewer::ExampleSourceViewer | ( | const std::string & | deployPath, |
| const std::string & | examplesRoot, | ||
| const std::string & | examplesType | ||
| ) |
Constructor.
Definition at line 71 of file ExampleSourceViewer.C.
: deployPath_(deployPath), examplesRoot_(examplesRoot), examplesType_(examplesType) { wApp->internalPathChanged().connect (this, &ExampleSourceViewer::handlePathChange); handlePathChange(); }
| void ExampleSourceViewer::cppTraverseDir | ( | Wt::WStandardItem * | parent, |
| const boost::filesystem::path & | path | ||
| ) | [private] |
| void ExampleSourceViewer::handlePathChange | ( | ) | [private] |
Definition at line 84 of file ExampleSourceViewer.C.
{
WApplication *app = wApp;
if (app->internalPathMatches(deployPath_)) {
std::string example = app->internalPathNextPart(deployPath_);
if (example.find("..") != std::string::npos
|| example.find('/') != std::string::npos
|| example.find('\\') != std::string::npos)
setExample("INVALID_DIR", "INVALID");
else
setExample(examplesRoot_ + example, example);
}
}
| void ExampleSourceViewer::javaTraverseDir | ( | Wt::WStandardItem * | parent, |
| const boost::filesystem::path & | path | ||
| ) | [private] |
| void ExampleSourceViewer::javaTraversePackages | ( | Wt::WStandardItem * | parent, |
| const boost::filesystem::path & | srcPath, | ||
| const std::string | packageName | ||
| ) | [private] |
| void ExampleSourceViewer::setExample | ( | const std::string & | exampleDir, |
| const std::string & | example | ||
| ) | [private] |
Definition at line 100 of file ExampleSourceViewer.C.
{
clear();
bool exists = false;
try {
exists = fs::exists(exampleDir);
} catch (std::exception&) {
}
if (!exists) {
addWidget(new WText("No such example: " + exampleDir));
return;
}
model_ = new WStandardItemModel(0, 1, this);
if (examplesType_ == "CPP") {
cppTraverseDir(model_->invisibleRootItem(), exampleDir);
} else if (examplesType_ == "JAVA") {
javaTraverseDir(model_->invisibleRootItem(), exampleDir);
}
WApplication::instance()->setTitle(tr("srcview.title." + example));
WText *title =
new WText(tr("srcview.title." + examplesType_ + "." + example));
title->setInternalPathEncoding(true);
exampleView_ = new WTreeView();
exampleView_->setHeaderHeight(0);
exampleView_->resize(300, WLength::Auto);
exampleView_->setSortingEnabled(false);
exampleView_->setModel(model_);
exampleView_->expandToDepth(1);
exampleView_->setSelectionMode(SingleSelection);
exampleView_->setAlternatingRowColors(false);
exampleView_->selectionChanged().connect
(this, &ExampleSourceViewer::showFile);
sourceView_ = new SourceView(FileItem::FileNameRole,
FileItem::ContentsRole,
FileItem::FilePathRole);
sourceView_->setStyleClass("source-view");
/*
* Expand path to first file, to show something in the source viewer
*/
WStandardItem *w = model_->item(0);
do {
exampleView_->setExpanded(w->index(), true);
if (w->rowCount() > 0)
w = w->child(0);
else {
exampleView_->select(w->index(), Select);
w = 0;
}
} while (w);
WVBoxLayout *topLayout = new WVBoxLayout();
topLayout->addWidget(title, 0, AlignTop | AlignJustify);
WHBoxLayout *gitLayout = new WHBoxLayout();
gitLayout->addWidget(exampleView_, 0);
gitLayout->addWidget(sourceView_, 1);
topLayout->addLayout(gitLayout, 1);
gitLayout->setResizable(0);
/*
* FIXME, in plain HTML mode, we should set a minimum size to the source
* view, and remove this in enableAjax() ?
*/
// sourceView_->setHeight("100%");
setLayout(topLayout);
setStyleClass("maindiv");
}
| void ExampleSourceViewer::showFile | ( | ) | [private] |
Displayed the currently selected file.
Definition at line 363 of file ExampleSourceViewer.C.
{
if (exampleView_->selectedIndexes().empty())
return;
WModelIndex selected = *exampleView_->selectedIndexes().begin();
// expand a folder when clicked
if (exampleView_->model()->rowCount(selected) > 0
&& !exampleView_->isExpanded(selected))
exampleView_->setExpanded(selected, true);
// (for a file,) load data in source viewer
sourceView_->setIndex(selected);
}
std::string ExampleSourceViewer::deployPath_ [private] |
Definition at line 34 of file ExampleSourceViewer.h.
std::string ExampleSourceViewer::examplesRoot_ [private] |
Definition at line 35 of file ExampleSourceViewer.h.
std::string ExampleSourceViewer::examplesType_ [private] |
Definition at line 36 of file ExampleSourceViewer.h.
Wt::WTreeView* ExampleSourceViewer::exampleView_ [private] |
Definition at line 31 of file ExampleSourceViewer.h.
Definition at line 38 of file ExampleSourceViewer.h.
SourceView* ExampleSourceViewer::sourceView_ [private] |
Definition at line 32 of file ExampleSourceViewer.h.
1.7.2