2009-03-10 14:20:07 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2009-03-10 14:20:07 +01:00
|
|
|
**
|
2012-07-19 12:26:56 +02:00
|
|
|
** Contact: http://www.qt-project.org/
|
2009-03-10 14:20:07 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2009-03-10 14:20:07 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2009-03-10 14:20:07 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "genericprojectnodes.h"
|
2009-03-12 15:07:54 +01:00
|
|
|
#include "genericproject.h"
|
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
#include <coreplugin/idocument.h>
|
2009-03-12 16:31:40 +01:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFileInfo>
|
2009-03-10 14:20:07 +01:00
|
|
|
|
2012-08-14 15:37:38 +02:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
|
|
|
|
namespace GenericProjectManager {
|
|
|
|
|
namespace Internal {
|
2009-03-10 14:20:07 +01:00
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
GenericProjectNode::GenericProjectNode(GenericProject *project, Core::IDocument *projectFile)
|
2012-08-14 15:37:38 +02:00
|
|
|
: ProjectNode(projectFile->fileName()), m_project(project), m_projectFile(projectFile)
|
2009-03-19 16:33:44 +01:00
|
|
|
{
|
2010-02-24 15:03:54 +01:00
|
|
|
setDisplayName(QFileInfo(projectFile->fileName()).completeBaseName());
|
2009-03-19 16:33:44 +01:00
|
|
|
}
|
2009-03-10 14:20:07 +01:00
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
Core::IDocument *GenericProjectNode::projectFile() const
|
2011-04-12 08:20:54 +02:00
|
|
|
{
|
|
|
|
|
return m_projectFile;
|
|
|
|
|
}
|
2009-03-10 14:20:07 +01:00
|
|
|
|
|
|
|
|
QString GenericProjectNode::projectFilePath() const
|
2011-04-12 08:20:54 +02:00
|
|
|
{
|
|
|
|
|
return m_projectFile->fileName();
|
|
|
|
|
}
|
2009-03-10 14:20:07 +01:00
|
|
|
|
2009-03-12 11:50:32 +01:00
|
|
|
void GenericProjectNode::refresh()
|
|
|
|
|
{
|
|
|
|
|
// remove the existing nodes.
|
|
|
|
|
removeFileNodes(fileNodes(), this);
|
|
|
|
|
removeFolderNodes(subFolderNodes(), this);
|
|
|
|
|
|
2009-03-31 15:07:05 +02:00
|
|
|
//ProjectExplorerPlugin::instance()->setCurrentNode(0); // ### remove me
|
2009-03-12 16:31:40 +01:00
|
|
|
|
2009-03-18 12:18:59 +01:00
|
|
|
FileNode *projectFilesNode = new FileNode(m_project->filesFileName(),
|
2009-03-16 11:49:57 +01:00
|
|
|
ProjectFileType,
|
|
|
|
|
/* generated = */ false);
|
|
|
|
|
|
2009-03-18 12:18:59 +01:00
|
|
|
FileNode *projectIncludesNode = new FileNode(m_project->includesFileName(),
|
2009-03-16 11:49:57 +01:00
|
|
|
ProjectFileType,
|
|
|
|
|
/* generated = */ false);
|
|
|
|
|
|
2009-03-18 12:18:59 +01:00
|
|
|
FileNode *projectConfigNode = new FileNode(m_project->configFileName(),
|
2009-03-16 11:49:57 +01:00
|
|
|
ProjectFileType,
|
|
|
|
|
/* generated = */ false);
|
|
|
|
|
|
2009-03-18 12:18:59 +01:00
|
|
|
QStringList files = m_project->files();
|
|
|
|
|
files.removeAll(m_project->filesFileName());
|
|
|
|
|
files.removeAll(m_project->includesFileName());
|
|
|
|
|
files.removeAll(m_project->configFileName());
|
2009-03-16 12:11:52 +01:00
|
|
|
|
2009-03-16 11:49:57 +01:00
|
|
|
addFileNodes(QList<FileNode *>()
|
|
|
|
|
<< projectFilesNode
|
|
|
|
|
<< projectIncludesNode
|
|
|
|
|
<< projectConfigNode,
|
|
|
|
|
this);
|
2009-03-12 11:50:32 +01:00
|
|
|
|
|
|
|
|
QStringList filePaths;
|
|
|
|
|
QHash<QString, QStringList> filesInPath;
|
2010-02-19 16:47:44 +01:00
|
|
|
const QString base = QFileInfo(path()).absolutePath();
|
|
|
|
|
const QDir baseDir(base);
|
2009-03-12 11:50:32 +01:00
|
|
|
|
2009-03-16 12:11:52 +01:00
|
|
|
foreach (const QString &absoluteFileName, files) {
|
2009-03-12 11:50:32 +01:00
|
|
|
QFileInfo fileInfo(absoluteFileName);
|
|
|
|
|
const QString absoluteFilePath = fileInfo.path();
|
2010-02-19 16:47:44 +01:00
|
|
|
QString relativeFilePath;
|
2009-03-12 11:50:32 +01:00
|
|
|
|
2010-02-19 16:47:44 +01:00
|
|
|
if (absoluteFilePath.startsWith(base)) {
|
|
|
|
|
relativeFilePath = absoluteFilePath.mid(base.length() + 1);
|
|
|
|
|
} else {
|
|
|
|
|
// `file' is not part of the project.
|
|
|
|
|
relativeFilePath = baseDir.relativeFilePath(absoluteFilePath);
|
|
|
|
|
}
|
2009-03-12 11:50:32 +01:00
|
|
|
|
|
|
|
|
if (! filePaths.contains(relativeFilePath))
|
|
|
|
|
filePaths.append(relativeFilePath);
|
|
|
|
|
|
|
|
|
|
filesInPath[relativeFilePath].append(absoluteFileName);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-12 08:29:42 +02:00
|
|
|
FolderByName folderByName;
|
2009-03-12 11:50:32 +01:00
|
|
|
foreach (const QString &filePath, filePaths) {
|
2011-04-12 08:29:42 +02:00
|
|
|
QStringList components = filePath.split(QLatin1Char('/'));
|
|
|
|
|
FolderNode *folder = findOrCreateFolderByName(&folderByName, components, components.size());
|
2009-03-12 11:50:32 +01:00
|
|
|
|
|
|
|
|
QList<FileNode *> fileNodes;
|
|
|
|
|
foreach (const QString &file, filesInPath.value(filePath)) {
|
|
|
|
|
FileType fileType = SourceType; // ### FIXME
|
|
|
|
|
FileNode *fileNode = new FileNode(file, fileType, /*generated = */ false);
|
|
|
|
|
fileNodes.append(fileNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addFileNodes(fileNodes, folder);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-14 15:37:38 +02:00
|
|
|
FolderNode *GenericProjectNode::findOrCreateFolderByName
|
2011-04-12 08:29:42 +02:00
|
|
|
(FolderByName *folderByName, const QStringList &components, int end)
|
2009-03-12 11:50:32 +01:00
|
|
|
{
|
2011-04-12 08:29:42 +02:00
|
|
|
if (!end)
|
2009-03-12 11:50:32 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
QString folderName;
|
|
|
|
|
for (int i = 0; i < end; ++i) {
|
|
|
|
|
folderName.append(components.at(i));
|
|
|
|
|
folderName += QLatin1Char('/'); // ### FIXME
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-13 15:12:54 +01:00
|
|
|
const QString component = components.at(end - 1);
|
|
|
|
|
|
|
|
|
|
if (component.isEmpty())
|
|
|
|
|
return this;
|
|
|
|
|
|
2011-04-12 08:29:42 +02:00
|
|
|
else if (FolderNode *folder = folderByName->value(folderName))
|
2009-03-13 15:12:54 +01:00
|
|
|
return folder;
|
|
|
|
|
|
2010-02-19 16:47:44 +01:00
|
|
|
const QString baseDir = QFileInfo(path()).path();
|
2010-02-01 12:43:56 +01:00
|
|
|
FolderNode *folder = new FolderNode(baseDir + QLatin1Char('/') + folderName);
|
2010-02-24 15:03:54 +01:00
|
|
|
folder->setDisplayName(component);
|
2011-04-12 08:29:42 +02:00
|
|
|
folderByName->insert(folderName, folder);
|
2009-03-13 15:12:54 +01:00
|
|
|
|
2011-04-12 08:29:42 +02:00
|
|
|
FolderNode *parent = findOrCreateFolderByName(folderByName, components, end - 1);
|
|
|
|
|
if (!parent)
|
2009-03-13 15:12:54 +01:00
|
|
|
parent = this;
|
|
|
|
|
addFolderNodes(QList<FolderNode*>() << folder, parent);
|
2009-03-12 11:50:32 +01:00
|
|
|
|
|
|
|
|
return folder;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-02 11:59:24 +01:00
|
|
|
bool GenericProjectNode::hasBuildTargets() const
|
2009-03-10 14:20:07 +01:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-14 15:37:38 +02:00
|
|
|
QList<ProjectNode::ProjectAction> GenericProjectNode::supportedActions(Node *node) const
|
2009-03-10 14:20:07 +01:00
|
|
|
{
|
2010-05-11 14:13:38 +02:00
|
|
|
Q_UNUSED(node);
|
2009-06-29 18:04:29 +02:00
|
|
|
return QList<ProjectAction>()
|
2010-08-24 17:17:11 +02:00
|
|
|
<< AddNewFile
|
|
|
|
|
<< AddExistingFile
|
2011-10-24 21:42:11 +02:00
|
|
|
<< RemoveFile
|
|
|
|
|
<< Rename;
|
2009-03-10 14:20:07 +01:00
|
|
|
}
|
|
|
|
|
|
2010-08-26 18:33:16 +02:00
|
|
|
bool GenericProjectNode::canAddSubProject(const QString &proFilePath) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(proFilePath)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-10 14:20:07 +01:00
|
|
|
bool GenericProjectNode::addSubProjects(const QStringList &proFilePaths)
|
|
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(proFilePaths)
|
2009-03-10 14:20:07 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GenericProjectNode::removeSubProjects(const QStringList &proFilePaths)
|
|
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(proFilePaths)
|
2009-03-10 14:20:07 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-14 15:37:38 +02:00
|
|
|
bool GenericProjectNode::addFiles(const FileType fileType,
|
2009-03-10 14:20:07 +01:00
|
|
|
const QStringList &filePaths, QStringList *notAdded)
|
|
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(fileType)
|
|
|
|
|
Q_UNUSED(notAdded)
|
2009-06-29 18:04:29 +02:00
|
|
|
|
|
|
|
|
return m_project->addFiles(filePaths);
|
2009-03-10 14:20:07 +01:00
|
|
|
}
|
|
|
|
|
|
2012-08-14 15:37:38 +02:00
|
|
|
bool GenericProjectNode::removeFiles(const FileType fileType,
|
2009-03-10 14:20:07 +01:00
|
|
|
const QStringList &filePaths, QStringList *notRemoved)
|
|
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(fileType)
|
|
|
|
|
Q_UNUSED(notRemoved)
|
2009-06-30 14:07:07 +02:00
|
|
|
|
|
|
|
|
return m_project->removeFiles(filePaths);
|
2009-03-10 14:20:07 +01:00
|
|
|
}
|
|
|
|
|
|
2012-08-14 15:37:38 +02:00
|
|
|
bool GenericProjectNode::deleteFiles(const FileType fileType,
|
2010-08-10 16:27:35 +02:00
|
|
|
const QStringList &filePaths)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(fileType)
|
|
|
|
|
Q_UNUSED(filePaths)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-14 15:37:38 +02:00
|
|
|
bool GenericProjectNode::renameFile(const FileType fileType,
|
2009-03-10 14:20:07 +01:00
|
|
|
const QString &filePath, const QString &newFilePath)
|
|
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(fileType)
|
2011-10-24 21:42:11 +02:00
|
|
|
|
|
|
|
|
return m_project->renameFile(filePath, newFilePath);
|
2009-03-10 14:20:07 +01:00
|
|
|
}
|
2011-01-20 18:05:58 +01:00
|
|
|
|
2012-08-14 15:37:38 +02:00
|
|
|
QList<RunConfiguration *> GenericProjectNode::runConfigurationsFor(Node *node)
|
2011-01-20 18:05:58 +01:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(node)
|
2012-08-14 15:37:38 +02:00
|
|
|
return QList<RunConfiguration *>();
|
2011-01-20 18:05:58 +01:00
|
|
|
}
|
2012-08-14 15:37:38 +02:00
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace GenericProjectManager
|