Project: Simplfy file adding/removing interface

The filetype is only relevant for Qt4 projects. But even for Qt4 projects
the file type is insufficient to decide where the file should be added.
So remove the file type from the interface and let the projectmanagers
themselves figure out what they want to do.

Also fix
Task-number: QTCREATORBUG-9688

Change-Id: I02f7b1cd2e05efaf76e36fb9af34b109d4482f88
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
Daniel Teske
2013-07-01 16:13:48 +02:00
parent a98fe15fe5
commit cc7fe5eac6
18 changed files with 180 additions and 231 deletions

View File

@@ -515,7 +515,7 @@ bool AndroidManager::createAndroidTemplatesIfNecessary(ProjectExplorer::Target *
} }
} }
if (!androidFiles.isEmpty()) if (!androidFiles.isEmpty())
qt4Project->rootProjectNode()->addFiles(ProjectExplorer::UnknownFileType, androidFiles); qt4Project->rootProjectNode()->addFiles(androidFiles);
int minApiLevel = 4; int minApiLevel = 4;
if (QtSupport::BaseQtVersion *qt = QtSupport::QtKitInformation::qtVersion(target->kit())) if (QtSupport::BaseQtVersion *qt = QtSupport::QtKitInformation::qtVersion(target->kit()))

View File

@@ -74,39 +74,31 @@ bool AutotoolsProjectNode::removeSubProjects(const QStringList &proFilePaths)
return false; return false;
} }
bool AutotoolsProjectNode::addFiles(const FileType fileType, bool AutotoolsProjectNode::addFiles( const QStringList &filePaths,
const QStringList &filePaths,
QStringList *notAdded) QStringList *notAdded)
{ {
Q_UNUSED(fileType);
Q_UNUSED(filePaths); Q_UNUSED(filePaths);
Q_UNUSED(notAdded); Q_UNUSED(notAdded);
return false; return false;
} }
bool AutotoolsProjectNode::removeFiles(const FileType fileType, bool AutotoolsProjectNode::removeFiles(const QStringList &filePaths,
const QStringList &filePaths,
QStringList *notRemoved) QStringList *notRemoved)
{ {
Q_UNUSED(fileType);
Q_UNUSED(filePaths); Q_UNUSED(filePaths);
Q_UNUSED(notRemoved); Q_UNUSED(notRemoved);
return false; return false;
} }
bool AutotoolsProjectNode::deleteFiles(const FileType fileType, bool AutotoolsProjectNode::deleteFiles(const QStringList &filePaths)
const QStringList &filePaths)
{ {
Q_UNUSED(fileType);
Q_UNUSED(filePaths); Q_UNUSED(filePaths);
return false; return false;
} }
bool AutotoolsProjectNode::renameFile(const FileType fileType, bool AutotoolsProjectNode::renameFile(const QString &filePath,
const QString &filePath,
const QString &newFilePath) const QString &newFilePath)
{ {
Q_UNUSED(fileType);
Q_UNUSED(filePath); Q_UNUSED(filePath);
Q_UNUSED(newFilePath); Q_UNUSED(newFilePath);
return false; return false;

View File

@@ -64,17 +64,11 @@ public:
bool canAddSubProject(const QString &proFilePath) const; bool canAddSubProject(const QString &proFilePath) const;
bool addSubProjects(const QStringList &proFilePaths); bool addSubProjects(const QStringList &proFilePaths);
bool removeSubProjects(const QStringList &proFilePaths); bool removeSubProjects(const QStringList &proFilePaths);
bool addFiles(const ProjectExplorer::FileType fileType, bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0);
const QStringList &filePaths, bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0);
QStringList *notAdded = 0); bool deleteFiles(const QStringList &filePaths);
bool removeFiles(const ProjectExplorer::FileType fileType, bool renameFile(const QString &filePath,
const QStringList &filePaths, const QString &newFilePath);
QStringList *notRemoved = 0);
bool deleteFiles(const ProjectExplorer::FileType fileType,
const QStringList &filePaths);
bool renameFile(const ProjectExplorer::FileType fileType,
const QString &filePath,
const QString &newFilePath);
QList<ProjectExplorer::RunConfiguration *> runConfigurationsFor(Node *node); QList<ProjectExplorer::RunConfiguration *> runConfigurationsFor(Node *node);
private: private:

View File

