How to dynamically enable/disable menu actions on-demand

David Nolden zwabel at googlemail.com
Thu Apr 2 11:03:33 UTC 2009


Anyone has an idea how to do that the best way?

The problem: When opening the "Navigation" menu, for example the "Jump to 
Declaration" action is active, even though there is no declaration under the 
cursor.

From what I understand there is a system in KDE to put the UI into "states", 
dynamically activating actions based on that.

However that is not flexible enough. I'm also facing this problem in some 
other places: For example I want to add an "Open project for current file" 
action to the project menu, and it should only be active if:
- There is a file open
- The file is not within a loaded project

So what's actually needed is this. A way of deciding on a per-action basis 
whether the action should be activated/deactivated, while showing the menu.

If there is no such mechanism yet, I'm proposing we use something like this:
Create a subclass of KAction, called KDevAction, that has a signal 
"showing(KAction*)", that should always be emitted when a menu containing the 
action is shown, and that can be used by the action owners to check the 
context, and enable/disable it.

Any better Ideas?

Greetings, David




More information about the KDevelop-devel mailing list