forked from qt-creator/qt-creator
CMakeProjectManager: Use Core::ActionBuilder in a few places
Change-Id: If2e852e744a070805a542ad62291ad791b1bddf5 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -43,6 +43,7 @@
|
|||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
using namespace Core;
|
||||||
using namespace CppEditor;
|
using namespace CppEditor;
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
@@ -50,128 +51,105 @@ using namespace Utils;
|
|||||||
namespace CMakeProjectManager::Internal {
|
namespace CMakeProjectManager::Internal {
|
||||||
|
|
||||||
CMakeManager::CMakeManager()
|
CMakeManager::CMakeManager()
|
||||||
: m_runCMakeAction(
|
|
||||||
new QAction(ProjectExplorer::Icons::CMAKE_LOGO.icon(), Tr::tr("Run CMake"), this))
|
|
||||||
, m_clearCMakeCacheAction(new QAction(QIcon(), Tr::tr("Clear CMake Configuration"), this))
|
|
||||||
, m_runCMakeActionContextMenu(
|
|
||||||
new QAction(ProjectExplorer::Icons::CMAKE_LOGO.icon(), Tr::tr("Run CMake"), this))
|
|
||||||
, m_rescanProjectAction(new QAction(QIcon(), Tr::tr("Rescan Project"), this))
|
|
||||||
, m_reloadCMakePresetsAction(
|
|
||||||
new QAction(Utils::Icons::RELOAD.icon(), Tr::tr("Reload CMake Presets"), this))
|
|
||||||
, m_cmakeProfilerAction(
|
|
||||||
new QAction(ProjectExplorer::Icons::CMAKE_LOGO.icon(), Tr::tr("CMake Profiler"), this))
|
|
||||||
, m_cmakeDebuggerAction(new QAction(ProjectExplorer::Icons::CMAKE_LOGO.icon(),
|
|
||||||
Tr::tr("Start CMake Debugging"),
|
|
||||||
this))
|
|
||||||
{
|
{
|
||||||
Core::ActionContainer *mbuild =
|
namespace PEC = ProjectExplorer::Constants;
|
||||||
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_BUILDPROJECT);
|
|
||||||
Core::ActionContainer *mproject =
|
|
||||||
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_PROJECTCONTEXT);
|
|
||||||
Core::ActionContainer *msubproject =
|
|
||||||
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_SUBPROJECTCONTEXT);
|
|
||||||
Core::ActionContainer *mfile =
|
|
||||||
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_FILECONTEXT);
|
|
||||||
Core::ActionContainer *manalyzer =
|
|
||||||
Core::ActionManager::actionContainer(Debugger::Constants::M_DEBUG_ANALYZER);
|
|
||||||
Core::ActionContainer *mdebugger =
|
|
||||||
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_DEBUG_STARTDEBUGGING);
|
|
||||||
|
|
||||||
const Core::Context projectContext(CMakeProjectManager::Constants::CMAKE_PROJECT_ID);
|
const Context projectContext(CMakeProjectManager::Constants::CMAKE_PROJECT_ID);
|
||||||
const Core::Context globalContext(Core::Constants::C_GLOBAL);
|
|
||||||
|
|
||||||
Core::Command *command = Core::ActionManager::registerAction(m_runCMakeAction,
|
ActionBuilder runCMakeAction(this, Constants::RUN_CMAKE);
|
||||||
Constants::RUN_CMAKE,
|
runCMakeAction.setText(Tr::tr("Run CMake"));
|
||||||
globalContext);
|
runCMakeAction.setIcon(ProjectExplorer::Icons::CMAKE_LOGO.icon());
|
||||||
command->setAttribute(Core::Command::CA_Hide);
|
runCMakeAction.bindContextAction(&m_runCMakeAction);
|
||||||
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD);
|
runCMakeAction.setCommandAttribute(Command::CA_Hide);
|
||||||
connect(m_runCMakeAction, &QAction::triggered, this, [this] {
|
runCMakeAction.setContainer(PEC::M_BUILDPROJECT, PEC::G_BUILD_BUILD);
|
||||||
runCMake(ProjectManager::startupBuildSystem());
|
runCMakeAction.setOnTriggered(this, [this] { runCMake(ProjectManager::startupBuildSystem()); });
|
||||||
});
|
|
||||||
|
|
||||||
command = Core::ActionManager::registerAction(m_clearCMakeCacheAction,
|
ActionBuilder clearCMakeCacheAction(this, Constants::CLEAR_CMAKE_CACHE);
|
||||||
Constants::CLEAR_CMAKE_CACHE,
|
clearCMakeCacheAction.setText(Tr::tr("Clear CMake Configuration"));
|
||||||
globalContext);
|
clearCMakeCacheAction.bindContextAction(&m_clearCMakeCacheAction);
|
||||||
command->setAttribute(Core::Command::CA_Hide);
|
clearCMakeCacheAction.setCommandAttribute(Command::CA_Hide);
|
||||||
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD);
|
clearCMakeCacheAction.setContainer(PEC::M_BUILDPROJECT, PEC::G_BUILD_BUILD);
|
||||||
connect(m_clearCMakeCacheAction, &QAction::triggered, this, [this] {
|
clearCMakeCacheAction.setOnTriggered(this, [this] {
|
||||||
clearCMakeCache(ProjectManager::startupBuildSystem());
|
clearCMakeCache(ProjectManager::startupBuildSystem());
|
||||||
});
|
});
|
||||||
|
|
||||||
command = Core::ActionManager::registerAction(m_runCMakeActionContextMenu,
|
ActionBuilder runCMakeActionContextMenu(this, Constants::RUN_CMAKE_CONTEXT_MENU);
|
||||||
Constants::RUN_CMAKE_CONTEXT_MENU,
|
runCMakeActionContextMenu.setText(Tr::tr("Run CMake"));
|
||||||
projectContext);
|
runCMakeActionContextMenu.setIcon(ProjectExplorer::Icons::CMAKE_LOGO.icon());
|
||||||
command->setAttribute(Core::Command::CA_Hide);
|
runCMakeActionContextMenu.setContext(projectContext);
|
||||||
mproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
|
runCMakeActionContextMenu.bindContextAction(&m_runCMakeActionContextMenu);
|
||||||
msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
|
runCMakeActionContextMenu.setCommandAttribute(Command::CA_Hide);
|
||||||
connect(m_runCMakeActionContextMenu, &QAction::triggered, this, [this] {
|
runCMakeActionContextMenu.setContainer(PEC::M_PROJECTCONTEXT, PEC::G_PROJECT_BUILD);
|
||||||
|
runCMakeActionContextMenu.setOnTriggered(this, [this] {
|
||||||
runCMake(ProjectTree::currentBuildSystem());
|
runCMake(ProjectTree::currentBuildSystem());
|
||||||
});
|
});
|
||||||
|
|
||||||
m_buildFileContextMenu = new QAction(Tr::tr("Build"), this);
|
ActionBuilder buildFileContextAction(this, Constants::BUILD_FILE_CONTEXT_MENU);
|
||||||
command = Core::ActionManager::registerAction(m_buildFileContextMenu,
|
buildFileContextAction.setText(Tr::tr("Build"));
|
||||||
Constants::BUILD_FILE_CONTEXT_MENU,
|
buildFileContextAction.bindContextAction(&m_buildFileContextMenu);
|
||||||
projectContext);
|
buildFileContextAction.setContext(projectContext);
|
||||||
command->setAttribute(Core::Command::CA_Hide);
|
buildFileContextAction.setCommandAttribute(Command::CA_Hide);
|
||||||
mfile->addAction(command, ProjectExplorer::Constants::G_FILE_OTHER);
|
buildFileContextAction.setContainer(PEC::M_FILECONTEXT, PEC::G_FILE_OTHER);
|
||||||
connect(m_buildFileContextMenu, &QAction::triggered,
|
buildFileContextAction.setOnTriggered(this, [this] { buildFileContextMenu(); });
|
||||||
this, &CMakeManager::buildFileContextMenu);
|
|
||||||
|
|
||||||
command = Core::ActionManager::registerAction(m_rescanProjectAction,
|
ActionBuilder rescanProjectAction(this, Constants::RESCAN_PROJECT);
|
||||||
Constants::RESCAN_PROJECT,
|
rescanProjectAction.setText(Tr::tr("Rescan Project"));
|
||||||
globalContext);
|
rescanProjectAction.bindContextAction(&m_rescanProjectAction);
|
||||||
command->setAttribute(Core::Command::CA_Hide);
|
rescanProjectAction.setCommandAttribute(Command::CA_Hide);
|
||||||
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD);
|
rescanProjectAction.setContainer(PEC::M_BUILDPROJECT, PEC::G_BUILD_BUILD);
|
||||||
connect(m_rescanProjectAction, &QAction::triggered, this, [this] {
|
rescanProjectAction.setOnTriggered(this, [this] {
|
||||||
rescanProject(ProjectTree::currentBuildSystem());
|
rescanProject(ProjectTree::currentBuildSystem());
|
||||||
});
|
});
|
||||||
|
|
||||||
command = Core::ActionManager::registerAction(m_reloadCMakePresetsAction,
|
ActionBuilder reloadCMakePresetsAction(this, Constants::RELOAD_CMAKE_PRESETS);
|
||||||
Constants::RELOAD_CMAKE_PRESETS,
|
reloadCMakePresetsAction.setText(Tr::tr("Reload CMake Presets"));
|
||||||
globalContext);
|
reloadCMakePresetsAction.setIcon(Utils::Icons::RELOAD.icon());
|
||||||
command->setAttribute(Core::Command::CA_Hide);
|
reloadCMakePresetsAction.bindContextAction(&m_reloadCMakePresetsAction);
|
||||||
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD);
|
reloadCMakePresetsAction.setCommandAttribute(Command::CA_Hide);
|
||||||
connect(m_reloadCMakePresetsAction, &QAction::triggered, this, [this] {
|
reloadCMakePresetsAction.setContainer(PEC::M_BUILDPROJECT, PEC::G_BUILD_BUILD);
|
||||||
reloadCMakePresets();
|
reloadCMakePresetsAction.setOnTriggered(this, [this] { reloadCMakePresets(); });
|
||||||
});
|
|
||||||
|
|
||||||
m_buildFileAction = new Utils::ParameterAction(Tr::tr("Build File"),
|
m_buildFileAction = new Utils::ParameterAction(Tr::tr("Build File"),
|
||||||
Tr::tr("Build File \"%1\""),
|
Tr::tr("Build File \"%1\""),
|
||||||
Utils::ParameterAction::AlwaysEnabled,
|
Utils::ParameterAction::AlwaysEnabled,
|
||||||
this);
|
this);
|
||||||
command = Core::ActionManager::registerAction(m_buildFileAction, Constants::BUILD_FILE);
|
Command *command = ActionManager::registerAction(m_buildFileAction, Constants::BUILD_FILE);
|
||||||
command->setAttribute(Core::Command::CA_Hide);
|
command->setAttribute(Command::CA_Hide);
|
||||||
command->setAttribute(Core::Command::CA_UpdateText);
|
command->setAttribute(Command::CA_UpdateText);
|
||||||
command->setDescription(m_buildFileAction->text());
|
command->setDescription(m_buildFileAction->text());
|
||||||
command->setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+Alt+B")));
|
command->setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+Alt+B")));
|
||||||
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD);
|
ActionContainer *mbuild = ActionManager::actionContainer(PEC::M_BUILDPROJECT);
|
||||||
|
mbuild->addAction(command, PEC::G_BUILD_BUILD);
|
||||||
connect(m_buildFileAction, &QAction::triggered, this, [this] { buildFile(); });
|
connect(m_buildFileAction, &QAction::triggered, this, [this] { buildFile(); });
|
||||||
|
|
||||||
// CMake Profiler
|
// CMake Profiler
|
||||||
command = Core::ActionManager::registerAction(m_cmakeProfilerAction,
|
ActionBuilder cmakeProfilerAction(this, Constants::RUN_CMAKE_PROFILER);
|
||||||
Constants::RUN_CMAKE_PROFILER,
|
cmakeProfilerAction.setIcon(ProjectExplorer::Icons::CMAKE_LOGO.icon());
|
||||||
globalContext);
|
cmakeProfilerAction.setText(Tr::tr("CMake Profiler"));
|
||||||
command->setDescription(m_cmakeProfilerAction->text());
|
cmakeProfilerAction.bindContextAction(&m_cmakeProfilerAction);
|
||||||
if (manalyzer)
|
cmakeProfilerAction.setCommandDescription(m_cmakeProfilerAction->text());
|
||||||
manalyzer->addAction(command, Debugger::Constants::G_ANALYZER_TOOLS);
|
cmakeProfilerAction.setContainer(Debugger::Constants::M_DEBUG_ANALYZER,
|
||||||
connect(m_cmakeProfilerAction, &QAction::triggered, this, [this] {
|
Debugger::Constants::G_ANALYZER_TOOLS,
|
||||||
|
false);
|
||||||
|
cmakeProfilerAction.setOnTriggered(this, [this] {
|
||||||
runCMakeWithProfiling(ProjectManager::startupBuildSystem());
|
runCMakeWithProfiling(ProjectManager::startupBuildSystem());
|
||||||
});
|
});
|
||||||
|
|
||||||
// CMake Debugger
|
// CMake Debugger
|
||||||
|
ActionContainer *mdebugger = ActionManager::actionContainer(PEC::M_DEBUG_STARTDEBUGGING);
|
||||||
mdebugger->appendGroup(Constants::CMAKE_DEBUGGING_GROUP);
|
mdebugger->appendGroup(Constants::CMAKE_DEBUGGING_GROUP);
|
||||||
mdebugger->addSeparator(Core::Context(Core::Constants::C_GLOBAL),
|
mdebugger->addSeparator(Context(Core::Constants::C_GLOBAL),
|
||||||
Constants::CMAKE_DEBUGGING_GROUP,
|
Constants::CMAKE_DEBUGGING_GROUP,
|
||||||
&m_cmakeDebuggerSeparator);
|
&m_cmakeDebuggerSeparator);
|
||||||
|
|
||||||
command = Core::ActionManager::registerAction(m_cmakeDebuggerAction,
|
ActionBuilder cmakeDebuggerAction(this, Constants::RUN_CMAKE_DEBUGGER);
|
||||||
Constants::RUN_CMAKE_DEBUGGER,
|
cmakeDebuggerAction.setText(Tr::tr("Start CMake Debugging"));
|
||||||
globalContext);
|
cmakeDebuggerAction.setIcon(ProjectExplorer::Icons::CMAKE_LOGO.icon());
|
||||||
command->setDescription(m_cmakeDebuggerAction->text());
|
cmakeDebuggerAction.bindContextAction(&m_cmakeDebuggerAction);
|
||||||
mdebugger->addAction(command, Constants::CMAKE_DEBUGGING_GROUP);
|
cmakeDebuggerAction.setCommandDescription(m_cmakeDebuggerAction->text());
|
||||||
connect(m_cmakeDebuggerAction, &QAction::triggered, this, [] {
|
cmakeDebuggerAction.setContainer(PEC::M_DEBUG_STARTDEBUGGING, Constants::CMAKE_DEBUGGING_GROUP);
|
||||||
ProjectExplorerPlugin::runStartupProject(ProjectExplorer::Constants::DAP_CMAKE_DEBUG_RUN_MODE,
|
cmakeDebuggerAction.setOnTriggered(this, [] {
|
||||||
false);
|
ProjectExplorerPlugin::runStartupProject(PEC::DAP_CMAKE_DEBUG_RUN_MODE, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(ProjectManager::instance(), &ProjectManager::startupProjectChanged, this, [this] {
|
connect(ProjectManager::instance(), &ProjectManager::startupProjectChanged, this, [this] {
|
||||||
@@ -188,7 +166,7 @@ CMakeManager::CMakeManager()
|
|||||||
connect(BuildManager::instance(), &BuildManager::buildStateChanged, this, [this] {
|
connect(BuildManager::instance(), &BuildManager::buildStateChanged, this, [this] {
|
||||||
updateCmakeActions(ProjectTree::currentNode());
|
updateCmakeActions(ProjectTree::currentNode());
|
||||||
});
|
});
|
||||||
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged,
|
connect(EditorManager::instance(), &EditorManager::currentEditorChanged,
|
||||||
this, &CMakeManager::updateBuildFileAction);
|
this, &CMakeManager::updateBuildFileAction);
|
||||||
connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged,
|
connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged,
|
||||||
this, &CMakeManager::updateCmakeActions);
|
this, &CMakeManager::updateCmakeActions);
|
||||||
|
@@ -130,12 +130,14 @@ void ActionBuilder::setCommandDescription(const QString &desc)
|
|||||||
d->command->setDescription(desc);
|
d->command->setDescription(desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionBuilder::setContainer(Id containerId, Id groupId)
|
void ActionBuilder::setContainer(Id containerId, Id groupId, bool needsToExist)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(containerId.isValid(), return);
|
QTC_ASSERT(containerId.isValid(), return);
|
||||||
ActionContainer *container = ActionManager::actionContainer(containerId);
|
if (ActionContainer *container = ActionManager::actionContainer(containerId)) {
|
||||||
QTC_ASSERT(container, return);
|
|
||||||
container->addAction(d->command, groupId);
|
container->addAction(d->command, groupId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QTC_CHECK(!needsToExist);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionBuilder::setOnTriggered(const std::function<void ()> &func)
|
void ActionBuilder::setOnTriggered(const std::function<void ()> &func)
|
||||||
|
@@ -42,7 +42,7 @@ public:
|
|||||||
void setToolTip(const QString &toolTip);
|
void setToolTip(const QString &toolTip);
|
||||||
void setCommandAttribute(Core::Command::CommandAttribute attr);
|
void setCommandAttribute(Core::Command::CommandAttribute attr);
|
||||||
void setCommandDescription(const QString &desc);
|
void setCommandDescription(const QString &desc);
|
||||||
void setContainer(Utils::Id containerId, Utils::Id groupId = {});
|
void setContainer(Utils::Id containerId, Utils::Id groupId = {}, bool needsToExist = true);
|
||||||
void setOnTriggered(const std::function<void()> &func);
|
void setOnTriggered(const std::function<void()> &func);
|
||||||
void setOnTriggered(QObject *guard, const std::function<void()> &func);
|
void setOnTriggered(QObject *guard, const std::function<void()> &func);
|
||||||
void setOnTriggered(QObject *guard, const std::function<void(bool)> &func);
|
void setOnTriggered(QObject *guard, const std::function<void(bool)> &func);
|
||||||
|
Reference in New Issue
Block a user