@@ -67,32 +67,28 @@ bool CMakeProjectNode::removeSubProjects(const QStringList &proFilePaths)
return false; return false;
} }
bool CMakeProjectNode::addFiles(const ProjectExplorer::FileType fileType, const QStringList &filePaths, QStringList *notAdded) bool CMakeProjectNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
{ {
Q_UNUSED(fileType)
Q_UNUSED(filePaths) Q_UNUSED(filePaths)
Q_UNUSED(notAdded) Q_UNUSED(notAdded)
return false; return false;
} }
bool CMakeProjectNode::removeFiles(const ProjectExplorer::FileType fileType, const QStringList &filePaths, QStringList *notRemoved) bool CMakeProjectNode::removeFiles(const QStringList &filePaths, QStringList *notRemoved)
{ {
Q_UNUSED(fileType)
Q_UNUSED(filePaths) Q_UNUSED(filePaths)
Q_UNUSED(notRemoved) Q_UNUSED(notRemoved)
return false; return false;
} }
bool CMakeProjectNode::deleteFiles(const ProjectExplorer::FileType fileType, const QStringList &filePaths) bool CMakeProjectNode::deleteFiles(const QStringList &filePaths)
{ {
Q_UNUSED(fileType)
Q_UNUSED(filePaths) Q_UNUSED(filePaths)
return false; return false;
} }
bool CMakeProjectNode::renameFile(const ProjectExplorer::FileType fileType, const QString &filePath, const QString &newFilePath) bool CMakeProjectNode::renameFile(const QString &filePath, const QString &newFilePath)
{ {
Q_UNUSED(fileType)
Q_UNUSED(filePath) Q_UNUSED(filePath)
Q_UNUSED(newFilePath) Q_UNUSED(newFilePath)
return false; return false;

View File

@@ -48,17 +48,13 @@ public:
virtual bool addSubProjects(const QStringList &proFilePaths); virtual bool addSubProjects(const QStringList &proFilePaths);
virtual bool removeSubProjects(const QStringList &proFilePaths); virtual bool removeSubProjects(const QStringList &proFilePaths);
virtual bool addFiles(const ProjectExplorer::FileType fileType, virtual bool addFiles( const QStringList &filePaths,
const QStringList &filePaths,
QStringList *notAdded = 0); QStringList *notAdded = 0);
virtual bool removeFiles(const ProjectExplorer::FileType fileType, virtual bool removeFiles(const QStringList &filePaths,
const QStringList &filePaths,
QStringList *notRemoved = 0); QStringList *notRemoved = 0);
virtual bool deleteFiles(const ProjectExplorer::FileType fileType, virtual bool deleteFiles(const QStringList &filePaths);
const QStringList &filePaths); virtual bool renameFile(const QString &filePath,
virtual bool renameFile(const ProjectExplorer::FileType fileType, const QString &newFilePath);
const QString &filePath,
const QString &newFilePath);
virtual QList<ProjectExplorer::RunConfiguration *> runConfigurationsFor(Node *node); virtual QList<ProjectExplorer::RunConfiguration *> runConfigurationsFor(Node *node);
}; };

View File

@@ -259,37 +259,28 @@ bool GenericProjectNode::removeSubProjects(const QStringList &proFilePaths)
return false; return false;
} }
bool GenericProjectNode::addFiles(const FileType fileType, bool GenericProjectNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
const QStringList &filePaths, QStringList *notAdded)
{ {
Q_UNUSED(fileType)
Q_UNUSED(notAdded) Q_UNUSED(notAdded)
return m_project->addFiles(filePaths); return m_project->addFiles(filePaths);
} }
bool GenericProjectNode::removeFiles(const FileType fileType, bool GenericProjectNode::removeFiles(const QStringList &filePaths, QStringList *notRemoved)
const QStringList &filePaths, QStringList *notRemoved)
{ {
Q_UNUSED(fileType)
Q_UNUSED(notRemoved) Q_UNUSED(notRemoved)
return m_project->removeFiles(filePaths); return m_project->removeFiles(filePaths);
} }
bool GenericProjectNode::deleteFiles(const FileType fileType, bool GenericProjectNode::deleteFiles(const QStringList &filePaths)
const QStringList &filePaths)
{ {
Q_UNUSED(fileType)
Q_UNUSED(filePaths) Q_UNUSED(filePaths)
return false; return false;
} }
bool GenericProjectNode::renameFile(const FileType fileType, bool GenericProjectNode::renameFile(const QString &filePath, const QString &newFilePath)
const QString &filePath, const QString &newFilePath)
{ {
Q_UNUSED(fileType)
return m_project->renameFile(filePath, newFilePath); return m_project->renameFile(filePath, newFilePath);
} }

View File

@@ -62,19 +62,10 @@ public:
bool addSubProjects(const QStringList &proFilePaths); bool addSubProjects(const QStringList &proFilePaths);
bool removeSubProjects(const QStringList &proFilePaths); bool removeSubProjects(const QStringList &proFilePaths);
bool addFiles(const ProjectExplorer::FileType fileType, bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0);
const QStringList &filePaths, bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0);
QStringList *notAdded = 0); bool deleteFiles(const QStringList &filePaths);
bool renameFile(const QString &filePath, const QString &newFilePath);
bool removeFiles(const ProjectExplorer::FileType fileType,
const QStringList &filePaths,
QStringList *notRemoved = 0);
bool deleteFiles(const ProjectExplorer::FileType fileType,
const QStringList &filePaths);
bool renameFile(const ProjectExplorer::FileType fileType,
const QString &filePath,
const QString &newFilePath);
QList<ProjectExplorer::RunConfiguration *> runConfigurationsFor(Node *node); QList<ProjectExplorer::RunConfiguration *> runConfigurationsFor(Node *node);

