2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-05-04 12:19:22 +02:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2009-05-04 12:19:22 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-05-04 12:19:22 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
2014-10-01 13:21:18 +02:00
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2009-05-04 12:19:22 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-05-04 12:19:22 +02:00
|
|
|
|
|
|
|
|
#include "qmlprojectnodes.h"
|
|
|
|
|
#include "qmlproject.h"
|
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
#include <coreplugin/idocument.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>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFileInfo>
|
|
|
|
|
#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
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
QmlProjectNode::QmlProjectNode(QmlProject *project, Core::IDocument *projectFile)
|
2013-07-04 13:30:26 +02:00
|
|
|
: ProjectExplorer::ProjectNode(QFileInfo(projectFile->filePath()).absoluteFilePath()),
|
2009-05-04 12:19:22 +02:00
|
|
|
m_project(project),
|
|
|
|
|
m_projectFile(projectFile)
|
|
|
|
|
{
|
2013-07-04 13:30:26 +02:00
|
|
|
setDisplayName(QFileInfo(projectFile->filePath()).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()
|
|
|
|
|
{ }
|
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
Core::IDocument *QmlProjectNode::projectFile() const
|
2009-05-04 12:19:22 +02:00
|
|
|
{ return m_projectFile; }
|
|
|
|
|
|
|
|
|
|
QString QmlProjectNode::projectFilePath() const
|
2013-07-04 13:30:26 +02:00
|
|
|
{ return m_projectFile->filePath(); }
|
2009-05-04 12:19:22 +02:00
|
|
|
|
|
|
|
|
void QmlProjectNode::refresh()
|
|
|
|
|
{
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
|
|
|
|
// remove the existing nodes.
|
2014-02-18 19:49:55 +01:00
|
|
|
removeFileNodes(fileNodes());
|
|
|
|
|
removeFolderNodes(subFolderNodes());
|
2009-05-04 12:19:22 +02:00
|
|
|
|
|
|
|
|
//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 *>()
|
2014-02-18 19:49:55 +01:00
|
|
|
<< projectFilesNode);
|
2009-05-04 12:19:22 +02:00
|
|
|
|
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();
|
2012-11-26 21:24:16 +02:00
|
|
|
if (relativeDirectory == QLatin1String("."))
|
2010-01-18 16:32:14 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2013-03-14 14:14:48 +01:00
|
|
|
const QHash<QString, QStringList>::ConstIterator cend = filesInDirectory.constEnd();
|
|
|
|
|
for (QHash<QString, QStringList>::ConstIterator it = filesInDirectory.constBegin(); it != cend; ++it) {
|
|
|
|
|
FolderNode *folder = findOrCreateFolderByName(it.key());
|
2009-05-04 12:19:22 +02:00
|
|
|
|
|
|
|
|
QList<FileNode *> fileNodes;
|
2013-03-14 14:14:48 +01:00
|
|
|
foreach (const QString &file, it.value()) {
|
2009-05-04 12:19:22 +02:00
|
|
|
FileType fileType = SourceType; // ### FIXME
|
|
|
|
|
FileNode *fileNode = new FileNode(file, fileType, /*generated = */ false);
|
|
|
|
|
fileNodes.append(fileNode);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-18 19:49:55 +01:00
|
|
|
folder->addFileNodes(fileNodes);
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2012-11-26 21:24:16 +02:00
|
|
|
FolderNode *folder = new FolderNode(baseDir + QLatin1Char('/') + 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
|
|
|
|
2014-02-18 19:49:55 +01:00
|
|
|
parent->addFolderNodes(QList<FolderNode*>() << folder);
|
2009-05-04 12:19:22 +02:00
|
|
|
|
|
|
|
|
return folder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::FolderNode *QmlProjectNode::findOrCreateFolderByName(const QString &filePath)
|
|
|
|
|
{
|
|
|
|
|
QStringList components = filePath.split(QLatin1Char('/'));
|
|
|
|
|
return findOrCreateFolderByName(components, components.length());
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-17 11:52:45 +01:00
|
|
|
bool QmlProjectNode::showInSimpleTree() const
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-03 14:45:28 +01:00
|
|
|
QList<ProjectExplorer::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);
|
2014-02-03 14:45:28 +01:00
|
|
|
QList<ProjectExplorer::ProjectAction> actions;
|
|
|
|
|
actions.append(ProjectExplorer::AddNewFile);
|
|
|
|
|
actions.append(ProjectExplorer::EraseFile);
|
2013-12-02 15:30:17 +01:00
|
|
|
if (node->nodeType() == ProjectExplorer::FileNodeType) {
|
|
|
|
|
ProjectExplorer::FileNode *fileNode = static_cast<ProjectExplorer::FileNode *>(node);
|
|
|
|
|
if (fileNode->fileType() != ProjectExplorer::ProjectFileType)
|
2014-02-03 14:45:28 +01:00
|
|
|
actions.append(ProjectExplorer::Rename);
|
2013-12-02 15:30:17 +01:00
|
|
|
}
|
2009-05-07 15:43:59 +02:00
|
|
|
return actions;
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-26 18:33:16 +02:00
|
|
|
bool QmlProjectNode::canAddSubProject(const QString &proFilePath) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(proFilePath)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-01 16:13:48 +02:00
|
|
|
bool QmlProjectNode::addFiles(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
|
|
|
}
|
|
|
|
|
|
2013-07-01 16:13:48 +02:00
|
|
|
bool QmlProjectNode::removeFiles(const QStringList & /*filePaths*/, QStringList * /*notRemoved*/)
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-01 16:13:48 +02:00
|
|
|
bool QmlProjectNode::deleteFiles(const QStringList & /*filePaths*/)
|
2010-08-10 16:27:35 +02:00
|
|
|
{
|
2010-09-30 11:16:51 +02:00
|
|
|
return true;
|
2010-08-10 16:27:35 +02:00
|
|
|
}
|
|
|
|
|
|
2013-07-01 16:13:48 +02:00
|
|
|
bool QmlProjectNode::renameFile(const QString & /*filePath*/, const QString & /*newFilePath*/)
|
2009-05-04 12:19:22 +02:00
|
|
|
{
|
2010-09-30 11:16:51 +02:00
|
|
|
return true;
|
2009-05-04 12:19:22 +02:00
|
|
|
}
|
2010-02-16 13:39:13 +01:00
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QmlProjectManager
|