Project

General

Profile

Bug #5889 » TreeViewApplication.C

Daniel Lier, 08/23/2017 12:56 PM

 
1
/*
2
 * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
3
 *
4
 * See the LICENSE file for terms of use.
5
 */
6
#include <Wt/WApplication.h>
7
#include <Wt/WText.h>
8

    
9
#include "TreeViewExample.h"
10

    
11
using namespace Wt;
12

    
13
class TreeViewApplication: public WApplication
14
{
15
public:
16
  TreeViewApplication(const WEnvironment &env):
17
    WApplication(env)
18
  {
19
    std::unique_ptr<TreeViewExample> upWidget = cpp14::make_unique<TreeViewExample>(WString::tr("treeview-introduction"));
20
    pWidget = upWidget.get();
21
    root()->addWidget(std::move(upWidget));
22

    
23
    aboutDrink_ = root()->addWidget(cpp14::make_unique<WText>(""));
24
    internalPathChanged().connect(this, &TreeViewApplication::handlePathChange);
25
    this->handlePathChange();
26

    
27
    this->globalKeyPressed().connect([=]
28
    {
29
      if ( nullptr!=pWidget )
30
        pWidget->update();
31
    });
32
  }
33
private:
34
  WText *aboutDrink_;
35
  TreeViewExample *pWidget;
36

    
37
  void handlePathChange() {
38
    if (internalPathMatches("/drinks/")) {
39
      std::string drink = internalPathNextPart("/drinks/");
40
      aboutDrink_->setText(WString::tr("drink-" + drink));
41
    }
42
  }
43
};
44

    
45
std::unique_ptr<WApplication> createApplication(const WEnvironment& env)
46
{
47
  auto app = cpp14::make_unique<TreeViewApplication>(env);
48
  app->setTitle("WTreeView example");
49
  app->messageResourceBundle().use(WApplication::appRoot() + "drinks");
50
  app->styleSheet().addRule("button", "margin: 2px");
51
  app->useStyleSheet("wt.css");
52
  
53
  return std::move(app);
54
}
55

    
56
int main(int argc, char **argv)
57
{
58
  return WRun(argc, argv, &createApplication);
59
}
(1-1/3)