forked from qt-creator/qt-creator
GenericProjectManager: Allow users to remove directories from a project
... via the project context menu. Fixes: QTCREATORBUG-16575 Change-Id: I02650a8ef70ffe22c6a42a5450588be4506af925 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <projectexplorer/project.h>
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
namespace CppTools { class CppProjectUpdater; }
|
||||
namespace Utils { class FileSystemWatcher; }
|
||||
@@ -46,6 +47,8 @@ public:
|
||||
bool setFiles(const QStringList &filePaths);
|
||||
bool renameFile(const QString &filePath, const QString &newFilePath);
|
||||
|
||||
Utils::FilePath filesFilePath() const { return Utils::FilePath::fromString(m_filesFileName); }
|
||||
|
||||
enum RefreshOptions {
|
||||
Files = 0x01,
|
||||
Configuration = 0x02,
|
||||
|
@@ -39,16 +39,21 @@
|
||||
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/projectmanager.h>
|
||||
#include <projectexplorer/projectnodes.h>
|
||||
#include <projectexplorer/projecttree.h>
|
||||
#include <projectexplorer/selectablefilesmodel.h>
|
||||
#include <projectexplorer/taskhub.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QAction>
|
||||
|
||||
using namespace Core;
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
namespace PEC = ProjectExplorer::Constants;
|
||||
|
||||
namespace GenericProjectManager {
|
||||
namespace Internal {
|
||||
@@ -85,13 +90,12 @@ GenericProjectPluginPrivate::GenericProjectPluginPrivate()
|
||||
|
||||
IWizardFactory::registerFactoryCreator([] { return QList<IWizardFactory *>{new GenericProjectWizard}; });
|
||||
|
||||
ActionContainer *mproject =
|
||||
ActionManager::actionContainer(ProjectExplorer::Constants::M_PROJECTCONTEXT);
|
||||
ActionContainer *mproject = ActionManager::actionContainer(PEC::M_PROJECTCONTEXT);
|
||||
|
||||
Command *command = ActionManager::registerAction(&editFilesAction,
|
||||
"GenericProjectManager.EditFiles", Context(Constants::GENERICPROJECT_ID));
|
||||
command->setAttribute(Command::CA_Hide);
|
||||
mproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_FILES);
|
||||
mproject->addAction(command, PEC::G_PROJECT_FILES);
|
||||
|
||||
connect(&editFilesAction, &QAction::triggered, this, [] {
|
||||
auto genericProject = qobject_cast<GenericProject *>(ProjectTree::currentProject());
|
||||
@@ -101,7 +105,26 @@ GenericProjectPluginPrivate::GenericProjectPluginPrivate()
|
||||
genericProject->files(Project::AllFiles),
|
||||
ICore::mainWindow());
|
||||
if (sfd.exec() == QDialog::Accepted)
|
||||
genericProject->setFiles(Utils::transform(sfd.selectedFiles(), &Utils::FilePath::toString));
|
||||
genericProject->setFiles(transform(sfd.selectedFiles(), &FilePath::toString));
|
||||
});
|
||||
|
||||
|
||||
const auto removeDirAction = new QAction(tr("Remove Directory"), this);
|
||||
Command * const cmd = ActionManager::registerAction(removeDirAction, "GenericProject.RemoveDir",
|
||||
Context(PEC::C_PROJECT_TREE));
|
||||
ActionManager::actionContainer(PEC::M_FOLDERCONTEXT)->addAction(cmd, PEC::G_FOLDER_OTHER);
|
||||
connect(removeDirAction, &QAction::triggered, this, [] {
|
||||
const auto folderNode = ProjectTree::currentNode()->asFolderNode();
|
||||
QTC_ASSERT(folderNode, return);
|
||||
const auto project = qobject_cast<GenericProject *>(folderNode->getProject());
|
||||
QTC_ASSERT(project, return);
|
||||
const QStringList filesToRemove = transform<QStringList>(
|
||||
folderNode->findNodes([](const Node *node) { return node->asFileNode(); }),
|
||||
[](const Node *node) { return node->filePath().toString();});
|
||||
if (!project->removeFiles(filesToRemove)) {
|
||||
TaskHub::addTask(Task::Error, tr("Project files list update failed."),
|
||||
PEC::TASK_CATEGORY_BUILDSYSTEM, project->filesFilePath());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user