Replace ToolAction by ToggleActionMenu

Authored by davidhurka on Feb 1 2020, 6:54 PM.


Replace ToolAction by ToggleActionMenu

This replaces ToolAction by a near-drop-in replacement named ToggleActionMenu. The new annotation toolbar already uses this (D15580).

Unlike ToolAction, ToggleActionMenu inherits from KActionMenu to be more flexible.

  • Menu can be set from outside, not hard coded.
  • Default action for toolbar button is controllable from outside. (Theoretically, the button could trigger anything now.)
  • KActionMenu instead of KSelectAction:
    • Pluggable in other menus, thus called “Menu”.
    • Doesn’t make the actions exclusive, so any actions can be added to the menu.
  • ImplicitDefaultAction mode can choose the default action of the toolbar buttons automatically, by looking for the first checked action in the menu.

Toolbar buttons use the default action of this menu, not this menu itself as action.

Because the default action is configurable now, D21622 and D21635 (where we tried to fine-tune ToolAction) become obsolete.

Everything like before, here with mouse_selecttool added to Tools menu to show submenu capability.

Test Plan:
ToolAction replacement and ImplicitDefaultAction mode:

  • Open Okular and look at toolbar button -> has correct tool selected.
  • Open a document.
  • Look at toolbar button menu -> Correct menu entries (like before, with ToolAction).
  • Select some selection tools through shortcuts and toolbar button -> behaves correctly.

Usage as submenu:

  • Add ToggleActionMenu ("mouse_selecttool") to menubar (..../kxmlgui5/okular/part.rc) -> Submenu looks correctly, has no checkbox attached and so on...

Toolbar buttons:

  • Add diverse other actions to the menu -> still works as before.
  • Add actions when toolbar buttons are already created -> actions are added to existing buttons.
  • setDefaultAction() to some completely unrelated action. -> ToggleActionMenu does not get confused.

Reviewers: simgunz

Reviewed By: simgunz

Subscribers: aacid, ngraham, simgunz, okular-devel

Tags: Okular

Differential Revision:


aacidFeb 2 2020, 12:33 AM
Differential Revision
D21971: Replace ToolAction by ToggleActionMenu
R223:5dfbee0a0039: SVN_SILENT made messages (.desktop file) - always resolve ours