pgaskin / NickelMenu

The easiest way to launch scripts, change settings, and run actions on Kobo e-readers.
https://pgaskin.net/NickelMenu
MIT License
591 stars 32 forks source link

Better menu item injection #43

Closed pgaskin closed 4 years ago

pgaskin commented 4 years ago

The current method is simple and reliable, but somewhat inflexible. Also see #42.

pgaskin commented 4 years ago

Basically, my current idea is to:

pgaskin commented 4 years ago

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>).

pgaskin commented 4 years ago

There are a few tricky things with implementing this:

I'm going to start actually implementing this later today.

pgaskin commented 4 years ago

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.

pgaskin commented 4 years ago

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.

pgaskin commented 4 years ago

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.

NiLuJe commented 4 years ago

A QAction has a "visible" state than can be toggled. Could we somehow rely on that, or is this lost in the Nickel implementation?

pgaskin commented 4 years ago

A QAction has a "visible" state than can be toggled.

But what would that be for?

NiLuJe commented 4 years ago

Well, hiding a menu entry ;).

pgaskin commented 4 years ago

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.