Hey Koen,

2013/4/18 Koen Deforche <[email protected]>

> Hey Dmitriy,
>
> It seems to me that it would be appropriate that item(s) of WMenu
>> that leads to a submenu(s) (WPopupMenu(s)) should *not* have
>> a path component(s) if WMenu participates in the internal path changing.
>> Clicking these items should just result to showing submenus and *not*
>> to changing current internal path, because in practice submenus
>> are useful only for grouping items (so in fact groupped items belongs
>> to the menu).
>>
>> Thoughts?
>>
>
> I agree, that makes sense indeed and we hadn't thought of that.
>
> We probably should add a virtual bool WMenuItem::hasInternalPath()
> function to return whether the item participates in the internal path
> handling, whose default implementation will check whether there's a submenu
> WPopupMenu, which is used whenever the pathComponent() would be used to
> check whether it's applicable.
>
Yes, I like the idea.
I think that the default implementation of WMenuItem::hasInternalPath()
should also return false if WMenuItem::pathComponent().size() == 0 (emtpy).
It will make possible to create menus with items which switch content in the
contents stack and affects current internal path and with items which just
reacting
to the events, e.g. consider a simple menu:

*Search* *Pictures* More Logout

where:
"Search", "Pictures" are items which participates in the internal path
handling (WMenuItem::pathComponent().size() > 0 for each of these items),
"More" is a submenu (possible with different internal base path and items
which
participates in the internal path handling),
"Logout" is item which just invokes slot which performs session user
changing and recreating menu, and does *not* affects current internal path
(WMenuItem::pathComponent().size == 0 for this item).

Hence, I believe that most people (including me) would have liked to have
the ability
to disable internal path participation of item by invoking
WMenuItem::setPathCompoment("").

>
> Dmitriy can you file a bug for this ?
>
Yes, sure, see the attachment.

// Dmitriy.
// 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"));

  // Submenu "More"
  Wt::WPopupMenu* const pm = new WPopupMenu(m->contentsStack());

  m->addMenu("More", pm);       // Will lead to change internal path.

  pm->addItem("Blogs", new WText("Blogs"));
  pm->addItem("Videos", new WText("Videos"));

  // Menuitem "Logout" / "Login"
  if (logged_out)
    // Will lead to change internal path.
    m->addItem("Login")->triggered().
      connect(boost::bind(&App::change_user, this, false)); 
  else
    // Will lead to change internal path.
    m->addItem("Logout")->triggered().
      connect(boost::bind(&App::change_user, this, true));

  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

Reply via email to