Hey,
1. It would be nice to make WMenu::select(int, bool) protected since it's
useful when
overriding WMenu::internalPathChanged(const std::string&).
2. Please note WMenu::handleInternalPathChange(const std::string&) which
looks as:
void WMenu::handleInternalPathChange(const std::string& path)
{
if (!parentItem_)
internalPathChanged(path);
}
should be rewritten to:
void WMenu::handleInternalPathChange(const std::string& path)
{
internalPathChanged(path);
}
because currently it's not possible to select an item of the
WPopupMenu which participates in the internal path change handling
when this popup menu attached to the WMenuItem which *not* participates
in it by specifying the URL manually in the browser bar.
For example, I have a menu which I want to participate in the internal path
change handling with four items:
Search Settings Profile Messages
Assume that all of these items have corresponding path components.
Next, I want to group items "Settings", "Profile", "Messages" and place
them in the popup menu, which I want to show by clicking grouping item.
So, the menu will looks like:
Search More
"More" is a grouping item here which just need to show the popup menu
by clicking it. I don't want (need) to allow "More" item to participates
in the internal path change handling, but I want (need) to allow it to items
of the popup menu (which are in fact belongs to the menu).
Interactively, all of the above works okay in Wt. But specifying the URL
to the item of popup menu manually does not works. Please, fix.
Please take a look at the attached test case.
--
// Dmitriy.
// -*- C++ -*-
//
// (C) 2013 Dmitry Igrishin
//
// Bug report.
// Description: incorrect WMenu internal path handling for submenu items.
// How to reproduce:
// 1) Open URL: host (or host/search)
// (works as expected)
// 2) Open URL: host/settings
// (OOPS, submenu "More" does not handle internal path at all since
// unnecessary check -- if (!parentItem_) in
// WMenu::handleInternalPathChange(const std::string&))
#include <Wt/WApplication>
#include <Wt/WMenu>
#include <Wt/WMenuItem>
#include <Wt/WPopupMenu>
#include <Wt/WStackedWidget>
#include <Wt/WText>
using namespace Wt;
namespace {
class App : public WApplication {
public:
App(const WEnvironment& e);
private:
WMenu*
make_menu(WStackedWidget*);
WPopupMenu*
make_submenu(WStackedWidget*);
};
App::App(const WEnvironment& e)
: WApplication(e)
{
// Contents associated with menu's and submenu's items will
// be placed in the same WStackedWidget.
WStackedWidget* const stack = new WStackedWidget(root());
root()->insertBefore(make_menu(stack), stack);
}
WMenu*
App::make_menu(WStackedWidget* const stack)
{
WMenu* const m = new WMenu(stack);
m->setInternalPathEnabled("/");
// Menuitem "Search" (participates in the internal path).
WMenuItem* mi = new WMenuItem("Search", new WText("Search page"));
mi->setInternalPathEnabled(true);
mi->setPathComponent("search");
m->addItem(mi);
// Menuitem "More" (does *not* participates in the internal path,
// has no associated content. Item just for popup the submenu.
mi = new WMenuItem("More");
mi->setInternalPathEnabled(false);
mi->setMenu(make_submenu(stack));
m->addItem(mi);
return m;
}
WPopupMenu*
App::make_submenu(WStackedWidget* const stack)
{
WPopupMenu* const m = new WPopupMenu(stack);
m->setInternalPathEnabled("/");
// Menuitem "Settings" of the submenu "More"
// (participates in the internal path).
WMenuItem* const mi = new WMenuItem("Settings", new WText("Settings page"));
mi->setInternalPathEnabled(true);
mi->setPathComponent("settings"); // NOTE: this *internal path* will *not*
// be handled (if you specify it in the
// browser's bar manually) by
// WMenu::handleInternalPathChange! -- this
// is a BUG.
m->addItem(mi);
return m;
}
WApplication*
create_app(const WEnvironment& env)
{
return new App(env);
}
} // namespace
int
main(int argc, char* argv[])
{
return WRun(argc, argv, create_app);
}
------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
witty-interest mailing list
witty-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/witty-interest