forked from qt-creator/qt-creator
CMake: Use ActionBuilder for buildTargetContextAction
And remove now-empty CMakeProjectPluginPrivate class. Change-Id: I2b0b28cddb84639a62f90ee1776674cc7808480f Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -43,26 +43,11 @@ using namespace Utils;
|
|||||||
|
|
||||||
namespace CMakeProjectManager::Internal {
|
namespace CMakeProjectManager::Internal {
|
||||||
|
|
||||||
class CMakeProjectPluginPrivate : public QObject
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Action buildTargetContextAction{
|
|
||||||
Tr::tr("Build"),
|
|
||||||
Tr::tr("Build \"%1\""),
|
|
||||||
Action::AlwaysEnabled/*handled manually*/
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
class CMakeProjectPlugin final : public ExtensionSystem::IPlugin
|
class CMakeProjectPlugin final : public ExtensionSystem::IPlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "CMakeProjectManager.json")
|
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "CMakeProjectManager.json")
|
||||||
|
|
||||||
~CMakeProjectPlugin()
|
|
||||||
{
|
|
||||||
delete d;
|
|
||||||
}
|
|
||||||
|
|
||||||
void initialize() final
|
void initialize() final
|
||||||
{
|
{
|
||||||
setupCMakeToolManager(this);
|
setupCMakeToolManager(this);
|
||||||
@@ -78,8 +63,6 @@ class CMakeProjectPlugin final : public ExtensionSystem::IPlugin
|
|||||||
setupCMakeLocatorFilters();
|
setupCMakeLocatorFilters();
|
||||||
setupCMakeFormatter();
|
setupCMakeFormatter();
|
||||||
|
|
||||||
d = new CMakeProjectPluginPrivate;
|
|
||||||
|
|
||||||
setupCMakeManager();
|
setupCMakeManager();
|
||||||
|
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
@@ -88,8 +71,6 @@ class CMakeProjectPlugin final : public ExtensionSystem::IPlugin
|
|||||||
addTestCreator(createCMakeProjectImporterTest);
|
addTestCreator(createCMakeProjectImporterTest);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const Context projectContext{CMakeProjectManager::Constants::CMAKE_PROJECT_ID};
|
|
||||||
|
|
||||||
FileIconProvider::registerIconOverlayForSuffix(Constants::Icons::FILE_OVERLAY, "cmake");
|
FileIconProvider::registerIconOverlayForSuffix(Constants::Icons::FILE_OVERLAY, "cmake");
|
||||||
FileIconProvider::registerIconOverlayForFilename(Constants::Icons::FILE_OVERLAY,
|
FileIconProvider::registerIconOverlayForFilename(Constants::Icons::FILE_OVERLAY,
|
||||||
Constants::CMAKE_LISTS_TXT);
|
Constants::CMAKE_LISTS_TXT);
|
||||||
@@ -98,27 +79,24 @@ class CMakeProjectPlugin final : public ExtensionSystem::IPlugin
|
|||||||
Tr::tr("CMake", "SnippetProvider"));
|
Tr::tr("CMake", "SnippetProvider"));
|
||||||
ProjectManager::registerProjectType<CMakeProject>(Utils::Constants::CMAKE_PROJECT_MIMETYPE);
|
ProjectManager::registerProjectType<CMakeProject>(Utils::Constants::CMAKE_PROJECT_MIMETYPE);
|
||||||
|
|
||||||
//register actions
|
ActionBuilder(this, Constants::BUILD_TARGET_CONTEXT_MENU)
|
||||||
Command *command = ActionManager::registerAction(&d->buildTargetContextAction,
|
.setParameterText(Tr::tr("Build"), Tr::tr("Build \"%1\""), ActionBuilder::AlwaysEnabled)
|
||||||
Constants::BUILD_TARGET_CONTEXT_MENU,
|
.setContext(CMakeProjectManager::Constants::CMAKE_PROJECT_ID)
|
||||||
projectContext);
|
.bindContextAction(&m_buildTargetContextAction)
|
||||||
command->setAttribute(Command::CA_Hide);
|
.setCommandAttribute(Command::CA_Hide)
|
||||||
command->setAttribute(Command::CA_UpdateText);
|
.setCommandAttribute(Command::CA_UpdateText)
|
||||||
command->setDescription(d->buildTargetContextAction.text());
|
.setCommandDescription(m_buildTargetContextAction->text())
|
||||||
|
.addToContainer(ProjectExplorer::Constants::M_SUBPROJECTCONTEXT,
|
||||||
ActionManager::actionContainer(ProjectExplorer::Constants::M_SUBPROJECTCONTEXT)
|
ProjectExplorer::Constants::G_PROJECT_BUILD)
|
||||||
->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
|
.addOnTriggered(this, [] {
|
||||||
|
|
||||||
// Wire up context menu updates:
|
|
||||||
connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged,
|
|
||||||
this, &CMakeProjectPlugin::updateContextActions);
|
|
||||||
|
|
||||||
connect(&d->buildTargetContextAction, &Action::triggered, this, [] {
|
|
||||||
if (auto bs = qobject_cast<CMakeBuildSystem *>(ProjectTree::currentBuildSystem())) {
|
if (auto bs = qobject_cast<CMakeBuildSystem *>(ProjectTree::currentBuildSystem())) {
|
||||||
auto targetNode = dynamic_cast<const CMakeTargetNode *>(ProjectTree::currentNode());
|
auto targetNode = dynamic_cast<const CMakeTargetNode *>(ProjectTree::currentNode());
|
||||||
bs->buildCMakeTarget(targetNode ? targetNode->displayName() : QString());
|
bs->buildCMakeTarget(targetNode ? targetNode->displayName() : QString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged,
|
||||||
|
this, &CMakeProjectPlugin::updateContextActions);
|
||||||
}
|
}
|
||||||
|
|
||||||
void extensionsInitialized() final
|
void extensionsInitialized() final
|
||||||
@@ -133,12 +111,12 @@ class CMakeProjectPlugin final : public ExtensionSystem::IPlugin
|
|||||||
const QString targetDisplayName = targetNode ? targetNode->displayName() : QString();
|
const QString targetDisplayName = targetNode ? targetNode->displayName() : QString();
|
||||||
|
|
||||||
// Build Target:
|
// Build Target:
|
||||||
d->buildTargetContextAction.setParameter(targetDisplayName);
|
m_buildTargetContextAction->setParameter(targetDisplayName);
|
||||||
d->buildTargetContextAction.setEnabled(targetNode);
|
m_buildTargetContextAction->setEnabled(targetNode);
|
||||||
d->buildTargetContextAction.setVisible(targetNode);
|
m_buildTargetContextAction->setVisible(targetNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
class CMakeProjectPluginPrivate *d = nullptr;
|
Action *m_buildTargetContextAction = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // CMakeProjectManager::Internal
|
} // CMakeProjectManager::Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user