ExampleSourceViewer Class Reference

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

#include <ExampleSourceViewer.h>

Inherits Wt::WContainerWidget.

List of all members.

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

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 67 of file ExampleSourceViewer.C.

00070   : deployPath_(deployPath),
00071     examplesRoot_(examplesRoot),
00072     examplesType_(examplesType)
00073 {
00074   wApp->internalPathChanged().connect
00075     (SLOT(this, ExampleSourceViewer::handlePathChange));
00076 
00077   handlePathChange();
00078 }


Member Function Documentation

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

Definition at line 80 of file ExampleSourceViewer.C.

00081 {
00082   WApplication *app = wApp;
00083 
00084   if (app->internalPathMatches(deployPath_)) {
00085     std::string example = app->internalPathNextPart(deployPath_);
00086 
00087     if (example.find("..") != std::string::npos
00088         || example.find('/') != std::string::npos
00089         || example.find('\\') != std::string::npos)
00090       setExample("INVALID_DIR", "INVALID");
00091     else
00092       setExample(examplesRoot_ + example, example);
00093   }
00094 }

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 96 of file ExampleSourceViewer.C.

00098 {
00099   clear();
00100 
00101   bool exists = false;
00102   try {
00103     exists = fs::exists(exampleDir);
00104   } catch (std::exception&) {
00105   }
00106 
00107   if (!exists) {
00108     addWidget(new WText("No such example: " + exampleDir));
00109     return;
00110   }
00111 
00112   model_ = new WStandardItemModel(0, 1, this);
00113   if (examplesType_ == "CPP") {
00114     cppTraverseDir(model_->invisibleRootItem(), exampleDir);
00115   } else if (examplesType_ == "JAVA") {
00116     javaTraverseDir(model_->invisibleRootItem(), exampleDir);
00117   }
00118 
00119   WApplication::instance()->setTitle(tr("srcview.title." + example));
00120   WText *title = 
00121     new WText(tr("srcview.title." + examplesType_ + "." + example));
00122 
00123   exampleView_ = new WTreeView();
00124   exampleView_->setHeaderHeight(0);
00125   exampleView_->resize(300, 300);
00126   exampleView_->setSortingEnabled(false);
00127   exampleView_->setModel(model_);
00128   exampleView_->expandToDepth(1);
00129   exampleView_->setSelectionMode(SingleSelection);
00130   exampleView_->setAlternatingRowColors(false);
00131   exampleView_->selectionChanged().connect
00132     (SLOT(this, ExampleSourceViewer::showFile));
00133 
00134   sourceView_ = new SourceView(FileItem::FileNameRole, 
00135                                FileItem::ContentsRole,
00136                                FileItem::FilePathRole);
00137   sourceView_->setStyleClass("source-view");
00138 
00139   /*
00140    * Expand path to first file, to show something in the source viewer
00141    */
00142   WStandardItem *w = model_->item(0);
00143   do {
00144     exampleView_->setExpanded(w->index(), true);
00145     if (w->rowCount() > 0)
00146       w = w->child(0);
00147     else {
00148       exampleView_->select(w->index(), Select);
00149       w = 0;
00150     }
00151   } while (w);
00152 
00153   WVBoxLayout *topLayout = new WVBoxLayout();
00154   topLayout->addWidget(title, 0, AlignTop | AlignJustify);
00155 
00156   WHBoxLayout *gitLayout = new WHBoxLayout();
00157   gitLayout->addWidget(exampleView_, 0);
00158   gitLayout->addWidget(sourceView_, 1);
00159   topLayout->addLayout(gitLayout, 1);
00160   gitLayout->setResizable(0);
00161 
00162   setLayout(topLayout);
00163   setStyleClass("maindiv");
00164 }

void ExampleSourceViewer::showFile (  )  [private]

Displayed the currently selected file.

Definition at line 352 of file ExampleSourceViewer.C.

00352                                    {
00353   if (exampleView_->selectedIndexes().empty())
00354     return;
00355 
00356   WModelIndex selected = *exampleView_->selectedIndexes().begin();
00357 
00358   // expand a folder when clicked
00359   if (exampleView_->model()->rowCount(selected) > 0
00360       && !exampleView_->isExpanded(selected))
00361     exampleView_->setExpanded(selected, true);
00362 
00363   // (for a file,) load data in source viewer
00364   sourceView_->setIndex(selected);
00365 }


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.

Definition at line 31 of file ExampleSourceViewer.h.

Definition at line 38 of file ExampleSourceViewer.h.

Definition at line 32 of file ExampleSourceViewer.h.


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

Generated on Thu May 13 05:16:01 2010 for Wt by doxygen 1.6.3