View File

@@ -2844,16 +2844,9 @@ void ProjectExplorerPlugin::addExistingFiles(ProjectNode *projectNode, const QSt
const QString dir = directoryFor(projectNode); const QString dir = directoryFor(projectNode);
QStringList fileNames = filePaths; QStringList fileNames = filePaths;
QHash<FileType, QString> fileTypeToFiles;
foreach (const QString &fileName, fileNames) {
FileType fileType = typeForFileName(Core::ICore::mimeDatabase(), QFileInfo(fileName));
fileTypeToFiles.insertMulti(fileType, fileName);
}
QStringList notAdded; QStringList notAdded;
foreach (const FileType type, fileTypeToFiles.uniqueKeys()) { projectNode->addFiles(fileNames, &notAdded);
projectNode->addFiles(type, fileTypeToFiles.values(type), &notAdded);
}
if (!notAdded.isEmpty()) { if (!notAdded.isEmpty()) {
QString message = tr("Could not add following files to project %1:\n").arg(projectNode->displayName()); QString message = tr("Could not add following files to project %1:\n").arg(projectNode->displayName());
QString files = notAdded.join(QString(QLatin1Char('\n'))); QString files = notAdded.join(QString(QLatin1Char('\n')));
@@ -2919,7 +2912,7 @@ void ProjectExplorerPlugin::removeFile()
ProjectNode *projectNode = fileNode->projectNode(); ProjectNode *projectNode = fileNode->projectNode();
Q_ASSERT(projectNode); Q_ASSERT(projectNode);
if (!projectNode->removeFiles(fileNode->fileType(), QStringList(filePath))) { if (!projectNode->removeFiles(QStringList(filePath))) {
QMessageBox::warning(Core::ICore::mainWindow(), tr("Removing File Failed"), QMessageBox::warning(Core::ICore::mainWindow(), tr("Removing File Failed"),
tr("Could not remove file %1 from project %2.").arg(filePath).arg(projectNode->displayName())); tr("Could not remove file %1 from project %2.").arg(filePath).arg(projectNode->displayName()));
return; return;
@@ -2947,7 +2940,7 @@ void ProjectExplorerPlugin::deleteFile()
ProjectNode *projectNode = fileNode->projectNode(); ProjectNode *projectNode = fileNode->projectNode();
QTC_ASSERT(projectNode, return); QTC_ASSERT(projectNode, return);
projectNode->deleteFiles(fileNode->fileType(), QStringList(filePath)); projectNode->deleteFiles(QStringList(filePath));
Core::DocumentManager::expectFileChange(filePath); Core::DocumentManager::expectFileChange(filePath);
if (Core::IVersionControl *vc = if (Core::IVersionControl *vc =
@@ -2988,7 +2981,7 @@ void ProjectExplorerPlugin::renameFile(Node *node, const QString &to)
if (Core::FileUtils::renameFile(orgFilePath, newFilePath)) { if (Core::FileUtils::renameFile(orgFilePath, newFilePath)) {
// Tell the project plugin about rename // Tell the project plugin about rename
ProjectNode *projectNode = fileNode->projectNode(); ProjectNode *projectNode = fileNode->projectNode();
if (!projectNode->renameFile(fileNode->fileType(), orgFilePath, newFilePath)) { if (!projectNode->renameFile(orgFilePath, newFilePath)) {
QMessageBox::warning(Core::ICore::mainWindow(), tr("Project Editing Failed"), QMessageBox::warning(Core::ICore::mainWindow(), tr("Project Editing Failed"),
tr("The file %1 was renamed to %2, but the project file %3 could not be automatically changed.") tr("The file %1 was renamed to %2, but the project file %3 could not be automatically changed.")
.arg(orgFilePath) .arg(orgFilePath)

View File

@@ -472,8 +472,6 @@ bool ProjectFileWizardExtension::processProject(
const QList<Core::GeneratedFile> &files, const QList<Core::GeneratedFile> &files,
bool *removeOpenProjectAttribute, QString *errorMessage) bool *removeOpenProjectAttribute, QString *errorMessage)
{ {
typedef QMultiMap<FileType, QString> TypeFileMap;
*removeOpenProjectAttribute = false; *removeOpenProjectAttribute = false;
QString generatedProject = generatedProjectFilePath(files); QString generatedProject = generatedProjectFilePath(files);
@@ -491,20 +489,13 @@ bool ProjectFileWizardExtension::processProject(
} }
*removeOpenProjectAttribute = true; *removeOpenProjectAttribute = true;
} else { } else {
// Split into lists by file type and bulk-add them. QStringList filePaths;
TypeFileMap typeFileMap; foreach (const Core::GeneratedFile &generatedFile, files)
const Core::MimeDatabase *mdb = Core::ICore::mimeDatabase(); filePaths << generatedFile.path();
foreach (const Core::GeneratedFile &generatedFile, files) { if (!project->addFiles(filePaths)) {
const QString path = generatedFile.path(); *errorMessage = tr("Failed to add one or more files to project\n'%1' (%2).").
typeFileMap.insert(typeForFileName(mdb, path), path); arg(project->path(), filePaths.join(QString(QLatin1Char(','))));
} return false;
foreach (FileType type, typeFileMap.uniqueKeys()) {
const QStringList typeFiles = typeFileMap.values(type);
if (!project->addFiles(type, typeFiles)) {
*errorMessage = tr("Failed to add one or more files to project\n'%1' (%2).").
arg(project->path(), typeFiles.join(QString(QLatin1Char(','))));
return false;
}
} }
} }
return true; return true;

View File

@@ -837,27 +837,3 @@ NodesWatcher::NodesWatcher(QObject *parent)
: QObject(parent) : QObject(parent)
{ {
} }
// TODO Maybe put this in core, so that all can benefit
FileType typeForFileName(const Core::MimeDatabase *db, const QFileInfo &file)
{
const Core::MimeType mt = db->findByFile(file);
if (!mt)
return UnknownFileType;
const QString typeName = mt.type();
if (typeName == QLatin1String(Constants::CPP_SOURCE_MIMETYPE)
|| typeName == QLatin1String(Constants::C_SOURCE_MIMETYPE))
return SourceType;
if (typeName == QLatin1String(Constants::CPP_HEADER_MIMETYPE)
|| typeName == QLatin1String(Constants::C_HEADER_MIMETYPE))
return HeaderType;
if (typeName == QLatin1String(Constants::RESOURCE_MIMETYPE))
return ResourceType;
if (typeName == QLatin1String(Constants::FORM_MIMETYPE))
return FormType;
if (mt.subClassesOf().contains(QLatin1String(Constants::QML_MIMETYPE))
|| typeName == QLatin1String(Constants::QML_MIMETYPE))
return QMLType;
return UnknownFileType;
}

View File

@@ -214,18 +214,10 @@ public:
virtual bool removeSubProjects(const QStringList &proFilePaths) = 0; virtual bool removeSubProjects(const QStringList &proFilePaths) = 0;
virtual bool addFiles(const FileType fileType, virtual bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0) = 0;
const QStringList &filePaths, virtual bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0) = 0;
QStringList *notAdded = 0) = 0; virtual bool deleteFiles(const QStringList &filePaths) = 0;
// TODO: Maybe remove fileType, can be detected by project virtual bool renameFile(const QString &filePath, const QString &newFilePath) = 0;
virtual bool removeFiles(const FileType fileType,
const QStringList &filePaths,
QStringList *notRemoved = 0) = 0;
virtual bool deleteFiles(const FileType fileType,
const QStringList &filePaths) = 0;
virtual bool renameFile(const FileType fileType,
const QString &filePath,
const QString &newFilePath) = 0;
// by default returns false // by default returns false
virtual bool deploysFolder(const QString &folder) const; virtual bool deploysFolder(const QString &folder) const;
@@ -343,7 +335,4 @@ private:
} // namespace ProjectExplorer } // namespace ProjectExplorer
// HACK: THERE SHOULD BE ONE PLACE TO MAKE THE FILE ENDING->FILE TYPE ASSOCIATION
ProjectExplorer::FileType typeForFileName(const Core::MimeDatabase *db, const QFileInfo &file);
#endif // PROJECTNODES_H #endif // PROJECTNODES_H

View File

@@ -286,32 +286,28 @@ bool QbsBaseProjectNode::removeSubProjects(const QStringList &proFilePaths)
return false; return false;
} }
bool QbsBaseProjectNode::addFiles(const ProjectExplorer::FileType fileType, const QStringList &filePaths, QStringList *notAdded) bool QbsBaseProjectNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
{ {
Q_UNUSED(fileType);
Q_UNUSED(filePaths); Q_UNUSED(filePaths);
Q_UNUSED(notAdded); Q_UNUSED(notAdded);
return false; return false;
} }
bool QbsBaseProjectNode::removeFiles(const ProjectExplorer::FileType fileType, const QStringList &filePaths, QStringList *notRemoved) bool QbsBaseProjectNode::removeFiles(const QStringList &filePaths, QStringList *notRemoved)
{ {
Q_UNUSED(fileType);
Q_UNUSED(filePaths); Q_UNUSED(filePaths);
Q_UNUSED(notRemoved); Q_UNUSED(notRemoved);
return false; return false;
} }
bool QbsBaseProjectNode::deleteFiles(const ProjectExplorer::FileType fileType, const QStringList &filePaths) bool QbsBaseProjectNode::deleteFiles(const QStringList &filePaths)
{ {
Q_UNUSED(fileType);
Q_UNUSED(filePaths); Q_UNUSED(filePaths);
return false; return false;
} }
bool QbsBaseProjectNode::renameFile(const ProjectExplorer::FileType fileType, const QString &filePath, const QString &newFilePath) bool QbsBaseProjectNode::renameFile(const QString &filePath, const QString &newFilePath)
{ {
Q_UNUSED(fileType);
Q_UNUSED(filePath); Q_UNUSED(filePath);
Q_UNUSED(newFilePath); Q_UNUSED(newFilePath);
return false; return false;

View File

@@ -90,17 +90,10 @@ public:
bool removeSubProjects(const QStringList &proFilePaths); bool removeSubProjects(const QStringList &proFilePaths);
bool addFiles(const ProjectExplorer::FileType fileType, bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0);
const QStringList &filePaths, bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0);
QStringList *notAdded = 0); bool deleteFiles(const QStringList &filePaths);
bool removeFiles(const ProjectExplorer::FileType fileType, bool renameFile(const QString &filePath, const QString &newFilePath);
const QStringList &filePaths,
QStringList *notRemoved = 0);
bool deleteFiles(const ProjectExplorer::FileType fileType,
const QStringList &filePaths);
bool renameFile(const ProjectExplorer::FileType fileType,
const QString &filePath,
const QString &newFilePath);
QList<ProjectExplorer::RunConfiguration *> runConfigurationsFor(Node *node); QList<ProjectExplorer::RunConfiguration *> runConfigurationsFor(Node *node);

View File

@@ -198,26 +198,22 @@ bool QmlProjectNode::removeSubProjects(const QStringList &proFilePaths)
return false; return false;
} }
bool QmlProjectNode::addFiles(const ProjectExplorer::FileType /*fileType*/, bool QmlProjectNode::addFiles(const QStringList &filePaths, QStringList * /*notAdded*/)
const QStringList &filePaths, QStringList * /*notAdded*/)
{ {
return m_project->addFiles(filePaths); return m_project->addFiles(filePaths);
} }
bool QmlProjectNode::removeFiles(const ProjectExplorer::FileType /*fileType*/, bool QmlProjectNode::removeFiles(const QStringList & /*filePaths*/, QStringList * /*notRemoved*/)
const QStringList & /*filePaths*/, QStringList * /*notRemoved*/)
{ {
return false; return false;
} }
bool QmlProjectNode::deleteFiles(const ProjectExplorer::FileType /*fileType*/, bool QmlProjectNode::deleteFiles(const QStringList & /*filePaths*/)
const QStringList & /*filePaths*/)
{ {
return true; return true;
} }
bool QmlProjectNode::renameFile(const ProjectExplorer::FileType /*fileType*/, bool QmlProjectNode::renameFile(const QString & /*filePath*/, const QString & /*newFilePath*/)
const QString & /*filePath*/, const QString & /*newFilePath*/)
{ {
return true; return true;
} }

View File

@@ -63,20 +63,10 @@ public:
virtual bool addSubProjects(const QStringList &proFilePaths); virtual bool addSubProjects(const QStringList &proFilePaths);
virtual bool removeSubProjects(const QStringList &proFilePaths); virtual bool removeSubProjects(const QStringList &proFilePaths);
virtual bool addFiles(const ProjectExplorer::FileType fileType, virtual bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0);
const QStringList &filePaths, virtual bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0);
QStringList *notAdded = 0); virtual bool deleteFiles(const QStringList &filePaths);
virtual bool renameFile(const QString &filePath, const QString &newFilePath);
virtual bool removeFiles(const ProjectExplorer::FileType fileType,
const QStringList &filePaths,
QStringList *notRemoved = 0);
virtual bool deleteFiles(const ProjectExplorer::FileType fileType,
const QStringList &filePaths);
virtual bool renameFile(const ProjectExplorer::FileType fileType,
const QString &filePath,
const QString &newFilePath);
virtual QList<ProjectExplorer::RunConfiguration *> runConfigurationsFor(Node *node); virtual QList<ProjectExplorer::RunConfiguration *> runConfigurationsFor(Node *node);

View File

@@ -52,6 +52,7 @@
#include <qtsupport/qtkitinformation.h> #include <qtsupport/qtkitinformation.h>
#include <cpptools/cppmodelmanagerinterface.h> #include <cpptools/cppmodelmanagerinterface.h>
#include <cpptools/cpptoolsconstants.h>
#include <utils/hostosinfo.h> #include <utils/hostosinfo.h>
#include <utils/stringutils.h> #include <utils/stringutils.h>
@@ -921,7 +922,7 @@ bool Qt4PriFileNode::addSubProjects(const QStringList &proFilePaths)
uniqueProFilePaths.append(simplifyProFilePath(proFile)); uniqueProFilePaths.append(simplifyProFilePath(proFile));
QStringList failedFiles; QStringList failedFiles;
changeFiles(ProjectExplorer::ProjectFileType, uniqueProFilePaths, &failedFiles, AddToProFile); changeFiles(QLatin1String(Constants::PROFILE_MIMETYPE), uniqueProFilePaths, &failedFiles, AddToProFile);
return failedFiles.isEmpty(); return failedFiles.isEmpty();
} }
@@ -929,20 +930,19 @@ bool Qt4PriFileNode::addSubProjects(const QStringList &proFilePaths)
bool Qt4PriFileNode::removeSubProjects(const QStringList &proFilePaths) bool Qt4PriFileNode::removeSubProjects(const QStringList &proFilePaths)
{ {
QStringList failedOriginalFiles; QStringList failedOriginalFiles;
changeFiles(ProjectExplorer::ProjectFileType, proFilePaths, &failedOriginalFiles, RemoveFromProFile); changeFiles(QLatin1String(Constants::PROFILE_MIMETYPE), proFilePaths, &failedOriginalFiles, RemoveFromProFile);
QStringList simplifiedProFiles; QStringList simplifiedProFiles;
foreach (const QString &proFile, failedOriginalFiles) foreach (const QString &proFile, failedOriginalFiles)
simplifiedProFiles.append(simplifyProFilePath(proFile)); simplifiedProFiles.append(simplifyProFilePath(proFile));
QStringList failedSimplifiedFiles; QStringList failedSimplifiedFiles;
changeFiles(ProjectExplorer::ProjectFileType, simplifiedProFiles, &failedSimplifiedFiles, RemoveFromProFile); changeFiles(QLatin1String(Constants::PROFILE_MIMETYPE), simplifiedProFiles, &failedSimplifiedFiles, RemoveFromProFile);
return failedSimplifiedFiles.isEmpty(); return failedSimplifiedFiles.isEmpty();
} }
bool Qt4PriFileNode::addFiles(const FileType fileType, const QStringList &filePaths, bool Qt4PriFileNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
QStringList *notAdded)
{ {
// If a file is already referenced in the .pro file then we don't add them. // If a file is already referenced in the .pro file then we don't add them.
// That ignores scopes and which variable was used to reference the file // That ignores scopes and which variable was used to reference the file
@@ -953,68 +953,103 @@ bool Qt4PriFileNode::addFiles(const FileType fileType, const QStringList &filePa
accept(&visitor); accept(&visitor);
const QStringList &allFiles = visitor.filePaths(); const QStringList &allFiles = visitor.filePaths();
QStringList qrcFiles; // the list of qrc files referenced from ui files typedef QMap<QString, QStringList> TypeFileMap;
if (fileType == ProjectExplorer::FormType) { // Split into lists by file type and bulk-add them.
foreach (const QString &formFile, filePaths) { TypeFileMap typeFileMap;
QStringList resourceFiles = formResources(formFile); const Core::MimeDatabase *mdb = Core::ICore::mimeDatabase();
foreach (const QString &resourceFile, resourceFiles) foreach (const QString file, filePaths) {
if (!qrcFiles.contains(resourceFile)) const Core::MimeType mt = mdb->findByFile(file);
qrcFiles.append(resourceFile); typeFileMap[mt.type()] << file;
}
}
QStringList uniqueQrcFiles;
foreach (const QString &file, qrcFiles) {
if (!allFiles.contains(file))
uniqueQrcFiles.append(file);
}
QStringList uniqueFilePaths;
foreach (const QString &file, filePaths) {
if (!allFiles.contains(file))
uniqueFilePaths.append(file);
} }
QStringList failedFiles; QStringList failedFiles;
changeFiles(fileType, uniqueFilePaths, &failedFiles, AddToProFile); foreach (const QString &type, typeFileMap.keys()) {
if (notAdded) const QStringList typeFiles = typeFileMap.value(type);
*notAdded = failedFiles; QStringList qrcFiles; // the list of qrc files referenced from ui files
changeFiles(ProjectExplorer::ResourceType, uniqueQrcFiles, &failedFiles, AddToProFile); if (type == QLatin1String(ProjectExplorer::Constants::RESOURCE_MIMETYPE)) {
if (notAdded) foreach (const QString &formFile, typeFiles) {
*notAdded += failedFiles; QStringList resourceFiles = formResources(formFile);
foreach (const QString &resourceFile, resourceFiles)
if (!qrcFiles.contains(resourceFile))
qrcFiles.append(resourceFile);
}
}
QStringList uniqueQrcFiles;
foreach (const QString &file, qrcFiles) {
if (!allFiles.contains(file))
uniqueQrcFiles.append(file);
}
QStringList uniqueFilePaths;
foreach (const QString &file, typeFiles) {
if (!allFiles.contains(file))
uniqueFilePaths.append(file);
}
changeFiles(type, uniqueFilePaths, &failedFiles, AddToProFile);
if (notAdded)
*notAdded += failedFiles;
changeFiles(QLatin1String(ProjectExplorer::Constants::RESOURCE_MIMETYPE), uniqueQrcFiles, &failedFiles, AddToProFile);
if (notAdded)
*notAdded += failedFiles;
}
return failedFiles.isEmpty(); return failedFiles.isEmpty();
} }
bool Qt4PriFileNode::removeFiles(const FileType fileType, const QStringList &filePaths, bool Qt4PriFileNode::removeFiles(const QStringList &filePaths,
QStringList *notRemoved) QStringList *notRemoved)
{ {
QStringList failedFiles; QStringList failedFiles;
changeFiles(fileType, filePaths, &failedFiles, RemoveFromProFile); typedef QMap<QString, QStringList> TypeFileMap;
if (notRemoved) // Split into lists by file type and bulk-add them.
*notRemoved = failedFiles; TypeFileMap typeFileMap;
const Core::MimeDatabase *mdb = Core::ICore::mimeDatabase();
foreach (const QString file, filePaths) {
const Core::MimeType mt = mdb->findByFile(file);
typeFileMap[mt.type()] << file;
}
foreach (const QString &type, typeFileMap.keys()) {
const QStringList typeFiles = typeFileMap.value(type);
changeFiles(type, typeFiles, &failedFiles, RemoveFromProFile);
if (notRemoved)
*notRemoved = failedFiles;
}
return failedFiles.isEmpty(); return failedFiles.isEmpty();
} }
bool Qt4PriFileNode::deleteFiles(const FileType fileType, const QStringList &filePaths) bool Qt4PriFileNode::deleteFiles(const QStringList &filePaths)
{ {
QStringList failedFiles; QStringList failedFiles;
changeFiles(fileType, filePaths, &failedFiles, RemoveFromProFile); typedef QMap<QString, QStringList> TypeFileMap;
// Split into lists by file type and bulk-add them.
TypeFileMap typeFileMap;
const Core::MimeDatabase *mdb = Core::ICore::mimeDatabase();
foreach (const QString file, filePaths) {
const Core::MimeType mt = mdb->findByFile(file);
typeFileMap[mt.type()] << file;
}
foreach (const QString &type, typeFileMap.keys()) {
const QStringList typeFiles = typeFileMap.value(type);
changeFiles(type, typeFiles, &failedFiles, RemoveFromProFile);
}
return true; return true;
} }
bool Qt4PriFileNode::renameFile(const FileType fileType, const QString &filePath, bool Qt4PriFileNode::renameFile(const QString &filePath, const QString &newFilePath)
const QString &newFilePath)
{ {
if (newFilePath.isEmpty()) if (newFilePath.isEmpty())
return false; return false;
bool changeProFileOptional = deploysFolder(QFileInfo(filePath).absolutePath()); bool changeProFileOptional = deploysFolder(QFileInfo(filePath).absolutePath());
const Core::MimeDatabase *mdb = Core::ICore::mimeDatabase();
const Core::MimeType mt = mdb->findByFile(filePath);
QStringList dummy; QStringList dummy;
changeFiles(fileType, QStringList() << filePath, &dummy, RemoveFromProFile);
changeFiles(mt.type(), QStringList() << filePath, &dummy, RemoveFromProFile);
if (!dummy.isEmpty() && !changeProFileOptional) if (!dummy.isEmpty() && !changeProFileOptional)
return false; return false;
changeFiles(fileType, QStringList() << newFilePath, &dummy, AddToProFile); changeFiles(mt.type(), QStringList() << newFilePath, &dummy, AddToProFile);
if (!dummy.isEmpty() && !changeProFileOptional) if (!dummy.isEmpty() && !changeProFileOptional)
return false; return false;
return true; return true;
@@ -1086,7 +1121,7 @@ QStringList Qt4PriFileNode::formResources(const QString &formFile) const
return resourceFiles; return resourceFiles;
} }
void Qt4PriFileNode::changeFiles(const FileType fileType, void Qt4PriFileNode::changeFiles(const QString &mimeType,
const QStringList &filePaths, const QStringList &filePaths,
QStringList *notChanged, QStringList *notChanged,
ChangeType change) ChangeType change)
@@ -1137,12 +1172,11 @@ void Qt4PriFileNode::changeFiles(const FileType fileType,
includeFile = parser.parsedProBlock(contents, m_projectFilePath, 1); includeFile = parser.parsedProBlock(contents, m_projectFilePath, 1);
} }
const QStringList vars = varNames(fileType); const QStringList vars = varNames(mimeType);
QDir priFileDir = QDir(m_qt4ProFileNode->m_projectDir); QDir priFileDir = QDir(m_qt4ProFileNode->m_projectDir);
if (change == AddToProFile) { if (change == AddToProFile) {
// Use the first variable for adding. // Use the first variable for adding.
// Yes, that's broken for adding objective c sources or other stuff.
ProWriter::addFiles(includeFile, &lines, priFileDir, filePaths, vars.first()); ProWriter::addFiles(includeFile, &lines, priFileDir, filePaths, vars.first());
notChanged->clear(); notChanged->clear();
} else { // RemoveFromProFile } else { // RemoveFromProFile
@@ -1217,6 +1251,40 @@ QStringList Qt4PriFileNode::varNames(ProjectExplorer::FileType type)
return vars; return vars;
} }
//!
//! \brief Qt4PriFileNode::varNames
//! \param mimeType
//! \return the qmake variable name for the mime type
//! Note: For adding the first variable in the list is used
//! For removal all variables returned a searched for the file
//!
QStringList Qt4PriFileNode::varNames(const QString &mimeType)
{
QStringList vars;
if (mimeType == QLatin1String(ProjectExplorer::Constants::CPP_HEADER_MIMETYPE)
|| mimeType == QLatin1String(ProjectExplorer::Constants::C_HEADER_MIMETYPE)) {
vars << QLatin1String("HEADERS");
vars << QLatin1String("OBJECTIVE_HEADERS");
} else if (mimeType == QLatin1String(ProjectExplorer::Constants::CPP_SOURCE_MIMETYPE)
|| mimeType == QLatin1String(ProjectExplorer::Constants::C_SOURCE_MIMETYPE)) {
vars << QLatin1String("SOURCES");
} else if (mimeType == QLatin1String(CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE)) {
vars << QLatin1String("OBJECTIVE_SOURCES");
} else if (mimeType == QLatin1String(ProjectExplorer::Constants::RESOURCE_MIMETYPE)) {
vars << QLatin1String("RESOURCES");
} else if (mimeType == QLatin1String(ProjectExplorer::Constants::FORM_MIMETYPE)) {
vars << QLatin1String("FORMS");
} else if (mimeType == QLatin1String(ProjectExplorer::Constants::QML_MIMETYPE)) {
vars << QLatin1String("OTHER_FILES");
} else if (mimeType == QLatin1String(Constants::PROFILE_MIMETYPE)) {
vars << QLatin1String("SUBDIRS");
} else {
vars << QLatin1String("OTHER_FILES");
vars << QLatin1String("ICON");
}
return vars;
}
QStringList Qt4PriFileNode::dynamicVarNames(QtSupport::ProFileReader *readerExact, QtSupport::ProFileReader *readerCumulative, QStringList Qt4PriFileNode::dynamicVarNames(QtSupport::ProFileReader *readerExact, QtSupport::ProFileReader *readerCumulative,
QtSupport::BaseQtVersion *qtVersion) QtSupport::BaseQtVersion *qtVersion)

