Wt examples  3.7.1
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. More...
 
- Public Member Functions inherited from Wt::WContainerWidget
 WContainerWidget ()
 
 ~WContainerWidget ()
 
void setLayout (std::unique_ptr< WLayout > layout)
 
Layout * setLayout (std::unique_ptr< Layout > layout)
 
WLayoutlayout () const
 
virtual void addWidget (std::unique_ptr< WWidget > widget)
 
Widget * addWidget (std::unique_ptr< Widget > widget)
 
Widget * addNew (Args &&...args)
 
virtual void insertBefore (std::unique_ptr< WWidget > widget, WWidget *before)
 
Widget * insertBefore (std::unique_ptr< Widget > widget, WWidget *before)
 
virtual void insertWidget (int index, std::unique_ptr< WWidget > widget)
 
Widget * insertWidget (int index, std::unique_ptr< Widget > widget)
 
Widget * insertNew (int index, Args &&...args)
 
virtual std::unique_ptr< WWidgetremoveWidget (WWidget *widget) override
 
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=AllSides)
 
WLength padding (Side side) const
 
WFlags< AlignmentFlagcontentAlignment () const
 
void setOverflow (Overflow overflow, WFlags< Orientation > orientation=(Orientation::Horizontal|Orientation::Vertical))
 
void setList (bool list, bool ordered=false)
 
bool isList () const
 
bool isUnorderedList () const
 
bool isOrderedList () const
 
EventSignal< WScrollEvent > & scrolled ()
 
int scrollTop () const
 
int scrollLeft () const
 
- Public Member Functions inherited from Wt::WInteractWidget
 WInteractWidget ()
 
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=nullptr, bool isDragWidgetOnly=false, WObject *sourceWidget=nullptr)
 
void unsetDraggable ()
 
void setMouseOverDelay (int delay)
 
int mouseOverDelay () const
 
virtual void setPopup (bool popup) override
 
virtual void load () override
 
virtual bool isEnabled () const override
 
- Public Member Functions inherited from Wt::WWebWidget
 WWebWidget ()
 
virtual std::vector< WWidget *> children () const override
 
SignalchildrenChanged ()
 
virtual void setPositionScheme (PositionScheme scheme) override
 
virtual PositionScheme positionScheme () const override
 
virtual void setOffsets (const WLength &offset, WFlags< Side > sides=AllSides) override
 
virtual WLength offset (Side s) const override
 
virtual void resize (const WLength &width, const WLength &height) override
 
virtual WLength width () const override
 
virtual WLength height () const override
 
virtual void setMinimumSize (const WLength &width, const WLength &height) override
 
virtual WLength minimumWidth () const override
 
virtual WLength minimumHeight () const override
 
virtual void setMaximumSize (const WLength &width, const WLength &height) override
 
virtual WLength maximumWidth () const override
 
virtual WLength maximumHeight () const override
 
virtual void setLineHeight (const WLength &height) override
 
virtual WLength lineHeight () const override
 
virtual void setFloatSide (Side s) override
 
virtual Side floatSide () const override
 
virtual void setClearSides (WFlags< Side > sides) override
 
virtual WFlags< SideclearSides () const override
 
virtual void setMargin (const WLength &margin, WFlags< Side > sides=AllSides) override
 
virtual WLength margin (Side side) const override
 
virtual void setHiddenKeepsGeometry (bool enabled) override
 
virtual bool hiddenKeepsGeometry () const override
 
virtual void setHidden (bool hidden, const WAnimation &animation=WAnimation()) override
 
virtual bool isHidden () const override
 
virtual bool isVisible () const override
 
virtual void setDisabled (bool disabled) override
 
virtual bool isDisabled () const override
 
virtual bool isPopup () const override
 
virtual void setInline (bool isInline) override
 
virtual bool isInline () const override
 
virtual void setDecorationStyle (const WCssDecorationStyle &style) override
 
