Wittyshare  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WsBreadCrumb.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-Today Guy Deleeuw
3  *
4  * See the LICENSE file for terms of use.
5 */
6 
7 #include <boost/filesystem/operations.hpp>
8 //#include <boost/filesystem/exception.hpp>
9 
10 #include <Wt/WStackedWidget>
11 #include <Wt/WTheme>
12 
13 #include <Main/WsApplication.h>
14 
15 #include "WsBreadCrumb.h"
16 
17 using namespace Wt;
18 
20 { }
21 
23 {
24 }
25 
26 
27 
28 
29 
30 
31 WsBreadCrumb::WsBreadCrumb(WContainerWidget* parent)
32  : WContainerWidget(parent), m_pMenu(0), m_bDebug(false)
33 {
34  if ( WString::tr("byObjectStyleSheet").narrow() == "true" )
35  wApp->useStyleSheet(wApp->theme()->resourcesUrl() + "wittyshare/Css/WsBreadcrumb.css");
36  addStyleClass("WsBreadcrumb");
37 }
38 
40 { }
41 
43 {
44  WContainerWidget::load();
45  doPathChanged(wApp->internalPath());
46  wApp->internalPathChanged().connect(SLOT(this, WsBreadCrumb::doPathChanged));
47 }
48 
49 void WsBreadCrumb::setDebugging(bool bDebug)
50 {
51  m_bDebug = bDebug;
52 }
53 
54 void WsBreadCrumb::doPathChanged(std::string newPathOrig)
55 {
56  std::string newPath = newPathOrig;
57  boost::algorithm::replace_all(newPath, "&amp;", "&");
58  clear();
59  m_vBreadCrumb.clear();
60  WsUser* pUser = WsApp->wsUser();
61  NodePtr startNode = pUser->getAccessRoot();
62  breadCrump bc;
63  bc.title = startNode.get()->getDisplayName(true);
64  bc.path = "/";
65  m_vBreadCrumb.push_back(bc);
66  std::string sWithoutPrefix = newPath; //WsApp->WsModules().pathWithoutPrefix(newPath);
67  std::string sPath = "/";
68  boost::filesystem::path myPath(sWithoutPrefix);
69  if ( myPath.string() != sPath )
70  while ( myPath.has_parent_path() ) {
71  breadCrump bc2;
72  NodePtr curNode = startNode.get()->eatPath(myPath.string());
73  if ( curNode ) bc2.title = curNode.get()->getDisplayName(true);
74  else bc2.title = myPath.filename().string();
75  bc2.path = myPath.string();
76  bc2.node = curNode;
77  m_vBreadCrumb.insert(m_vBreadCrumb.begin() + 1, bc2);
78  myPath = myPath.parent_path();
79  if ( myPath.string() == sPath ) break;
80  }
81  Wt::WStackedWidget* contents = new Wt::WStackedWidget();
82  m_pMenu = new Wt::WMenu(contents, Wt::Horizontal);
83  m_pMenu->itemSelected().connect(SLOT(this, WsBreadCrumb::onBreadCrumbSelected));
84  addWidget(m_pMenu);
85  for (int ibc = 0; ibc < m_vBreadCrumb.size(); ++ibc) {
86  WMenuItem* pItem = new WMenuItem(m_vBreadCrumb[ibc].title);
87  // pItem->setLink(WLink(WLink::InternalPath, m_vBreadCrumb[ibc].path));
88  m_pMenu->addItem(pItem);
89  }
90 }
91 
92 void WsBreadCrumb::onBreadCrumbSelected(WMenuItem* pMenuItem)
93 {
94  if ( m_vBreadCrumb[m_pMenu->currentIndex()].path.empty() ) return;
95  if (
96  m_vBreadCrumb[m_pMenu->currentIndex()].node &&
97  m_vBreadCrumb[m_pMenu->currentIndex()].node->isDirectory() &&
98  asString(option("directorySelectable")) == "false"
99  ) return;
100  wApp->setInternalPath(m_vBreadCrumb[m_pMenu->currentIndex()].path, true);
101 }
102 
std::vector< breadCrump > m_vBreadCrumb
Definition: WsBreadCrumb.h:36
WsBreadCrumb(Wt::WContainerWidget *parent=0)
boost::shared_ptr< WsAbstractNode > NodePtr
virtual void load()
void setDebugging(bool bDebug)
void doPathChanged(std::string newPath)
Interface that provides differents methods for accessing the FsTree as well as other features...
Definition: WsUser.h:33
const boost::any & option(const std::string &attribute) const
Get an options value.
Definition: WsOption.cpp:62
#define WsApp
Define a shortcut to the application instance.
Definition: WsApplication.h:62
Wt::WMenu * m_pMenu
Definition: WsBreadCrumb.h:37
NodePtr getAccessRoot()
return the root node of the access tree starting from the root
Definition: WsUser.cpp:50
void onBreadCrumbSelected(Wt::WMenuItem *pMenuItem)