2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01: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
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01: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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01: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
|
|
|
****************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "projectnodes.h"
|
2008-12-09 15:25:01 +01:00
|
|
|
|
|
|
|
|
#include "nodesvisitor.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "projectexplorerconstants.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/mimedatabase.h>
|
2010-03-10 13:56:57 +01:00
|
|
|
#include <coreplugin/fileiconprovider.h>
|
2012-11-07 21:17:11 +02:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/iversioncontrol.h>
|
|
|
|
|
#include <coreplugin/vcsmanager.h>
|
2014-06-16 18:25:52 +04:00
|
|
|
#include <utils/algorithm.h>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QIcon>
|
|
|
|
|
#include <QStyle>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
|
|
|
|
/*!
|
2011-04-14 12:58:14 +02:00
|
|
|
\class ProjectExplorer::Node
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The Node class is the base class of all nodes in the node hierarchy.
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
The nodes are arranged in a tree where leaves are FileNodes and non-leaves are FolderNodes
|
|
|
|
|
A Project is a special Folder that manages the files and normal folders underneath it.
|
|
|
|
|
|
|
|
|
|
The Watcher emits signals for structural changes in the hierarchy.
|
|
|
|
|
A Visitor can be used to traverse all Projects and other Folders.
|
|
|
|
|
|
|
|
|
|
\sa ProjectExplorer::FileNode, ProjectExplorer::FolderNode, ProjectExplorer::ProjectNode
|
|
|
|
|
\sa ProjectExplorer::NodesWatcher, ProjectExplorer::NodesVisitor
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
2011-04-14 12:58:14 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
Node::Node(NodeType nodeType,
|
2014-02-18 18:06:05 +01:00
|
|
|
const QString &filePath, int line)
|
2008-12-02 12:01:29 +01:00
|
|
|
: QObject(),
|
|
|
|
|
m_nodeType(nodeType),
|
|
|
|
|
m_projectNode(0),
|
|
|
|
|
m_folderNode(0),
|
2014-02-18 18:06:05 +01:00
|
|
|
m_path(filePath),
|
|
|
|
|
m_line(line)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-10 16:55:37 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2013-02-01 12:20:15 +01:00
|
|
|
void Node::emitNodeSortKeyAboutToChange()
|
|
|
|
|
{
|
|
|
|
|
if (ProjectNode *project = projectNode()) {
|
|
|
|
|
foreach (NodesWatcher *watcher, project->watchers())
|
|
|
|
|
emit watcher->nodeSortKeyAboutToChange(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::emitNodeSortKeyChanged()
|
|
|
|
|
{
|
|
|
|
|
if (ProjectNode *project = projectNode()) {
|
|
|
|
|
foreach (NodesWatcher *watcher, project->watchers())
|
|
|
|
|
emit watcher->nodeSortKeyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-30 18:13:46 +01:00
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
* The path of the file representing this node.
|
2013-01-30 18:13:46 +01:00
|
|
|
*
|
2013-10-07 13:34:40 +02:00
|
|
|
* This function does not emit any signals. That has to be done by the calling
|
2013-09-10 17:16:10 +02:00
|
|
|
* class.
|
2013-01-30 18:13:46 +01:00
|
|
|
*/
|
|
|
|
|
void Node::setPath(const QString &path)
|
|
|
|
|
{
|
2013-02-01 12:20:15 +01:00
|
|
|
if (m_path == path)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
emitNodeSortKeyAboutToChange();
|
2013-01-30 18:13:46 +01:00
|
|
|
m_path = path;
|
2013-02-01 12:20:15 +01:00
|
|
|
emitNodeSortKeyChanged();
|
|
|
|
|
emitNodeUpdated();
|
2013-01-30 18:13:46 +01:00
|
|
|
}
|
|
|
|
|
|
2014-02-18 18:06:05 +01:00
|
|
|
void Node::setLine(int line)
|
|
|
|
|
{
|
|
|
|
|
if (m_line == line)
|
|
|
|
|
return;
|
|
|
|
|
emitNodeSortKeyAboutToChange();
|
|
|
|
|
m_line = line;
|
|
|
|
|
emitNodeSortKeyChanged();
|
|
|
|
|
emitNodeUpdated();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::setPathAndLine(const QString &path, int line)
|
|
|
|
|
{
|
|
|
|
|
if (m_path == path
|
|
|
|
|
&& m_line == line)
|
|
|
|
|
return;
|
|
|
|
|
emitNodeSortKeyAboutToChange();
|
|
|
|
|
m_path = path;
|
|
|
|
|
m_line = line;
|
|
|
|
|
emitNodeSortKeyChanged();
|
|
|
|
|
emitNodeUpdated();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
NodeType Node::nodeType() const
|
|
|
|
|
{
|
|
|
|
|
return m_nodeType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
The project that owns and manages the node. It is the first project in the list
|
|
|
|
|
of ancestors.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
ProjectNode *Node::projectNode() const
|
|
|
|
|
{
|
|
|
|
|
return m_projectNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
The parent in the node hierarchy.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
FolderNode *Node::parentFolderNode() const
|
|
|
|
|
{
|
|
|
|
|
return m_folderNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
The path of the file or folder in the filesystem the node represents.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
QString Node::path() const
|
|
|
|
|
{
|
|
|
|
|
return m_path;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-30 18:13:46 +01:00
|
|
|
int Node::line() const
|
|
|
|
|
{
|
2014-07-22 13:15:03 +02:00
|
|
|
return m_line;
|
2013-01-30 18:13:46 +01:00
|
|
|
}
|
|
|
|
|
|
2012-05-04 11:49:37 +02:00
|
|
|
QString Node::displayName() const
|
|
|
|
|
{
|
|
|
|
|
return QFileInfo(path()).fileName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString Node::tooltip() const
|
|
|
|
|
{
|
|
|
|
|
return QDir::toNativeSeparators(path());
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-16 15:27:03 +01:00
|
|
|
bool Node::isEnabled() const
|
|
|
|
|
{
|
|
|
|
|
return parentFolderNode()->isEnabled();
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-03 14:45:28 +01:00
|
|
|
QList<ProjectAction> Node::supportedActions(Node *node) const
|
|
|
|
|
{
|
2014-02-18 16:31:36 +01:00
|
|
|
QList<ProjectAction> list = parentFolderNode()->supportedActions(node);
|
|
|
|
|
list.append(ProjectExplorer::InheritedFromParent);
|
|
|
|
|
return list;
|
2014-02-03 14:45:28 +01:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void Node::setNodeType(NodeType type)
|
|
|
|
|
{
|
|
|
|
|
m_nodeType = type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::setProjectNode(ProjectNode *project)
|
|
|
|
|
{
|
|
|
|
|
m_projectNode = project;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-16 15:27:03 +01:00
|
|
|
void Node::emitNodeUpdated()
|
|
|
|
|
{
|
2013-02-01 12:20:15 +01:00
|
|
|
if (ProjectNode *node = projectNode())
|
|
|
|
|
foreach (NodesWatcher *watcher, node->watchers())
|
|
|
|
|
emit watcher->nodeUpdated(this);
|
2013-01-16 15:27:03 +01:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void Node::setParentFolderNode(FolderNode *parentFolder)
|
|
|
|
|
{
|
|
|
|
|
m_folderNode = parentFolder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2011-04-14 12:58:14 +02:00
|
|
|
\class ProjectExplorer::FileNode
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
\brief The FileNode class is an in-memory presentation of a file.
|
|
|
|
|
|
|
|
|
|
All file nodes are leaf nodes.
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
\sa ProjectExplorer::FolderNode, ProjectExplorer::ProjectNode
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
FileNode::FileNode(const QString &filePath,
|
|
|
|
|
const FileType fileType,
|
2014-02-18 18:06:05 +01:00
|
|
|
bool generated, int line)
|
|
|
|
|
: Node(FileNodeType, filePath, line),
|
2008-12-02 12:01:29 +01:00
|
|
|
m_fileType(fileType),
|
|
|
|
|
m_generated(generated)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileType FileNode::fileType() const
|
|
|
|
|
{
|
|
|
|
|
return m_fileType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Returns \c true if the file is automatically generated by a compile step.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
bool FileNode::isGenerated() const
|
|
|
|
|
{
|
|
|
|
|
return m_generated;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2011-04-14 12:58:14 +02:00
|
|
|
\class ProjectExplorer::FolderNode
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
In-memory presentation of a folder. Note that the node itself + all children (files and folders) are "managed" by the owning project.
|
|
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
\sa ProjectExplorer::FileNode, ProjectExplorer::ProjectNode
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
2014-09-23 13:05:00 +02:00
|
|
|
FolderNode::FolderNode(const QString &folderPath, NodeType nodeType, const QString &displayName) :
|
2012-05-04 11:49:37 +02:00
|
|
|
Node(nodeType, folderPath),
|
2014-09-23 13:05:00 +02:00
|
|
|
m_displayName(displayName)
|
2010-02-12 12:54:12 +01:00
|
|
|
{
|
2014-09-23 13:05:00 +02:00
|
|
|
if (m_displayName.isEmpty())
|
|
|
|
|
m_displayName = QDir::toNativeSeparators(folderPath);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FolderNode::~FolderNode()
|
|
|
|
|
{
|
|
|
|
|
qDeleteAll(m_subFolderNodes);
|
|
|
|
|
qDeleteAll(m_fileNodes);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Contains the display name that should be used in a view.
|
2011-04-14 12:58:14 +02:00
|
|
|
\sa setFolderName()
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
2011-04-14 12:58:14 +02:00
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
QString FolderNode::displayName() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-02-24 15:03:54 +01:00
|
|
|
return m_displayName;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Contains the icon that should be used in a view. Default is the directory icon
|
|
|
|
|
(QStyle::S_PDirIcon).
|
2011-04-14 12:58:14 +02:00
|
|
|
s\a setIcon()
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
QIcon FolderNode::icon() const
|
|
|
|
|
{
|
2010-07-07 12:16:09 +02:00
|
|
|
// Instantiating the Icon provider is expensive.
|
|
|
|
|
if (m_icon.isNull())
|
2013-09-12 16:06:33 +02:00
|
|
|
m_icon = Core::FileIconProvider::icon(QFileIconProvider::Folder);
|
2008-12-02 12:01:29 +01:00
|
|
|
return m_icon;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<FileNode*> FolderNode::fileNodes() const
|
|
|
|
|
{
|
|
|
|
|
return m_fileNodes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<FolderNode*> FolderNode::subFolderNodes() const
|
|
|
|
|
{
|
|
|
|
|
return m_subFolderNodes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FolderNode::accept(NodesVisitor *visitor)
|
|
|
|
|
{
|
|
|
|
|
visitor->visitFolderNode(this);
|
|
|
|
|
foreach (FolderNode *subFolder, m_subFolderNodes)
|
|
|
|
|
subFolder->accept(visitor);
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-24 15:03:54 +01:00
|
|
|
void FolderNode::setDisplayName(const QString &name)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-02-01 12:20:15 +01:00
|
|
|
if (m_displayName == name)
|
|
|
|
|
return;
|
|
|
|
|
emitNodeSortKeyAboutToChange();
|
2010-02-24 15:03:54 +01:00
|
|
|
m_displayName = name;
|
2013-02-01 12:20:15 +01:00
|
|
|
emitNodeSortKeyChanged();
|
|
|
|
|
emitNodeUpdated();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FolderNode::setIcon(const QIcon &icon)
|
|
|
|
|
{
|
|
|
|
|
m_icon = icon;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-03 15:18:33 +01:00
|
|
|
bool FolderNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
|
|
|
|
|
{
|
|
|
|
|
if (projectNode())
|
|
|
|
|
return projectNode()->addFiles(filePaths, notAdded);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FolderNode::removeFiles(const QStringList &filePaths, QStringList *notRemoved)
|
|
|
|
|
{
|
|
|
|
|
if (projectNode())
|
|
|
|
|
return projectNode()->removeFiles(filePaths, notRemoved);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FolderNode::deleteFiles(const QStringList &filePaths)
|
|
|
|
|
{
|
|
|
|
|
if (projectNode())
|
|
|
|
|
return projectNode()->deleteFiles(filePaths);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FolderNode::renameFile(const QString &filePath, const QString &newFilePath)
|
|
|
|
|
{
|
|
|
|
|
if (projectNode())
|
|
|
|
|
return projectNode()->renameFile(filePath, newFilePath);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-07 16:23:04 +01:00
|
|
|
FolderNode::AddNewInformation FolderNode::addNewInformation(const QStringList &files, Node *context) const
|
2014-02-18 16:31:36 +01:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(files);
|
2014-03-07 16:23:04 +01:00
|
|
|
return AddNewInformation(QFileInfo(path()).fileName(), context == this ? 120 : 100);
|
2014-02-18 16:31:36 +01:00
|
|
|
}
|
|
|
|
|
|
2014-02-18 19:49:55 +01:00
|
|
|
/*!
|
|
|
|
|
Adds file nodes specified by \a files to the internal list of the folder
|
|
|
|
|
and emits the corresponding signals from the projectNode.
|
|
|
|
|
|
|
|
|
|
This function should be called within an implementation of the public function
|
|
|
|
|
addFiles.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
void FolderNode::addFileNodes(const QList<FileNode *> &files)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(projectNode());
|
|
|
|
|
ProjectNode *pn = projectNode();
|
|
|
|
|
if (files.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
foreach (NodesWatcher *watcher, pn->watchers())
|
|
|
|
|
emit watcher->filesAboutToBeAdded(this, files);
|
|
|
|
|
|
|
|
|
|
foreach (FileNode *file, files) {
|
|
|
|
|
QTC_ASSERT(!file->parentFolderNode(),
|
|
|
|
|
qDebug("File node has already a parent folder"));
|
|
|
|
|
|
|
|
|
|
file->setParentFolderNode(this);
|
|
|
|
|
file->setProjectNode(pn);
|
|
|
|
|
// Now find the correct place to insert file
|
|
|
|
|
if (m_fileNodes.count() == 0
|
|
|
|
|
|| m_fileNodes.last() < file) {
|
|
|
|
|
// empty list or greater then last node
|
|
|
|
|
m_fileNodes.append(file);
|
|
|
|
|
} else {
|
|
|
|
|
QList<FileNode *>::iterator it
|
|
|
|
|
= qLowerBound(m_fileNodes.begin(),
|
|
|
|
|
m_fileNodes.end(),
|
|
|
|
|
file);
|
|
|
|
|
m_fileNodes.insert(it, file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (NodesWatcher *watcher, pn->watchers())
|
|
|
|
|
emit watcher->filesAdded();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Removes \a files from the internal list and emits the corresponding signals.
|
|
|
|
|
|
|
|
|
|
All objects in the \a files list are deleted.
|
|
|
|
|
This function should be called within an implementation of the public function
|
|
|
|
|
removeFiles.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
void FolderNode::removeFileNodes(const QList<FileNode *> &files)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(projectNode());
|
|
|
|
|
ProjectNode *pn = projectNode();
|
|
|
|
|
|
|
|
|
|
if (files.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QList<FileNode*> toRemove = files;
|
2014-06-16 18:25:52 +04:00
|
|
|
Utils::sort(toRemove);
|
2014-02-18 19:49:55 +01:00
|
|
|
|
|
|
|
|
foreach (NodesWatcher *watcher, pn->watchers())
|
|
|
|
|
emit watcher->filesAboutToBeRemoved(this, toRemove);
|
|
|
|
|
|
|
|
|
|
QList<FileNode*>::const_iterator toRemoveIter = toRemove.constBegin();
|
|
|
|
|
QList<FileNode*>::iterator filesIter = m_fileNodes.begin();
|
|
|
|
|
for (; toRemoveIter != toRemove.constEnd(); ++toRemoveIter) {
|
|
|
|
|
while (*filesIter != *toRemoveIter) {
|
|
|
|
|
++filesIter;
|
|
|
|
|
QTC_ASSERT(filesIter != m_fileNodes.end(),
|
|
|
|
|
qDebug("File to remove is not part of specified folder!"));
|
|
|
|
|
}
|
|
|
|
|
delete *filesIter;
|
|
|
|
|
filesIter = m_fileNodes.erase(filesIter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (NodesWatcher *watcher, pn->watchers())
|
|
|
|
|
emit watcher->filesRemoved();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Adds folder nodes specified by \a subFolders to the node hierarchy below
|
|
|
|
|
\a parentFolder and emits the corresponding signals.
|
|
|
|
|
*/
|
|
|
|
|
void FolderNode::addFolderNodes(const QList<FolderNode*> &subFolders)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(projectNode());
|
|
|
|
|
ProjectNode *pn = projectNode();
|
|
|
|
|
|
|
|
|
|
if (subFolders.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
foreach (NodesWatcher *watcher, pn->watchers())
|
|
|
|
|
watcher->foldersAboutToBeAdded(this, subFolders);
|
|
|
|
|
|
|
|
|
|
foreach (FolderNode *folder, subFolders) {
|
|
|
|
|
QTC_ASSERT(!folder->parentFolderNode(),
|
|
|
|
|
qDebug("Project node has already a parent folder"));
|
|
|
|
|
folder->setParentFolderNode(this);
|
|
|
|
|
folder->setProjectNode(pn);
|
|
|
|
|
|
|
|
|
|
// Find the correct place to insert
|
|
|
|
|
if (m_subFolderNodes.count() == 0
|
|
|
|
|
|| m_subFolderNodes.last() < folder) {
|
|
|
|
|
// empty list or greater then last node
|
|
|
|
|
m_subFolderNodes.append(folder);
|
|
|
|
|
} else {
|
|
|
|
|
// Binary Search for insertion point
|
|
|
|
|
QList<FolderNode*>::iterator it
|
|
|
|
|
= qLowerBound(m_subFolderNodes.begin(),
|
|
|
|
|
m_subFolderNodes.end(),
|
|
|
|
|
folder);
|
|
|
|
|
m_subFolderNodes.insert(it, folder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// project nodes have to be added via addProjectNodes
|
|
|
|
|
QTC_ASSERT(folder->nodeType() != ProjectNodeType,
|
|
|
|
|
qDebug("project nodes have to be added via addProjectNodes"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (NodesWatcher *watcher, pn->watchers())
|
|
|
|
|
emit watcher->foldersAdded();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Removes file nodes specified by \a subFolders from the node hierarchy and emits
|
|
|
|
|
the corresponding signals.
|
|
|
|
|
|
|
|
|
|
All objects in the \a subFolders list are deleted.
|
|
|
|
|
*/
|
|
|
|
|
void FolderNode::removeFolderNodes(const QList<FolderNode*> &subFolders)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(projectNode());
|
|
|
|
|
ProjectNode *pn = projectNode();
|
|
|
|
|
|
|
|
|
|
if (subFolders.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QList<FolderNode*> toRemove = subFolders;
|
2014-06-16 18:25:52 +04:00
|
|
|
Utils::sort(toRemove);
|
2014-02-18 19:49:55 +01:00
|
|
|
|
|
|
|
|
foreach (NodesWatcher *watcher, pn->watchers())
|
|
|
|
|
emit watcher->foldersAboutToBeRemoved(this, toRemove);
|
|
|
|
|
|
|
|
|
|
QList<FolderNode*>::const_iterator toRemoveIter = toRemove.constBegin();
|
|
|
|
|
QList<FolderNode*>::iterator folderIter = m_subFolderNodes.begin();
|
|
|
|
|
for (; toRemoveIter != toRemove.constEnd(); ++toRemoveIter) {
|
|
|
|
|
QTC_ASSERT((*toRemoveIter)->nodeType() != ProjectNodeType,
|
|
|
|
|
qDebug("project nodes have to be removed via removeProjectNodes"));
|
|
|
|
|
while (*folderIter != *toRemoveIter) {
|
|
|
|
|
++folderIter;
|
|
|
|
|
QTC_ASSERT(folderIter != m_subFolderNodes.end(),
|
|
|
|
|
qDebug("Folder to remove is not part of specified folder!"));
|
|
|
|
|
}
|
|
|
|
|
delete *folderIter;
|
|
|
|
|
folderIter = m_subFolderNodes.erase(folderIter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (NodesWatcher *watcher, pn->watchers())
|
|
|
|
|
emit watcher->foldersRemoved();
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-17 11:52:45 +01:00
|
|
|
void FolderNode::aboutToChangeShowInSimpleTree()
|
|
|
|
|
{
|
|
|
|
|
foreach (NodesWatcher *watcher, projectNode()->watchers())
|
|
|
|
|
emit watcher->aboutToChangeShowInSimpleTree(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FolderNode::showInSimpleTreeChanged()
|
|
|
|
|
{
|
|
|
|
|
foreach (NodesWatcher *watcher, projectNode()->watchers())
|
|
|
|
|
emit watcher->showInSimpleTreeChanged(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FolderNode::showInSimpleTree() const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-04 11:49:37 +02:00
|
|
|
/*!
|
|
|
|
|
\class ProjectExplorer::VirtualFolderNode
|
|
|
|
|
|
|
|
|
|
In-memory presentation of a virtual folder.
|
|
|
|
|
Note that the node itself + all children (files and folders) are "managed" by the owning project.
|
|
|
|
|
A virtual folder does not correspond to a actual folder on the file system. See for example the
|
2013-10-29 17:37:39 +01:00
|
|
|
sources, headers and forms folder the QmakeProjectManager creates
|
2012-05-04 11:49:37 +02:00
|
|
|
VirtualFolderNodes are always sorted before FolderNodes and are sorted according to their priority.
|
|
|
|
|
|
|
|
|
|
\sa ProjectExplorer::FileNode, ProjectExplorer::ProjectNode
|
|
|
|
|
*/
|
|
|
|
|
VirtualFolderNode::VirtualFolderNode(const QString &folderPath, int priority)
|
|
|
|
|
: FolderNode(folderPath, VirtualFolderNodeType), m_priority(priority)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VirtualFolderNode::~VirtualFolderNode()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int VirtualFolderNode::priority() const
|
|
|
|
|
{
|
|
|
|
|
return m_priority;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
/*!
|
2011-04-14 12:58:14 +02:00
|
|
|
\class ProjectExplorer::ProjectNode
|
|
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
\brief The ProjectNode class is an in-memory presentation of a Project.
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
A concrete subclass must implement the persistent data.
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
\sa ProjectExplorer::FileNode, ProjectExplorer::FolderNode
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Creates an uninitialized project node object.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
ProjectNode::ProjectNode(const QString &projectFilePath)
|
|
|
|
|
: FolderNode(projectFilePath)
|
|
|
|
|
{
|
|
|
|
|
setNodeType(ProjectNodeType);
|
|
|
|
|
// project node "manages" itself
|
|
|
|
|
setProjectNode(this);
|
2010-02-24 15:03:54 +01:00
|
|
|
setDisplayName(QFileInfo(projectFilePath).fileName());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-30 17:13:29 +02:00
|
|
|
QString ProjectNode::vcsTopic() const
|
|
|
|
|
{
|
2012-11-07 21:17:11 +02:00
|
|
|
const QString dir = QFileInfo(path()).absolutePath();
|
|
|
|
|
|
|
|
|
|
if (Core::IVersionControl *const vc =
|
2013-08-30 17:13:29 +02:00
|
|
|
Core::VcsManager::findVersionControlForDirectory(dir))
|
2012-11-07 21:17:11 +02:00
|
|
|
return vc->vcsTopic(dir);
|
|
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QList<ProjectNode*> ProjectNode::subProjectNodes() const
|
|
|
|
|
{
|
|
|
|
|
return m_subProjectNodes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\function bool ProjectNode::addSubProjects(const QStringList &)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\function bool ProjectNode::removeSubProjects(const QStringList &)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\function bool ProjectNode::addFiles(const FileType, const QStringList &, QStringList *)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\function bool ProjectNode::removeFiles(const FileType, const QStringList &, QStringList *)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\function bool ProjectNode::renameFile(const FileType, const QString &, const QString &)
|
|
|
|
|
*/
|
|
|
|
|
|
2010-08-24 17:17:11 +02:00
|
|
|
bool ProjectNode::deploysFolder(const QString &folder) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(folder);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-29 08:35:00 +02:00
|
|
|
/*!
|
|
|
|
|
\function bool ProjectNode::runConfigurations() const
|
|
|
|
|
|
|
|
|
|
Returns a list of \c RunConfiguration suitable for this node.
|
|
|
|
|
*/
|
|
|
|
|
QList<RunConfiguration *> ProjectNode::runConfigurations() const
|
|
|
|
|
{
|
|
|
|
|
return QList<RunConfiguration *>();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QList<NodesWatcher*> ProjectNode::watchers() const
|
|
|
|
|
{
|
|
|
|
|
return m_watchers;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Registers \a watcher for the current project and all subprojects.
|
2011-04-14 12:58:14 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
It does not take ownership of the watcher.
|
2011-04-14 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void ProjectNode::registerWatcher(NodesWatcher *watcher)
|
|
|
|
|
{
|
|
|
|
|
if (!watcher)
|
|
|
|
|
return;
|
2012-03-05 22:30:59 +01:00
|
|
|
connect(watcher, SIGNAL(destroyed(QObject*)),
|
|
|
|
|
this, SLOT(watcherDestroyed(QObject*)));
|
2008-12-02 12:01:29 +01:00
|
|
|
m_watchers.append(watcher);
|
|
|
|
|
foreach (ProjectNode *subProject, m_subProjectNodes)
|
|
|
|
|
subProject->registerWatcher(watcher);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Removes \a watcher from the current project and all subprojects.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
void ProjectNode::unregisterWatcher(NodesWatcher *watcher)
|
|
|
|
|
{
|
|
|
|
|
if (!watcher)
|
|
|
|
|
return;
|
|
|
|
|
m_watchers.removeOne(watcher);
|
|
|
|
|
foreach (ProjectNode *subProject, m_subProjectNodes)
|
|
|
|
|
subProject->unregisterWatcher(watcher);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectNode::accept(NodesVisitor *visitor)
|
|
|
|
|
{
|
|
|
|
|
visitor->visitProjectNode(this);
|
|
|
|
|
|
|
|
|
|
foreach (FolderNode *folder, m_subFolderNodes)
|
|
|
|
|
folder->accept(visitor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Adds project nodes specified by \a subProjects to the node hierarchy and
|
|
|
|
|
emits the corresponding signals.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
void ProjectNode::addProjectNodes(const QList<ProjectNode*> &subProjects)
|
|
|
|
|
{
|
|
|
|
|
if (!subProjects.isEmpty()) {
|
|
|
|
|
QList<FolderNode*> folderNodes;
|
|
|
|
|
foreach (ProjectNode *projectNode, subProjects)
|
|
|
|
|
folderNodes << projectNode;
|
|
|
|
|
|
|
|
|
|
foreach (NodesWatcher *watcher, m_watchers)
|
|
|
|
|
emit watcher->foldersAboutToBeAdded(this, folderNodes);
|
|
|
|
|
|
|
|
|
|
foreach (ProjectNode *project, subProjects) {
|
2010-05-20 16:02:24 +02:00
|
|
|
QTC_ASSERT(!project->parentFolderNode() || project->parentFolderNode() == this,
|
|
|
|
|
qDebug("Project node has already a parent"));
|
2008-12-02 12:01:29 +01:00
|
|
|
project->setParentFolderNode(this);
|
|
|
|
|
foreach (NodesWatcher *watcher, m_watchers)
|
|
|
|
|
project->registerWatcher(watcher);
|
|
|
|
|
m_subFolderNodes.append(project);
|
|
|
|
|
m_subProjectNodes.append(project);
|
|
|
|
|
}
|
2014-06-16 18:25:52 +04:00
|
|
|
Utils::sort(m_subFolderNodes);
|
|
|
|
|
Utils::sort(m_subProjectNodes);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
foreach (NodesWatcher *watcher, m_watchers)
|
|
|
|
|
emit watcher->foldersAdded();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Removes project nodes specified by \a subProjects from the node hierarchy
|
|
|
|
|
and emits the corresponding signals.
|
2011-04-14 12:58:14 +02:00
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
All objects in the \a subProjects list are deleted.
|
2011-04-14 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void ProjectNode::removeProjectNodes(const QList<ProjectNode*> &subProjects)
|
|
|
|
|
{
|
|
|
|
|
if (!subProjects.isEmpty()) {
|
|
|
|
|
QList<FolderNode*> toRemove;
|
|
|
|
|
foreach (ProjectNode *projectNode, subProjects)
|
|
|
|
|
toRemove << projectNode;
|
2014-06-16 18:25:52 +04:00
|
|
|
Utils::sort(toRemove);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
foreach (NodesWatcher *watcher, m_watchers)
|
|
|
|
|
emit watcher->foldersAboutToBeRemoved(this, toRemove);
|
|
|
|
|
|
|
|
|
|
QList<FolderNode*>::const_iterator toRemoveIter = toRemove.constBegin();
|
|
|
|
|
QList<FolderNode*>::iterator folderIter = m_subFolderNodes.begin();
|
|
|
|
|
QList<ProjectNode*>::iterator projectIter = m_subProjectNodes.begin();
|
|
|
|
|
for (; toRemoveIter != toRemove.constEnd(); ++toRemoveIter) {
|
2012-05-04 11:49:37 +02:00
|
|
|
while (*projectIter != *toRemoveIter) {
|
2008-12-02 12:01:29 +01:00
|
|
|
++projectIter;
|
2008-12-09 16:18:28 +01:00
|
|
|
QTC_ASSERT(projectIter != m_subProjectNodes.end(),
|
|
|
|
|
qDebug("Project to remove is not part of specified folder!"));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2012-05-04 11:49:37 +02:00
|
|
|
while (*folderIter != *toRemoveIter) {
|
2008-12-02 12:01:29 +01:00
|
|
|
++folderIter;
|
2008-12-09 16:18:28 +01:00
|
|
|
QTC_ASSERT(folderIter != m_subFolderNodes.end(),
|
|
|
|
|
qDebug("Project to remove is not part of specified folder!"));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
delete *projectIter;
|
|
|
|
|
projectIter = m_subProjectNodes.erase(projectIter);
|
|
|
|
|
folderIter = m_subFolderNodes.erase(folderIter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (NodesWatcher *watcher, m_watchers)
|
|
|
|
|
emit watcher->foldersRemoved();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectNode::watcherDestroyed(QObject *watcher)
|
|
|
|
|
{
|
|
|
|
|
// cannot use qobject_cast here
|
|
|
|
|
unregisterWatcher(static_cast<NodesWatcher*>(watcher));
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-17 17:59:57 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
/*!
|
2011-04-14 12:58:14 +02:00
|
|
|
\class ProjectExplorer::SessionNode
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
2012-01-31 13:40:59 +01:00
|
|
|
SessionNode::SessionNode(QObject *parentObject)
|
|
|
|
|
: FolderNode(QLatin1String("session"))
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
setParent(parentObject);
|
|
|
|
|
setNodeType(SessionNodeType);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-03 14:45:28 +01:00
|
|
|
QList<ProjectAction> SessionNode::supportedActions(Node *node) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(node)
|
|
|
|
|
return QList<ProjectAction>();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QList<NodesWatcher*> SessionNode::watchers() const
|
|
|
|
|
{
|
|
|
|
|
return m_watchers;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Registers \a watcher for the complete session tree.
|
2008-12-02 12:01:29 +01:00
|
|
|
It does not take ownership of the watcher.
|
|
|
|
|
*/
|
2011-04-14 12:58:14 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void SessionNode::registerWatcher(NodesWatcher *watcher)
|
|
|
|
|
{
|
|
|
|
|
if (!watcher)
|
|
|
|
|
return;
|
|
|
|
|
connect(watcher, SIGNAL(destroyed(QObject*)),
|
|
|
|
|
this, SLOT(watcherDestroyed(QObject*)));
|
|
|
|
|
m_watchers.append(watcher);
|
|
|
|
|
foreach (ProjectNode *project, m_projectNodes)
|
|
|
|
|
project->registerWatcher(watcher);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Removes \a watcher from the complete session tree.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
2011-04-14 12:58:14 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void SessionNode::unregisterWatcher(NodesWatcher *watcher)
|
|
|
|
|
{
|
|
|
|
|
if (!watcher)
|
|
|
|
|
return;
|
|
|
|
|
m_watchers.removeOne(watcher);
|
|
|
|
|
foreach (ProjectNode *project, m_projectNodes)
|
|
|
|
|
project->unregisterWatcher(watcher);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionNode::accept(NodesVisitor *visitor)
|
|
|
|
|
{
|
|
|
|
|
visitor->visitSessionNode(this);
|
|
|
|
|
foreach (ProjectNode *project, m_projectNodes)
|
|
|
|
|
project->accept(visitor);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-17 11:52:45 +01:00
|
|
|
bool SessionNode::showInSimpleTree() const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-14 17:39:46 +02:00
|
|
|
void SessionNode::projectDisplayNameChanged(Node *node)
|
|
|
|
|
{
|
|
|
|
|
foreach (NodesWatcher *watcher, m_watchers)
|
|
|
|
|
emit watcher->nodeSortKeyAboutToChange(node);
|
|
|
|
|
foreach (NodesWatcher *watcher, m_watchers)
|
|
|
|
|
emit watcher->nodeSortKeyChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QList<ProjectNode*> SessionNode::projectNodes() const
|
|
|
|
|
{
|
|
|
|
|
return m_projectNodes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionNode::addProjectNodes(const QList<ProjectNode*> &projectNodes)
|
|
|
|
|
{
|
|
|
|
|
if (!projectNodes.isEmpty()) {
|
|
|
|
|
QList<FolderNode*> folderNodes;
|
|
|
|
|
foreach (ProjectNode *projectNode, projectNodes)
|
|
|
|
|
folderNodes << projectNode;
|
|
|
|
|
|
|
|
|
|
foreach (NodesWatcher *watcher, m_watchers)
|
|
|
|
|
emit watcher->foldersAboutToBeAdded(this, folderNodes);
|
|
|
|
|
|
|
|
|
|
foreach (ProjectNode *project, projectNodes) {
|
2008-12-09 16:18:28 +01:00
|
|
|
QTC_ASSERT(!project->parentFolderNode(),
|
|
|
|
|
qDebug("Project node has already a parent folder"));
|
2008-12-02 12:01:29 +01:00
|
|
|
project->setParentFolderNode(this);
|
|
|
|
|
foreach (NodesWatcher *watcher, m_watchers)
|
|
|
|
|
project->registerWatcher(watcher);
|
|
|
|
|
m_subFolderNodes.append(project);
|
|
|
|
|
m_projectNodes.append(project);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-16 18:25:52 +04:00
|
|
|
Utils::sort(m_subFolderNodes);
|
|
|
|
|
Utils::sort(m_projectNodes);
|
2012-05-04 11:49:37 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
foreach (NodesWatcher *watcher, m_watchers)
|
|
|
|
|
emit watcher->foldersAdded();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionNode::removeProjectNodes(const QList<ProjectNode*> &projectNodes)
|
|
|
|
|
{
|
|
|
|
|
if (!projectNodes.isEmpty()) {
|
|
|
|
|
QList<FolderNode*> toRemove;
|
|
|
|
|
foreach (ProjectNode *projectNode, projectNodes)
|
|
|
|
|
toRemove << projectNode;
|
|
|
|
|
|
2014-06-16 18:25:52 +04:00
|
|
|
Utils::sort(toRemove);
|
2012-05-04 11:49:37 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
foreach (NodesWatcher *watcher, m_watchers)
|
|
|
|
|
emit watcher->foldersAboutToBeRemoved(this, toRemove);
|
|
|
|
|
|
|
|
|
|
QList<FolderNode*>::const_iterator toRemoveIter = toRemove.constBegin();
|
|
|
|
|
QList<FolderNode*>::iterator folderIter = m_subFolderNodes.begin();
|
|
|
|
|
QList<ProjectNode*>::iterator projectIter = m_projectNodes.begin();
|
|
|
|
|
for (; toRemoveIter != toRemove.constEnd(); ++toRemoveIter) {
|
2012-05-04 11:49:37 +02:00
|
|
|
while (*projectIter != *toRemoveIter) {
|
2008-12-02 12:01:29 +01:00
|
|
|
++projectIter;
|
2008-12-09 16:18:28 +01:00
|
|
|
QTC_ASSERT(projectIter != m_projectNodes.end(),
|
|
|
|
|
qDebug("Project to remove is not part of specified folder!"));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2012-05-04 11:49:37 +02:00
|
|
|
while (*folderIter != *toRemoveIter) {
|
2008-12-02 12:01:29 +01:00
|
|
|
++folderIter;
|
2008-12-09 16:18:28 +01:00
|
|
|
QTC_ASSERT(folderIter != m_subFolderNodes.end(),
|
|
|
|
|
qDebug("Project to remove is not part of specified folder!"));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
projectIter = m_projectNodes.erase(projectIter);
|
|
|
|
|
folderIter = m_subFolderNodes.erase(folderIter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (NodesWatcher *watcher, m_watchers)
|
|
|
|
|
emit watcher->foldersRemoved();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionNode::watcherDestroyed(QObject *watcher)
|
|
|
|
|
{
|
|
|
|
|
// cannot use qobject_cast here
|
|
|
|
|
unregisterWatcher(static_cast<NodesWatcher*>(watcher));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2011-04-14 12:58:14 +02:00
|
|
|
\class ProjectExplorer::NodesWatcher
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
\brief The NodesWatcher class enables you to keep track of changes in the
|
|
|
|
|
tree.
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
Add a watcher by calling ProjectNode::registerWatcher() or
|
|
|
|
|
SessionNode::registerWatcher(). Whenever the tree underneath the
|
2013-09-10 17:16:10 +02:00
|
|
|
project node or session node changes (for example, nodes are added or removed),
|
|
|
|
|
the corresponding signals of the watcher are emitted.
|
2008-12-02 12:01:29 +01:00
|
|
|
Watchers can be removed from the complete tree or a subtree
|
|
|
|
|
by calling ProjectNode::unregisterWatcher and
|
|
|
|
|
SessionNode::unregisterWatcher().
|
|
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
The NodesWatcher class is similar to the Observer class in the
|
2008-12-02 12:01:29 +01:00
|
|
|
well-known Observer pattern (Booch et al).
|
2011-04-14 12:58:14 +02:00
|
|
|
|
|
|
|
|
\sa ProjectExplorer::Node
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
NodesWatcher::NodesWatcher(QObject *parent)
|
|
|
|
|
: QObject(parent)
|
|
|
|
|
{
|
|
|
|
|
}
|