Wt examples  3.2.2
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ExampleSourceViewer Class Reference

A simple widget to visualise a set of example source files. More...

#include <ExampleSourceViewer.h>

Inheritance diagram for ExampleSourceViewer:
Inheritance graph
[legend]

Public Member Functions

 ExampleSourceViewer (const std::string &deployPath, const std::string &examplesRoot, const std::string &examplesType)
 Constructor.
- Public Member Functions inherited from Wt::WContainerWidget
 WContainerWidget (WContainerWidget *parent=0)
 ~WContainerWidget ()
void setLayout (WLayout *layout)
void setLayout (WLayout *layout, WFlags< AlignmentFlag > alignment)
WLayoutlayout ()
virtual void addWidget (WWidget *widget)
virtual void insertBefore (WWidget *widget, WWidget *before)
virtual void insertWidget (int index, WWidget *widget)
virtual void removeWidget (WWidget *widget)
virtual void clear ()
virtual int indexOf (WWidget *widget) const
virtual WWidgetwidget (int index) const
virtual int count () const
void setContentAlignment (WFlags< AlignmentFlag > contentAlignment)
void setPadding (const WLength &padding, WFlags< Side > sides=All)
WLength padding (Side side) const
WFlags< AlignmentFlagcontentAlignment () const
void setOverflow (Overflow overflow, WFlags< Orientation > orientation=(Horizontal|Vertical))
void setList (bool list, bool ordered=false)
bool isList () const
bool isUnorderedList () const
bool isOrderedList () const
EventSignal< WScrollEvent > & scrolled ()
 WInteractWidget (WContainerWidget *parent=0)
EventSignal< WKeyEvent > & keyWentDown ()
EventSignal< WKeyEvent > & keyPressed ()
EventSignal< WKeyEvent > & keyWentUp ()
EventSignalenterPressed ()
EventSignalescapePressed ()
EventSignal< WMouseEvent > & clicked ()
EventSignal< WMouseEvent > & doubleClicked ()
EventSignal< WMouseEvent > & mouseWentDown ()
EventSignal< WMouseEvent > & mouseWentUp ()
EventSignal< WMouseEvent > & mouseWentOut ()
EventSignal< WMouseEvent > & mouseWentOver ()
EventSignal< WMouseEvent > & mouseMoved ()
EventSignal< WMouseEvent > & mouseDragged ()
EventSignal< WMouseEvent > & mouseWheel ()
EventSignal< WTouchEvent > & touchStarted ()
EventSignal< WTouchEvent > & touchEnded ()
EventSignal< WTouchEvent > & touchMoved ()
EventSignal< WGestureEvent > & gestureStarted ()
EventSignal< WGestureEvent > & gestureChanged ()
EventSignal< WGestureEvent > & gestureEnded ()
void setDraggable (const std::string &mimeType, WWidget *dragWidget=0, bool isDragWidgetOnly=false, WObject *sourceWidget=0)
void setMouseOverDelay (int delay)
int mouseOverDelay () const
virtual void load ()
virtual bool isEnabled () const
 WWebWidget (WContainerWidget *parent=0)
