Hey Jeffrey,
If you connect to each of the WMenuItem's triggered() signal separately,
you should get that behaviour. I missed that in my original code.
for (unsigned i = 0; i < languages.size(); ++i)
{
// Get Languages
const Lang& l = languages[i];
// Add Popup Item with Description.
WMenuItem *mi = popup->addItem(WString::
fromUTF8(l.longDescription_));
*mi->triggered().connect(boost::bind(&Home::handlePopup, this,
i)); // Binds to all menu events*
}
BR,
Wim.
2014-02-21 22:31 GMT+01:00 Jeffrey Scott Flesher Gmail <
[email protected]>:
> Sorry about my last reply, I realized after I sent it, that all I needed
> to do was use a template that was supported, like int.
>
> But I still have the same issue, triggered effects all the menu items and
> not the one I last added, so all menu items get executed, how do I attach
> it for the menu item being added?
> I see no way to bind this to addItem, I did see a Feature request
> http://redmine.webtoolkit.eu/issues/577 that is 3 years old, which seems
> to be what I need, but the best way would seem to be like WMenu.
>
> ...
> for (unsigned i = 0; i < languages.size(); ++i)
>
>
> {
> // Get Languages
> const Lang& l = languages[i];
> // Add Popup Item with Description.
> popup->addItem(WString::
> fromUTF8(l.longDescription_));
>
> *popup->triggered().connect(boost::bind(&Home::handlePopup, this,
> i)); // Binds to all menu events*
> }
> ...
>
> void Home::handlePopup(int data)
>
> {
> Wt::log("notice") << "(data: " << data << ")";
> if (data == 2) // English
> {
> Wt::log("notice") << "(set language to English: " << ")";
> Wt::WApplication::instance()->setInternalPath("/", true);
> }
> else if (data == 1) // 中文 (Chinese)
> {
> Wt::log("notice") << "(set language to Chinese: " << ")";
> Wt::WApplication::instance()->setInternalPath("/cn", true);
> }
> else if (data == 0) // Русский (Russian)
> {
> Wt::log("notice") << "(set language to Russian: " << ")";
> Wt::WApplication::instance()->setInternalPath("/ru", true);
> }
> }
>
>
> On Fri, 2014-02-21 at 10:53 +0100, Wim Dumon wrote:
>
> Hi,
>
>
> WSignalMapper is deprecated, we recommend to use boost::bind instead. I
> modified the widget gallery so that it won't recommend it anymore. This is
> the alternative using boost::bind().
>
>
> ...
>
> for (unsigned i = 0; i < languages.size(); ++i)
> {
> // Get Languages
> const Lang& l = languages[i];
> // Add Popup Item with Description.
> popup->addItem(WString::fromUTF8(l.longDescription_));
> popup->triggered().connect(boost::bind(&Home::handlePopup, this,
> WString::fromUTF8(l.path_));
> }
> ...
> void Home::handlePopup(const Wt::WString &data)
> {
> Wt::log("notice") << "(data: " << data << ")";
> Wt::WApplication* const app = wApp;
> if (data == "/") // English
> {
> Wt::log("notice") << "(set language to English: " << ")";
> app->setInternalPath("/", true);
> }
> else if (data == "/cn/") // 中文 (Chinese)
> {
> Wt::log("notice") << "(set language to Chinese: " << ")";
> app->setInternalPath("/cn", true);
> }
> else if (data == "/ru/") // Русский (Russian)
> {
> Wt::log("notice") << "(set language to Russian: " << ")";
> app->setInternalPath("/ru", true);
> }
> }
>
>
> Best regards,
> Wim.
>
>
>
>
> 2014-02-21 7:00 GMT+01:00 Jeffrey Scott Flesher Gmail <
> [email protected]>:
>
> I could not find an example or any function to do this, but what I want
> is for the dropdown example in Navigation to send an internal path change,
> so I can use it to change languages; this did not work, it gets called for
> every menu item, no idea why, can anyone help?
> The documentation says You can use a
> WSignalMapper<http://www.webtoolkit.eu/jwt/latest/doc/javadoc/eu/webtoolkit/jwt/WSignalMapper.html>to
> bind extra data with an item's
> WMenuItem.triggered signal, and handle them in a single slot.
> http://jwt.emweb.be/jwt-gallery/gallery/navigation/popup-menu
> my guess is that popup->triggered() is the event for all of them, and not
> just the one I need, so how do you reference the addItem?
>
> ...
>
> for (unsigned i = 0; i < languages.size(); ++i)
> {
> // Get Languages
> const Lang& l = languages[i];
> // Add Popup Item with Description.
> popup->addItem(WString::fromUTF8(l.longDescription_));
> // Create Signal Mapper
> Wt::WSignalMapper<Wt::WString*> *myMap = new
> Wt::WSignalMapper<Wt::WString*>(popup);
> // Connect to callback function
> myMap->mapped().connect(this, &Home::handlePopup);
> // Connect on triggered to path
> myMap->mapConnect(*popup->triggered()*, new
> WString(WString::fromUTF8(l.path_)));
> }
> ...
> void Home::handlePopup(Wt::WString * data)
> {
> Wt::log("notice") << "(data: " << *data << ")";
> Wt::WApplication* const app = wApp;
> if (*data == "/") // English
> {
> Wt::log("notice") << "(set language to English: " << ")";
> app->setInternalPath("/", true);
> }
> else if (*data == "/cn/") // 中文 (Chinese)
> {
> Wt::log("notice") << "(set language to Chinese: " << ")";
> app->setInternalPath("/cn", true);
> }
> else if (*data == "/ru/") // Русский (Russian)
> {
> Wt::log("notice") << "(set language to Russian: " << ")";
> app->setInternalPath("/ru", true);
> }
> }
>
>
>
>
>
>
>
> ------------------------------------------------------------------------------
> Managing the Performance of Cloud-Based Applications
> Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
> Read the Whitepaper.
>
> http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
> _______________________________________________
> witty-interest mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/witty-interest
>
>
>
>
> ------------------------------------------------------------------------------
> Managing the Performance of Cloud-Based Applications
> Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
> Read the
> Whitepaper.http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
> _______________________________________________
> witty-interest mailing
> [email protected]https://lists.sourceforge.net/lists/listinfo/witty-interest
>
>
>
> ------------------------------------------------------------------------------
> Managing the Performance of Cloud-Based Applications
> Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
> Read the Whitepaper.
>
> http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
> _______________________________________________
> witty-interest mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/witty-interest
>
>
------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest