GenericProject: Use new Core::Action

Change-Id: I694b29565089baa14b316bca07a8ac29747ac32a
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2023-11-08 15:23:52 +01:00
parent fd1956a91c
commit 5334154ecb

View File

@@ -13,8 +13,6 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/command.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectmanager.h> #include <projectexplorer/projectmanager.h>
@@ -23,11 +21,8 @@
#include <projectexplorer/selectablefilesmodel.h> #include <projectexplorer/selectablefilesmodel.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/fileutils.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QAction>
using namespace Core; using namespace Core;
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils; using namespace Utils;
@@ -44,8 +39,8 @@ public:
ProjectFilesFactory projectFilesFactory; ProjectFilesFactory projectFilesFactory;
GenericMakeStepFactory makeStepFactory; GenericMakeStepFactory makeStepFactory;
GenericBuildConfigurationFactory buildConfigFactory; GenericBuildConfigurationFactory buildConfigFactory;
Action editAction;
QAction editFilesAction{Tr::tr("Edit Files..."), nullptr}; Action removeDirAction;
}; };
GenericProjectPlugin::~GenericProjectPlugin() GenericProjectPlugin::~GenericProjectPlugin()
@@ -64,23 +59,21 @@ GenericProjectPluginPrivate::GenericProjectPluginPrivate()
IWizardFactory::registerFactoryCreator([] { return new GenericProjectWizard; }); IWizardFactory::registerFactoryCreator([] { return new GenericProjectWizard; });
ActionContainer *mproject = ActionManager::actionContainer(PEC::M_PROJECTCONTEXT); editAction.setId("GenericProjectManager.EditFiles");
editAction.setContext(Constants::GENERICPROJECT_ID);
Command *command = ActionManager::registerAction(&editFilesAction, editAction.setText(Tr::tr("Edit Files..."));
"GenericProjectManager.EditFiles", Context(Constants::GENERICPROJECT_ID)); editAction.setCommandAttribute(Command::CA_Hide);
command->setAttribute(Command::CA_Hide); editAction.setContainer(PEC::M_PROJECTCONTEXT, PEC::G_PROJECT_FILES);
mproject->addAction(command, PEC::G_PROJECT_FILES); editAction.setOnTriggered([] {
connect(&editFilesAction, &QAction::triggered, this, [] {
if (auto genericProject = qobject_cast<GenericProject *>(ProjectTree::currentProject())) if (auto genericProject = qobject_cast<GenericProject *>(ProjectTree::currentProject()))
genericProject->editFilesTriggered(); genericProject->editFilesTriggered();
}); });
const auto removeDirAction = new QAction(Tr::tr("Remove Directory"), this); removeDirAction.setId("GenericProject.RemoveDir");
Command * const cmd = ActionManager::registerAction(removeDirAction, "GenericProject.RemoveDir", removeDirAction.setContext(PEC::C_PROJECT_TREE);
Context(PEC::C_PROJECT_TREE)); removeDirAction.setText(Tr::tr("Remove Directory"));
ActionManager::actionContainer(PEC::M_FOLDERCONTEXT)->addAction(cmd, PEC::G_FOLDER_OTHER); removeDirAction.setContainer(PEC::M_FOLDERCONTEXT, PEC::G_FOLDER_OTHER);
connect(removeDirAction, &QAction::triggered, this, [] { removeDirAction.setOnTriggered([] {
const auto folderNode = ProjectTree::currentNode()->asFolderNode(); const auto folderNode = ProjectTree::currentNode()->asFolderNode();
QTC_ASSERT(folderNode, return); QTC_ASSERT(folderNode, return);
const auto project = qobject_cast<GenericProject *>(folderNode->getProject()); const auto project = qobject_cast<GenericProject *>(folderNode->getProject());