Actions in the context-menu

Andreas Pakulat apaku at gmx.de
Mon Feb 15 18:02:21 UTC 2010


On 15.02.10 02:41:00, Jonathan Schmidt-Dominé - Developer wrote:
> What is the proper way to add an action to the context-menu from a plugin? I 
> simply used KTextEditor::View::contextMenu in the KIcon-Inserter-Plugin. Now 
> KDevelop seems to have a new context-menu and it does not work in KDevelop. I 
> used contextMenuAboutToShow to ensure that it has been created, but it does 
> not work, it will be replaced by KDevelop.

Ok, here's the solution I've now found and implemented for KDevelop ('s
plugins):

1. don't clear the menu in the slot connected to the signal, as this
will break kte-plugins that did the connection earlier than kdevelop's
code.

2. Any action that is added to the menu in KDevelop's slot needs to be
kept around until end of app lifetime, so when its again added to the
menu QMenu takes care of not creating duplicate entries in the menu.

3. For the case of plugins adding a whole submenu, the submenu instance
needs to be kept around only. If it has dynamic content, it should be
cleared and then the actions can be added as needed without any problem.
If the menu-instance stays the same, the menuAction on it also stays the
same (which is being added to the KTE-provided context menu).

Andreas

-- 
Next Friday will not be your lucky day.  As a matter of fact, you don't
have a lucky day this year.




More information about the KDevelop-devel mailing list