diff --git a/interfaces/context.h b/interfaces/context.h --- a/interfaces/context.h +++ b/interfaces/context.h @@ -60,13 +60,13 @@ -# Create a context: @code FileContext context(list). @endcode -# Query for plugins: @code QList extensions = - ICore::self()->pluginController()->queryPluginsForContextMenuExtensions( context ); @endcode + ICore::self()->pluginController()->queryPluginsForContextMenuExtensions(context, &menu); @endcode -# Populate the menu: @code ContextMenuExtension::populateMenu(menu, extensions); @endcode -# Show the popup menu: @code menu.exec(mapToGlobal(pos)); @endcode How to fill a context menu from a plugin: --# Implement the @code contextMenuExtension(Context*) @endcode +-# Implement the @code contextMenuExtension(Context*, QWidget*) @endcode function in your plugin class. -# Depending on the context fill the returned ContextMenuExtension with actions:\n @code diff --git a/interfaces/iplugin.h b/interfaces/iplugin.h --- a/interfaces/iplugin.h +++ b/interfaces/iplugin.h @@ -176,9 +176,10 @@ * Ask the plugin for a ContextActionContainer, which contains actions * that will be merged into the context menu. * @param context the context describing where the context menu was requested + * @param parent a widget to use for memory manageent of QActions, QMenus etc. created only for this request * @returns a container describing which actions to merge into which context menu part */ - virtual ContextMenuExtension contextMenuExtension( KDevelop::Context* context ); + virtual ContextMenuExtension contextMenuExtension(KDevelop::Context* context, QWidget* parent); /** * Can create a new KXMLGUIClient, and set it up correctly with all the plugins per-window GUI actions. diff --git a/interfaces/iplugin.cpp b/interfaces/iplugin.cpp --- a/interfaces/iplugin.cpp +++ b/interfaces/iplugin.cpp @@ -132,9 +132,10 @@ } -KDevelop::ContextMenuExtension KDevelop::IPlugin::contextMenuExtension( - KDevelop::Context* ) +KDevelop::ContextMenuExtension KDevelop::IPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent) { + Q_UNUSED(context); + Q_UNUSED(parent); return KDevelop::ContextMenuExtension(); } diff --git a/interfaces/iplugincontroller.h b/interfaces/iplugincontroller.h --- a/interfaces/iplugincontroller.h +++ b/interfaces/iplugincontroller.h @@ -177,7 +177,7 @@ */ virtual QVector queryExtensionPlugins(const QString &extension, const QVariantMap& constraints = QVariantMap()) const = 0; - virtual QList queryPluginsForContextMenuExtensions( KDevelop::Context* context ) const = 0; + virtual QList queryPluginsForContextMenuExtensions(KDevelop::Context* context, QWidget* parent) const = 0; Q_SIGNALS: void loadingPlugin( const QString& ); diff --git a/language/codegen/basicrefactoring.h b/language/codegen/basicrefactoring.h --- a/language/codegen/basicrefactoring.h +++ b/language/codegen/basicrefactoring.h @@ -70,7 +70,7 @@ explicit BasicRefactoring(QObject *parent = nullptr); /// Update the context menu with the "Rename" action. - virtual void fillContextMenu(KDevelop::ContextMenuExtension &extension, KDevelop::Context *context); + virtual void fillContextMenu(KDevelop::ContextMenuExtension &extension, KDevelop::Context *context, QWidget* parent); struct NameAndCollector { QString newName; diff --git a/language/codegen/basicrefactoring.cpp b/language/codegen/basicrefactoring.cpp --- a/language/codegen/basicrefactoring.cpp +++ b/language/codegen/basicrefactoring.cpp @@ -94,7 +94,7 @@ /* There's nothing to do here. */ } -void BasicRefactoring::fillContextMenu(ContextMenuExtension &extension, Context *context) +void BasicRefactoring::fillContextMenu(ContextMenuExtension &extension, Context *context, QWidget* parent) { DeclarationContext *declContext = dynamic_cast(context); if (!declContext) @@ -105,7 +105,7 @@ if (declaration && acceptForContextMenu(declaration)) { QFileInfo finfo(declaration->topContext()->url().str()); if (finfo.isWritable()) { - QAction *action = new QAction(i18n("Rename \"%1\"...", declaration->qualifiedIdentifier().toString()), nullptr); + QAction *action = new QAction(i18n("Rename \"%1\"...", declaration->qualifiedIdentifier().toString()), parent); action->setData(QVariant::fromValue(IndexedDeclaration(declaration))); action->setIcon(QIcon::fromTheme(QStringLiteral("edit-rename"))); connect(action, &QAction::triggered, this, &BasicRefactoring::executeRenameAction); diff --git a/plugins/appwizard/appwizardplugin.h b/plugins/appwizard/appwizardplugin.h --- a/plugins/appwizard/appwizardplugin.h +++ b/plugins/appwizard/appwizardplugin.h @@ -30,7 +30,7 @@ public: explicit AppWizardPlugin(QObject *parent, const QVariantList & = QVariantList()); ~AppWizardPlugin() override; - KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context) override; + KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context, QWidget* parent) override; QAbstractItemModel* templatesModel() override; QString knsConfigurationFile() const override; diff --git a/plugins/appwizard/appwizardplugin.cpp b/plugins/appwizard/appwizardplugin.cpp --- a/plugins/appwizard/appwizardplugin.cpp +++ b/plugins/appwizard/appwizardplugin.cpp @@ -500,8 +500,9 @@ } } } -KDevelop::ContextMenuExtension AppWizardPlugin::contextMenuExtension(KDevelop::Context* context) +KDevelop::ContextMenuExtension AppWizardPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent) { + Q_UNUSED(parent); KDevelop::ContextMenuExtension ext; if ( context->type() != KDevelop::Context::ProjectItemContext || !static_cast(context)->items().isEmpty() ) { return ext; diff --git a/plugins/bazaar/bazaarplugin.h b/plugins/bazaar/bazaarplugin.h --- a/plugins/bazaar/bazaarplugin.h +++ b/plugins/bazaar/bazaarplugin.h @@ -65,7 +65,7 @@ KDevelop::VcsJob* status(const QList& localLocations, RecursionMode recursion=Recursive) override; KDevelop::VcsJob* update(const QList& localLocations, const KDevelop::VcsRevision& rev, RecursionMode recursion=Recursive) override; KDevelop::VcsLocationWidget* vcsLocation(QWidget* parent) const override; - KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context) override; + KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context, QWidget* parent) override; private Q_SLOTS: void parseBzrStatus(KDevelop::DVcsJob* job); diff --git a/plugins/bazaar/bazaarplugin.cpp b/plugins/bazaar/bazaarplugin.cpp --- a/plugins/bazaar/bazaarplugin.cpp +++ b/plugins/bazaar/bazaarplugin.cpp @@ -317,7 +317,7 @@ return new KDevelop::StandardVcsLocationWidget(parent); } -ContextMenuExtension BazaarPlugin::contextMenuExtension(Context* context) +ContextMenuExtension BazaarPlugin::contextMenuExtension(Context* context, QWidget* parent) { m_vcsPluginHelper->setupFromContext(context); QList const& ctxUrlList = m_vcsPluginHelper->contextUrlList(); @@ -334,7 +334,7 @@ return ContextMenuExtension(); } - QMenu* menu = m_vcsPluginHelper->commonActions(); + QMenu* menu = m_vcsPluginHelper->commonActions(parent); ContextMenuExtension menuExt; menuExt.addAction(ContextMenuExtension::VcsGroup, menu->menuAction()); diff --git a/plugins/classbrowser/classbrowserplugin.h b/plugins/classbrowser/classbrowserplugin.h --- a/plugins/classbrowser/classbrowserplugin.h +++ b/plugins/classbrowser/classbrowserplugin.h @@ -47,7 +47,7 @@ public: // KDevelop::Plugin overrides void unload() override; - KDevelop::ContextMenuExtension contextMenuExtension( KDevelop::Context* ) override; + KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context, QWidget* parent) override; // The duchain must not be locked when this is called! void showDefinition(KDevelop::DeclarationPointer declaration); diff --git a/plugins/classbrowser/classbrowserplugin.cpp b/plugins/classbrowser/classbrowserplugin.cpp --- a/plugins/classbrowser/classbrowserplugin.cpp +++ b/plugins/classbrowser/classbrowserplugin.cpp @@ -97,9 +97,9 @@ core()->uiController()->removeToolView(m_factory); } -KDevelop::ContextMenuExtension ClassBrowserPlugin::contextMenuExtension( KDevelop::Context* context) +KDevelop::ContextMenuExtension ClassBrowserPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent) { - KDevelop::ContextMenuExtension menuExt = KDevelop::IPlugin::contextMenuExtension( context ); + KDevelop::ContextMenuExtension menuExt = KDevelop::IPlugin::contextMenuExtension(context, parent); // No context menu if we don't have a class browser at hand. if ( m_activeClassTree == nullptr ) diff --git a/plugins/classbrowser/classtree.cpp b/plugins/classbrowser/classtree.cpp --- a/plugins/classbrowser/classtree.cpp +++ b/plugins/classbrowser/classtree.cpp @@ -87,7 +87,7 @@ } _populatingClassBrowserContextMenu = true; - QList extensions = ICore::self()->pluginController()->queryPluginsForContextMenuExtensions( c ); + QList extensions = ICore::self()->pluginController()->queryPluginsForContextMenuExtensions(c, menu); ContextMenuExtension::populateMenu( menu, extensions ); _populatingClassBrowserContextMenu = false; diff --git a/plugins/contextbrowser/contextbrowser.h b/plugins/contextbrowser/contextbrowser.h --- a/plugins/contextbrowser/contextbrowser.h +++ b/plugins/contextbrowser/contextbrowser.h @@ -106,7 +106,7 @@ void registerToolView(ContextBrowserView* view); void unRegisterToolView(ContextBrowserView* view); - KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context*) override; + KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context, QWidget* parent) override; KXMLGUIClient* createGUIForMainWindow( Sublime::MainWindow* window ) override; diff --git a/plugins/contextbrowser/contextbrowser.cpp b/plugins/contextbrowser/contextbrowser.cpp --- a/plugins/contextbrowser/contextbrowser.cpp +++ b/plugins/contextbrowser/contextbrowser.cpp @@ -331,9 +331,9 @@ core()->uiController()->removeToolView(m_viewFactory); } -KDevelop::ContextMenuExtension ContextBrowserPlugin::contextMenuExtension(KDevelop::Context* context) +KDevelop::ContextMenuExtension ContextBrowserPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent) { - KDevelop::ContextMenuExtension menuExt = KDevelop::IPlugin::contextMenuExtension( context ); + KDevelop::ContextMenuExtension menuExt = KDevelop::IPlugin::contextMenuExtension(context, parent); KDevelop::DeclarationContext *codeContext = dynamic_cast(context); diff --git a/plugins/contextbrowser/contextbrowserview.cpp b/plugins/contextbrowser/contextbrowserview.cpp --- a/plugins/contextbrowser/contextbrowserview.cpp +++ b/plugins/contextbrowser/contextbrowserview.cpp @@ -166,7 +166,7 @@ KDevelop::DeclarationContext* c = new KDevelop::DeclarationContext(navigationContext->declaration().data()); lock.unlock(); QMenu menu(this); - QList extensions = ICore::self()->pluginController()->queryPluginsForContextMenuExtensions( c ); + QList extensions = ICore::self()->pluginController()->queryPluginsForContextMenuExtensions(c, &menu); ContextMenuExtension::populateMenu(&menu, extensions); menu.exec(QCursor::pos()); diff --git a/plugins/cvs/cvsplugin.h b/plugins/cvs/cvsplugin.h --- a/plugins/cvs/cvsplugin.h +++ b/plugins/cvs/cvsplugin.h @@ -46,7 +46,7 @@ KDevelop::VcsImportMetadataWidget* createImportMetadataWidget(QWidget* parent) override; // From KDevelop::IPlugin - KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context*) override; + KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context, QWidget* parent) override; // Begin: KDevelop::IBasicVersionControl bool isValidRemoteRepositoryUrl(const QUrl& remoteLocation) override; diff --git a/plugins/cvs/cvsplugin.cpp b/plugins/cvs/cvsplugin.cpp --- a/plugins/cvs/cvsplugin.cpp +++ b/plugins/cvs/cvsplugin.cpp @@ -172,7 +172,7 @@ } -KDevelop::ContextMenuExtension CvsPlugin::contextMenuExtension(KDevelop::Context* context) +KDevelop::ContextMenuExtension CvsPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent) { d->m_common->setupFromContext(context); QList const & ctxUrlList = d->m_common->contextUrlList(); @@ -188,22 +188,22 @@ qCDebug(PLUGIN_CVS) << "version controlled?" << hasVersionControlledEntries; if (!hasVersionControlledEntries) - return IPlugin::contextMenuExtension(context); + return IPlugin::contextMenuExtension(context, parent); - QMenu* menu = d->m_common->commonActions(); + QMenu* menu = d->m_common->commonActions(parent); menu->addSeparator(); QAction *action; // Just add actions which are not covered by the cvscommon plugin - action = new QAction(i18n("Edit"), this); + action = new QAction(i18n("Edit"), menu); connect(action, &QAction::triggered, this, &CvsPlugin::ctxEdit); menu->addAction(action); - action = new QAction(i18n("Unedit"), this); + action = new QAction(i18n("Unedit"), menu); connect(action, &QAction::triggered, this, &CvsPlugin::ctxUnEdit); menu->addAction(action); - action = new QAction(i18n("Show Editors"), this); + action = new QAction(i18n("Show Editors"), menu); connect(action, &QAction::triggered, this, &CvsPlugin::ctxEditors); menu->addAction(action); diff --git a/plugins/docker/dockerplugin.h b/plugins/docker/dockerplugin.h --- a/plugins/docker/dockerplugin.h +++ b/plugins/docker/dockerplugin.h @@ -33,7 +33,7 @@ DockerPlugin(QObject *parent, const QVariantList & args); ~DockerPlugin() override; - KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context * context) override; + KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context, QWidget* parent) override; void imagesListFinished(int code); diff --git a/plugins/docker/dockerplugin.cpp b/plugins/docker/dockerplugin.cpp --- a/plugins/docker/dockerplugin.cpp +++ b/plugins/docker/dockerplugin.cpp @@ -94,7 +94,7 @@ } } -KDevelop::ContextMenuExtension DockerPlugin::contextMenuExtension(KDevelop::Context* context) +KDevelop::ContextMenuExtension DockerPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent) { QList urls; @@ -123,7 +123,7 @@ foreach(const QUrl &url, urls) { const KDevelop::Path file(url); - auto action = new QAction(QIcon::fromTheme("text-dockerfile"), i18n("docker build '%1'", file.path()), this); + auto action = new QAction(QIcon::fromTheme("text-dockerfile"), i18n("docker build '%1'", file.path()), parent); connect(action, &QAction::triggered, this, [this, file]() { const auto dir = file.parent(); const QString name = QInputDialog::getText( @@ -149,7 +149,7 @@ return ext; } - return KDevelop::IPlugin::contextMenuExtension( context ); + return KDevelop::IPlugin::contextMenuExtension(context, parent); } int DockerPlugin::configPages() const diff --git a/plugins/documentview/kdevdocumentview.cpp b/plugins/documentview/kdevdocumentview.cpp --- a/plugins/documentview/kdevdocumentview.cpp +++ b/plugins/documentview/kdevdocumentview.cpp @@ -185,7 +185,7 @@ KDevelop::FileContext context(m_selectedDocs); QList extensions = - m_plugin->core()->pluginController()->queryPluginsForContextMenuExtensions( &context ); + m_plugin->core()->pluginController()->queryPluginsForContextMenuExtensions(&context, ctxMenu); QList vcsActions; QList fileActions; diff --git a/plugins/externalscript/externalscriptplugin.h b/plugins/externalscript/externalscriptplugin.h --- a/plugins/externalscript/externalscriptplugin.h +++ b/plugins/externalscript/externalscriptplugin.h @@ -43,7 +43,7 @@ ~ExternalScriptPlugin() override; void unload() override; - KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context) override; + KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context, QWidget* parent) override; static ExternalScriptPlugin* self(); diff --git a/plugins/externalscript/externalscriptplugin.cpp b/plugins/externalscript/externalscriptplugin.cpp --- a/plugins/externalscript/externalscriptplugin.cpp +++ b/plugins/externalscript/externalscriptplugin.cpp @@ -166,7 +166,7 @@ m_self = nullptr; } -KDevelop::ContextMenuExtension ExternalScriptPlugin::contextMenuExtension( KDevelop::Context* context ) +KDevelop::ContextMenuExtension ExternalScriptPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent) { m_urls.clear(); @@ -192,8 +192,7 @@ if ( !m_urls.isEmpty() ) { KDevelop::ContextMenuExtension ext; - QMenu* menu = new QMenu(); - menu->setTitle( i18n("External Scripts") ); + QMenu* menu = nullptr; for ( int row = 0; row < m_model->rowCount(); ++row ) { ExternalScriptItem* item = dynamic_cast( m_model->item( row ) ); @@ -224,19 +223,24 @@ } } - QAction* scriptAction = new QAction( item->text(), this ); + if (!menu) { + menu = new QMenu(i18n("External Scripts"), parent); + } + + QAction* scriptAction = new QAction(item->text(), menu); scriptAction->setData( QVariant::fromValue( item )); connect( scriptAction, &QAction::triggered, this, &ExternalScriptPlugin::executeScriptFromContextMenu ); menu->addAction( scriptAction ); } - if (!menu->actions().isEmpty()) + if (menu) { ext.addAction( KDevelop::ContextMenuExtension::ExtensionGroup, menu->menuAction() ); + } return ext; } - return KDevelop::IPlugin::contextMenuExtension( context ); + return KDevelop::IPlugin::contextMenuExtension(context, parent); } void ExternalScriptPlugin::unload() diff --git a/plugins/filemanager/filemanager.cpp b/plugins/filemanager/filemanager.cpp --- a/plugins/filemanager/filemanager.cpp +++ b/plugins/filemanager/filemanager.cpp @@ -109,7 +109,7 @@ menu->addAction(newFileAction); contextActions.append(newFileAction); KDevelop::FileContext context(QList() << item.url()); - QList extensions = KDevelop::ICore::self()->pluginController()->queryPluginsForContextMenuExtensions( &context ); + QList extensions = KDevelop::ICore::self()->pluginController()->queryPluginsForContextMenuExtensions(&context, menu); KDevelop::ContextMenuExtension::populateMenu(menu, extensions); QMenu* tmpMenu = new QMenu(); KDevelop::ContextMenuExtension::populateMenu(tmpMenu, extensions); diff --git a/plugins/filetemplates/filetemplatesplugin.h b/plugins/filetemplates/filetemplatesplugin.h --- a/plugins/filetemplates/filetemplatesplugin.h +++ b/plugins/filetemplates/filetemplatesplugin.h @@ -30,7 +30,7 @@ ~FileTemplatesPlugin() override; void unload() override; - KDevelop::ContextMenuExtension contextMenuExtension (KDevelop::Context* context) override; + KDevelop::ContextMenuExtension contextMenuExtension (KDevelop::Context* context, QWidget* parent) override; QString name() const override; QIcon icon() const override; diff --git a/plugins/filetemplates/filetemplatesplugin.cpp b/plugins/filetemplates/filetemplatesplugin.cpp --- a/plugins/filetemplates/filetemplatesplugin.cpp +++ b/plugins/filetemplates/filetemplatesplugin.cpp @@ -87,7 +87,7 @@ core()->uiController()->removeToolView(m_toolView); } -ContextMenuExtension FileTemplatesPlugin::contextMenuExtension (Context* context) +ContextMenuExtension FileTemplatesPlugin::contextMenuExtension(Context* context, QWidget* parent) { ContextMenuExtension ext; QUrl fileUrl; @@ -113,7 +113,7 @@ } if (url.isValid()) { - QAction* action = new QAction(i18n("Create From Template..."), this); + QAction* action = new QAction(i18n("Create From Template..."), parent); action->setIcon(QIcon::fromTheme(QStringLiteral("code-class"))); action->setData(url); connect(action, &QAction::triggered, this, &FileTemplatesPlugin::createFromTemplate); @@ -133,7 +133,7 @@ if (fileUrl.isValid() && determineTemplateType(fileUrl) != NoTemplate) { - QAction* action = new QAction(i18n("Show Template Preview"), this); + QAction* action = new QAction(i18n("Show Template Preview"), parent); action->setIcon(QIcon::fromTheme(QStringLiteral("document-preview"))); action->setData(fileUrl); connect(action, &QAction::triggered, this, &FileTemplatesPlugin::previewTemplate); diff --git a/plugins/flatpak/flatpakplugin.h b/plugins/flatpak/flatpakplugin.h --- a/plugins/flatpak/flatpakplugin.h +++ b/plugins/flatpak/flatpakplugin.h @@ -31,7 +31,7 @@ FlatpakPlugin(QObject *parent, const QVariantList & args); ~FlatpakPlugin() override; - KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context * context) override; + KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context * context, QWidget* parent) override; private: void runtimeChanged(KDevelop::IRuntime* newRuntime); diff --git a/plugins/flatpak/flatpakplugin.cpp b/plugins/flatpak/flatpakplugin.cpp --- a/plugins/flatpak/flatpakplugin.cpp +++ b/plugins/flatpak/flatpakplugin.cpp @@ -148,7 +148,7 @@ return ret; } -KDevelop::ContextMenuExtension FlatpakPlugin::contextMenuExtension(KDevelop::Context* context) +KDevelop::ContextMenuExtension FlatpakPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent) { QList urls; @@ -179,7 +179,7 @@ const KDevelop::Path file(url); foreach(const QString &arch, availableArches(file)) { - auto action = new QAction(i18n("Build flatpak %1 for %2", file.lastPathSegment(), arch), this); + auto action = new QAction(i18n("Build flatpak %1 for %2", file.lastPathSegment(), arch), parent); connect(action, &QAction::triggered, this, [this, file, arch]() { createRuntime(file, arch); }); @@ -190,7 +190,7 @@ return ext; } - return KDevelop::IPlugin::contextMenuExtension( context ); + return KDevelop::IPlugin::contextMenuExtension(context, parent); } void FlatpakPlugin::executeOnRemoteDevice() diff --git a/plugins/grepview/grepviewplugin.h b/plugins/grepview/grepviewplugin.h --- a/plugins/grepview/grepviewplugin.h +++ b/plugins/grepview/grepviewplugin.h @@ -37,7 +37,7 @@ void unload() override; void rememberSearchDirectory(QString const & directory); - KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context) override; + KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context, QWidget* parent) override; void showDialog(bool setLastUsed = false, const QString& pattern = QString(), bool show = true); /** diff --git a/plugins/grepview/grepviewplugin.cpp b/plugins/grepview/grepviewplugin.cpp --- a/plugins/grepview/grepviewplugin.cpp +++ b/plugins/grepview/grepviewplugin.cpp @@ -122,15 +122,15 @@ showDialog(false, pattern, show); } -KDevelop::ContextMenuExtension GrepViewPlugin::contextMenuExtension(KDevelop::Context* context) +KDevelop::ContextMenuExtension GrepViewPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent) { - KDevelop::ContextMenuExtension extension = KDevelop::IPlugin::contextMenuExtension(context); + KDevelop::ContextMenuExtension extension = KDevelop::IPlugin::contextMenuExtension(context, parent); if( context->type() == KDevelop::Context::ProjectItemContext ) { KDevelop::ProjectItemContext* ctx = static_cast(context); QList items = ctx->items(); // verify if there is only one folder selected if ((items.count() == 1) && (items.first()->folder())) { - QAction* action = new QAction( i18n( "Find/Replace in This Folder..." ), this ); + QAction* action = new QAction(i18n("Find/Replace in This Folder..."), parent); action->setIcon(QIcon::fromTheme(QStringLiteral("edit-find"))); m_contextMenuDirectory = items.at(0)->folder()->path().toLocalFile(); connect( action, &QAction::triggered, this, &GrepViewPlugin::showDialogFromProject); @@ -141,7 +141,7 @@ if ( context->type() == KDevelop::Context::EditorContext ) { KDevelop::EditorContext* econtext = static_cast(context); if ( econtext->view()->selection() ) { - QAction* action = new QAction(QIcon::fromTheme(QStringLiteral("edit-find")), i18n("&Find/Replace in Files..."), this); + QAction* action = new QAction(QIcon::fromTheme(QStringLiteral("edit-find")), i18n("&Find/Replace in Files..."), parent); connect(action, &QAction::triggered, this, &GrepViewPlugin::showDialogFromMenu); extension.addAction(KDevelop::ContextMenuExtension::ExtensionGroup, action); } @@ -153,7 +153,7 @@ QMimeType mimetype = QMimeDatabase().mimeTypeForUrl(fcontext->urls().at(0)); static const QMimeType directoryMime = QMimeDatabase().mimeTypeForName(QStringLiteral("inode/directory")); if (mimetype == directoryMime) { - QAction* action = new QAction( i18n( "Find/Replace in This Folder..." ), this ); + QAction* action = new QAction(i18n("Find/Replace in This Folder..."), parent); action->setIcon(QIcon::fromTheme(QStringLiteral("edit-find"))); m_contextMenuDirectory = fcontext->urls().at(0).toLocalFile(); connect( action, &QAction::triggered, this, &GrepViewPlugin::showDialogFromProject); diff --git a/plugins/openwith/openwithplugin.h b/plugins/openwith/openwithplugin.h --- a/plugins/openwith/openwithplugin.h +++ b/plugins/openwith/openwithplugin.h @@ -37,7 +37,7 @@ public: OpenWithPlugin( QObject* parent, const QVariantList& args ); ~OpenWithPlugin() override; - KDevelop::ContextMenuExtension contextMenuExtension ( KDevelop::Context* context ) override; + KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context, QWidget* parent) override; protected: void openFilesInternal( const QList& files ) override; @@ -48,7 +48,7 @@ void openDefault(); private: - QList actionsForServiceType( const QString& serviceType ); + QList actionsForServiceType(const QString& serviceType, QWidget* parent); QScopedPointer m_actionMap; QList m_urls; QString m_mimeType; diff --git a/plugins/openwith/openwithplugin.cpp b/plugins/openwith/openwithplugin.cpp --- a/plugins/openwith/openwithplugin.cpp +++ b/plugins/openwith/openwithplugin.cpp @@ -97,7 +97,7 @@ { } -KDevelop::ContextMenuExtension OpenWithPlugin::contextMenuExtension( KDevelop::Context* context ) +KDevelop::ContextMenuExtension OpenWithPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent) { // do not recurse if (context->hasType(KDevelop::Context::OpenWithContext)) { @@ -136,18 +136,18 @@ QMimeType mimetype = QMimeDatabase().mimeTypeForUrl(m_urls.first()); m_mimeType = mimetype.name(); - QList partActions = actionsForServiceType(QStringLiteral("KParts/ReadOnlyPart")); - QList appActions = actionsForServiceType(QStringLiteral("Application")); + QList partActions = actionsForServiceType(QStringLiteral("KParts/ReadOnlyPart"), parent); + QList appActions = actionsForServiceType(QStringLiteral("Application"), parent); OpenWithContext subContext(m_urls, mimetype); - QList extensions = ICore::self()->pluginController()->queryPluginsForContextMenuExtensions( &subContext ); + QList extensions = ICore::self()->pluginController()->queryPluginsForContextMenuExtensions( &subContext, parent); foreach( const ContextMenuExtension& ext, extensions ) { appActions += ext.actions(ContextMenuExtension::OpenExternalGroup); partActions += ext.actions(ContextMenuExtension::OpenEmbeddedGroup); } { - auto other = new QAction(i18n("Other..."), this); + auto other = new QAction(i18n("Other..."), parent); connect(other, &QAction::triggered, this, [this] { auto dialog = new KOpenWithDialog(m_urls, ICore::self()->uiController()->activeMainWindow()); if (dialog->exec() == QDialog::Accepted && dialog->service()) { @@ -158,7 +158,7 @@ } // Now setup a menu with actions for each part and app - QMenu* menu = new QMenu( i18n("Open With" ) ); + QMenu* menu = new QMenu(i18n("Open With"), parent); auto documentOpenIcon = QIcon::fromTheme( QStringLiteral("document-open") ); menu->setIcon( documentOpenIcon ); @@ -174,7 +174,7 @@ KDevelop::ContextMenuExtension ext; if (canOpenDefault(m_mimeType)) { - QAction* openAction = new QAction( i18n( "Open" ), this ); + QAction* openAction = new QAction(i18n("Open"), parent); openAction->setIcon( documentOpenIcon ); connect( openAction, &QAction::triggered, this, &OpenWithPlugin::openDefault ); ext.addAction( KDevelop::ContextMenuExtension::FileGroup, openAction ); @@ -184,7 +184,7 @@ return ext; } -QList OpenWithPlugin::actionsForServiceType( const QString& serviceType ) +QList OpenWithPlugin::actionsForServiceType(const QString& serviceType, QWidget* parent) { KService::List list = KMimeTypeTrader::self()->query( m_mimeType, serviceType ); KService::Ptr pref = KMimeTypeTrader::self()->preferredService( m_mimeType, serviceType ); @@ -194,7 +194,7 @@ QAction* standardAction = nullptr; const QString defaultId = defaultForMimeType(m_mimeType); foreach( KService::Ptr svc, list ) { - QAction* act = new QAction( isTextEditor(svc) ? i18n("Default Editor") : svc->name(), this ); + QAction* act = new QAction(isTextEditor(svc) ? i18n("Default Editor") : svc->name(), parent); act->setIcon( QIcon::fromTheme( svc->icon() ) ); if (svc->storageId() == defaultId || (defaultId.isEmpty() && isTextEditor(svc))) { QFont font = act->font(); diff --git a/plugins/patchreview/patchreview.h b/plugins/patchreview/patchreview.h --- a/plugins/patchreview/patchreview.h +++ b/plugins/patchreview/patchreview.h @@ -83,7 +83,7 @@ QUrl urlForFileModel( const Diff2::DiffModel* model ); QAction* finishReviewAction() const { return m_finishReview; } - KDevelop::ContextMenuExtension contextMenuExtension( KDevelop::Context* context ) override; + KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context, QWidget* parent) override; Q_SIGNALS: void startingNewReview(); diff --git a/plugins/patchreview/patchreview.cpp b/plugins/patchreview/patchreview.cpp --- a/plugins/patchreview/patchreview.cpp +++ b/plugins/patchreview/patchreview.cpp @@ -575,7 +575,7 @@ } } -KDevelop::ContextMenuExtension PatchReviewPlugin::contextMenuExtension( KDevelop::Context* context ) +KDevelop::ContextMenuExtension PatchReviewPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent) { QList urls; @@ -596,15 +596,15 @@ if (urls.size() == 1) { QAction* reviewAction = new QAction( QIcon::fromTheme(QStringLiteral("text-x-patch")), - i18n( "Review Patch" ), this ); + i18n("Review Patch"), parent); reviewAction->setData(QVariant(urls[0])); connect( reviewAction, &QAction::triggered, this, &PatchReviewPlugin::executeFileReviewAction ); ContextMenuExtension cm; cm.addAction( KDevelop::ContextMenuExtension::VcsGroup, reviewAction ); return cm; } - return KDevelop::IPlugin::contextMenuExtension( context ); + return KDevelop::IPlugin::contextMenuExtension(context, parent); } void PatchReviewPlugin::executeFileReviewAction() diff --git a/plugins/patchreview/patchreviewtoolview.cpp b/plugins/patchreview/patchreviewtoolview.cpp --- a/plugins/patchreview/patchreviewtoolview.cpp +++ b/plugins/patchreview/patchreviewtoolview.cpp @@ -272,7 +272,7 @@ QList extensions; if(!urls.isEmpty()) { KDevelop::FileContext context(urls); - extensions = ICore::self()->pluginController()->queryPluginsForContextMenuExtensions( &context ); + extensions = ICore::self()->pluginController()->queryPluginsForContextMenuExtensions(&context, menu); } QList vcsActions; diff --git a/plugins/perforce/perforceplugin.h b/plugins/perforce/perforceplugin.h --- a/plugins/perforce/perforceplugin.h +++ b/plugins/perforce/perforceplugin.h @@ -127,7 +127,7 @@ KDevelop::VcsJob* edit(const QList& localLocations); - KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context) override; + KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context, QWidget* parent) override; public Q_SLOTS: diff --git a/plugins/perforce/perforceplugin.cpp b/plugins/perforce/perforceplugin.cpp --- a/plugins/perforce/perforceplugin.cpp +++ b/plugins/perforce/perforceplugin.cpp @@ -450,7 +450,7 @@ return nullptr; } -KDevelop::ContextMenuExtension PerforcePlugin::contextMenuExtension(KDevelop::Context* context) +KDevelop::ContextMenuExtension PerforcePlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent) { m_common->setupFromContext(context); @@ -465,9 +465,9 @@ } if (!hasVersionControlledEntries) - return IPlugin::contextMenuExtension(context); + return IPlugin::contextMenuExtension(context, parent); - QMenu * perforceMenu = m_common->commonActions(); + QMenu * perforceMenu = m_common->commonActions(parent); perforceMenu->addSeparator(); perforceMenu->addSeparator(); diff --git a/plugins/problemreporter/problemreporterplugin.h b/plugins/problemreporter/problemreporterplugin.h --- a/plugins/problemreporter/problemreporterplugin.h +++ b/plugins/problemreporter/problemreporterplugin.h @@ -50,7 +50,7 @@ explicit ProblemReporterPlugin(QObject* parent, const QVariantList& = QVariantList()); ~ProblemReporterPlugin() override; - KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context) override; + KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context, QWidget* parent) override; // KDevelop::Plugin methods void unload() override; diff --git a/plugins/problemreporter/problemreporterplugin.cpp b/plugins/problemreporter/problemreporterplugin.cpp --- a/plugins/problemreporter/problemreporterplugin.cpp +++ b/plugins/problemreporter/problemreporterplugin.cpp @@ -176,7 +176,7 @@ w->showModel(id); } -KDevelop::ContextMenuExtension ProblemReporterPlugin::contextMenuExtension(KDevelop::Context* context) +KDevelop::ContextMenuExtension ProblemReporterPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent) { KDevelop::ContextMenuExtension extension; @@ -200,7 +200,7 @@ if (solution) { title = solution->title(); foreach (KDevelop::IAssistantAction::Ptr action, solution->actions()) - actions << action->toQAction(); + actions << action->toQAction(parent); } } } @@ -214,13 +214,11 @@ text = i18n("Solve: %1", KDevelop::htmlToPlainText(title)); } - QAction* menuAction = new QAction(text, nullptr); - QMenu* menu(new QMenu(text, nullptr)); - menuAction->setMenu(menu); + QMenu* menu = new QMenu(text, parent); foreach (QAction* action, actions) menu->addAction(action); - extension.addAction(ContextMenuExtension::ExtensionGroup, menuAction); + extension.addAction(ContextMenuExtension::ExtensionGroup, menu->menuAction()); } } return extension; diff --git a/plugins/projectfilter/projectfilterprovider.h b/plugins/projectfilter/projectfilterprovider.h --- a/plugins/projectfilter/projectfilterprovider.h +++ b/plugins/projectfilter/projectfilterprovider.h @@ -41,7 +41,7 @@ QSharedPointer createFilter(IProject* project) const override; - ContextMenuExtension contextMenuExtension(Context* context) override; + ContextMenuExtension contextMenuExtension(Context* context, QWidget* parent) override; int perProjectConfigPages() const override; ConfigPage* perProjectConfigPage(int number, const ProjectConfigOptions& options, QWidget* parent) override; diff --git a/plugins/projectfilter/projectfilterprovider.cpp b/plugins/projectfilter/projectfilterprovider.cpp --- a/plugins/projectfilter/projectfilterprovider.cpp +++ b/plugins/projectfilter/projectfilterprovider.cpp @@ -63,7 +63,7 @@ return QSharedPointer(new ProjectFilter(project, m_filters[project])); } -ContextMenuExtension ProjectFilterProvider::contextMenuExtension(Context* context) +ContextMenuExtension ProjectFilterProvider::contextMenuExtension(Context* context, QWidget* parent) { ContextMenuExtension ret; if (!context->hasType(Context::ProjectItemContext)) { @@ -89,7 +89,7 @@ QAction* action = new QAction(QIcon::fromTheme(QStringLiteral("view-filter")), i18np("Exclude Item From Project", "Exclude Items From Project", - items.size()), this); + items.size()), parent); action->setData(QVariant::fromValue(items)); connect(action, &QAction::triggered, this, &ProjectFilterProvider::addFilterFromContextMenu); ret.addAction(ContextMenuExtension::FileGroup, action); diff --git a/plugins/projectmanagerview/projectbuildsetwidget.cpp b/plugins/projectmanagerview/projectbuildsetwidget.cpp --- a/plugins/projectmanagerview/projectbuildsetwidget.cpp +++ b/plugins/projectmanagerview/projectbuildsetwidget.cpp @@ -147,7 +147,7 @@ if( !itemlist.isEmpty() ) { KDevelop::ProjectItemContextImpl context(itemlist); - QList extensions = KDevelop::ICore::self()->pluginController()->queryPluginsForContextMenuExtensions( &context ); + QList extensions = KDevelop::ICore::self()->pluginController()->queryPluginsForContextMenuExtensions(&context, &m); QList buildActions; QList vcsActions; diff --git a/plugins/projectmanagerview/projectmanagerviewplugin.h b/plugins/projectmanagerview/projectmanagerviewplugin.h --- a/plugins/projectmanagerview/projectmanagerviewplugin.h +++ b/plugins/projectmanagerview/projectmanagerviewplugin.h @@ -43,7 +43,7 @@ // Plugin methods void unload() override; - KDevelop::ContextMenuExtension contextMenuExtension( KDevelop::Context* ) override; + KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context, QWidget* parent) override; void removeItems(const QList& items); void renameItems(const QList< KDevelop::ProjectBaseItem* >& items); diff --git a/plugins/projectmanagerview/projectmanagerviewplugin.cpp b/plugins/projectmanagerview/projectmanagerviewplugin.cpp --- a/plugins/projectmanagerview/projectmanagerviewplugin.cpp +++ b/plugins/projectmanagerview/projectmanagerviewplugin.cpp @@ -194,18 +194,18 @@ core()->uiController()->removeToolView(d->factory); } -ContextMenuExtension ProjectManagerViewPlugin::contextMenuExtension( KDevelop::Context* context ) +ContextMenuExtension ProjectManagerViewPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent) { if( context->type() != KDevelop::Context::ProjectItemContext ) - return IPlugin::contextMenuExtension( context ); + return IPlugin::contextMenuExtension(context, parent); KDevelop::ProjectItemContext* ctx = static_cast(context); QList items = ctx->items(); d->ctxProjectItemList.clear(); if( items.isEmpty() ) - return IPlugin::contextMenuExtension( context ); + return IPlugin::contextMenuExtension(context, parent); //TODO: also needs: removeTarget, removeFileFromTarget, runTargetsFromContextMenu ContextMenuExtension menuExt; @@ -243,73 +243,73 @@ } if ( needsCreateFile ) { - QAction* action = new QAction( i18n( "Create &File..." ), this ); + QAction* action = new QAction(i18n("Create &File..."), parent); action->setIcon(QIcon::fromTheme(QStringLiteral("document-new"))); connect( action, &QAction::triggered, this, &ProjectManagerViewPlugin::createFileFromContextMenu ); menuExt.addAction( ContextMenuExtension::FileGroup, action ); } if ( needsCreateFolder ) { - QAction* action = new QAction( i18n( "Create F&older..." ), this ); + QAction* action = new QAction(i18n("Create F&older..."), parent); action->setIcon(QIcon::fromTheme(QStringLiteral("folder-new"))); connect( action, &QAction::triggered, this, &ProjectManagerViewPlugin::createFolderFromContextMenu ); menuExt.addAction( ContextMenuExtension::FileGroup, action ); } if ( needsBuildItems ) { - QAction* action = new QAction( i18nc( "@action", "&Build" ), this ); + QAction* action = new QAction(i18nc("@action", "&Build"), parent); action->setIcon(QIcon::fromTheme(QStringLiteral("run-build"))); connect( action, &QAction::triggered, this, &ProjectManagerViewPlugin::buildItemsFromContextMenu ); menuExt.addAction( ContextMenuExtension::BuildGroup, action ); - action = new QAction( i18nc( "@action", "&Install" ), this ); + action = new QAction(i18nc("@action", "&Install"), parent); action->setIcon(QIcon::fromTheme(QStringLiteral("run-build-install"))); connect( action, &QAction::triggered, this, &ProjectManagerViewPlugin::installItemsFromContextMenu ); menuExt.addAction( ContextMenuExtension::BuildGroup, action ); - action = new QAction( i18nc( "@action", "&Clean" ), this ); + action = new QAction(i18nc("@action", "&Clean"), parent); action->setIcon(QIcon::fromTheme(QStringLiteral("run-build-clean"))); connect( action, &QAction::triggered, this, &ProjectManagerViewPlugin::cleanItemsFromContextMenu ); menuExt.addAction( ContextMenuExtension::BuildGroup, action ); - action = new QAction( i18n( "&Add to Build Set" ), this ); + action = new QAction(i18n("&Add to Build Set"), parent); action->setIcon(QIcon::fromTheme(QStringLiteral("list-add"))); connect( action, &QAction::triggered, this, &ProjectManagerViewPlugin::addItemsFromContextMenuToBuildset ); menuExt.addAction( ContextMenuExtension::BuildGroup, action ); } if ( needsCloseProjects ) { - QAction* close = new QAction( i18np( "C&lose Project", "Close Projects", items.count() ), this ); + QAction* close = new QAction(i18np("C&lose Project", "Close Projects", items.count()), parent); close->setIcon(QIcon::fromTheme(QStringLiteral("project-development-close"))); connect( close, &QAction::triggered, this, &ProjectManagerViewPlugin::closeProjects ); menuExt.addAction( ContextMenuExtension::ProjectGroup, close ); } if ( needsFolderItems ) { - QAction* action = new QAction( i18n( "&Reload" ), this ); + QAction* action = new QAction(i18n("&Reload"), parent); action->setIcon(QIcon::fromTheme(QStringLiteral("view-refresh"))); connect( action, &QAction::triggered, this, &ProjectManagerViewPlugin::reloadFromContextMenu ); menuExt.addAction( ContextMenuExtension::FileGroup, action ); } if ( needsRemoveAndRename ) { - QAction* remove = new QAction( i18n( "Remo&ve" ), this ); + QAction* remove = new QAction(i18n("Remo&ve"), parent); remove->setIcon(QIcon::fromTheme(QStringLiteral("user-trash"))); connect( remove, &QAction::triggered, this, &ProjectManagerViewPlugin::removeFromContextMenu ); menuExt.addAction( ContextMenuExtension::FileGroup, remove ); - QAction* rename = new QAction( i18n( "Re&name..." ), this ); + QAction* rename = new QAction(i18n("Re&name..."), parent); rename->setIcon(QIcon::fromTheme(QStringLiteral("edit-rename"))); connect( rename, &QAction::triggered, this, &ProjectManagerViewPlugin::renameItemFromContextMenu ); menuExt.addAction( ContextMenuExtension::FileGroup, rename ); } if ( needsRemoveTargetFiles ) { - QAction* remove = new QAction( i18n( "Remove From &Target" ), this ); + QAction* remove = new QAction(i18n("Remove From &Target"), parent); remove->setIcon(QIcon::fromTheme(QStringLiteral("user-trash"))); connect( remove, &QAction::triggered, this, &ProjectManagerViewPlugin::removeTargetFilesFromContextMenu ); menuExt.addAction( ContextMenuExtension::FileGroup, remove ); } { - QAction* copy = KStandardAction::copy(this, SLOT(copyFromContextMenu()), this); + QAction* copy = KStandardAction::copy(this, SLOT(copyFromContextMenu()), parent); copy->setShortcutContext(Qt::WidgetShortcut); menuExt.addAction( ContextMenuExtension::FileGroup, copy ); } if (needsPaste) { - QAction* paste = KStandardAction::paste(this, SLOT(pasteFromContextMenu()), this); + QAction* paste = KStandardAction::paste(this, SLOT(pasteFromContextMenu()), parent); paste->setShortcutContext(Qt::WidgetShortcut); menuExt.addAction( ContextMenuExtension::FileGroup, paste ); } diff --git a/plugins/projectmanagerview/projecttreeview.cpp b/plugins/projectmanagerview/projecttreeview.cpp --- a/plugins/projectmanagerview/projecttreeview.cpp +++ b/plugins/projectmanagerview/projecttreeview.cpp @@ -339,7 +339,7 @@ QMenu menu( this ); KDevelop::ProjectItemContextImpl context(itemlist); - QList extensions = ICore::self()->pluginController()->queryPluginsForContextMenuExtensions( &context ); + QList extensions = ICore::self()->pluginController()->queryPluginsForContextMenuExtensions(&context, &menu); QList buildActions; QList vcsActions; diff --git a/plugins/quickopen/quickopenplugin.h b/plugins/quickopen/quickopenplugin.h --- a/plugins/quickopen/quickopenplugin.h +++ b/plugins/quickopen/quickopenplugin.h @@ -55,7 +55,7 @@ // KDevelop::Plugin methods void unload() override; - KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context) override; + KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context, QWidget* parent) override; enum ModelTypes { Files = 1, diff --git a/plugins/quickopen/quickopenplugin.cpp b/plugins/quickopen/quickopenplugin.cpp --- a/plugins/quickopen/quickopenplugin.cpp +++ b/plugins/quickopen/quickopenplugin.cpp @@ -412,9 +412,9 @@ { } -ContextMenuExtension QuickOpenPlugin::contextMenuExtension(Context* context) +ContextMenuExtension QuickOpenPlugin::contextMenuExtension(Context* context, QWidget* parent) { - KDevelop::ContextMenuExtension menuExt = KDevelop::IPlugin::contextMenuExtension(context); + KDevelop::ContextMenuExtension menuExt = KDevelop::IPlugin::contextMenuExtension(context, parent); KDevelop::DeclarationContext* codeContext = dynamic_cast(context); diff --git a/plugins/subversion/kdevsvnplugin.h b/plugins/subversion/kdevsvnplugin.h --- a/plugins/subversion/kdevsvnplugin.h +++ b/plugins/subversion/kdevsvnplugin.h @@ -132,7 +132,7 @@ KDevelop::VcsRevision::RevisionType) override; // End: KDevelop::ICentralizedVersionControl - KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context*) override; + KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context, QWidget* parent) override; ThreadWeaver::Queue* jobQueue() const; diff --git a/plugins/subversion/kdevsvnplugin.cpp b/plugins/subversion/kdevsvnplugin.cpp --- a/plugins/subversion/kdevsvnplugin.cpp +++ b/plugins/subversion/kdevsvnplugin.cpp @@ -317,7 +317,7 @@ } -KDevelop::ContextMenuExtension KDevSvnPlugin::contextMenuExtension(KDevelop::Context* context) +KDevelop::ContextMenuExtension KDevSvnPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent) { m_common->setupFromContext(context); @@ -334,10 +334,10 @@ qCDebug(PLUGIN_SVN) << "version controlled?" << hasVersionControlledEntries; if (!hasVersionControlledEntries) - return IPlugin::contextMenuExtension(context); + return IPlugin::contextMenuExtension(context, parent); - QMenu* svnmenu= m_common->commonActions(); + QMenu* svnmenu = m_common->commonActions(parent); svnmenu->addSeparator(); if( !copy_action ) diff --git a/plugins/switchtobuddy/switchtobuddyplugin.h b/plugins/switchtobuddy/switchtobuddyplugin.h --- a/plugins/switchtobuddy/switchtobuddyplugin.h +++ b/plugins/switchtobuddy/switchtobuddyplugin.h @@ -50,7 +50,7 @@ explicit SwitchToBuddyPlugin( QObject *parent, const QVariantList & = QVariantList()); ~SwitchToBuddyPlugin() override; - KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context) override; + KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context, QWidget* parent) override; void createActionsForMainWindow(Sublime::MainWindow* window, QString& xmlFile, KActionCollection& actions) override; private Q_SLOTS: diff --git a/plugins/switchtobuddy/switchtobuddyplugin.cpp b/plugins/switchtobuddy/switchtobuddyplugin.cpp --- a/plugins/switchtobuddy/switchtobuddyplugin.cpp +++ b/plugins/switchtobuddy/switchtobuddyplugin.cpp @@ -101,7 +101,7 @@ { } -ContextMenuExtension SwitchToBuddyPlugin::contextMenuExtension(Context* context) +ContextMenuExtension SwitchToBuddyPlugin::contextMenuExtension(Context* context, QWidget* parent) { EditorContext* ctx = dynamic_cast(context); if (!ctx) { @@ -129,7 +129,7 @@ continue; } - QAction* action = new QAction(i18n("Switch to '%1'", url.fileName()), this); + QAction* action = new QAction(i18n("Switch to '%1'", url.fileName()), parent); connect(action, &QAction::triggered, m_signalMapper, static_cast(&QSignalMapper::map), Qt::QueuedConnection); m_signalMapper->setMapping(action, url.toLocalFile()); connect(m_signalMapper, static_cast(&QSignalMapper::mapped), diff --git a/plugins/vcschangesview/vcschangesview.cpp b/plugins/vcschangesview/vcschangesview.cpp --- a/plugins/vcschangesview/vcschangesview.cpp +++ b/plugins/vcschangesview/vcschangesview.cpp @@ -97,14 +97,14 @@ QList extensions; if(!urls.isEmpty()) { KDevelop::FileContext context(urls); - extensions = ICore::self()->pluginController()->queryPluginsForContextMenuExtensions( &context ); + extensions = ICore::self()->pluginController()->queryPluginsForContextMenuExtensions(&context, menu); } else { QList items; foreach(IProject* p, projects) items += p->projectItem(); KDevelop::ProjectItemContextImpl context(items); - extensions = ICore::self()->pluginController()->queryPluginsForContextMenuExtensions( &context ); + extensions = ICore::self()->pluginController()->queryPluginsForContextMenuExtensions(&context, menu); } diff --git a/shell/debugcontroller.h b/shell/debugcontroller.h --- a/shell/debugcontroller.h +++ b/shell/debugcontroller.h @@ -62,7 +62,7 @@ void addSession(IDebugSession* session) override; IDebugSession* currentSession() override; - ContextMenuExtension contextMenuExtension( Context* context ); + ContextMenuExtension contextMenuExtension(Context* context, QWidget* parent); BreakpointModel* breakpointModel() override; VariableCollection* variableCollection() override; diff --git a/shell/debugcontroller.cpp b/shell/debugcontroller.cpp --- a/shell/debugcontroller.cpp +++ b/shell/debugcontroller.cpp @@ -447,8 +447,10 @@ } } -ContextMenuExtension DebugController::contextMenuExtension( Context* context ) +ContextMenuExtension DebugController::contextMenuExtension(Context* context, QWidget* parent) { + Q_UNUSED(parent); + ContextMenuExtension menuExt; if( context->type() != Context::EditorContext ) diff --git a/shell/documentationcontroller.h b/shell/documentationcontroller.h --- a/shell/documentationcontroller.h +++ b/shell/documentationcontroller.h @@ -45,7 +45,7 @@ QList documentationProviders() const override; IDocumentation::Ptr documentationForDeclaration(Declaration* declaration) override; void showDocumentation(const IDocumentation::Ptr& doc) override; - ContextMenuExtension contextMenuExtension( Context* context ); + ContextMenuExtension contextMenuExtension(Context* context, QWidget* parent); public Q_SLOTS: void changedDocumentationProviders() override; diff --git a/shell/documentationcontroller.cpp b/shell/documentationcontroller.cpp --- a/shell/documentationcontroller.cpp +++ b/shell/documentationcontroller.cpp @@ -143,8 +143,10 @@ } } -KDevelop::ContextMenuExtension KDevelop::DocumentationController::contextMenuExtension ( Context* context ) +KDevelop::ContextMenuExtension KDevelop::DocumentationController::contextMenuExtension(Context* context, QWidget* parent) { + Q_UNUSED(parent); + ContextMenuExtension menuExt; DeclarationContext* ctx = dynamic_cast(context); diff --git a/shell/plugincontroller.h b/shell/plugincontroller.h --- a/shell/plugincontroller.h +++ b/shell/plugincontroller.h @@ -124,7 +124,7 @@ QVector queryExtensionPlugins(const QString& extension, const QVariantMap& constraints = QVariantMap()) const override; - QList queryPluginsForContextMenuExtensions( KDevelop::Context* context ) const override; + QList queryPluginsForContextMenuExtensions(KDevelop::Context* context, QWidget* parent) const override; QStringList projectPlugins(); diff --git a/shell/plugincontroller.cpp b/shell/plugincontroller.cpp --- a/shell/plugincontroller.cpp +++ b/shell/plugincontroller.cpp @@ -683,7 +683,7 @@ return names; } -QList PluginController::queryPluginsForContextMenuExtensions(KDevelop::Context* context) const +QList PluginController::queryPluginsForContextMenuExtensions(KDevelop::Context* context, QWidget* parent) const { // This fixes random order of extension menu items between different runs of KDevelop. // Without sorting we have random reordering of "Analyze With" submenu for example: @@ -696,14 +696,14 @@ QList exts; foreach (IPlugin* plugin, sortedPlugins) { - exts << plugin->contextMenuExtension(context); + exts << plugin->contextMenuExtension(context, parent); } - exts << Core::self()->debugControllerInternal()->contextMenuExtension(context); - exts << Core::self()->documentationControllerInternal()->contextMenuExtension(context); - exts << Core::self()->sourceFormatterControllerInternal()->contextMenuExtension(context); - exts << Core::self()->runControllerInternal()->contextMenuExtension(context); - exts << Core::self()->projectControllerInternal()->contextMenuExtension(context); + exts << Core::self()->debugControllerInternal()->contextMenuExtension(context, parent); + exts << Core::self()->documentationControllerInternal()->contextMenuExtension(context, parent); + exts << Core::self()->sourceFormatterControllerInternal()->contextMenuExtension(context, parent); + exts << Core::self()->runControllerInternal()->contextMenuExtension(context, parent); + exts << Core::self()->projectControllerInternal()->contextMenuExtension(context, parent); return exts; } diff --git a/shell/projectcontroller.h b/shell/projectcontroller.h --- a/shell/projectcontroller.h +++ b/shell/projectcontroller.h @@ -94,7 +94,7 @@ QString prettyFileName(const QUrl& url, FormattingOptions format = FormatHtml) const override; QString prettyFilePath(const QUrl& url, FormattingOptions format = FormatHtml) const override; - ContextMenuExtension contextMenuExtension( KDevelop::Context* ctx ); + ContextMenuExtension contextMenuExtension(KDevelop::Context* ctx, QWidget* parent); void fetchProjectFromUrl(const QUrl& repoUrl, IPlugin* vcsOrProviderPlugin); diff --git a/shell/projectcontroller.cpp b/shell/projectcontroller.cpp --- a/shell/projectcontroller.cpp +++ b/shell/projectcontroller.cpp @@ -1121,8 +1121,9 @@ } } -ContextMenuExtension ProjectController::contextMenuExtension ( Context* ctx ) +ContextMenuExtension ProjectController::contextMenuExtension(Context* ctx, QWidget* parent) { + Q_UNUSED(parent); ContextMenuExtension ext; if ( ctx->type() != Context::ProjectItemContext || !static_cast(ctx)->items().isEmpty() ) { return ext; diff --git a/shell/runcontroller.h b/shell/runcontroller.h --- a/shell/runcontroller.h +++ b/shell/runcontroller.h @@ -117,7 +117,7 @@ */ void showConfigurationDialog() const override; - ContextMenuExtension contextMenuExtension( KDevelop::Context* ctx ); + ContextMenuExtension contextMenuExtension(KDevelop::Context* ctx, QWidget* parent); public Q_SLOTS: Q_SCRIPTABLE void executeDefaultLaunch(const QString& runMode) override; diff --git a/shell/runcontroller.cpp b/shell/runcontroller.cpp --- a/shell/runcontroller.cpp +++ b/shell/runcontroller.cpp @@ -965,7 +965,7 @@ return d->delegate; } -ContextMenuExtension RunController::contextMenuExtension ( Context* ctx ) +ContextMenuExtension RunController::contextMenuExtension(Context* ctx, QWidget* parent) { delete d->launchAsMapper; d->launchAsMapper = new QSignalMapper( this ); @@ -981,7 +981,7 @@ int i = 0; foreach( ILaunchMode* mode, d->launchModes ) { - KActionMenu* menu = new KActionMenu( i18n("%1 As...", mode->name() ), this ); + KActionMenu* menu = new KActionMenu(i18n("%1 As...", mode->name() ), parent); foreach( LaunchConfigurationType* type, launchConfigurationTypes() ) { bool hasLauncher = false; @@ -1007,6 +1007,8 @@ if( menu->menu()->actions().count() > 0 ) { ext.addAction( ContextMenuExtension::RunGroup, menu); + } else { + delete menu; } } if( ext.actions( ContextMenuExtension::RunGroup ).count() > 0 ) diff --git a/shell/sourceformattercontroller.h b/shell/sourceformattercontroller.h --- a/shell/sourceformattercontroller.h +++ b/shell/sourceformattercontroller.h @@ -119,7 +119,7 @@ */ ISourceFormatter* findFirstFormatterForMimeType(const QMimeType& mime) const; - KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context); + KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context, QWidget* parent); KDevelop::SourceFormatterStyle styleForMimeType(const QMimeType& mime) override; diff --git a/shell/sourceformattercontroller.cpp b/shell/sourceformattercontroller.cpp --- a/shell/sourceformattercontroller.cpp +++ b/shell/sourceformattercontroller.cpp @@ -595,8 +595,10 @@ } } -KDevelop::ContextMenuExtension SourceFormatterController::contextMenuExtension(KDevelop::Context* context) +KDevelop::ContextMenuExtension SourceFormatterController::contextMenuExtension(KDevelop::Context* context, QWidget* parent) { + Q_UNUSED(parent); + KDevelop::ContextMenuExtension ext; m_urls.clear(); m_prjItems.clear(); diff --git a/shell/textdocument.cpp b/shell/textdocument.cpp --- a/shell/textdocument.cpp +++ b/shell/textdocument.cpp @@ -720,7 +720,7 @@ d->m_addedContextMenu = new QMenu(); EditorContext c(v, v->cursorPosition()); - auto extensions = Core::self()->pluginController()->queryPluginsForContextMenuExtensions(&c); + auto extensions = Core::self()->pluginController()->queryPluginsForContextMenuExtensions(&c, d->m_addedContextMenu); ContextMenuExtension::populateMenu(d->m_addedContextMenu, extensions); diff --git a/tests/testplugincontroller.h b/tests/testplugincontroller.h --- a/tests/testplugincontroller.h +++ b/tests/testplugincontroller.h @@ -44,7 +44,7 @@ KDevelop::IPlugin* pluginForExtension(const QString& extension, const QString& pluginName = {}, const QVariantMap& constraints = QVariantMap()) override; KDevelop::IPlugin* loadPlugin(const QString& pluginName) override; KPluginMetaData pluginInfo(const KDevelop::IPlugin*) const override; - QList< KDevelop::ContextMenuExtension > queryPluginsForContextMenuExtensions(KDevelop::Context* context)const override ; + QList< KDevelop::ContextMenuExtension > queryPluginsForContextMenuExtensions(KDevelop::Context* context, QWidget* parent) const override ; QVector queryExtensionPlugins(const QString& extension, const QVariantMap& constraints = QVariantMap()) const override; bool unloadPlugin(const QString& plugin) override; void initialize() override; diff --git a/tests/testplugincontroller.cpp b/tests/testplugincontroller.cpp --- a/tests/testplugincontroller.cpp +++ b/tests/testplugincontroller.cpp @@ -75,9 +75,10 @@ return KPluginMetaData(); } -QList< ContextMenuExtension > TestPluginController::queryPluginsForContextMenuExtensions(Context* context) const +QList< ContextMenuExtension > TestPluginController::queryPluginsForContextMenuExtensions(Context* context, QWidget* parent) const { Q_UNUSED(context); + Q_UNUSED(parent); return QList< ContextMenuExtension >(); } diff --git a/vcs/dvcs/dvcsplugin.h b/vcs/dvcs/dvcsplugin.h --- a/vcs/dvcs/dvcsplugin.h +++ b/vcs/dvcs/dvcsplugin.h @@ -63,7 +63,7 @@ /** Creates context menu * @note Create only special items here (like checkout), all standard menu items are created in vcscommon plugin! */ - ContextMenuExtension contextMenuExtension(Context*) override; + ContextMenuExtension contextMenuExtension(Context* context, QWidget* parent) override; /** * Parses the output generated by a @code dvcs log @endcode command and diff --git a/vcs/dvcs/dvcsplugin.cpp b/vcs/dvcs/dvcsplugin.cpp --- a/vcs/dvcs/dvcsplugin.cpp +++ b/vcs/dvcs/dvcsplugin.cpp @@ -84,7 +84,7 @@ } KDevelop::ContextMenuExtension -DistributedVersionControlPlugin::contextMenuExtension(Context* context) +DistributedVersionControlPlugin::contextMenuExtension(Context* context, QWidget* parent) { d->m_common->setupFromContext(context); QList const & ctxUrlList = d->m_common->contextUrlList(); @@ -101,7 +101,7 @@ return ContextMenuExtension(); } - QMenu * menu = d->m_common->commonActions(); + QMenu * menu = d->m_common->commonActions(parent); menu->addSeparator(); menu->addAction(i18n("Branches..."), this, SLOT(ctxBranchManager()))->setEnabled(ctxUrlList.count()==1); additionalMenuEntries(menu, ctxUrlList); diff --git a/vcs/vcspluginhelper.h b/vcs/vcspluginhelper.h --- a/vcs/vcspluginhelper.h +++ b/vcs/vcspluginhelper.h @@ -47,10 +47,10 @@ QList contextUrlList() const; /** * Creates and returns a menu with common actions. - * Ownership of the menu itself is passed to the caller. * Ownership of the actions in the menu stays with this VcsPluginHelper object. + * @param parent the parent widget set for the QMenu for memory menagement */ - QMenu* commonActions(); + QMenu* commonActions(QWidget* parent); public Q_SLOTS: void commit(); diff --git a/vcs/vcspluginhelper.cpp b/vcs/vcspluginhelper.cpp --- a/vcs/vcspluginhelper.cpp +++ b/vcs/vcspluginhelper.cpp @@ -112,7 +112,7 @@ return ret; } - QMenu* createMenu() + QMenu* createMenu(QWidget* parent) { bool allVersioned=true; foreach(const QUrl &url, ctxUrls) { @@ -122,7 +122,7 @@ break; } - QMenu* menu = new QMenu(vcs->name()); + QMenu* menu = new QMenu(vcs->name(), parent); menu->setIcon(QIcon::fromTheme(ICore::self()->pluginController()->pluginInfo(plugin).iconName())); menu->addAction(commitAction); if(plugin->extension()) { @@ -191,7 +191,7 @@ return d->ctxUrls; } -QMenu* VcsPluginHelper::commonActions() +QMenu* VcsPluginHelper::commonActions(QWidget* parent) { /* TODO: the following logic to determine which actions need to be enabled * or disabled does not work properly. What needs to be implemented is that @@ -202,7 +202,7 @@ * one we assume the urls can be added but are not currently controlled. If * the url is already version controlled then just enable all except add */ - return d->createMenu(); + return d->createMenu(parent); } #define EXECUTE_VCS_METHOD( method ) \