virtual WCssDecorationStyledecorationStyle () override
 
virtual void setStyleClass (const WString &styleClass) override
 
virtual WString styleClass () const override
 
virtual void addStyleClass (const WString &styleClass, bool force=false) override
 
virtual void removeStyleClass (const WString &styleClass, bool force=false) override
 
virtual bool hasStyleClass (const WString &styleClass) const override
 
virtual void setVerticalAlignment (AlignmentFlag alignment, const WLength &length=WLength()) override
 
virtual AlignmentFlag verticalAlignment () const override
 
virtual WLength verticalAlignmentLength () const override
 
virtual void setToolTip (const WString &text, TextFormat textFormat=TextFormat::Plain) override
 
virtual void setDeferredToolTip (bool enable, TextFormat textFormat=TextFormat::Plain) override
 
virtual WString toolTip () const override
 
virtual void refresh () override
 
virtual void setAttributeValue (const std::string &name, const WString &value) override
 
virtual WString attributeValue (const std::string &name) const override
 
virtual void setJavaScriptMember (const std::string &name, const std::string &value) override
 
virtual std::string javaScriptMember (const std::string &name) const override
 
virtual void callJavaScriptMember (const std::string &name, const std::string &args) override
 
virtual bool loaded () const override
 
virtual void setId (const std::string &id) override
 
virtual WWidgetfind (const std::string &name) override
 
virtual WWidgetfindById (const std::string &id) override
 
virtual void setSelectable (bool selectable) override
 
virtual void doJavaScript (const std::string &javascript) override
 
virtual const std::string id () const override
 
void setLoadLaterWhenInvisible (bool)
 
std::string htmlTagName () const
 
void setHtmlTagName (const std::string &tag)
 
virtual void setCanReceiveFocus (bool enabled) override
 
virtual bool canReceiveFocus () const override
 
virtual bool setFirstFocus () override
 
virtual void setFocus (bool focus) override
 
virtual bool hasFocus () const override
 
virtual void setTabIndex (int index) override
 
virtual int tabIndex () const override
 
EventSignalblurred ()
 
EventSignalfocussed ()
 
virtual bool scrollVisibilityEnabled () const final override
 
virtual void setScrollVisibilityEnabled (bool enabled) final override
 
virtual int scrollVisibilityMargin () const final override
 
virtual void setScrollVisibilityMargin (int margin) final override
 
virtual Signal< bool > & scrollVisibilityChanged () final override
 
virtual bool isScrollVisible () const final override
 
virtual void setThemeStyleEnabled (bool enabled) final override
 
virtual bool isThemeStyleEnabled () const final override
 
virtual void setObjectName (const std::string &name) override
 
- Public Member Functions inherited from Wt::WWidget
virtual ~WWidget ()
 
WWidgetparent () const
 
std::unique_ptr< Widget > removeWidget (Widget *widget)
 
std::unique_ptr< WWidgetremoveFromParent ()
 
void setWidth (const WLength &width)
 
void setHeight (const WLength &height)
 
virtual void positionAt (const WWidget *widget, Orientation orientation=Orientation::Vertical)
 
virtual void toggleStyleClass (const WString &styleClass, bool add, bool force=false)
 
std::string jsRef () const
 
void setFocus ()
 
virtual void acceptDrops (const std::string &mimeType, const WString &hoverStyleClass=WString())
 
virtual void stopAcceptDrops (const std::string &mimeType)
 
virtual void htmlText (std::ostream &out)
 
bool isRendered () const
 
void hide ()
 
void animateHide (const WAnimation &animation)
 
void show ()
 
void animateShow (const WAnimation &animation)
 
void enable ()
 
void disable ()
 
bool layoutSizeAware () const
 
- Public Member Functions inherited from Wt::WObject
void addChild (std::unique_ptr< WObject > child)
 
Child * addChild (std::unique_ptr< Child > child)
 
std::unique_ptr< WObjectremoveChild (WObject *child)
 
