CMake: Use setup functions for a few more cmake related items

Change-Id: I7a1bbea9507d7d168584348a51d557f4a910de47
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
hjk
2024-01-29 14:27:33 +01:00
parent cc64c84b5f
commit 5646aae859
7 changed files with 69 additions and 61 deletions

View File

@@ -803,11 +803,20 @@ void CMakeBuildStep::updateDeploymentData()
// CMakeBuildStepFactory
CMakeBuildStepFactory::CMakeBuildStepFactory()
class CMakeBuildStepFactory final : public BuildStepFactory
{
registerStep<CMakeBuildStep>(Constants::CMAKE_BUILD_STEP_ID);
setDisplayName(Tr::tr("CMake Build", "Display name for CMakeProjectManager::CMakeBuildStep id."));
setSupportedProjectType(Constants::CMAKE_PROJECT_ID);
public:
CMakeBuildStepFactory()
{
registerStep<CMakeBuildStep>(Constants::CMAKE_BUILD_STEP_ID);
setDisplayName(Tr::tr("CMake Build", "Display name for CMakeProjectManager::CMakeBuildStep id."));
setSupportedProjectType(Constants::CMAKE_PROJECT_ID);
}
};
void setupCMakeBuildStep()
{
static CMakeBuildStepFactory theCMakeBuildStepFactory;
}
} // CMakeProjectManager::Internal

View File

@@ -118,10 +118,6 @@ private:
std::optional<QString> m_configuration;
};
class CMakeBuildStepFactory : public ProjectExplorer::BuildStepFactory
{
public:
CMakeBuildStepFactory();
};
void setupCMakeBuildStep();
} // CMakeProjectManager::Internal

View File

@@ -25,14 +25,13 @@
#include <texteditor/basehoverhandler.h>
#include <texteditor/textdocument.h>
#include <texteditor/texteditor.h>
#include <texteditor/texteditoractionhandler.h>
#include <utils/mimeconstants.h>
#include <utils/textutils.h>
#include <utils/tooltip/tooltip.h>
#include <QTextDocument>
#include <functional>
using namespace Core;
@@ -501,38 +500,45 @@ void CMakeHoverHandler::operateTooltip(TextEditorWidget *editorWidget, const QPo
setToolTip(m_helpToolTip);
}
//
// CMakeEditorFactory
//
CMakeEditorFactory::CMakeEditorFactory()
class CMakeEditorFactory final : public TextEditorFactory
{
setId(Constants::CMAKE_EDITOR_ID);
setDisplayName(::Core::Tr::tr("CMake Editor"));
addMimeType(Utils::Constants::CMAKE_MIMETYPE);
addMimeType(Utils::Constants::CMAKE_PROJECT_MIMETYPE);
public:
CMakeEditorFactory()
{
setId(Constants::CMAKE_EDITOR_ID);
setDisplayName(::Core::Tr::tr("CMake Editor"));
addMimeType(Utils::Constants::CMAKE_MIMETYPE);
addMimeType(Utils::Constants::CMAKE_PROJECT_MIMETYPE);
setEditorCreator([] { return new CMakeEditor; });
setEditorWidgetCreator([] { return new CMakeEditorWidget; });
setDocumentCreator(createCMakeDocument);
setIndenterCreator(createCMakeIndenter);
setUseGenericHighlighter(true);
setCommentDefinition(Utils::CommentDefinition::HashStyle);
setCodeFoldingSupported(true);
setEditorCreator([] { return new CMakeEditor; });
setEditorWidgetCreator([] { return new CMakeEditorWidget; });
setDocumentCreator(createCMakeDocument);
setIndenterCreator(createCMakeIndenter);
setUseGenericHighlighter(true);
setCommentDefinition(Utils::CommentDefinition::HashStyle);
setCodeFoldingSupported(true);
setCompletionAssistProvider(new CMakeFileCompletionAssistProvider);
setAutoCompleterCreator([] { return new CMakeAutoCompleter; });
setCompletionAssistProvider(new CMakeFileCompletionAssistProvider);
setAutoCompleterCreator([] { return new CMakeAutoCompleter; });
setEditorActionHandlers(TextEditorActionHandler::UnCommentSelection
| TextEditorActionHandler::FollowSymbolUnderCursor
| TextEditorActionHandler::Format);
setEditorActionHandlers(TextEditorActionHandler::UnCommentSelection
| TextEditorActionHandler::FollowSymbolUnderCursor
| TextEditorActionHandler::Format);
addHoverHandler(new CMakeHoverHandler);
addHoverHandler(new CMakeHoverHandler);
ActionContainer *contextMenu = ActionManager::createMenu(Constants::M_CONTEXT);
contextMenu->addAction(ActionManager::command(TextEditor::Constants::FOLLOW_SYMBOL_UNDER_CURSOR));
contextMenu->addSeparator(Context(Constants::CMAKE_EDITOR_ID));
contextMenu->addAction(ActionManager::command(TextEditor::Constants::UN_COMMENT_SELECTION));
ActionContainer *contextMenu = ActionManager::createMenu(Constants::M_CONTEXT);
contextMenu->addAction(ActionManager::command(TextEditor::Constants::FOLLOW_SYMBOL_UNDER_CURSOR));
contextMenu->addSeparator(Context(Constants::CMAKE_EDITOR_ID));
contextMenu->addAction(ActionManager::command(TextEditor::Constants::UN_COMMENT_SELECTION));
}
};
void setupCMakeEditor()
{
static CMakeEditorFactory theCMakeEditorFactory;
}
} // CMakeProjectManager::Internal

