2009-05-04 12:19:22 +02:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2009-05-04 12:19:22 +02:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2009-05-04 12:19:22 +02:00
|
|
|
**
|
|
|
|
** Commercial Usage
|
|
|
|
**
|
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and Nokia.
|
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
**
|
|
|
|
** Alternatively, 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.
|
|
|
|
**
|
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2009-05-04 12:19:22 +02:00
|
|
|
**
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
#include "qmlprojectnodes.h"
|
2009-05-07 15:43:59 +02:00
|
|
|
#include "qmlprojectmanager.h"
|
2009-05-04 12:19:22 +02:00
|
|
|
#include "qmlproject.h"
|
|
|
|
|
|
|
|
#include <coreplugin/ifile.h>
|
2010-04-01 17:21:18 +02:00
|
|
|
#include <coreplugin/fileiconprovider.h>
|
2009-05-04 12:19:22 +02:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
|
|
|
|
|
|
|
#include <QFileInfo>
|
2009-05-08 13:00:05 +02:00
|
|
|
#include <QDir>
|
2010-02-16 13:39:13 +01:00
|
|
|
#include <QTextStream>
|
2010-04-01 17:21:18 +02:00
|
|
|
#include <QStyle>
|
2009-05-04 12:19:22 +02:00
|
|
|
|
2010-02-16 13:39:13 +01:00
|
|
|
namespace QmlProjectManager {
|
|
|
|
namespace Internal {
|
2009-05-04 12:19:22 +02:00
|
|
|
|
|
|
|
QmlProjectNode::QmlProjectNode(QmlProject *project, Core::IFile *projectFile)
|
2010-01-29 10:36:00 +01:00
|
|
|
: ProjectExplorer::ProjectNode(QFileInfo(projectFile->fileName()).absoluteFilePath()),
|
2009-05-04 12:19:22 +02:00
|
|
|
m_project(project),
|
|
|
|
m_projectFile(projectFile)
|
|
|
|
{
|
2010-02-24 15:03:54 +01:00
|
|
|
setDisplayName(QFileInfo(projectFile->fileName()).completeBaseName());
|
2010-04-01 17:21:18 +02:00
|
|
|
// make overlay
|
|
|
|
const QSize desiredSize = QSize(16, 16);
|
|
|
|
const QIcon projectBaseIcon(QLatin1String(":/qmlproject/images/qmlfolder.png"));
|
|
|
|
const QPixmap projectPixmap = Core::FileIconProvider::overlayIcon(QStyle::SP_DirIcon,
|
|
|
|
projectBaseIcon,
|
|
|
|
desiredSize);
|
|
|
|
setIcon(QIcon(projectPixmap));
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QmlProjectNode::~QmlProjectNode()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
Core::IFile *QmlProjectNode::projectFile() const
|
|
|
|
{ return m_projectFile; }
|
|
|
|
|
|
|
|
QString QmlProjectNode::projectFilePath() const
|
|
|
|
{ return m_projectFile->fileName(); }
|
|
|
|
|
|
|
|
void QmlProjectNode::refresh()
|
|
|
|
{
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
|
|
// remove the existing nodes.
|
|
|
|
removeFileNodes(fileNodes(), this);
|
|
|
|
removeFolderNodes(subFolderNodes(), this);
|
|
|
|
|
|
|
|
//ProjectExplorerPlugin::instance()->setCurrentNode(0); // ### remove me
|
|
|
|
|
|
|
|
FileNode *projectFilesNode = new FileNode(m_project->filesFileName(),
|
|
|
|
ProjectFileType,
|
|
|
|
/* generated = */ false);
|
|
|
|
|
|
|
|
QStringList files = m_project->files();
|
|
|
|
files.removeAll(m_project->filesFileName());
|
|
|
|
|
|
|
|
addFileNodes(QList<FileNode *>()
|
|
|
|
<< projectFilesNode,
|
|
|
|
this);
|
|
|
|
|
2010-01-18 16:32:14 +01:00
|
|
|
QHash<QString, QStringList> filesInDirectory;
|
|
|
|
|
|
|
|
foreach (const QString &fileName, files) {
|
|
|
|
QFileInfo fileInfo(fileName);
|
|
|
|
|
|
|
|
QString absoluteFilePath;
|
|
|
|
QString relativeDirectory;
|
|
|
|
|
|
|
|
if (fileInfo.isAbsolute()) {
|
|
|
|
// plain old file format
|
|
|
|
absoluteFilePath = fileInfo.filePath();
|
|
|
|
relativeDirectory = m_project->projectDir().relativeFilePath(fileInfo.path());
|
|
|
|
} else {
|
|
|
|
absoluteFilePath = m_project->projectDir().absoluteFilePath(fileInfo.filePath());
|
|
|
|
relativeDirectory = fileInfo.path();
|
|
|
|
if (relativeDirectory == ".")
|
|
|
|
relativeDirectory.clear();
|
|
|
|
}
|
2009-05-04 12:19:22 +02:00
|
|
|
|
2010-01-18 16:32:14 +01:00
|
|
|
filesInDirectory[relativeDirectory].append(absoluteFilePath);
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
2010-01-18 16:32:14 +01:00
|
|
|
foreach (const QString &directory, filesInDirectory.keys()) {
|
|
|
|
FolderNode *folder = findOrCreateFolderByName(directory);
|
2009-05-04 12:19:22 +02:00
|
|
|
|
|
|
|
QList<FileNode *> fileNodes;
|
2010-01-18 16:32:14 +01:00
|
|
|
foreach (const QString &file, filesInDirectory.value(directory)) {
|
2009-05-04 12:19:22 +02:00
|
|
|
FileType fileType = SourceType; // ### FIXME
|
|
|
|
FileNode *fileNode = new FileNode(file, fileType, /*generated = */ false);
|
|
|
|
fileNodes.append(fileNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
addFileNodes(fileNodes, folder);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_folderByName.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectExplorer::FolderNode *QmlProjectNode::findOrCreateFolderByName(const QStringList &components, int end)
|
|
|
|
{
|
|
|
|
if (! end)
|
|
|
|
return 0;
|
|
|
|
|
2009-12-09 14:43:13 +01:00
|
|
|
QString baseDir = QFileInfo(path()).path();
|
|
|
|
|
2009-05-04 12:19:22 +02:00
|
|
|
QString folderName;
|
|
|
|
for (int i = 0; i < end; ++i) {
|
|
|
|
folderName.append(components.at(i));
|
|
|
|
folderName += QLatin1Char('/'); // ### FIXME
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString component = components.at(end - 1);
|
|
|
|
|
|
|
|
if (component.isEmpty())
|
|
|
|
return this;
|
|
|
|
|
|
|
|
else if (FolderNode *folder = m_folderByName.value(folderName))
|
|
|
|
return folder;
|
|
|
|
|
2009-12-09 14:43:13 +01:00
|
|
|
FolderNode *folder = new FolderNode(baseDir + "/" + folderName);
|
2010-02-24 15:42:52 +01:00
|
|
|
folder->setDisplayName(component);
|
2009-12-09 14:43:13 +01:00
|
|
|
|
2009-05-04 12:19:22 +02:00
|
|
|
m_folderByName.insert(folderName, folder);
|
|
|
|
|
|
|
|
FolderNode *parent = findOrCreateFolderByName(components, end - 1);
|
|
|
|
if (! parent)
|
|
|
|
parent = this;
|
2010-01-29 10:36:00 +01:00
|
|
|
|
2009-05-04 12:19:22 +02:00
|
|
|
addFolderNodes(QList<FolderNode*>() << folder, parent);
|
|
|
|
|
|
|
|
return folder;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectExplorer::FolderNode *QmlProjectNode::findOrCreateFolderByName(const QString &filePath)
|
|
|
|
{
|
|
|
|
QStringList components = filePath.split(QLatin1Char('/'));
|
|
|
|
return findOrCreateFolderByName(components, components.length());
|
|
|
|
}
|
|
|
|
|
2010-02-02 11:59:24 +01:00
|
|
|
bool QmlProjectNode::hasBuildTargets() const
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-11 14:13:38 +02:00
|
|
|
QList<ProjectExplorer::ProjectNode::ProjectAction> QmlProjectNode::supportedActions(Node *node) const
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
2010-05-11 14:13:38 +02:00
|
|
|
Q_UNUSED(node);
|
2009-05-07 15:43:59 +02:00
|
|
|
QList<ProjectAction> actions;
|
|
|
|
actions.append(AddFile);
|
|
|
|
return actions;
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool QmlProjectNode::addSubProjects(const QStringList &proFilePaths)
|
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(proFilePaths)
|
2009-05-04 12:19:22 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QmlProjectNode::removeSubProjects(const QStringList &proFilePaths)
|
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(proFilePaths)
|
2009-05-04 12:19:22 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-02-17 10:19:17 +01:00
|
|
|
bool QmlProjectNode::addFiles(const ProjectExplorer::FileType /*fileType*/,
|
2010-02-17 11:20:35 +01:00
|
|
|
const QStringList &filePaths, QStringList * /*notAdded*/)
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
2010-02-17 11:20:35 +01:00
|
|
|
return m_project->addFiles(filePaths);
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
2010-02-17 10:19:17 +01:00
|
|
|
bool QmlProjectNode::removeFiles(const ProjectExplorer::FileType /*fileType*/,
|
|
|
|
const QStringList & /*filePaths*/, QStringList * /*notRemoved*/)
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-02-17 10:19:17 +01:00
|
|
|
bool QmlProjectNode::renameFile(const ProjectExplorer::FileType /*fileType*/,
|
|
|
|
const QString & /*filePath*/, const QString & /*newFilePath*/)
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2010-02-16 13:39:13 +01:00
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
} // namespace QmlProjectManager
|