std::unique_ptr< Child > removeChild (Child *child)
 
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)())
 
void isNotStateless ()
 
WStatelessSlot * implementJavaScript (void(T::*method)(), const std::string &jsCode)
 
- Public Member Functions inherited from Wt::Core::observable
 observable () noexcept
 
virtual ~observable ()
 
auto bindSafe (void(C::*method)(Args...)) noexcept
 
auto bindSafe (void(C::*method)(Args...) const) const noexcept
 
auto bindSafe (const Function &function) noexcept
 

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. More...
 
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::WObject
typedef void(WObject::* Method) ()
 
- Static Public Member Functions inherited from Wt::WWebWidget
static std::string jsStringLiteral (const std::string &v, char delimiter='\'')
 
- Static Public Member Functions inherited from Wt::WWidget
static WString tr (const char *key)
 
- Protected Member Functions inherited from Wt::WInteractWidget
virtual void propagateSetEnabled (bool enabled) override
 
- Protected Member Functions inherited from Wt::WWebWidget
virtual void enableAjax () override
 
virtual WStatelessSlot * getStateless (Method method) override
 
virtual void render (WFlags< RenderFlag > flags) override
 
- Protected Member Functions inherited from Wt::WWidget
void setLayoutSizeAware (bool sizeAware)
 
virtual void layoutSizeChanged (int width, int height)
 
 WWidget ()
 
virtual void dropEvent (WDropEvent dropEvent)
 
virtual int boxPadding (Orientation orientation) const
 
virtual int boxBorder (Orientation orientation) const
 
void scheduleRender (WFlags< RepaintFlag > flags=None)
 

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::ExampleSourceViewer ( const std::string &  deployPath,
const std::string &  examplesRoot,
const std::string &  examplesType 
)

Constructor.

Definition at line 71 of file ExampleSourceViewer.C.

74  : deployPath_(deployPath),
75  examplesRoot_(examplesRoot),
76  examplesType_(examplesType)
77 {
78  wApp->internalPathChanged().connect
80 
82 }

Member Function Documentation

◆ cppTraverseDir()

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

Definition at line 194 of file ExampleSourceViewer.C.

196 {
197  static const char *supportedFiles[] = {
198  ".C", ".cpp", ".h", ".css", ".xml", ".png", ".gif", ".csv", ".ico", 0
199  };
200 
201  FileItem* dir = new FileItem("/icons/yellow-folder-open.png", filename(path),
202  "");
203  parent->appendRow(dir);
204  parent = dir;
205  try {
206  std::set<fs::path> paths;
207 
208  fs::directory_iterator end_itr;
209  for (fs::directory_iterator i(path); i != end_itr; ++i)
210  paths.insert(*i);
211 
212  std::vector<FileItem*> classes, files;
213  std::vector<fs::path> dirs;
214 
215  while (!paths.empty()) {
216  fs::path p = *paths.begin();
217  paths.erase(p);
218 
219  // skip symbolic links and other files
220  if (fs::is_symlink(p))
221  continue;
222 
223  // skip files with an extension we do not want to handle
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)
228  if (*s == ext) {
229  supported = true;
230  break;
231  }
232 
233  if (!supported)
234  continue;
235  }
236 
237  // see if we have one file of a class (.C, .h)
238  fs::path companion = getCompanion(p);
239  if (!companion.empty()) {
240  std::set<fs::path>::iterator it_companion = paths.find(companion);
241 
242  if (it_companion != paths.end()) {
243  std::string className = stem(p);
244  escapeText(className);
245  std::string label = "<i>class</i> " + className;
246 
247  FileItem *classItem =
248  new FileItem("/icons/cppclass.png", label, std::string());
249  classItem->setFlags(classItem->flags() | ItemIsXHTMLText);
250 
251  FileItem *header = new FileItem("/icons/document.png", filename(p),
252  p.string());
253  FileItem *cpp = new FileItem("/icons/document.png",
254  filename(*it_companion),
255  (*it_companion).string());
256  classItem->appendRow(header);
257  classItem->appendRow(cpp);
258 
259  classes.push_back(classItem);
260  paths.erase(it_companion);
261  } else {
262  FileItem *file = new FileItem("/icons/document.png", filename(p),
263  p.string());
264  files.push_back(file);
265  }
266  } else if (fs::is_directory(p)) {
267  dirs.push_back(p);
268  } else {
269  FileItem *file = new FileItem("/icons/document.png", filename(p),
270  p.string());
271  files.push_back(file);
272  }
273  }
274 
275  std::sort(dirs.begin(), dirs.end(), comparePaths);
276 
277  for (unsigned int i = 0; i < classes.size(); i++)
278  parent->appendRow(classes[i]);
279 
280  for (unsigned int i = 0; i < files.size(); i++)
281  parent->appendRow(files[i]);
282 
283  for (unsigned int i = 0; i < dirs.size(); i++)
284  cppTraverseDir(parent, dirs[i]);
285  } catch (fs::filesystem_error& e) {
286  std::cerr << e.what() << std::endl;
287  }
288 }
static std::string stem(const fs::path &p)
WFlags< ItemFlag > flags() const
WStandardItem which stores a file.
Definition: FileItem.h:28
void appendRow(std::vector< std::unique_ptr< WStandardItem > > items)
void cppTraverseDir(Wt::WStandardItem *parent, const boost::filesystem::path &path)
static std::string filename(const fs::path &p)
static bool comparePaths(const fs::path &p1, const fs::path &p2)
void setFlags(WFlags< ItemFlag > flags)
static fs::path getCompanion(const fs::path &path)

