1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "genericprojectnodes.h"
35 #include "genericproject.h"
37 #include <coreplugin/ifile.h>
38 #include <projectexplorer/projectexplorer.h>
40 #include <QtCore/QFileInfo>
42 using namespace GenericProjectManager;
43 using namespace GenericProjectManager::Internal;
45 GenericProjectNode::GenericProjectNode(GenericProject *project, Core::IFile *projectFile)
46 : ProjectExplorer::ProjectNode(projectFile->fileName()),
48 m_projectFile(projectFile)
50 setDisplayName(QFileInfo(projectFile->fileName()).completeBaseName());
53 GenericProjectNode::~GenericProjectNode()
56 Core::IFile *GenericProjectNode::projectFile() const
57 { return m_projectFile; }
59 QString GenericProjectNode::projectFilePath() const
60 { return m_projectFile->fileName(); }
62 void GenericProjectNode::refresh()
64 using namespace ProjectExplorer;
66 // remove the existing nodes.
67 removeFileNodes(fileNodes(), this);
68 removeFolderNodes(subFolderNodes(), this);
70 //ProjectExplorerPlugin::instance()->setCurrentNode(0); // ### remove me
72 FileNode *projectFilesNode = new FileNode(m_project->filesFileName(),
74 /* generated = */ false);
76 FileNode *projectIncludesNode = new FileNode(m_project->includesFileName(),
78 /* generated = */ false);
80 FileNode *projectConfigNode = new FileNode(m_project->configFileName(),
82 /* generated = */ false);
84 QStringList files = m_project->files();
85 files.removeAll(m_project->filesFileName());
86 files.removeAll(m_project->includesFileName());
87 files.removeAll(m_project->configFileName());
89 addFileNodes(QList<FileNode *>()
91 << projectIncludesNode
95 QStringList filePaths;
96 QHash<QString, QStringList> filesInPath;
97 const QString base = QFileInfo(path()).absolutePath();
98 const QDir baseDir(base);
100 foreach (const QString &absoluteFileName, files) {
101 QFileInfo fileInfo(absoluteFileName);
102 const QString absoluteFilePath = fileInfo.path();
103 QString relativeFilePath;
105 if (absoluteFilePath.startsWith(base)) {
106 relativeFilePath = absoluteFilePath.mid(base.length() + 1);
108 // `file' is not part of the project.
109 relativeFilePath = baseDir.relativeFilePath(absoluteFilePath);
112 if (! filePaths.contains(relativeFilePath))
113 filePaths.append(relativeFilePath);
115 filesInPath[relativeFilePath].append(absoluteFileName);
118 foreach (const QString &filePath, filePaths) {
119 FolderNode *folder = findOrCreateFolderByName(filePath);
121 QList<FileNode *> fileNodes;
122 foreach (const QString &file, filesInPath.value(filePath)) {
123 FileType fileType = SourceType; // ### FIXME
124 FileNode *fileNode = new FileNode(file, fileType, /*generated = */ false);
125 fileNodes.append(fileNode);
128 addFileNodes(fileNodes, folder);
131 m_folderByName.clear();
134 ProjectExplorer::FolderNode *GenericProjectNode::findOrCreateFolderByName(const QStringList &components, int end)
140 for (int i = 0; i < end; ++i) {
141 folderName.append(components.at(i));
142 folderName += QLatin1Char('/'); // ### FIXME
145 const QString component = components.at(end - 1);
147 if (component.isEmpty())
150 else if (FolderNode *folder = m_folderByName.value(folderName))
153 const QString baseDir = QFileInfo(path()).path();
154 FolderNode *folder = new FolderNode(baseDir + QLatin1Char('/') + folderName);
155 folder->setDisplayName(component);
156 m_folderByName.insert(folderName, folder);
158 FolderNode *parent = findOrCreateFolderByName(components, end - 1);
161 addFolderNodes(QList<FolderNode*>() << folder, parent);
166 ProjectExplorer::FolderNode *GenericProjectNode::findOrCreateFolderByName(const QString &filePath)
168 QStringList components = filePath.split(QLatin1Char('/'));
169 return findOrCreateFolderByName(components, components.length());
172 bool GenericProjectNode::hasBuildTargets() const
177 QList<ProjectExplorer::ProjectNode::ProjectAction> GenericProjectNode::supportedActions(Node *node) const
180 return QList<ProjectAction>()
186 bool GenericProjectNode::canAddSubProject(const QString &proFilePath) const
188 Q_UNUSED(proFilePath)
192 bool GenericProjectNode::addSubProjects(const QStringList &proFilePaths)
194 Q_UNUSED(proFilePaths)
198 bool GenericProjectNode::removeSubProjects(const QStringList &proFilePaths)
200 Q_UNUSED(proFilePaths)
204 bool GenericProjectNode::addFiles(const ProjectExplorer::FileType fileType,
205 const QStringList &filePaths, QStringList *notAdded)
210 return m_project->addFiles(filePaths);
213 bool GenericProjectNode::removeFiles(const ProjectExplorer::FileType fileType,
214 const QStringList &filePaths, QStringList *notRemoved)
219 return m_project->removeFiles(filePaths);
222 bool GenericProjectNode::deleteFiles(const ProjectExplorer::FileType fileType,
223 const QStringList &filePaths)
230 bool GenericProjectNode::renameFile(const ProjectExplorer::FileType fileType,
231 const QString &filePath, const QString &newFilePath)
235 Q_UNUSED(newFilePath)
239 QList<ProjectExplorer::RunConfiguration *> GenericProjectNode::runConfigurationsFor(Node *node)
242 return QList<ProjectExplorer::RunConfiguration *>();