Plugin causing duplicate entries in the document context menu (fix)
René J.V. Bertin
rjvbertin at gmail.com
Tue Nov 13 16:53:55 GMT 2018
Here's a beginning of an explanation how all of KDevelop's own entries end up multiple times in the context menu. Output from TextDocument::populateContextMenu showing the arguments to that method, the actions in the target menu, and the additional actions to be added. This output obtained as follows from step 3:
1) start KDevelop with a set of documents opened automatically
2) open the context menu in the initial document
3) switch to another doc and open the context menu once more.
http://paste.openstack.org/show/734772/
So what happens is that TextDocument::populateContextMenu() gets called with the same QMenu instance for each document that has been active.
I do not yet have a clue why this happens only when a plugin adds its own contextmenu entry via KXMLGUI, that will be a damn lot harder to figure out.
FWIW, v->isActiveWindow() is true for both (all) instances of v here, but starting populateTextMenu() like this seems to address the issue:
```
void KDevelop::TextDocument::populateContextMenu( KTextEditor::View* v, QMenu* menu )
{
if (d->addedContextMenu) {
foreach ( QAction* action, d->addedContextMenu->actions() ) {
menu->removeAction(action);
}
delete d->addedContextMenu;
d->addedContextMenu = nullptr;
}
if (v->mainWindow()->activeView() != v) {
return;
}
d->addedContextMenu = new QMenu();
// etc
}
```
Fix or (horrible) workaround? There can only be 1 contextmenu open at a time so an alternative could be to move populateContextMenu() (and d->addedContextMenu) into KDevelop::MainWindow because calling it multiple times there should be safe (but will rebuild d->addedCOntextMenu once for every document that has been active).
R.
More information about the KDevelop-devel
mailing list