Hey Koen,
The better test case in the attachment.
Regardless of, whether you like idea of disabling internal path
participation
for individual menu item by invoking setPathComponent(""), please, make
WMenuItem::setPathComponent() virtual.
// The bug test case.
//
// Proposed behaviour:
// item "More" should not lead to change internal path.
// either "Logout"/"Login" items should not lead to change internal path.
//
// Gdb run command: run --docroot . --http-address 0.0.0.0 --http-port 8888
#include <Wt/WApplication>
#include <Wt/WMenu>
#include <Wt/WPopupMenu>
#include <Wt/WMenuItem>
#include <Wt/WText>
#include <Wt/WStackedWidget>
namespace {
using namespace Wt;
class App : public WApplication {
public:
App(const WEnvironment& env);
private:
void change_user(bool logged_out);
WMenu* make_menu(bool logged_out);
WMenu* menu_;
};
void App::change_user(bool logged_out)
{
if (menu_)
delete menu_->contentsStack();
delete menu_;
menu_ = make_menu(logged_out);
root()->addWidget(menu_);
root()->addWidget(menu_->contentsStack());
}
WMenu* App::make_menu(bool logged_out)
{
WMenu* const m = new WMenu(new WStackedWidget);
m->setInternalPathEnabled("/");
m->addItem("Search", new WText("Search"));
m->addItem("Pictures", new WText("Pictures"));
WMenuItem* const mi_without_internal_path = new WMenuItem("Just item");
mi_without_internal_path->setPathComponent(""); // This should disable internal path participation.
m->addItem(mi_without_internal_path);
// Submenu "More"
Wt::WPopupMenu* const pm = new WPopupMenu(m->contentsStack());
m->addMenu("More", pm); // This should not lead to change internal path.
// Menuitem "Logout" / "Login"
if (logged_out) {
WMenuItem* const mi = new WMenuItem("Login");
mi->setPathComponent(""); // This should disable internal path participation.
mi->triggered().connect(boost::bind(&App::change_user, this, false));
pm->addItem(mi);
} else {
WMenuItem* const mi = new WMenuItem("Logout");
mi->setPathComponent(""); // This should disable internal path participation.
mi->triggered().connect(boost::bind(&App::change_user, this, true));
pm->addItem(mi);
}
return m;
}
App::App(const Wt::WEnvironment& env)
: WApplication(env)
{
root()->addWidget(menu_ = make_menu(true));
root()->addWidget(menu_->contentsStack());
}
Wt::WApplication* createApp(const Wt::WEnvironment& env)
{
return new App(env);
}
} // namespace
int main(int argc, char* argv[])
{
return Wt::WRun(argc, argv, createApp);
}
------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest