Commit cc7fe5ea authored by Daniel Teske's avatar Daniel Teske
Browse files

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: default avatarTobias Hunger <tobias.hunger@digia.com>
parent a98fe15f
...@@ -515,7 +515,7 @@ bool AndroidManager::createAndroidTemplatesIfNecessary(ProjectExplorer::Target * ...@@ -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()))
......
...@@ -74,39 +74,31 @@ bool AutotoolsProjectNode::removeSubProjects(const QStringList &proFilePaths) ...@@ -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;
......
...@@ -64,17 +64,11 @@ public: ...@@ -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:
......
...@@ -67,32 +67,28 @@ bool CMakeProjectNode::removeSubProjects(const QStringList &proFilePaths) ...@@ -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;
......
...@@ -48,17 +48,13 @@ public: ...@@ -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);
}; };
......
...@@ -259,37 +259,28 @@ bool GenericProjectNode::removeSubProjects(const QStringList &proFilePaths) ...@@ -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);
} }
......
...@@ -62,19 +62,10 @@ public: ...@@ -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);
......
...@@ -2844,16 +2844,9 @@ void ProjectExplorerPlugin::addExistingFiles(ProjectNode *projectNode, const QSt ...@@ -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() ...@@ -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() ...@@ -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) ...@@ -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)
......
...@@ -472,8 +472,6 @@ bool ProjectFileWizardExtension::processProject( ...@@ -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( ...@@ -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;
......
...@@ -837,27 +837,3 @@ NodesWatcher::NodesWatcher(QObject *parent) ...@@ -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;
}
...@@ -214,18 +214,10 @@ public: ...@@ -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: ...@@ -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
...@@ -286,32 +286,28 @@ bool QbsBaseProjectNode::removeSubProjects(const QStringList &proFilePaths) ...@@ -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;
......
...@@ -90,17 +90,10 @@ public: ...@@ -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);
......
...@@ -198,26 +198,22 @@ bool QmlProjectNode::removeSubProjects(const QStringList &proFilePaths) ...@@ -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;
} }