virtual void setPositionScheme (PositionScheme scheme)
virtual PositionScheme positionScheme () const
virtual void setOffsets (const WLength &offset, WFlags< Side > sides=All)
virtual WLength offset (Side s) const
virtual void resize (const WLength &width, const WLength &height)
virtual WLength width () const
virtual WLength height () const
virtual void setMinimumSize (const WLength &width, const WLength &height)
virtual WLength minimumWidth () const
virtual WLength minimumHeight () const
virtual void setMaximumSize (const WLength &width, const WLength &height)
virtual WLength maximumWidth () const
virtual WLength maximumHeight () const
virtual void setLineHeight (const WLength &height)
virtual WLength lineHeight () const
virtual void setFloatSide (Side s)
virtual Side floatSide () const
virtual void setClearSides (WFlags< Side > sides)
virtual WFlags< SideclearSides () const
virtual void setMargin (const WLength &margin, WFlags< Side > sides=All)
virtual WLength margin (Side side) const
virtual void setHiddenKeepsGeometry (bool enabled)
virtual bool hiddenKeepsGeometry () const
virtual void setHidden (bool hidden, const WAnimation &animation=WAnimation())
virtual bool isHidden () const
virtual bool isVisible () const
virtual void setDisabled (bool disabled)
virtual bool isDisabled () const
virtual void setPopup (bool popup)
virtual bool isPopup () const
virtual void setInline (bool isInline)
virtual bool isInline () const
virtual void setDecorationStyle (const WCssDecorationStyle &style)
virtual WCssDecorationStyledecorationStyle ()
virtual void setStyleClass (const WString &styleClass)
virtual WString styleClass () const
virtual void addStyleClass (const WString &styleClass, bool force=false)
virtual void removeStyleClass (const WString &styleClass, bool force=false)
virtual void setVerticalAlignment (AlignmentFlag alignment, const WLength &length=WLength())
virtual AlignmentFlag verticalAlignment () const
virtual WLength verticalAlignmentLength () const
virtual void setToolTip (const WString &text, TextFormat textFormat=PlainText)
virtual WString toolTip () const
virtual void refresh ()
virtual void setAttributeValue (const std::string &name, const WString &value)
virtual WString attributeValue (const std::string &name) const
virtual void setJavaScriptMember (const std::string &name, const std::string &value)
virtual std::string javaScriptMember (const std::string &name) const
virtual void callJavaScriptMember (const std::string &name, const std::string &args)
virtual bool loaded () const
virtual void setTabIndex (int index)
virtual int tabIndex () const
virtual void setId (const std::string &id)
virtual WWidgetfind (const std::string &name)
virtual void setSelectable (bool selectable)
virtual void doJavaScript (const std::string &javascript)
virtual const std::string id () const
void setLoadLaterWhenInvisible (bool)
const std::vector< WWidget * > & children () const
SignalchildrenChanged ()
bool isRendered () const
virtual ~WWidget ()
WWidgetparent () const
void setWidth (const WLength &width)
void setHeight (const WLength &height)
virtual void positionAt (const WWidget *widget, Orientation orientation=Vertical)
virtual void toggleStyleClass (const WString &styleClass, bool add, bool force=false)
std::string jsRef () const
virtual void acceptDrops (const std::string &mimeType, const WString &hoverStyleClass=WString())
virtual void stopAcceptDrops (const std::string &mimeType)
virtual void htmlText (std::ostream &out)
void hide ()
void animateHide (const WAnimation &animation)
void show ()
void animateShow (const WAnimation &animation)
void enable ()
void disable ()
bool layoutSizeAware () const
 WObject (WObject *parent=0)
virtual ~WObject ()
void setObjectName (const std::string &name)
virtual std::string objectName () const
void resetLearnedSlots ()
void resetLearnedSlot (void(T::*method)())
WStatelessSlot * implementStateless (void(T::*method)())
WStatelessSlot * implementStateless (void(T::*method)(), void(T::*undoMethod)())
WStatelessSlot * implementJavaScript (void(T::*method)(), const std::string &jsCode)
void addChild (WObject *child)

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::WTreeViewexampleView_
SourceViewsourceView_
std::string deployPath_
std::string examplesRoot_
std::string examplesType_
Wt::WStandardItemModelmodel_

Additional Inherited Members

- Public Types inherited from Wt::WContainerWidget
enum  Overflow
- Static Public Member Functions inherited from Wt::WContainerWidget
static WString escapeText (const WString &text, bool newlinesToo=false)
static std::string & escapeText (std::string &text, bool newlinestoo=false)
static bool removeScript (WString &text)
static std::string jsStringLiteral (const std::string &v, char delimiter= '\'')
- Public Attributes inherited from Wt::WContainerWidget
 OverflowVisible
 OverflowAuto
 OverflowHidden
 OverflowScroll
- Protected Member Functions inherited from Wt::WContainerWidget
virtual void propagateSetEnabled (bool enabled)
- Static Protected Member Functions inherited from Wt::WContainerWidget
static WObjectsender ()

Detailed Description

A simple widget to visualise a set of example source files.

Definition at line 21 of file ExampleSourceViewer.h.

Constructor & Destructor Documentation

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
}

Member Function Documentation

void ExampleSourceViewer::cppTraverseDir ( Wt::WStandardItem parent,
const boost::filesystem::path &  path 
)
private

Definition at line 192 of file ExampleSourceViewer.C.