◆ handlePathChange()

void ExampleSourceViewer::handlePathChange ( )
private

Definition at line 84 of file ExampleSourceViewer.C.

85 {
86  WApplication *app = wApp;
87 
88  if (app->internalPathMatches(deployPath_)) {
89  std::string example = app->internalPathNextPart(deployPath_);
90 
91  if (example.find("..") != std::string::npos
92  || example.find('/') != std::string::npos
93  || example.find('\\') != std::string::npos) {
94  app->setInternalPathValid(false);
95  setExample("INVALID_DIR", "INVALID");
96  } else
97  setExample(examplesRoot_ + example, example);
98  }
99 }
void setExample(const std::string &exampleDir, const std::string &example)
bool internalPathMatches(const std::string &path) const
void setInternalPathValid(bool valid)
std::string internalPathNextPart(const std::string &path) const

◆ javaTraverseDir()

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

Definition at line 324 of file ExampleSourceViewer.C.

326 {
327  FileItem* dir = new FileItem("/icons/yellow-folder-open.png", filename(path),
328  "");
329  parent->appendRow(dir);
330  parent = dir;
331 
332  std::vector<fs::path> files, dirs;
333 
334  fs::directory_iterator end_itr;
335  for (fs::directory_iterator i(path); i != end_itr; ++i) {
336  fs::path p = *i;
337  if (fs::is_directory(p)) {
338  if (filename(p) == "src") {
339  FileItem* dir = new FileItem("/icons/package-folder-open.png",
340  filename(p), "");
341  parent->appendRow(dir);
342  javaTraversePackages(dir, p, "");
343  } else
344  dirs.push_back(p);
345  } else {
346  files.push_back(p);
347  }
348  }
349 
350  std::sort(dirs.begin(), dirs.end(), comparePaths);
351  std::sort(files.begin(), files.end(), comparePaths);
352 
353  for (unsigned int i = 0; i < dirs.size(); i++)
354  javaTraverseDir(parent, dirs[i]);
355 
356  for (unsigned int i = 0; i < files.size(); i++) {
357  FileItem *file = new FileItem("/icons/document.png", filename(files[i]),
358  files[i].string());
359  parent->appendRow(file);
360  }
361 }
WStandardItem which stores a file.
Definition: FileItem.h:28
void javaTraverseDir(Wt::WStandardItem *parent, const boost::filesystem::path &path)
void appendRow(std::vector< std::unique_ptr< WStandardItem > > items)
void javaTraversePackages(Wt::WStandardItem *parent, const boost::filesystem::path &srcPath, const std::string packageName)
static std::string filename(const fs::path &p)
static bool comparePaths(const fs::path &p1, const fs::path &p2)

