Public Member Functions | Private Member Functions | Private Attributes

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.

  : deployPath_(deployPath),
    examplesRoot_(examplesRoot),
    examplesType_(examplesType)
{
  wApp->internalPathChanged().connect
    (SLOT(this, ExampleSourceViewer::handlePathChange));

  handlePathChange();
}


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.

{
  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 96 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));

  exampleView_ = new WTreeView();
  exampleView_->setHeaderHeight(0);
  exampleView_->resize(300, 300);
  exampleView_->setSortingEnabled(false);
  exampleView_->setModel(model_);
  exampleView_->expandToDepth(1);
  exampleView_->setSelectionMode(SingleSelection);
  exampleView_->setAlternatingRowColors(false);
  exampleView_->selectionChanged().connect
    (SLOT(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);

  setLayout(topLayout);
  setStyleClass("maindiv");
}

void ExampleSourceViewer::showFile (  )  [private]

Displayed the currently selected file.

Definition at line 352 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.

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 Mon Nov 29 2010 08:03:14 for Wt by doxygen 1.7.1