{
static const char *supportedFiles[] = {
".C", ".cpp", ".h", ".css", ".xml", ".png", ".gif", ".csv", ".ico", 0
};
FileItem* dir = new FileItem("/icons/yellow-folder-open.png", filename(path),
"");
parent->appendRow(dir);
parent = dir;
try {
std::set<fs::path> paths;
fs::directory_iterator end_itr;
for (fs::directory_iterator i(path); i != end_itr; ++i)
paths.insert(*i);
std::vector<FileItem*> classes, files;
std::vector<fs::path> dirs;
while (!paths.empty()) {
fs::path p = *paths.begin();
paths.erase(p);
// skip symbolic links and other files
if (fs::is_symlink(p))
continue;
// skip files with an extension we do not want to handle
if (fs::is_regular(p)) {
std::string ext = fs::extension(p);
bool supported = false;
for (const char **s = supportedFiles; *s != 0; ++s)
if (*s == ext) {
supported = true;
break;
}
if (!supported)
continue;
}
// see if we have one file of a class (.C, .h)
fs::path companion = getCompanion(p);
if (!companion.empty()) {
std::set<fs::path>::iterator it_companion = paths.find(companion);
if (it_companion != paths.end()) {
std::string className = stem(p);
escapeText(className);
std::string label = "<i>class</i> " + className;
FileItem *classItem =
new FileItem("/icons/cppclass.png", label, std::string());
classItem->setFlags(classItem->flags() | ItemIsXHTMLText);
FileItem *header = new FileItem("/icons/document.png", filename(p),
p.string());
FileItem *cpp = new FileItem("/icons/document.png",
filename(*it_companion),
(*it_companion).string());
classItem->appendRow(header);
classItem->appendRow(cpp);
classes.push_back(classItem);
paths.erase(it_companion);
} else {
FileItem *file = new FileItem("/icons/document.png", filename(p),
p.string());
files.push_back(file);
}
} else if (fs::is_directory(p)) {
dirs.push_back(p);
} else {
FileItem *file = new FileItem("/icons/document.png", filename(p),
p.string());
files.push_back(file);
}
}
std::sort(dirs.begin(), dirs.end(), comparePaths);
for (unsigned int i = 0; i < classes.size(); i++)
parent->appendRow(classes[i]);
for (unsigned int i = 0; i < files.size(); i++)
parent->appendRow(files[i]);
for (unsigned int i = 0; i < dirs.size(); i++)
cppTraverseDir(parent, dirs[i]);
} catch (fs::filesystem_error& e) {
std::cerr << e.what() << std::endl;
}
}
void ExampleSourceViewer::handlePathChange ( )
private

Definition at line 84 of file ExampleSourceViewer.C.

{
WApplication *app = wApp;
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

Definition at line 322 of file ExampleSourceViewer.C.

{
FileItem* dir = new FileItem("/icons/yellow-folder-open.png", filename(path),
"");
parent->appendRow(dir);
parent = dir;
std::vector<fs::path> files, dirs;
fs::directory_iterator end_itr;
for (fs::directory_iterator i(path); i != end_itr; ++i) {
fs::path p = *i;
if (fs::is_directory(p)) {
if (filename(p) == "src") {
FileItem* dir = new FileItem("/icons/package-folder-open.png",
filename(p), "");
parent->appendRow(dir);
javaTraversePackages(dir, p, "");
} else
dirs.push_back(p);
} else {
files.push_back(p);
}
}
std::sort(dirs.begin(), dirs.end(), comparePaths);
std::sort(files.begin(), files.end(), comparePaths);
for (unsigned int i = 0; i < dirs.size(); i++)
javaTraverseDir(parent, dirs[i]);
for (unsigned int i = 0; i < files.size(); i++) {
FileItem *file = new FileItem("/icons/document.png", filename(files[i]),
files[i].string());
parent->appendRow(file);
}
}
void ExampleSourceViewer::javaTraversePackages ( Wt::WStandardItem parent,
const boost::filesystem::path &  srcPath,
const std::string  packageName 
)
private

Definition at line 288 of file ExampleSourceViewer.C.

{
fs::directory_iterator end_itr;
FileItem *packageItem = 0;
for (fs::directory_iterator i(srcPath); i != end_itr; ++i) {
fs::path p = *i;
if (fs::is_regular(p)) {
if (!packageItem) {
packageItem = new FileItem("/icons/package.png", packageName, "");
parent->appendRow(packageItem);
}
FileItem *file = new FileItem("/icons/javaclass.png", filename(p),
p.string());
packageItem->appendRow(file);
}
}
for (fs::directory_iterator i(srcPath); i != end_itr; ++i) {
fs::path p = *i;
if (fs::is_directory(p)) {
std::string pn = packageName;
if (!pn.empty())
pn += ".";
pn += filename(p);
javaTraversePackages(parent, p, pn);
}
}
}
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") {
} else if (examplesType_ == "JAVA") {
}
WApplication::instance()->setTitle(tr("srcview.title." + example));
WText *title =
new WText(tr("srcview.title." + examplesType_ + "." + example));
exampleView_->resize(300, WLength::Auto);
exampleView_->setSelectionMode(SingleSelection);
sourceView_->setStyleClass("source-view");
/*
* Expand path to first file, to show something in the source viewer
*/
do {
if (w->rowCount() > 0)
w = w->child(0);
else {
w = 0;
}
} while (w);
WVBoxLayout *topLayout = new WVBoxLayout();
topLayout->addWidget(title);
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);
}

Member Data Documentation

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.

Wt::WStandardItemModel* ExampleSourceViewer::model_
private

Definition at line 38 of file ExampleSourceViewer.h.

SourceView* ExampleSourceViewer::sourceView_
private

Definition at line 32 of file ExampleSourceViewer.h.


The documentation for this class was generated from the following files:

Generated on Tue Oct 30 2012 for the C++ Web Toolkit (Wt) by doxygen 1.8.1.2