Closed pgaskin closed 4 years ago
Basically, my current idea is to:
NickelMenu
set to true
). Then, find the action we're appending stuff after, and insert out actions after it.This also has another advantage: we can remove any menu item we want without having to intercept it's creation. If this idea works, I'll probably add a feature to hide arbitrary items (menu_item_hide:<loc>:<translated_label>
).
There are a few tricky things with implementing this:
addAction
directly one day, we won't have to deal with the next point anymore]).
clear
will delete the items, but not removeAction
. This means we should be fine if we just call removeAction
on each (and if anyone's wondering about what happens if Nickel has a pointer to the action and still uses it afterwards, the object is a reference, not a value, so it will still work fine).AbstractNickelMenuController::createMenuTextItem
deals with the touch gesture stuff for us. So, we need to insert the action, then remove and reorder it later (and this at least won't run into the aforementioned issue since the actions are created externally).I'm going to start actually implementing this later today.
Hiding actions won't be possible with additional work because MenuTextItem has its own text getter/setter, and doesn't use the one from the QAction itself.
Another option might be to use AbstractNickelMenuController::createMenuTextItem
, but deal with separators manually. Then, we wouldn't have to remove the existing items and re-add them again.
The best (in terms of compatibility and simplicity) thing to do, although it isn't the most efficient, is probably to use createMenuTextItem
, but immediately remove the added action and put it in the right spot, and handle the separator manually so we don't have to move it as well.
A QAction has a "visible" state than can be toggled. Could we somehow rely on that, or is this lost in the Nickel implementation?
A QAction has a "visible" state than can be toggled.
But what would that be for?
Well, hiding a menu entry ;).
Well, hiding a menu entry
The issue isn't so much hiding it as being able to add them to an arbitrary location when the menu is opened rather than when the menu is being initialized.
The current method is simple and reliable, but somewhat inflexible. Also see #42.