From 493d1873d222725df56a026dcb7f958db7078d97 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 20 Sep 2023 14:31:46 +0200 Subject: [PATCH] CppEditor: Populate the refactor menu on demand That is, collect the quickfixes only when the refactor menu is expanded, not when opening the context menu. Task-number: QTCREATORBUG-29611 Change-Id: Ib827940ecbe8878e0b695e4f453926f759b05572 Reviewed-by: David Schulz Reviewed-by: --- src/plugins/cppeditor/cppeditorwidget.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/plugins/cppeditor/cppeditorwidget.cpp b/src/plugins/cppeditor/cppeditorwidget.cpp index acc0c478034..a06977ae5c1 100644 --- a/src/plugins/cppeditor/cppeditorwidget.cpp +++ b/src/plugins/cppeditor/cppeditorwidget.cpp @@ -1089,11 +1089,15 @@ protected: QMenu *CppEditorWidget::createRefactorMenu(QWidget *parent) const { auto *menu = new QMenu(Tr::tr("&Refactor"), parent); + connect(menu, &QMenu::aboutToShow, this, [this, menu] { + menu->disconnect(this); - // ### enable - // updateSemanticInfo(m_semanticHighlighter->semanticInfo(currentSource())); + // ### enable + // updateSemanticInfo(m_semanticHighlighter->semanticInfo(currentSource())); + + if (!isSemanticInfoValidExceptLocalUses()) + return; - if (isSemanticInfoValidExceptLocalUses()) { d->m_useSelectionsUpdater.abortSchedule(); const CppUseSelectionsUpdater::RunnerInfo runnerInfo = d->m_useSelectionsUpdater.update(); @@ -1118,7 +1122,7 @@ QMenu *CppEditorWidget::createRefactorMenu(QWidget *parent) const case CppUseSelectionsUpdater::RunnerInfo::Invalid: QTC_CHECK(false && "Unexpected CppUseSelectionsUpdater runner result"); } - } + }); return menu; }