View File

@@ -3,14 +3,8 @@
#pragma once
#include <texteditor/texteditor.h>
namespace CMakeProjectManager::Internal {
class CMakeEditorFactory : public TextEditor::TextEditorFactory
{
public:
CMakeEditorFactory();
};
void setupCMakeEditor();
} // CMakeProjectManager::Internal

View File

@@ -52,11 +52,7 @@ public:
Action::AlwaysEnabled/*handled manually*/
};
CMakeSettingsPage settingsPage;
CMakeBuildStepFactory buildStepFactory;
CMakeBuildConfigurationFactory buildConfigFactory;
CMakeEditorFactory editorFactor;
CMakeInstallStepFactory installStepFactory;
CMakeBuildTargetFilter cMakeBuildTargetFilter;
CMakeOpenTargetFilter cMakeOpenTargetFilter;
@@ -78,6 +74,11 @@ class CMakeProjectPlugin final : public ExtensionSystem::IPlugin
{
setupCMakeToolManager(this);
setupCMakeSettingsPage();
setupCMakeBuildStep();
setupCMakeEditor();
d = new CMakeProjectPluginPrivate;
setupCMakeManager();

View File

@@ -10,6 +10,7 @@
#include <coreplugin/dialogs/ioptionspage.h>
#include <coreplugin/icore.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <utils/detailswidget.h>
@@ -652,17 +653,24 @@ void CMakeToolConfigWidget::currentCMakeToolChanged(const QModelIndex &newCurren
m_makeDefButton->setEnabled(m_currentItem && (!m_model.defaultItemId().isValid() || m_currentItem->m_id != m_model.defaultItemId()));
}
//
// CMakeSettingsPage
//
CMakeSettingsPage::CMakeSettingsPage()
class CMakeSettingsPage final : public Core::IOptionsPage
{
setId(Constants::Settings::TOOLS_ID);
setDisplayName(Tr::tr("Tools"));
setDisplayCategory("CMake");
setCategory(Constants::Settings::CATEGORY);
setWidgetCreator([] { return new CMakeToolConfigWidget; });
public:
CMakeSettingsPage()
{
setId(Constants::Settings::TOOLS_ID);
setDisplayName(Tr::tr("Tools"));
setDisplayCategory("CMake");
setCategory(Constants::Settings::CATEGORY);
setWidgetCreator([] { return new CMakeToolConfigWidget; });
}
};
void setupCMakeSettingsPage()
{
static CMakeSettingsPage theCMakeSettingsPage;
}
} // CMakeProjectManager::Internal

View File

@@ -3,14 +3,8 @@
#pragma once
#include <coreplugin/dialogs/ioptionspage.h>
namespace CMakeProjectManager::Internal {
class CMakeSettingsPage final : public Core::IOptionsPage
{
public:
CMakeSettingsPage();
};
void setupCMakeSettingsPage();
} // CMakeProjectManager::Internal