diff --git a/src/plugins/cppeditor/cppcodemodelsettingspage.cpp b/src/plugins/cppeditor/cppcodemodelsettingspage.cpp index 8c24fb79a4a..bc47a78c9df 100644 --- a/src/plugins/cppeditor/cppcodemodelsettingspage.cpp +++ b/src/plugins/cppeditor/cppcodemodelsettingspage.cpp @@ -10,6 +10,7 @@ #include "cppeditortr.h" #include "cpptoolsreuse.h" +#include #include #include @@ -185,14 +186,23 @@ bool CppCodeModelSettingsWidget::applyGeneralWidgetsToSettings() const return settingsChanged; } -CppCodeModelSettingsPage::CppCodeModelSettingsPage() +class CppCodeModelSettingsPage final : public Core::IOptionsPage { - setId(Constants::CPP_CODE_MODEL_SETTINGS_ID); - setDisplayName(Tr::tr("Code Model")); - setCategory(Constants::CPP_SETTINGS_CATEGORY); - setDisplayCategory(Tr::tr("C++")); - setCategoryIconPath(":/projectexplorer/images/settingscategory_cpp.png"); - setWidgetCreator([] { return new CppCodeModelSettingsWidget; }); +public: + CppCodeModelSettingsPage() + { + setId(Constants::CPP_CODE_MODEL_SETTINGS_ID); + setDisplayName(Tr::tr("Code Model")); + setCategory(Constants::CPP_SETTINGS_CATEGORY); + setDisplayCategory(Tr::tr("C++")); + setCategoryIconPath(":/projectexplorer/images/settingscategory_cpp.png"); + setWidgetCreator([] { return new CppCodeModelSettingsWidget; }); + } +}; + +void setupCppCodeModelSettings() +{ + static CppCodeModelSettingsPage theCppCodeModelSettingsPage; } class ClangdSettingsWidget final : public QWidget diff --git a/src/plugins/cppeditor/cppcodemodelsettingspage.h b/src/plugins/cppeditor/cppcodemodelsettingspage.h index b2ee8657079..35a6bc51110 100644 --- a/src/plugins/cppeditor/cppcodemodelsettingspage.h +++ b/src/plugins/cppeditor/cppcodemodelsettingspage.h @@ -3,16 +3,9 @@ #pragma once -#include - namespace CppEditor::Internal { -class CppCodeModelSettingsPage final : public Core::IOptionsPage -{ -public: - CppCodeModelSettingsPage(); -}; - +void setupCppCodeModelSettings(); void setupClangdProjectSettingsPanel(); void setupClangdSettingsPage(); diff --git a/src/plugins/cppeditor/cppcodestylesettingspage.cpp b/src/plugins/cppeditor/cppcodestylesettingspage.cpp index 65abc1da5ea..74f505d663c 100644 --- a/src/plugins/cppeditor/cppcodestylesettingspage.cpp +++ b/src/plugins/cppeditor/cppcodestylesettingspage.cpp @@ -607,12 +607,21 @@ public: // CppCodeStyleSettingsPage -CppCodeStyleSettingsPage::CppCodeStyleSettingsPage() +class CppCodeStyleSettingsPage : public Core::IOptionsPage { - setId(Constants::CPP_CODE_STYLE_SETTINGS_ID); - setDisplayName(Tr::tr("Code Style")); - setCategory(Constants::CPP_SETTINGS_CATEGORY); - setWidgetCreator([] { return new CppCodeStyleSettingsPageWidget; }); +public: + CppCodeStyleSettingsPage() + { + setId(Constants::CPP_CODE_STYLE_SETTINGS_ID); + setDisplayName(Tr::tr("Code Style")); + setCategory(Constants::CPP_SETTINGS_CATEGORY); + setWidgetCreator([] { return new CppCodeStyleSettingsPageWidget; }); + } +}; + +void setupCppCodeStyleSettings() +{ + static CppCodeStyleSettingsPage theCppCodeStyleSettingsPage; } } // namespace CppEditor::Internal diff --git a/src/plugins/cppeditor/cppcodestylesettingspage.h b/src/plugins/cppeditor/cppcodestylesettingspage.h index be3fb4af48a..2a8bce064c8 100644 --- a/src/plugins/cppeditor/cppcodestylesettingspage.h +++ b/src/plugins/cppeditor/cppcodestylesettingspage.h @@ -64,12 +64,7 @@ signals: void finishEmitted(); }; - -class CppCodeStyleSettingsPage : public Core::IOptionsPage -{ -public: - CppCodeStyleSettingsPage(); -}; +void setupCppCodeStyleSettings(); } // namespace Internal } // namespace CppEditor diff --git a/src/plugins/cppeditor/cppeditorplugin.cpp b/src/plugins/cppeditor/cppeditorplugin.cpp index 18eec99a446..b68c739f82e 100644 --- a/src/plugins/cppeditor/cppeditorplugin.cpp +++ b/src/plugins/cppeditor/cppeditorplugin.cpp @@ -160,18 +160,12 @@ public: QAction *m_reparseExternallyChangedFiles = nullptr; QAction *m_findRefsCategorizedAction = nullptr; - CppQuickFixSettingsPage m_quickFixSettingsPage; - QPointer m_cppCodeModelInspectorDialog; - CppOutlineWidgetFactory m_cppOutlineWidgetFactory; CppEditorFactory m_cppEditorFactory; CppModelManager modelManager; CppToolsSettings settings; - CppCodeModelSettingsPage m_cppCodeModelSettingsPage; - CppCodeStyleSettingsPage m_cppCodeStyleSettingsPage; - CppProjectUpdaterFactory m_cppProjectUpdaterFactory; }; class CppEditorPlugin final : public ExtensionSystem::IPlugin @@ -206,6 +200,12 @@ void CppEditorPlugin::initialize() { d = new CppEditorPluginPrivate; + setupCppQuickFixSettings(); + setupCppCodeModelSettings(); + setupCppOutline(); + setupCppCodeStyleSettings(); + setupCppProjectUpdater(); + CppModelManager::registerJsExtension(); setupMenus(); diff --git a/src/plugins/cppeditor/cppoutline.cpp b/src/plugins/cppeditor/cppoutline.cpp index ed7c66df0d9..dd053dc255f 100644 --- a/src/plugins/cppeditor/cppoutline.cpp +++ b/src/plugins/cppeditor/cppoutline.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -24,6 +25,8 @@ #include #include +using namespace TextEditor; + namespace CppEditor::Internal { class CppOutlineTreeView final : public Utils::NavigationTreeView @@ -255,22 +258,36 @@ bool CppOutlineWidget::syncCursor() return m_enableCursorSync && !m_blockCursorSync; } -bool CppOutlineWidgetFactory::supportsEditor(Core::IEditor *editor) const +class CppOutlineWidgetFactory final : public IOutlineWidgetFactory { - const auto cppEditor = qobject_cast(editor); - if (!cppEditor || !CppModelManager::isCppEditor(cppEditor)) - return false; - return !CppModelManager::usesClangd(cppEditor->textDocument()); -} +public: + bool supportsEditor(Core::IEditor *editor) const final + { + const auto cppEditor = qobject_cast(editor); + if (!cppEditor || !CppModelManager::isCppEditor(cppEditor)) + return false; + return !CppModelManager::usesClangd(cppEditor->textDocument()); + } -TextEditor::IOutlineWidget *CppOutlineWidgetFactory::createWidget(Core::IEditor *editor) + bool supportsSorting() const final + { + return true; + } + + IOutlineWidget *createWidget(Core::IEditor *editor) final + { + const auto cppEditor = qobject_cast(editor); + QTC_ASSERT(cppEditor, return nullptr); + const auto cppEditorWidget = qobject_cast(cppEditor->widget()); + QTC_ASSERT(cppEditorWidget, return nullptr); + + return new CppOutlineWidget(cppEditorWidget); + } +}; + +void setupCppOutline() { - const auto cppEditor = qobject_cast(editor); - QTC_ASSERT(cppEditor, return nullptr); - const auto cppEditorWidget = qobject_cast(cppEditor->widget()); - QTC_ASSERT(cppEditorWidget, return nullptr); - - return new CppOutlineWidget(cppEditorWidget); + static CppOutlineWidgetFactory theCppOutlineWidgetFactory; } } // namespace CppEditor::Internal diff --git a/src/plugins/cppeditor/cppoutline.h b/src/plugins/cppeditor/cppoutline.h index 724f623bd3a..322b4b71ed3 100644 --- a/src/plugins/cppeditor/cppoutline.h +++ b/src/plugins/cppeditor/cppoutline.h @@ -3,16 +3,8 @@ #pragma once -#include - namespace CppEditor::Internal { -class CppOutlineWidgetFactory final : public TextEditor::IOutlineWidgetFactory -{ -public: - bool supportsEditor(Core::IEditor *editor) const final; - bool supportsSorting() const final { return true; } - TextEditor::IOutlineWidget *createWidget(Core::IEditor *editor) final; -}; +void setupCppOutline(); -} // namespace CppEditor::Internal +} // CppEditor::Internal diff --git a/src/plugins/cppeditor/cppprojectupdater.cpp b/src/plugins/cppeditor/cppprojectupdater.cpp index e93d0f94c28..1861824a2d1 100644 --- a/src/plugins/cppeditor/cppprojectupdater.cpp +++ b/src/plugins/cppeditor/cppprojectupdater.cpp @@ -97,14 +97,19 @@ void CppProjectUpdater::cancel() m_futureSynchronizer.cancelAllFutures(); } -namespace Internal { - -CppProjectUpdaterFactory::CppProjectUpdaterFactory() +class CppProjectUpdaterFactory final : public ProjectUpdaterFactory { - setLanguage(Constants::CXX_LANGUAGE_ID); - setCreator([] { return new CppProjectUpdater; }); +public: + CppProjectUpdaterFactory() + { + setLanguage(Constants::CXX_LANGUAGE_ID); + setCreator([] { return new CppProjectUpdater; }); + } +}; + +void setupCppProjectUpdater() +{ + static CppProjectUpdaterFactory theCppProjectUpdaterFactory; } -} // namespace Internal - } // namespace CppEditor diff --git a/src/plugins/cppeditor/cppprojectupdater.h b/src/plugins/cppeditor/cppprojectupdater.h index 0d9cf8c0357..1057feaed6a 100644 --- a/src/plugins/cppeditor/cppprojectupdater.h +++ b/src/plugins/cppeditor/cppprojectupdater.h @@ -16,18 +16,6 @@ namespace ProjectExplorer { class ExtraCompiler; } namespace CppEditor { -namespace Internal { - -// registered in extensionsystem's object pool for plugins with weak dependency to CppEditor -class CppProjectUpdaterFactory final - : public ProjectExplorer::ProjectUpdaterFactory -{ -public: - CppProjectUpdaterFactory(); -}; - -} // namespace Internal - class CPPEDITOR_EXPORT CppProjectUpdater final : public QObject, public ProjectExplorer::ProjectUpdater { @@ -43,4 +31,6 @@ private: Tasking::TaskTreeRunner m_taskTreeRunner; }; +void setupCppProjectUpdater(); + } // namespace CppEditor diff --git a/src/plugins/cppeditor/cppquickfixsettingspage.cpp b/src/plugins/cppeditor/cppquickfixsettingspage.cpp index 735dbea3b4d..4e1297f5c2e 100644 --- a/src/plugins/cppeditor/cppquickfixsettingspage.cpp +++ b/src/plugins/cppeditor/cppquickfixsettingspage.cpp @@ -7,14 +7,25 @@ #include "cppeditortr.h" #include "cppquickfixsettingswidget.h" +#include + namespace CppEditor::Internal { -CppQuickFixSettingsPage::CppQuickFixSettingsPage() +class CppQuickFixSettingsPage : public Core::IOptionsPage { - setId(Constants::QUICK_FIX_SETTINGS_ID); - setDisplayName(Tr::tr(Constants::QUICK_FIX_SETTINGS_DISPLAY_NAME)); - setCategory(Constants::CPP_SETTINGS_CATEGORY); - setWidgetCreator([] { return new CppQuickFixSettingsWidget; }); +public: + CppQuickFixSettingsPage() + { + setId(Constants::QUICK_FIX_SETTINGS_ID); + setDisplayName(Tr::tr(Constants::QUICK_FIX_SETTINGS_DISPLAY_NAME)); + setCategory(Constants::CPP_SETTINGS_CATEGORY); + setWidgetCreator([] { return new CppQuickFixSettingsWidget; }); + } +}; + +void setupCppQuickFixSettings() +{ + static CppQuickFixSettingsPage theCppQuickFixSettingsPage; } } // CppEditor::Internal diff --git a/src/plugins/cppeditor/cppquickfixsettingspage.h b/src/plugins/cppeditor/cppquickfixsettingspage.h index 1965aae9569..6288c9f9f25 100644 --- a/src/plugins/cppeditor/cppquickfixsettingspage.h +++ b/src/plugins/cppeditor/cppquickfixsettingspage.h @@ -3,14 +3,8 @@ #pragma once -#include - namespace CppEditor::Internal { -class CppQuickFixSettingsPage : public Core::IOptionsPage -{ -public: - CppQuickFixSettingsPage(); -}; +void setupCppQuickFixSettings(); } // CppEditor::Internal