Feature #1849
closedWMenu API proporsal
0%
Description
Hey,
How about making following WMenu's function members virtual:
addItem(WMenuItem*),
removeItem(WMenuItem*),
addMenu (const std::string &iconPath, const WString &text, WMenu *menu),
setInternalPathEnabled,
internalPathEnabled,
setInternalBasePath,
internalBasePath ?
It can be useful when specializing WMenu to non-trivial internal path
changes handling (for example, with global handler).
Note, that overriding WMenu::internalPathChanged is insufficient for
such purposes.
Updated by Koen Deforche over 11 years ago
- Status changed from New to Feedback
- Assignee set to Koen Deforche
Hey Dmitriy,
Good idea to open up some of these methods.
I can see the benefit for addItem() and removeItem(), but what's the use case for internal path related methods? What's an example of a non-trivial internal path handler and why is the virtual internalPathChanged() insufficient?
Regards,
koen
Updated by Dmitriy Igrishin over 11 years ago
Hey Koen,
Currently, calling setInternalPathEnabled() results in that all WMenu
items participates in the internal path changes. By overriding
setInternalPathEnabled() this behaviour can be overriden as the user see fit.
The first use case that comes to my mind --- the menu item for calling a submenu.
But we discussed this use case in the mailing list in april (see
"WMenu behaviour proporsal." thread) and decided to add virtual bool WMenuItem::hasInternalPath().
Example of overriding setInternalPathEnabled() may looks like this:
void Menu::setInternalBasePath(const std::string& base_path)
{
if (internal_base_path_ == base_path)
return;
internal_base_path_ = terminate(base_path, '/');
for (auto i : items_)
activate(i~~first, i~~>second);
}
void Menu::activate(Menuitem* mi, Ipc_handler& h)
{
const auto path = internal_base_path();
if (!path.empty()) {
mi~~setLink(WLink(WLink::InternalPath, path + mi~~>subpath()));
h = Ipc_handler(path, [=]() { mi->select(); });
}
}
Please, check the "WMenu behaviour proporsal." thread in the mailing list for completeness.
Updated by Koen Deforche over 11 years ago
- Status changed from Feedback to InProgress
Updated by Koen Deforche over 11 years ago
- Status changed from InProgress to Resolved
Updated by Koen Deforche over 11 years ago
- Status changed from Resolved to Closed