◆ 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.

293 {
294  fs::directory_iterator end_itr;
295 
296  FileItem *packageItem = 0;
297  for (fs::directory_iterator i(srcPath); i != end_itr; ++i) {
298  fs::path p = *i;
299  if (fs::is_regular(p)) {
300  if (!packageItem) {
301  packageItem = new FileItem("/icons/package.png", packageName, "");
302  parent->appendRow(packageItem);
303  }
304 
305  FileItem *file = new FileItem("/icons/javaclass.png", filename(p),
306  p.string());
307  packageItem->appendRow(file);
308  }
309  }
310 
311  for (fs::directory_iterator i(srcPath); i != end_itr; ++i) {
312  fs::path p = *i;
313  if (fs::is_directory(p)) {
314  std::string pn = packageName;
315  if (!pn.empty())
316  pn += ".";
317  pn += filename(p);
318 
319  javaTraversePackages(parent, p, pn);
320  }
321  }
322 }
WStandardItem which stores a file.
Definition: FileItem.h:28
void appendRow(std::vector< std::unique_ptr< WStandardItem > > items)
void javaTraversePackages(Wt::WStandardItem *parent, const boost::filesystem::path &srcPath, const std::string packageName)
static std::string filename(const fs::path &p)

◆ setExample()

void ExampleSourceViewer::setExample ( const std::string &  exampleDir,
const std::string &  example 
)
private

Definition at line 101 of file ExampleSourceViewer.C.

