Project

General

Profile

WMenu itemSelected() emitted multiple times

Added by Daniel Walter over 13 years ago

I build the following WMenu and connect to the itemSelected signal my own handler.

WMenu* m_topMenu = new WMenu(Horizontal);
m_topMenu->setInternalPathEnabled("/page");
m_topMenu->itemSelected().connect(this, &WebsiteImpl::pageSelected);
m_topMenu->addItem("HOME", new WText("HOME"));
m_topMenu->addItem("HOMER", new WText("HOMER"));

void pageSelected(WMenuItem*  sender) {
std::cout << "pageSelected():" << sender->pathComponent() << wApp->internalPathNextPart("/page") << std::endl;
}

If i create a new session with a url like http://localhost:8080/project#/page/homer the pageSelected is called twice! If i click on the link homer the signal is emmited once. Why this happens?


Replies (7)

RE: WMenu itemSelected() emitted multiple times - Added by Koen Deforche over 13 years ago

Hey Daniel,

I suspect the reason is that you connect the itemSelected() and setInternalPathEnabled() before adding the items, and not after. While adding an item, the item may become selected if the current path matches.

Regards,

koen

RE: WMenu itemSelected() emitted multiple times - Added by Daniel Walter over 13 years ago

Hi Koen,

tank you for your reply.

If i connect my slot to this signal after adding the items, the slot gets only called if an item is clicked. how to know which page is active when there is a new session/reload?

Best regards,

Daniel

RE: WMenu itemSelected() emitted multiple times - Added by Koen Deforche over 13 years ago

If you setInternalPathEnabled() before adding the items, then your callback should be called when the item that corresponds to the current page is being added. You are not seeing that behaviour ?

If you setInternalPathEnabled() after you've added the items, then the callback is called at that time.

RE: WMenu itemSelected() emitted multiple times - Added by Daniel Walter over 13 years ago

If i setInternalPathEnabled() after adding the items, the callback is not called on a new session/reload. it is only called if i click an entry of the WMenu.

RE: WMenu itemSelected() emitted multiple times - Added by Daniel Walter over 13 years ago

There is definitely something wrong!

WMenu* m_topMenu = new WMenu(Horizontal);
m_topMenu->setInternalPathEnabled("/page");
m_topMenu->addItem("HOME", new WText("HOME"));
m_topMenu->addItem("HOMER", new WText("HOMER"));

When i go to http://localhost:8080/project#/page/homer the correct entry (homer) in the WMenu is marked as selected on a new session/reload.

That seems to be correct.

WMenu* m_topMenu = new WMenu(Horizontal);
m_topMenu->setInternalPathEnabled("/page");
m_topMenu->addItem("HOMER", new WText("HOMER"));
m_topMenu->addItem("HOME", new WText("HOME"));

When i go to http://localhost:8080/project#/page/homer the item "home" is selected.

That seems to be NOT correct.

If i call m_topMenu->setInternalPathEnabled("/page"); after adding the items and go to this url http://localhost:8080/project#/page/homer no item is selcted.

Is this behavior correct? Am i doing something wrong?

In my opinion the problem is located in the file WMenu.C on line 199 to 200.

199     if (app->internalPathMatches(basePath_ + item->pathComponent()))
200       select(items_.size() - 1, false);

app->internalPathMatches(std::string("/page/") + "home");      //true
app->internalPathMatches(std::string("/page/") + "homer");     //true
app->internalPathMatches(std::string("/page/") + "home-er");   //false
app->internalPathMatches(std::string("/page/") + "homerrrrr"); //false

Should not this return false for all the values?

RE: WMenu itemSelected() emitted multiple times - Added by Koen Deforche over 13 years ago

Hey Daniel,

I believe your are spot-on, the problem is in internalPathMatches() not correctly delineating the path parts!

I've filed this as a bug: http://redmine.emweb.be/issues/693

Regards,

koen

RE: WMenu itemSelected() emitted multiple times - Added by Daniel Walter over 13 years ago

Ok, i hope it gets fixed quickly! :-)

This bug also explains this post from me:

http://redmine.webtoolkit.eu/boards/2/topics/1294

Best regards,

Daniel

    (1-7/7)