forked from qt-creator/qt-creator
CppEditor: Split up CppEditorPlugin::initialize()
Change-Id: Ib2b1ac670138ca87edb908a32f44aba16410035a Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -168,7 +168,6 @@ public:
|
|||||||
delete m_clangdSettingsPage;
|
delete m_clangdSettingsPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialize() { m_codeModelSettings.fromSettings(ICore::settings()); }
|
|
||||||
void onTaskStarted(Utils::Id type);
|
void onTaskStarted(Utils::Id type);
|
||||||
void onAllTasksFinished(Utils::Id type);
|
void onAllTasksFinished(Utils::Id type);
|
||||||
void inspectCppCodeModel();
|
void inspectCppCodeModel();
|
||||||
@@ -228,12 +227,54 @@ CppQuickFixAssistProvider *CppEditorPlugin::quickFixProvider() const
|
|||||||
void CppEditorPlugin::initialize()
|
void CppEditorPlugin::initialize()
|
||||||
{
|
{
|
||||||
d = new CppEditorPluginPrivate;
|
d = new CppEditorPluginPrivate;
|
||||||
d->initialize();
|
d->m_codeModelSettings.fromSettings(ICore::settings());
|
||||||
|
|
||||||
CppModelManager::registerJsExtension();
|
CppModelManager::registerJsExtension();
|
||||||
ExtensionSystem::PluginManager::addObject(&d->m_cppProjectUpdaterFactory);
|
ExtensionSystem::PluginManager::addObject(&d->m_cppProjectUpdaterFactory);
|
||||||
|
|
||||||
// Menus
|
setupMenus();
|
||||||
|
registerVariables();
|
||||||
|
createCppQuickFixes();
|
||||||
|
registerTests();
|
||||||
|
|
||||||
|
SnippetProvider::registerGroup(Constants::CPP_SNIPPETS_GROUP_ID, Tr::tr("C++", "SnippetProvider"),
|
||||||
|
&decorateCppEditor);
|
||||||
|
|
||||||
|
connect(ProgressManager::instance(), &ProgressManager::taskStarted,
|
||||||
|
d, &CppEditorPluginPrivate::onTaskStarted);
|
||||||
|
connect(ProgressManager::instance(), &ProgressManager::allTasksFinished,
|
||||||
|
d, &CppEditorPluginPrivate::onAllTasksFinished);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CppEditorPlugin::extensionsInitialized()
|
||||||
|
{
|
||||||
|
setupProjectPanels();
|
||||||
|
|
||||||
|
d->m_fileSettings.fromSettings(ICore::settings());
|
||||||
|
d->m_fileSettings.addMimeInitializer();
|
||||||
|
|
||||||
|
// Add the hover handler factories here instead of in initialize()
|
||||||
|
// so that the Clang Code Model has a chance to hook in.
|
||||||
|
d->m_cppEditorFactory.addHoverHandler(CppModelManager::createHoverHandler());
|
||||||
|
d->m_cppEditorFactory.addHoverHandler(new ColorPreviewHoverHandler);
|
||||||
|
d->m_cppEditorFactory.addHoverHandler(new ResourcePreviewHoverHandler);
|
||||||
|
|
||||||
|
FileIconProvider::registerIconOverlayForMimeType(
|
||||||
|
creatorTheme()->imageFile(Theme::IconOverlayCppSource,
|
||||||
|
ProjectExplorer::Constants::FILEOVERLAY_CPP),
|
||||||
|
Constants::CPP_SOURCE_MIMETYPE);
|
||||||
|
FileIconProvider::registerIconOverlayForMimeType(
|
||||||
|
creatorTheme()->imageFile(Theme::IconOverlayCSource,
|
||||||
|
ProjectExplorer::Constants::FILEOVERLAY_C),
|
||||||
|
Constants::C_SOURCE_MIMETYPE);
|
||||||
|
FileIconProvider::registerIconOverlayForMimeType(
|
||||||
|
creatorTheme()->imageFile(Theme::IconOverlayCppHeader,
|
||||||
|
ProjectExplorer::Constants::FILEOVERLAY_H),
|
||||||
|
Constants::CPP_HEADER_MIMETYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CppEditorPlugin::setupMenus()
|
||||||
|
{
|
||||||
ActionContainer *mtools = ActionManager::actionContainer(Core::Constants::M_TOOLS);
|
ActionContainer *mtools = ActionManager::actionContainer(Core::Constants::M_TOOLS);
|
||||||
ActionContainer *mcpptools = ActionManager::createMenu(Constants::M_TOOLS_CPP);
|
ActionContainer *mcpptools = ActionManager::createMenu(Constants::M_TOOLS_CPP);
|
||||||
QMenu *menu = mcpptools->menu();
|
QMenu *menu = mcpptools->menu();
|
||||||
@@ -241,79 +282,50 @@ void CppEditorPlugin::initialize()
|
|||||||
menu->setEnabled(true);
|
menu->setEnabled(true);
|
||||||
mtools->addMenu(mcpptools);
|
mtools->addMenu(mcpptools);
|
||||||
|
|
||||||
// Actions
|
|
||||||
Context context(Constants::CPPEDITOR_ID);
|
Context context(Constants::CPPEDITOR_ID);
|
||||||
|
|
||||||
QAction *switchAction = new QAction(Tr::tr("Switch Header/Source"), this);
|
|
||||||
Command *command = ActionManager::registerAction(switchAction, Constants::SWITCH_HEADER_SOURCE, context, true);
|
|
||||||
command->setDefaultKeySequence(QKeySequence(Qt::Key_F4));
|
|
||||||
mcpptools->addAction(command);
|
|
||||||
connect(switchAction, &QAction::triggered,
|
|
||||||
this, [] { CppModelManager::switchHeaderSource(false); });
|
|
||||||
|
|
||||||
QAction *openInNextSplitAction = new QAction(Tr::tr("Open Corresponding Header/Source in Next Split"), this);
|
|
||||||
command = ActionManager::registerAction(openInNextSplitAction, Constants::OPEN_HEADER_SOURCE_IN_NEXT_SPLIT, context, true);
|
|
||||||
command->setDefaultKeySequence(QKeySequence(HostOsInfo::isMacHost()
|
|
||||||
? Tr::tr("Meta+E, F4")
|
|
||||||
: Tr::tr("Ctrl+E, F4")));
|
|
||||||
mcpptools->addAction(command);
|
|
||||||
connect(openInNextSplitAction, &QAction::triggered,
|
|
||||||
this, [] { CppModelManager::switchHeaderSource(true); });
|
|
||||||
|
|
||||||
MacroExpander *expander = globalMacroExpander();
|
|
||||||
|
|
||||||
// TODO: Per-project variants of these three?
|
|
||||||
expander->registerVariable("Cpp:LicenseTemplate",
|
|
||||||
Tr::tr("The license template."),
|
|
||||||
[]() { return CppEditorPlugin::licenseTemplate(nullptr); });
|
|
||||||
expander->registerFileVariables("Cpp:LicenseTemplatePath",
|
|
||||||
Tr::tr("The configured path to the license template"),
|
|
||||||
[]() { return CppEditorPlugin::licenseTemplatePath(nullptr); });
|
|
||||||
expander->registerVariable(
|
|
||||||
"Cpp:PragmaOnce",
|
|
||||||
Tr::tr("Insert \"#pragma once\" instead of \"#ifndef\" include guards into header file"),
|
|
||||||
[] { return usePragmaOnce(nullptr) ? QString("true") : QString(); });
|
|
||||||
|
|
||||||
const auto quickFixSettingsPanelFactory = new ProjectPanelFactory;
|
|
||||||
quickFixSettingsPanelFactory->setPriority(100);
|
|
||||||
quickFixSettingsPanelFactory->setId(Constants::QUICK_FIX_PROJECT_PANEL_ID);
|
|
||||||
quickFixSettingsPanelFactory->setDisplayName(Tr::tr(Constants::QUICK_FIX_SETTINGS_DISPLAY_NAME));
|
|
||||||
quickFixSettingsPanelFactory->setCreateWidgetFunction([](Project *project) {
|
|
||||||
return new CppQuickFixProjectSettingsWidget(project);
|
|
||||||
});
|
|
||||||
ProjectPanelFactory::registerFactory(quickFixSettingsPanelFactory);
|
|
||||||
|
|
||||||
SnippetProvider::registerGroup(Constants::CPP_SNIPPETS_GROUP_ID, Tr::tr("C++", "SnippetProvider"),
|
|
||||||
&decorateCppEditor);
|
|
||||||
|
|
||||||
createCppQuickFixes();
|
|
||||||
|
|
||||||
ActionContainer *contextMenu = ActionManager::createMenu(Constants::M_CONTEXT);
|
ActionContainer *contextMenu = ActionManager::createMenu(Constants::M_CONTEXT);
|
||||||
contextMenu->insertGroup(Core::Constants::G_DEFAULT_ONE, Constants::G_CONTEXT_FIRST);
|
contextMenu->insertGroup(Core::Constants::G_DEFAULT_ONE, Constants::G_CONTEXT_FIRST);
|
||||||
|
|
||||||
Command *cmd;
|
|
||||||
ActionContainer *cppToolsMenu = ActionManager::actionContainer(Constants::M_TOOLS_CPP);
|
|
||||||
ActionContainer *touchBar = ActionManager::actionContainer(Core::Constants::TOUCH_BAR);
|
ActionContainer *touchBar = ActionManager::actionContainer(Core::Constants::TOUCH_BAR);
|
||||||
|
|
||||||
cmd = ActionManager::command(Constants::SWITCH_HEADER_SOURCE);
|
QAction *switchAction = new QAction(Tr::tr("Switch Header/Source"), this);
|
||||||
|
Command *cmd = ActionManager::registerAction(switchAction, Constants::SWITCH_HEADER_SOURCE,
|
||||||
|
context, true);
|
||||||
cmd->setTouchBarText(Tr::tr("Header/Source", "text on macOS touch bar"));
|
cmd->setTouchBarText(Tr::tr("Header/Source", "text on macOS touch bar"));
|
||||||
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
||||||
touchBar->addAction(cmd, Core::Constants::G_TOUCHBAR_NAVIGATION);
|
touchBar->addAction(cmd, Core::Constants::G_TOUCHBAR_NAVIGATION);
|
||||||
|
cmd->setDefaultKeySequence(QKeySequence(Qt::Key_F4));
|
||||||
|
mcpptools->addAction(cmd);
|
||||||
|
connect(switchAction, &QAction::triggered,
|
||||||
|
this, [] { CppModelManager::switchHeaderSource(false); });
|
||||||
|
|
||||||
|
QAction *openInNextSplitAction
|
||||||
|
= new QAction(Tr::tr("Open Corresponding Header/Source in Next Split"), this);
|
||||||
|
cmd = ActionManager::registerAction(
|
||||||
|
openInNextSplitAction, Constants::OPEN_HEADER_SOURCE_IN_NEXT_SPLIT, context, true);
|
||||||
|
cmd->setDefaultKeySequence(QKeySequence(HostOsInfo::isMacHost()
|
||||||
|
? Tr::tr("Meta+E, F4")
|
||||||
|
: Tr::tr("Ctrl+E, F4")));
|
||||||
|
mcpptools->addAction(cmd);
|
||||||
|
connect(openInNextSplitAction, &QAction::triggered,
|
||||||
|
this, [] { CppModelManager::switchHeaderSource(true); });
|
||||||
|
|
||||||
cmd = ActionManager::command(TextEditor::Constants::FOLLOW_SYMBOL_UNDER_CURSOR);
|
cmd = ActionManager::command(TextEditor::Constants::FOLLOW_SYMBOL_UNDER_CURSOR);
|
||||||
cmd->setTouchBarText(Tr::tr("Follow", "text on macOS touch bar"));
|
cmd->setTouchBarText(Tr::tr("Follow", "text on macOS touch bar"));
|
||||||
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
||||||
cppToolsMenu->addAction(cmd);
|
mcpptools->addAction(cmd);
|
||||||
touchBar->addAction(cmd, Core::Constants::G_TOUCHBAR_NAVIGATION);
|
touchBar->addAction(cmd, Core::Constants::G_TOUCHBAR_NAVIGATION);
|
||||||
|
|
||||||
QAction *openPreprocessorDialog = new QAction(Tr::tr("Additional Preprocessor Directives..."), this);
|
QAction *openPreprocessorDialog = new QAction(Tr::tr("Additional Preprocessor Directives..."),
|
||||||
|
this);
|
||||||
cmd = ActionManager::registerAction(openPreprocessorDialog,
|
cmd = ActionManager::registerAction(openPreprocessorDialog,
|
||||||
Constants::OPEN_PREPROCESSOR_DIALOG, context);
|
Constants::OPEN_PREPROCESSOR_DIALOG, context);
|
||||||
cmd->setDefaultKeySequence(QKeySequence());
|
cmd->setDefaultKeySequence(QKeySequence());
|
||||||
connect(openPreprocessorDialog, &QAction::triggered, this, &CppEditorPlugin::showPreProcessorDialog);
|
connect(openPreprocessorDialog, &QAction::triggered,
|
||||||
cppToolsMenu->addAction(cmd);
|
this, &CppEditorPlugin::showPreProcessorDialog);
|
||||||
|
mcpptools->addAction(cmd);
|
||||||
|
|
||||||
QAction *switchDeclarationDefinition = new QAction(Tr::tr("Switch Between Function Declaration/Definition"), this);
|
QAction *switchDeclarationDefinition
|
||||||
|
= new QAction(Tr::tr("Switch Between Function Declaration/Definition"), this);
|
||||||
cmd = ActionManager::registerAction(switchDeclarationDefinition,
|
cmd = ActionManager::registerAction(switchDeclarationDefinition,
|
||||||
Constants::SWITCH_DECLARATION_DEFINITION, context, true);
|
Constants::SWITCH_DECLARATION_DEFINITION, context, true);
|
||||||
cmd->setDefaultKeySequence(QKeySequence(Tr::tr("Shift+F2")));
|
cmd->setDefaultKeySequence(QKeySequence(Tr::tr("Shift+F2")));
|
||||||
@@ -321,22 +333,23 @@ void CppEditorPlugin::initialize()
|
|||||||
connect(switchDeclarationDefinition, &QAction::triggered,
|
connect(switchDeclarationDefinition, &QAction::triggered,
|
||||||
this, &CppEditorPlugin::switchDeclarationDefinition);
|
this, &CppEditorPlugin::switchDeclarationDefinition);
|
||||||
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
||||||
cppToolsMenu->addAction(cmd);
|
mcpptools->addAction(cmd);
|
||||||
touchBar->addAction(cmd, Core::Constants::G_TOUCHBAR_NAVIGATION);
|
touchBar->addAction(cmd, Core::Constants::G_TOUCHBAR_NAVIGATION);
|
||||||
|
|
||||||
cmd = ActionManager::command(TextEditor::Constants::FOLLOW_SYMBOL_UNDER_CURSOR_IN_NEXT_SPLIT);
|
cmd = ActionManager::command(TextEditor::Constants::FOLLOW_SYMBOL_UNDER_CURSOR_IN_NEXT_SPLIT);
|
||||||
cppToolsMenu->addAction(cmd);
|
mcpptools->addAction(cmd);
|
||||||
|
|
||||||
QAction *openDeclarationDefinitionInNextSplit =
|
QAction *openDeclarationDefinitionInNextSplit =
|
||||||
new QAction(Tr::tr("Open Function Declaration/Definition in Next Split"), this);
|
new QAction(Tr::tr("Open Function Declaration/Definition in Next Split"), this);
|
||||||
cmd = ActionManager::registerAction(openDeclarationDefinitionInNextSplit,
|
cmd = ActionManager::registerAction(openDeclarationDefinitionInNextSplit,
|
||||||
Constants::OPEN_DECLARATION_DEFINITION_IN_NEXT_SPLIT, context, true);
|
Constants::OPEN_DECLARATION_DEFINITION_IN_NEXT_SPLIT,
|
||||||
|
context, true);
|
||||||
cmd->setDefaultKeySequence(QKeySequence(HostOsInfo::isMacHost()
|
cmd->setDefaultKeySequence(QKeySequence(HostOsInfo::isMacHost()
|
||||||
? Tr::tr("Meta+E, Shift+F2")
|
? Tr::tr("Meta+E, Shift+F2")
|
||||||
: Tr::tr("Ctrl+E, Shift+F2")));
|
: Tr::tr("Ctrl+E, Shift+F2")));
|
||||||
connect(openDeclarationDefinitionInNextSplit, &QAction::triggered,
|
connect(openDeclarationDefinitionInNextSplit, &QAction::triggered,
|
||||||
this, &CppEditorPlugin::openDeclarationDefinitionInNextSplit);
|
this, &CppEditorPlugin::openDeclarationDefinitionInNextSplit);
|
||||||
cppToolsMenu->addAction(cmd);
|
mcpptools->addAction(cmd);
|
||||||
|
|
||||||
QAction * const followSymbolToType = new QAction(Tr::tr("Follow Symbol Under Cursor to Type"),
|
QAction * const followSymbolToType = new QAction(Tr::tr("Follow Symbol Under Cursor to Type"),
|
||||||
this);
|
this);
|
||||||
@@ -348,11 +361,12 @@ void CppEditorPlugin::initialize()
|
|||||||
editorWidget->followSymbolToType(false);
|
editorWidget->followSymbolToType(false);
|
||||||
});
|
});
|
||||||
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
||||||
cppToolsMenu->addAction(cmd);
|
mcpptools->addAction(cmd);
|
||||||
QAction * const followSymbolToTypeInNextSplit =
|
QAction * const followSymbolToTypeInNextSplit =
|
||||||
new QAction(Tr::tr("Follow Symbol to Type in Next Split"), this);
|
new QAction(Tr::tr("Follow Symbol to Type in Next Split"), this);
|
||||||
cmd = ActionManager::registerAction(followSymbolToTypeInNextSplit,
|
cmd = ActionManager::registerAction(followSymbolToTypeInNextSplit,
|
||||||
Constants::FOLLOW_SYMBOL_TO_TYPE_IN_NEXT_SPLIT, context, true);
|
Constants::FOLLOW_SYMBOL_TO_TYPE_IN_NEXT_SPLIT,
|
||||||
|
context, true);
|
||||||
cmd->setDefaultKeySequence(QKeySequence(HostOsInfo::isMacHost()
|
cmd->setDefaultKeySequence(QKeySequence(HostOsInfo::isMacHost()
|
||||||
? Tr::tr("Meta+E, Ctrl+Shift+F2")
|
? Tr::tr("Meta+E, Ctrl+Shift+F2")
|
||||||
: Tr::tr("Ctrl+E, Ctrl+Shift+F2")));
|
: Tr::tr("Ctrl+E, Ctrl+Shift+F2")));
|
||||||
@@ -360,11 +374,11 @@ void CppEditorPlugin::initialize()
|
|||||||
if (CppEditorWidget *editorWidget = currentCppEditorWidget())
|
if (CppEditorWidget *editorWidget = currentCppEditorWidget())
|
||||||
editorWidget->followSymbolToType(true);
|
editorWidget->followSymbolToType(true);
|
||||||
});
|
});
|
||||||
cppToolsMenu->addAction(cmd);
|
mcpptools->addAction(cmd);
|
||||||
|
|
||||||
cmd = ActionManager::command(TextEditor::Constants::FIND_USAGES);
|
cmd = ActionManager::command(TextEditor::Constants::FIND_USAGES);
|
||||||
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
||||||
cppToolsMenu->addAction(cmd);
|
mcpptools->addAction(cmd);
|
||||||
|
|
||||||
d->m_findRefsCategorizedAction = new QAction(Tr::tr("Find References With Access Type"), this);
|
d->m_findRefsCategorizedAction = new QAction(Tr::tr("Find References With Access Type"), this);
|
||||||
cmd = ActionManager::registerAction(d->m_findRefsCategorizedAction,
|
cmd = ActionManager::registerAction(d->m_findRefsCategorizedAction,
|
||||||
@@ -377,57 +391,58 @@ void CppEditorPlugin::initialize()
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
||||||
cppToolsMenu->addAction(cmd);
|
mcpptools->addAction(cmd);
|
||||||
|
|
||||||
cmd = ActionManager::command(TextEditor::Constants::RENAME_SYMBOL);
|
cmd = ActionManager::command(TextEditor::Constants::RENAME_SYMBOL);
|
||||||
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
||||||
cppToolsMenu->addAction(cmd);
|
mcpptools->addAction(cmd);
|
||||||
|
|
||||||
QAction * const showPreprocessedAction = new QAction(Tr::tr("Show Preprocessed Source"), this);
|
QAction * const showPreprocessedAction = new QAction(Tr::tr("Show Preprocessed Source"), this);
|
||||||
command = ActionManager::registerAction(showPreprocessedAction,
|
cmd = ActionManager::registerAction(showPreprocessedAction,
|
||||||
Constants::SHOW_PREPROCESSED_FILE, context);
|
Constants::SHOW_PREPROCESSED_FILE, context);
|
||||||
mcpptools->addAction(command);
|
mcpptools->addAction(cmd);
|
||||||
contextMenu->addAction(command, Constants::G_CONTEXT_FIRST);
|
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
||||||
connect(showPreprocessedAction, &QAction::triggered,
|
connect(showPreprocessedAction, &QAction::triggered,
|
||||||
this, [] { CppModelManager::showPreprocessedFile(false); });
|
this, [] { CppModelManager::showPreprocessedFile(false); });
|
||||||
|
|
||||||
QAction * const showPreprocessedInSplitAction = new QAction
|
QAction * const showPreprocessedInSplitAction = new QAction
|
||||||
(Tr::tr("Show Preprocessed Source in Next Split"), this);
|
(Tr::tr("Show Preprocessed Source in Next Split"), this);
|
||||||
command = ActionManager::registerAction(showPreprocessedInSplitAction,
|
cmd = ActionManager::registerAction(showPreprocessedInSplitAction,
|
||||||
Constants::SHOW_PREPROCESSED_FILE_SPLIT, context);
|
Constants::SHOW_PREPROCESSED_FILE_SPLIT, context);
|
||||||
mcpptools->addAction(command);
|
mcpptools->addAction(cmd);
|
||||||
connect(showPreprocessedInSplitAction, &QAction::triggered,
|
connect(showPreprocessedInSplitAction, &QAction::triggered,
|
||||||
this, [] { CppModelManager::showPreprocessedFile(true); });
|
this, [] { CppModelManager::showPreprocessedFile(true); });
|
||||||
|
|
||||||
QAction * const foldCommentsAction = new QAction(Tr::tr("Fold All Comment Blocks"), this);
|
QAction * const foldCommentsAction = new QAction(Tr::tr("Fold All Comment Blocks"), this);
|
||||||
command = ActionManager::registerAction(foldCommentsAction,
|
cmd = ActionManager::registerAction(foldCommentsAction,
|
||||||
"CppTools.FoldCommentBlocks", context);
|
"CppTools.FoldCommentBlocks", context);
|
||||||
mcpptools->addAction(command);
|
mcpptools->addAction(cmd);
|
||||||
contextMenu->addAction(command, Constants::G_CONTEXT_FIRST);
|
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
||||||
connect(foldCommentsAction, &QAction::triggered, this, [] { CppModelManager::foldComments(); });
|
connect(foldCommentsAction, &QAction::triggered, this, [] { CppModelManager::foldComments(); });
|
||||||
QAction * const unfoldCommentsAction = new QAction(Tr::tr("Unfold All Comment Blocks"), this);
|
QAction * const unfoldCommentsAction = new QAction(Tr::tr("Unfold All Comment Blocks"), this);
|
||||||
command = ActionManager::registerAction(unfoldCommentsAction,
|
cmd = ActionManager::registerAction(unfoldCommentsAction,
|
||||||
"CppTools.UnfoldCommentBlocks", context);
|
"CppTools.UnfoldCommentBlocks", context);
|
||||||
mcpptools->addAction(command);
|
mcpptools->addAction(cmd);
|
||||||
contextMenu->addAction(command, Constants::G_CONTEXT_FIRST);
|
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
||||||
connect(unfoldCommentsAction, &QAction::triggered, this, [] { CppModelManager::unfoldComments(); });
|
connect(unfoldCommentsAction, &QAction::triggered,
|
||||||
|
this, [] { CppModelManager::unfoldComments(); });
|
||||||
|
|
||||||
QAction *const findUnusedFunctionsAction = new QAction(Tr::tr("Find Unused Functions"), this);
|
QAction *const findUnusedFunctionsAction = new QAction(Tr::tr("Find Unused Functions"), this);
|
||||||
command = ActionManager::registerAction(findUnusedFunctionsAction,
|
cmd = ActionManager::registerAction(findUnusedFunctionsAction,
|
||||||
"CppTools.FindUnusedFunctions");
|
"CppTools.FindUnusedFunctions");
|
||||||
mcpptools->addAction(command);
|
mcpptools->addAction(cmd);
|
||||||
connect(findUnusedFunctionsAction, &QAction::triggered, this, [] {
|
connect(findUnusedFunctionsAction, &QAction::triggered, this, [] {
|
||||||
CppModelManager::findUnusedFunctions({});
|
CppModelManager::findUnusedFunctions({});
|
||||||
});
|
});
|
||||||
QAction *const findUnusedFunctionsInSubProjectAction
|
QAction *const findUnusedFunctionsInSubProjectAction
|
||||||
= new QAction(Tr::tr("Find Unused C/C++ Functions"), this);
|
= new QAction(Tr::tr("Find Unused C/C++ Functions"), this);
|
||||||
command = ActionManager::registerAction(findUnusedFunctionsInSubProjectAction,
|
cmd = ActionManager::registerAction(findUnusedFunctionsInSubProjectAction,
|
||||||
"CppTools.FindUnusedFunctionsInSubProject");
|
"CppTools.FindUnusedFunctionsInSubProject");
|
||||||
for (ActionContainer *const projectContextMenu :
|
for (ActionContainer *const projectContextMenu :
|
||||||
{ActionManager::actionContainer(ProjectExplorer::Constants::M_SUBPROJECTCONTEXT),
|
{ActionManager::actionContainer(ProjectExplorer::Constants::M_SUBPROJECTCONTEXT),
|
||||||
ActionManager::actionContainer(ProjectExplorer::Constants::M_PROJECTCONTEXT)}) {
|
ActionManager::actionContainer(ProjectExplorer::Constants::M_PROJECTCONTEXT)}) {
|
||||||
projectContextMenu->addSeparator(ProjectExplorer::Constants::G_PROJECT_TREE);
|
projectContextMenu->addSeparator(ProjectExplorer::Constants::G_PROJECT_TREE);
|
||||||
projectContextMenu->addAction(command, ProjectExplorer::Constants::G_PROJECT_TREE);
|
projectContextMenu->addAction(cmd, ProjectExplorer::Constants::G_PROJECT_TREE);
|
||||||
}
|
}
|
||||||
connect(findUnusedFunctionsInSubProjectAction, &QAction::triggered, this, [] {
|
connect(findUnusedFunctionsInSubProjectAction, &QAction::triggered, this, [] {
|
||||||
if (const Node *const node = ProjectTree::currentNode(); node && node->asFolderNode())
|
if (const Node *const node = ProjectTree::currentNode(); node && node->asFolderNode())
|
||||||
@@ -435,22 +450,28 @@ void CppEditorPlugin::initialize()
|
|||||||
});
|
});
|
||||||
|
|
||||||
d->m_openTypeHierarchyAction = new QAction(Tr::tr("Open Type Hierarchy"), this);
|
d->m_openTypeHierarchyAction = new QAction(Tr::tr("Open Type Hierarchy"), this);
|
||||||
cmd = ActionManager::registerAction(d->m_openTypeHierarchyAction, Constants::OPEN_TYPE_HIERARCHY, context);
|
cmd = ActionManager::registerAction(d->m_openTypeHierarchyAction,
|
||||||
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? Tr::tr("Meta+Shift+T") : Tr::tr("Ctrl+Shift+T")));
|
Constants::OPEN_TYPE_HIERARCHY, context);
|
||||||
connect(d->m_openTypeHierarchyAction, &QAction::triggered, this, &CppEditorPlugin::openTypeHierarchy);
|
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts
|
||||||
|
? Tr::tr("Meta+Shift+T") : Tr::tr("Ctrl+Shift+T")));
|
||||||
|
connect(d->m_openTypeHierarchyAction, &QAction::triggered,
|
||||||
|
this, &CppEditorPlugin::openTypeHierarchy);
|
||||||
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
||||||
cppToolsMenu->addAction(cmd);
|
mcpptools->addAction(cmd);
|
||||||
|
|
||||||
d->m_openIncludeHierarchyAction = new QAction(Tr::tr("Open Include Hierarchy"), this);
|
d->m_openIncludeHierarchyAction = new QAction(Tr::tr("Open Include Hierarchy"), this);
|
||||||
cmd = ActionManager::registerAction(d->m_openIncludeHierarchyAction, Constants::OPEN_INCLUDE_HIERARCHY, context);
|
cmd = ActionManager::registerAction(d->m_openIncludeHierarchyAction,
|
||||||
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? Tr::tr("Meta+Shift+I") : Tr::tr("Ctrl+Shift+I")));
|
Constants::OPEN_INCLUDE_HIERARCHY, context);
|
||||||
connect(d->m_openIncludeHierarchyAction, &QAction::triggered, this, &CppEditorPlugin::openIncludeHierarchy);
|
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts
|
||||||
|
? Tr::tr("Meta+Shift+I") : Tr::tr("Ctrl+Shift+I")));
|
||||||
|
connect(d->m_openIncludeHierarchyAction, &QAction::triggered,
|
||||||
|
this, &CppEditorPlugin::openIncludeHierarchy);
|
||||||
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
||||||
cppToolsMenu->addAction(cmd);
|
mcpptools->addAction(cmd);
|
||||||
|
|
||||||
cmd = ActionManager::command(TextEditor::Constants::OPEN_CALL_HIERARCHY);
|
cmd = ActionManager::command(TextEditor::Constants::OPEN_CALL_HIERARCHY);
|
||||||
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
||||||
cppToolsMenu->addAction(cmd);
|
mcpptools->addAction(cmd);
|
||||||
|
|
||||||
// Refactoring sub-menu
|
// Refactoring sub-menu
|
||||||
Command *sep = contextMenu->addSeparator();
|
Command *sep = contextMenu->addSeparator();
|
||||||
@@ -458,18 +479,22 @@ void CppEditorPlugin::initialize()
|
|||||||
contextMenu->addSeparator();
|
contextMenu->addSeparator();
|
||||||
|
|
||||||
// Update context in global context
|
// Update context in global context
|
||||||
cppToolsMenu->addSeparator(Core::Constants::G_DEFAULT_THREE);
|
mcpptools->addSeparator(Core::Constants::G_DEFAULT_THREE);
|
||||||
d->m_reparseExternallyChangedFiles = new QAction(Tr::tr("Reparse Externally Changed Files"), this);
|
d->m_reparseExternallyChangedFiles = new QAction(Tr::tr("Reparse Externally Changed Files"),
|
||||||
cmd = ActionManager::registerAction(d->m_reparseExternallyChangedFiles, Constants::UPDATE_CODEMODEL);
|
this);
|
||||||
|
cmd = ActionManager::registerAction(d->m_reparseExternallyChangedFiles,
|
||||||
|
Constants::UPDATE_CODEMODEL);
|
||||||
connect(d->m_reparseExternallyChangedFiles, &QAction::triggered,
|
connect(d->m_reparseExternallyChangedFiles, &QAction::triggered,
|
||||||
CppModelManager::instance(), &CppModelManager::updateModifiedSourceFiles);
|
CppModelManager::instance(), &CppModelManager::updateModifiedSourceFiles);
|
||||||
cppToolsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
|
mcpptools->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
|
||||||
|
|
||||||
ActionContainer *toolsDebug = ActionManager::actionContainer(Core::Constants::M_TOOLS_DEBUG);
|
ActionContainer *toolsDebug = ActionManager::actionContainer(Core::Constants::M_TOOLS_DEBUG);
|
||||||
QAction *inspectCppCodeModel = new QAction(Tr::tr("Inspect C++ Code Model..."), this);
|
QAction *inspectCppCodeModel = new QAction(Tr::tr("Inspect C++ Code Model..."), this);
|
||||||
cmd = ActionManager::registerAction(inspectCppCodeModel, Constants::INSPECT_CPP_CODEMODEL);
|
cmd = ActionManager::registerAction(inspectCppCodeModel, Constants::INSPECT_CPP_CODEMODEL);
|
||||||
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? Tr::tr("Meta+Shift+F12") : Tr::tr("Ctrl+Shift+F12")));
|
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts
|
||||||
connect(inspectCppCodeModel, &QAction::triggered, d, &CppEditorPluginPrivate::inspectCppCodeModel);
|
? Tr::tr("Meta+Shift+F12") : Tr::tr("Ctrl+Shift+F12")));
|
||||||
|
connect(inspectCppCodeModel, &QAction::triggered,
|
||||||
|
d, &CppEditorPluginPrivate::inspectCppCodeModel);
|
||||||
toolsDebug->addAction(cmd);
|
toolsDebug->addAction(cmd);
|
||||||
|
|
||||||
contextMenu->addSeparator(context);
|
contextMenu->addSeparator(context);
|
||||||
@@ -479,12 +504,58 @@ void CppEditorPlugin::initialize()
|
|||||||
|
|
||||||
cmd = ActionManager::command(TextEditor::Constants::UN_COMMENT_SELECTION);
|
cmd = ActionManager::command(TextEditor::Constants::UN_COMMENT_SELECTION);
|
||||||
contextMenu->addAction(cmd);
|
contextMenu->addAction(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
connect(ProgressManager::instance(), &ProgressManager::taskStarted,
|
void CppEditorPlugin::setupProjectPanels()
|
||||||
d, &CppEditorPluginPrivate::onTaskStarted);
|
{
|
||||||
connect(ProgressManager::instance(), &ProgressManager::allTasksFinished,
|
const auto quickFixSettingsPanelFactory = new ProjectPanelFactory;
|
||||||
d, &CppEditorPluginPrivate::onAllTasksFinished);
|
quickFixSettingsPanelFactory->setPriority(100);
|
||||||
|
quickFixSettingsPanelFactory->setId(Constants::QUICK_FIX_PROJECT_PANEL_ID);
|
||||||
|
quickFixSettingsPanelFactory->setDisplayName(Tr::tr(Constants::QUICK_FIX_SETTINGS_DISPLAY_NAME));
|
||||||
|
quickFixSettingsPanelFactory->setCreateWidgetFunction([](Project *project) {
|
||||||
|
return new CppQuickFixProjectSettingsWidget(project);
|
||||||
|
});
|
||||||
|
ProjectPanelFactory::registerFactory(quickFixSettingsPanelFactory);
|
||||||
|
|
||||||
|
const auto fileNamesPanelFactory = new ProjectPanelFactory;
|
||||||
|
fileNamesPanelFactory->setPriority(99);
|
||||||
|
fileNamesPanelFactory->setDisplayName(Tr::tr("C++ File Naming"));
|
||||||
|
fileNamesPanelFactory->setCreateWidgetFunction([](Project *project) {
|
||||||
|
return new CppFileSettingsForProjectWidget(project);
|
||||||
|
});
|
||||||
|
ProjectPanelFactory::registerFactory(fileNamesPanelFactory);
|
||||||
|
|
||||||
|
if (CppModelManager::isClangCodeModelActive()) {
|
||||||
|
d->m_clangdSettingsPage = new ClangdSettingsPage;
|
||||||
|
const auto clangdPanelFactory = new ProjectPanelFactory;
|
||||||
|
clangdPanelFactory->setPriority(100);
|
||||||
|
clangdPanelFactory->setDisplayName(Tr::tr("Clangd"));
|
||||||
|
clangdPanelFactory->setCreateWidgetFunction([](Project *project) {
|
||||||
|
return new ClangdProjectSettingsWidget(project);
|
||||||
|
});
|
||||||
|
ProjectPanelFactory::registerFactory(clangdPanelFactory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CppEditorPlugin::registerVariables()
|
||||||
|
{
|
||||||
|
MacroExpander * const expander = globalMacroExpander();
|
||||||
|
|
||||||
|
// TODO: Per-project variants of these three?
|
||||||
|
expander->registerVariable("Cpp:LicenseTemplate",
|
||||||
|
Tr::tr("The license template."),
|
||||||
|
[]() { return CppEditorPlugin::licenseTemplate(nullptr); });
|
||||||
|
expander->registerFileVariables("Cpp:LicenseTemplatePath",
|
||||||
|
Tr::tr("The configured path to the license template"),
|
||||||
|
[]() { return CppEditorPlugin::licenseTemplatePath(nullptr); });
|
||||||
|
expander->registerVariable(
|
||||||
|
"Cpp:PragmaOnce",
|
||||||
|
Tr::tr("Insert \"#pragma once\" instead of \"#ifndef\" include guards into header file"),
|
||||||
|
[] { return usePragmaOnce(nullptr) ? QString("true") : QString(); });
|
||||||
|
}
|
||||||
|
|
||||||
|
void CppEditorPlugin::registerTests()
|
||||||
|
{
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
addTest<CodegenTest>();
|
addTest<CodegenTest>();
|
||||||
addTest<CompilerOptionsBuilderTest>();
|
addTest<CompilerOptionsBuilderTest>();
|
||||||
@@ -516,49 +587,6 @@ void CppEditorPlugin::initialize()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppEditorPlugin::extensionsInitialized()
|
|
||||||
{
|
|
||||||
d->m_fileSettings.fromSettings(ICore::settings());
|
|
||||||
d->m_fileSettings.addMimeInitializer();
|
|
||||||
const auto fileNamesPanelFactory = new ProjectPanelFactory;
|
|
||||||
fileNamesPanelFactory->setPriority(99);
|
|
||||||
fileNamesPanelFactory->setDisplayName(Tr::tr("C++ File Naming"));
|
|
||||||
fileNamesPanelFactory->setCreateWidgetFunction([](Project *project) {
|
|
||||||
return new CppFileSettingsForProjectWidget(project);
|
|
||||||
});
|
|
||||||
ProjectPanelFactory::registerFactory(fileNamesPanelFactory);
|
|
||||||
|
|
||||||
if (CppModelManager::isClangCodeModelActive()) {
|
|
||||||
d->m_clangdSettingsPage = new ClangdSettingsPage;
|
|
||||||
const auto clangdPanelFactory = new ProjectPanelFactory;
|
|
||||||
clangdPanelFactory->setPriority(100);
|
|
||||||
clangdPanelFactory->setDisplayName(Tr::tr("Clangd"));
|
|
||||||
clangdPanelFactory->setCreateWidgetFunction([](Project *project) {
|
|
||||||
return new ClangdProjectSettingsWidget(project);
|
|
||||||
});
|
|
||||||
ProjectPanelFactory::registerFactory(clangdPanelFactory);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the hover handler factories here instead of in initialize()
|
|
||||||
// so that the Clang Code Model has a chance to hook in.
|
|
||||||
d->m_cppEditorFactory.addHoverHandler(CppModelManager::createHoverHandler());
|
|
||||||
d->m_cppEditorFactory.addHoverHandler(new ColorPreviewHoverHandler);
|
|
||||||
d->m_cppEditorFactory.addHoverHandler(new ResourcePreviewHoverHandler);
|
|
||||||
|
|
||||||
FileIconProvider::registerIconOverlayForMimeType(
|
|
||||||
creatorTheme()->imageFile(Theme::IconOverlayCppSource,
|
|
||||||
ProjectExplorer::Constants::FILEOVERLAY_CPP),
|
|
||||||
Constants::CPP_SOURCE_MIMETYPE);
|
|
||||||
FileIconProvider::registerIconOverlayForMimeType(
|
|
||||||
creatorTheme()->imageFile(Theme::IconOverlayCSource,
|
|
||||||
ProjectExplorer::Constants::FILEOVERLAY_C),
|
|
||||||
Constants::C_SOURCE_MIMETYPE);
|
|
||||||
FileIconProvider::registerIconOverlayForMimeType(
|
|
||||||
creatorTheme()->imageFile(Theme::IconOverlayCppHeader,
|
|
||||||
ProjectExplorer::Constants::FILEOVERLAY_H),
|
|
||||||
Constants::CPP_HEADER_MIMETYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CppEditorPlugin::switchDeclarationDefinition()
|
void CppEditorPlugin::switchDeclarationDefinition()
|
||||||
{
|
{
|
||||||
if (CppEditorWidget *editorWidget = currentCppEditorWidget())
|
if (CppEditorWidget *editorWidget = currentCppEditorWidget())
|
||||||
|
|||||||
@@ -56,6 +56,11 @@ private:
|
|||||||
void initialize() override;
|
void initialize() override;
|
||||||
void extensionsInitialized() override;
|
void extensionsInitialized() override;
|
||||||
|
|
||||||
|
void setupMenus();
|
||||||
|
void setupProjectPanels();
|
||||||
|
void registerVariables();
|
||||||
|
void registerTests();
|
||||||
|
|
||||||
CppEditorPluginPrivate *d = nullptr;
|
CppEditorPluginPrivate *d = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user