View File

@@ -153,14 +153,10 @@ public:
bool addSubProjects(const QStringList &proFilePaths); bool addSubProjects(const QStringList &proFilePaths);
bool removeSubProjects(const QStringList &proFilePaths); bool removeSubProjects(const QStringList &proFilePaths);
bool addFiles(const FileType fileType, const QStringList &filePaths, bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0);
QStringList *notAdded = 0); bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0);
bool removeFiles(const FileType fileType, const QStringList &filePaths, bool deleteFiles(const QStringList &filePaths);
QStringList *notRemoved = 0); bool renameFile(const QString &filePath, const QString &newFilePath);
bool deleteFiles(const FileType fileType,
const QStringList &filePaths);
bool renameFile(const FileType fileType,
const QString &filePath, const QString &newFilePath);
bool folderChanged(const QString &changedFolder, const QSet<Utils::FileName> &newFiles); bool folderChanged(const QString &changedFolder, const QSet<Utils::FileName> &newFiles);
@@ -175,7 +171,8 @@ public:
static QSet<Utils::FileName> recursiveEnumerate(const QString &folder); static QSet<Utils::FileName> recursiveEnumerate(const QString &folder);
protected: protected:
void setIncludedInExactParse(bool b); void setIncludedInExactParse(bool b);
static QStringList varNames(FileType type); static QStringList varNames(ProjectExplorer::FileType type);
static QStringList varNames(const QString &mimeType);
static QStringList dynamicVarNames(QtSupport::ProFileReader *readerExact, QtSupport::ProFileReader *readerCumulative, QtSupport::BaseQtVersion *qtVersion); static QStringList dynamicVarNames(QtSupport::ProFileReader *readerExact, QtSupport::ProFileReader *readerCumulative, QtSupport::BaseQtVersion *qtVersion);
static QSet<Utils::FileName> filterFilesProVariables(ProjectExplorer::FileType fileType, const QSet<Utils::FileName> &files); static QSet<Utils::FileName> filterFilesProVariables(ProjectExplorer::FileType fileType, const QSet<Utils::FileName> &files);
static QSet<Utils::FileName> filterFilesRecursiveEnumerata(ProjectExplorer::FileType fileType, const QSet<Utils::FileName> &files); static QSet<Utils::FileName> filterFilesRecursiveEnumerata(ProjectExplorer::FileType fileType, const QSet<Utils::FileName> &files);
@@ -185,7 +182,7 @@ protected:
RemoveFromProFile RemoveFromProFile
}; };
void changeFiles(const FileType fileType, void changeFiles(const QString &mimeType,
const QStringList &filePaths, const QStringList &filePaths,
QStringList *notChanged, QStringList *notChanged,
ChangeType change); ChangeType change);

View File

@@ -216,7 +216,7 @@ void SuppressionDialog::accept()
if (!session->projectForFile(path)) { if (!session->projectForFile(path)) {
foreach (ProjectExplorer::Project *p, session->projects()) { foreach (ProjectExplorer::Project *p, session->projects()) {
if (path.startsWith(p->projectDirectory())) { if (path.startsWith(p->projectDirectory())) {
p->rootProjectNode()->addFiles(ProjectExplorer::UnknownFileType, QStringList() << path); p->rootProjectNode()->addFiles(QStringList() << path);
break; break;
} }
} }