103 {
104  clear();
105 
106  bool exists = false;
107  try {
108  exists = fs::exists(exampleDir);
109  } catch (std::exception&) {
110  }
111 
112  if (!exists) {
113  WApplication::instance()->setInternalPathValid(false);
114  addWidget(new WText("No such example: " + exampleDir));
115  return;
116  }
117 
118  model_ = new WStandardItemModel(0, 1, this);
119  if (examplesType_ == "CPP") {
120  cppTraverseDir(model_->invisibleRootItem(), exampleDir);
121  } else if (examplesType_ == "JAVA") {
122  javaTraverseDir(model_->invisibleRootItem(), exampleDir);
123  }
124 
125  WApplication::instance()->setTitle(tr("srcview.title." + example));
126  WText *title =
127  new WText(tr("srcview.title." + examplesType_ + "." + example));
128  title->setInternalPathEncoding(true);
129 
130  exampleView_ = new WTreeView();
132  exampleView_->resize(300, WLength::Auto);
136  exampleView_->setSelectionMode(SingleSelection);
140 
144  sourceView_->setStyleClass("source-view");
145 
146  /*
147  * Expand path to first file, to show something in the source viewer
148  */
149  WStandardItem *w = model_->item(0);
150  do {
151  exampleView_->setExpanded(w->index(), true);
152  if (w->rowCount() > 0)
153  w = w->child(0);
154  else {
156  w = 0;
157  }
158  } while (w);
159 
160  WVBoxLayout *topLayout = new WVBoxLayout();
161  topLayout->addWidget(title);
162 
163  WHBoxLayout *gitLayout = new WHBoxLayout();
164  gitLayout->addWidget(exampleView_, 0);
165  gitLayout->addWidget(sourceView_, 1);
166  topLayout->addLayout(gitLayout, 1);
167  gitLayout->setResizable(0);
168 
169  /*
170  * FIXME, in plain HTML mode, we should set a minimum size to the source
171  * view, and remove this in enableAjax() ?
172  */
173  // sourceView_->setHeight("100%");
174 
175  setLayout(topLayout);
176  setStyleClass("maindiv");
177 }
static const int FileNameRole
Definition: FileItem.h:33
void setLayout(std::unique_ptr< WLayout > layout)
Wt::WStandardItemModel * model_
WStandardItem * item(int row, int column=0) const
virtual void setStyleClass(const WString &styleClass) override
static WString tr(const char *key)
void showFile()
Displayed the currently selected file.
void addLayout(std::unique_ptr< WLayout > layout, int stretch, WFlags< AlignmentFlag > alignment)
void addWidget(std::unique_ptr< WWidget > widget, int stretch, WFlags< AlignmentFlag > alignment)
static const int FilePathRole
Definition: FileItem.h:32
virtual void resize(const WLength &width, const WLength &height) override
void setSelectionMode(SelectionMode mode)
Wt::WTreeView * exampleView_
WStandardItem * child(int row, int column=0) const
virtual void setAlternatingRowColors(bool enable) override
virtual void setHeaderHeight(const WLength &height) override
virtual void clear()
static const int ContentsRole
Definition: FileItem.h:31
Signal & selectionChanged()
int rowCount() const
virtual void setModel(const std::shared_ptr< WAbstractItemModel > &model) override
void javaTraverseDir(Wt::WStandardItem *parent, const boost::filesystem::path &path)
void setInternalPathEncoding(bool enabled)
void setResizable(int index, bool enabled=true, const WLength &initialSize=WLength::Auto)
void expandToDepth(int depth)
View class for source code.
Definition: SourceView.h:26
void cppTraverseDir(Wt::WStandardItem *parent, const boost::filesystem::path &path)
void select(const WModelIndex &index, SelectionFlag option=SelectionFlag::Select)
void setExpanded(const WModelIndex &, bool expanded)
void setSortingEnabled(bool enabled)
virtual Wt::Signals::connection connect(WObject *target, WObject::Method method) override
virtual void addWidget(std::unique_ptr< WWidget > widget)
WStandardItem * invisibleRootItem() const
WModelIndex index() const

◆ showFile()

void ExampleSourceViewer::showFile ( )
private

Displayed the currently selected file.

Definition at line 365 of file ExampleSourceViewer.C.

365  {
366  if (exampleView_->selectedIndexes().empty())
367  return;
368 
369  WModelIndex selected = *exampleView_->selectedIndexes().begin();
370 
371  // expand a folder when clicked
372  if (exampleView_->model()->rowCount(selected) > 0
373  && !exampleView_->isExpanded(selected))
374  exampleView_->setExpanded(selected, true);
375 
376  // (for a file,) load data in source viewer
377  sourceView_->setIndex(selected);
378 }
bool isExpanded(const WModelIndex &index) const
Wt::WTreeView * exampleView_
std::shared_ptr< WAbstractItemModel > model() const
WModelIndexSet selectedIndexes() const
void setExpanded(const WModelIndex &, bool expanded)
bool setIndex(const Wt::WModelIndex &index)
Sets the model index.
Definition: SourceView.C:30

Member Data Documentation

◆ deployPath_

std::string ExampleSourceViewer::deployPath_
private

Definition at line 34 of file ExampleSourceViewer.h.

◆ examplesRoot_

std::string ExampleSourceViewer::examplesRoot_
private

Definition at line 35 of file ExampleSourceViewer.h.

◆ examplesType_

std::string ExampleSourceViewer::examplesType_
private

Definition at line 36 of file ExampleSourceViewer.h.

◆ exampleView_

Wt::WTreeView* ExampleSourceViewer::exampleView_
private

Definition at line 31 of file ExampleSourceViewer.h.

◆ model_

Wt::WStandardItemModel* ExampleSourceViewer::model_
private

Definition at line 38 of file ExampleSourceViewer.h.

◆ sourceView_

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 Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13