CMake: Use setup functions for more plugin items

Change-Id: I48ff764248f29ef2a8f46757cba84705983c7740
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2024-01-29 14:59:59 +01:00
parent a615b236e5
commit d016ef67b3
7 changed files with 76 additions and 89 deletions

View File

@@ -271,11 +271,11 @@ public:
} }
}; };
const CMakeFormatterSettingsPage settingsPage; void setupCMakeFormatter()
CMakeFormatter::CMakeFormatter()
{ {
static const CMakeFormatterSettingsPage theCMakeFormatterSettingsPage;
formatterSettings(); formatterSettings();
} };
} // CMakeProjectManager::Internal } // CMakeProjectManager::Internal

View File

@@ -4,14 +4,8 @@
#pragma once #pragma once
namespace Core { class IDocument; }
namespace CMakeProjectManager::Internal { namespace CMakeProjectManager::Internal {
class CMakeFormatter void setupCMakeFormatter();
{
public:
CMakeFormatter();
};
} // CMakeProjectManager::Internal } // CMakeProjectManager::Internal

View File

@@ -11,6 +11,7 @@
#include "cmakeprojectmanagertr.h" #include "cmakeprojectmanagertr.h"
#include "cmaketool.h" #include "cmaketool.h"
#include <projectexplorer/buildstep.h>
#include <projectexplorer/buildsteplist.h> #include <projectexplorer/buildsteplist.h>
#include <projectexplorer/processparameters.h> #include <projectexplorer/processparameters.h>
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
@@ -27,7 +28,7 @@ namespace CMakeProjectManager::Internal {
// CMakeInstallStep // CMakeInstallStep
class CMakeInstallStep : public CMakeAbstractProcessStep class CMakeInstallStep final : public CMakeAbstractProcessStep
{ {
public: public:
CMakeInstallStep(BuildStepList *bsl, Id id) CMakeInstallStep(BuildStepList *bsl, Id id)
@@ -112,14 +113,22 @@ QWidget *CMakeInstallStep::createConfigWidget()
// CMakeInstallStepFactory // CMakeInstallStepFactory
CMakeInstallStepFactory::CMakeInstallStepFactory() class CMakeInstallStepFactory : public ProjectExplorer::BuildStepFactory
{ {
registerStep<CMakeInstallStep>(Constants::CMAKE_INSTALL_STEP_ID); public:
setDisplayName( CMakeInstallStepFactory()
Tr::tr("CMake Install", "Display name for CMakeProjectManager::CMakeInstallStep id.")); {
setSupportedProjectType(Constants::CMAKE_PROJECT_ID); registerStep<CMakeInstallStep>(Constants::CMAKE_INSTALL_STEP_ID);
setSupportedStepLists({ProjectExplorer::Constants::BUILDSTEPS_DEPLOY}); setDisplayName(
Tr::tr("CMake Install", "Display name for CMakeProjectManager::CMakeInstallStep id."));
setSupportedProjectType(Constants::CMAKE_PROJECT_ID);
setSupportedStepLists({ProjectExplorer::Constants::BUILDSTEPS_DEPLOY});
}
};
void setupCMakeInstallStep()
{
static CMakeInstallStepFactory theCMakeInstallStepFactory;
} }
} // CMakeProjectManager::Internal } // CMakeProjectManager::Internal

View File

@@ -3,14 +3,8 @@
#pragma once #pragma once
#include <projectexplorer/buildstep.h>
namespace CMakeProjectManager::Internal { namespace CMakeProjectManager::Internal {
class CMakeInstallStepFactory : public ProjectExplorer::BuildStepFactory void setupCMakeInstallStep();
{
public:
CMakeInstallStepFactory();
};
} // CMakeProjectManager::Internal } // CMakeProjectManager::Internal

View File

@@ -8,6 +8,8 @@
#include "cmakeproject.h" #include "cmakeproject.h"
#include "cmakeprojectmanagertr.h" #include "cmakeprojectmanagertr.h"
#include <coreplugin/locator/ilocatorfilter.h>
#include <projectexplorer/buildmanager.h> #include <projectexplorer/buildmanager.h>
#include <projectexplorer/buildsteplist.h> #include <projectexplorer/buildsteplist.h>
#include <projectexplorer/projectmanager.h> #include <projectexplorer/projectmanager.h>
@@ -23,6 +25,8 @@ namespace CMakeProjectManager::Internal {
using BuildAcceptor = std::function<void(const FilePath &, const QString &)>; using BuildAcceptor = std::function<void(const FilePath &, const QString &)>;
// CMakeBuildTargetFilter
static LocatorMatcherTasks cmakeMatchers(const BuildAcceptor &acceptor) static LocatorMatcherTasks cmakeMatchers(const BuildAcceptor &acceptor)
{ {
using namespace Tasking; using namespace Tasking;
@@ -80,7 +84,7 @@ static LocatorMatcherTasks cmakeMatchers(const BuildAcceptor &acceptor)
return {{Sync(onSetup), storage}}; return {{Sync(onSetup), storage}};
} }
void setupFilter(ILocatorFilter *filter) static void setupFilter(ILocatorFilter *filter)
{ {
const auto projectListUpdated = [filter] { const auto projectListUpdated = [filter] {
filter->setEnabled(Utils::contains(ProjectManager::projects(), filter->setEnabled(Utils::contains(ProjectManager::projects(),
@@ -92,10 +96,6 @@ void setupFilter(ILocatorFilter *filter)
filter, projectListUpdated); filter, projectListUpdated);
} }
// --------------------------------------------------------------------
// BuildCMakeTargetLocatorFilter:
// --------------------------------------------------------------------
static void buildAcceptor(const FilePath &projectPath, const QString &displayName) static void buildAcceptor(const FilePath &projectPath, const QString &displayName)
{ {
// Get the project containing the target selected // Get the project containing the target selected
@@ -126,38 +126,48 @@ static void buildAcceptor(const FilePath &projectPath, const QString &displayNam
buildStep->setBuildTargets(oldTargets); buildStep->setBuildTargets(oldTargets);
} }
CMakeBuildTargetFilter::CMakeBuildTargetFilter() class CMakeBuildTargetFilter final : ILocatorFilter
{ {
setId("Build CMake target"); public:
setDisplayName(Tr::tr("Build CMake Target")); CMakeBuildTargetFilter()
setDescription(Tr::tr("Builds a target of any open CMake project.")); {
setDefaultShortcutString("cm"); setId("Build CMake target");
setPriority(High); setDisplayName(Tr::tr("Build CMake Target"));
setupFilter(this); setDescription(Tr::tr("Builds a target of any open CMake project."));
setDefaultShortcutString("cm");
setPriority(High);
setupFilter(this);
}
private:
LocatorMatcherTasks matchers() final { return cmakeMatchers(&buildAcceptor); }
};
// OpenCMakeTargetLocatorFilter
class CMakeOpenTargetFilter final : ILocatorFilter
{
public:
CMakeOpenTargetFilter()
{
setId("Open CMake target definition");
setDisplayName(Tr::tr("Open CMake Target"));
setDescription(Tr::tr("Locates the definition of a target of any open CMake project."));
setDefaultShortcutString("cmo");
setPriority(Medium);
setupFilter(this);
}
private:
LocatorMatcherTasks matchers() final { return cmakeMatchers({}); }
};
// Setup
void setupCMakeLocatorFilters()
{
static CMakeBuildTargetFilter theCMakeBuildTargetFilter;
static CMakeOpenTargetFilter theCMakeOpenTargetFilter;
} }
Core::LocatorMatcherTasks CMakeBuildTargetFilter::matchers() } // CMakeProjectManager::Internal
{
return cmakeMatchers(&buildAcceptor);
}
// --------------------------------------------------------------------
// OpenCMakeTargetLocatorFilter:
// --------------------------------------------------------------------
CMakeOpenTargetFilter::CMakeOpenTargetFilter()
{
setId("Open CMake target definition");
setDisplayName(Tr::tr("Open CMake Target"));
setDescription(Tr::tr("Locates the definition of a target of any open CMake project."));
setDefaultShortcutString("cmo");
setPriority(Medium);
setupFilter(this);
}
Core::LocatorMatcherTasks CMakeOpenTargetFilter::matchers()
{
return cmakeMatchers({});
}
} // namespace CMakeProjectManager::Internal

View File

@@ -3,26 +3,8 @@
#pragma once #pragma once
#include <coreplugin/locator/ilocatorfilter.h>
namespace CMakeProjectManager::Internal { namespace CMakeProjectManager::Internal {
class CMakeBuildTargetFilter : Core::ILocatorFilter void setupCMakeLocatorFilters();
{
public:
CMakeBuildTargetFilter();
private: } // CMakeProjectManager::Internal
Core::LocatorMatcherTasks matchers() final;
};
class CMakeOpenTargetFilter : Core::ILocatorFilter
{
public:
CMakeOpenTargetFilter();
private:
Core::LocatorMatcherTasks matchers() final;
};
} // namespace CMakeProjectManager::Internal

View File

@@ -51,12 +51,6 @@ public:
Tr::tr("Build \"%1\""), Tr::tr("Build \"%1\""),
Action::AlwaysEnabled/*handled manually*/ Action::AlwaysEnabled/*handled manually*/
}; };
CMakeInstallStepFactory installStepFactory;
CMakeBuildTargetFilter cMakeBuildTargetFilter;
CMakeOpenTargetFilter cMakeOpenTargetFilter;
CMakeFormatter cmakeFormatter;
}; };
class CMakeProjectPlugin final : public ExtensionSystem::IPlugin class CMakeProjectPlugin final : public ExtensionSystem::IPlugin
@@ -77,9 +71,13 @@ class CMakeProjectPlugin final : public ExtensionSystem::IPlugin
setupCMakeBuildConfiguration(); setupCMakeBuildConfiguration();
setupCMakeBuildStep(); setupCMakeBuildStep();
setupCMakeInstallStep();
setupCMakeEditor(); setupCMakeEditor();
setupCMakeLocatorFilters();
setupCMakeFormatter();
d = new CMakeProjectPluginPrivate; d = new CMakeProjectPluginPrivate;
setupCMakeManager(); setupCMakeManager();