Commit 7c35a381 authored by Tobias Hunger's avatar Tobias Hunger

Session: Move all functionality related to Nodes into ProjectTree

Do no longer expose Nodes from the SessionManager's API. These are now
exclusively handled by the ProjectTree.

Change-Id: I585c2ac919462073870363436e767640775d9045
Reviewed-by: Eike Ziller's avatarEike Ziller <eike.ziller@qt.io>
parent 34b8ed14
......@@ -31,13 +31,12 @@
#include "cmakekitinformation.h"
#include <texteditor/codeassist/assistinterface.h>
#include <projectexplorer/projecttree.h>
#include <projectexplorer/project.h>
#include <projectexplorer/kit.h>
#include <projectexplorer/project.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
#include <coreplugin/editormanager/editormanager.h>
#include <projectexplorer/session.h>
using namespace CMakeProjectManager::Internal;
using namespace TextEditor;
......
......@@ -36,7 +36,7 @@
#include <coreplugin/progressmanager/progressmanager.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectnodes.h>
#include <projectexplorer/session.h>
#include <projectexplorer/projecttree.h>
#include <texteditor/basefilefind.h>
#include <utils/algorithm.h>
......@@ -560,7 +560,7 @@ static void displayResults(SearchResult *search, QFutureWatcher<CPlusPlus::Usage
if (Utils::contains(parameters.filesToRename, Utils::equal(&Node::filePath, result.path)))
continue;
Node *node = SessionManager::nodeForFile(result.path);
Node *node = ProjectTree::nodeForFile(result.path);
if (!node) // Not part of any project
continue;
......
......@@ -27,8 +27,8 @@
#include <cpptools/cppmodelmanager.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
#include <QCoreApplication>
......
......@@ -42,6 +42,7 @@
#include <texteditor/texteditor.h>
#include <texteditor/textdocument.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projecttree.h>
#include <projectexplorer/session.h>
#include <utils/asconst.h>
#include <utils/mimetypes/mimedatabase.h>
......
......@@ -24,9 +24,9 @@
****************************************************************************/
#include "editorconfiguration.h"
#include "session.h"
#include "projectexplorer.h"
#include "project.h"
#include "projectexplorer.h"
#include "session.h"
#include <utils/algorithm.h>
......
......@@ -29,6 +29,7 @@
#include "../project.h"
#include "../projectexplorerconstants.h"
#include "../projectnodes.h"
#include "../projecttree.h"
#include "../session.h"
#include "../projecttree.h"
......@@ -245,7 +246,7 @@ void JsonSummaryPage::updateFileList()
void JsonSummaryPage::updateProjectData(FolderNode *node)
{
Project *project = SessionManager::projectForNode(node);
Project *project = ProjectTree::projectForNode(node);
m_wizard->setValue(QLatin1String(KEY_SELECTED_PROJECT), QVariant::fromValue(project));
m_wizard->setValue(QLatin1String(KEY_SELECTED_NODE), QVariant::fromValue(node));
......
......@@ -27,6 +27,7 @@
#include "projectexplorer.h"
#include "session.h"
#include "projectnodes.h"
#include "projecttree.h"
#include "projectwizardpage.h"
#include <utils/algorithm.h>
......@@ -247,7 +248,7 @@ void ProjectFileWizardExtension::applyCodeStyle(GeneratedFile *file) const
return; // don't modify files like *.ui *.pro
FolderNode *folder = m_context->page->currentNode();
Project *baseProject = SessionManager::projectForNode(folder);
Project *baseProject = ProjectTree::projectForNode(folder);
ICodeStylePreferencesFactory *factory = TextEditorSettings::codeStyleFactory(languageId);
......
......@@ -156,7 +156,7 @@ void ProjectTree::update()
void ProjectTree::updateFromProjectTreeWidget(ProjectTreeWidget *widget)
{
Node *currentNode = widget->currentNode();
Project *project = SessionManager::projectForNode(currentNode);
Project *project = projectForNode(currentNode);
setCurrent(currentNode, project);
}
......@@ -175,7 +175,7 @@ void ProjectTree::updateFromNode(Node *node)
{
Project *project;
if (node)
project = SessionManager::projectForNode(node);
project = projectForNode(node);
else
project = SessionManager::startupProject();
......@@ -321,7 +321,7 @@ bool ProjectTree::hasFocus(ProjectTreeWidget *widget)
void ProjectTree::showContextMenu(ProjectTreeWidget *focus, const QPoint &globalPos, Node *node)
{
QMenu *contextMenu = nullptr;
Project *project = SessionManager::projectForNode(node);
Project *project = projectForNode(node);
emit s_instance->aboutToShowContextMenu(project, node);
if (!node) {
......@@ -403,6 +403,40 @@ void ProjectTree::forEachNode(const std::function<void(Node *)> &task)
}
}
Project *ProjectTree::projectForNode(Node *node)
{
if (!node)
return nullptr;
FolderNode *folder = node->asFolderNode();
if (!folder)
folder = node->parentFolderNode();
while (folder && folder->parentFolderNode())
folder = folder->parentFolderNode();
return Utils::findOrDefault(SessionManager::projects(), [folder](const Project *pro) {
return pro->containerNode() == folder;
});
}
Node *ProjectTree::nodeForFile(const FileName &fileName)
{
Node *node = nullptr;
for (const Project *project : SessionManager::projects()) {
if (ProjectNode *projectNode = project->rootProjectNode()) {
projectNode->forEachGenericNode([&](Node *n) {
if (n->filePath() == fileName) {
// prefer file nodes
if (!node || (node->nodeType() != NodeType::File && n->nodeType() == NodeType::File))
node = n;
}
});
}
}
return node;
}
void ProjectTree::hideContextMenu()
{
m_focusForContextMenu = nullptr;
......
......@@ -71,10 +71,13 @@ public:
static void registerTreeManager(const TreeManagerFunction &treeChange);
static void applyTreeManager(FolderNode *folder);
// Nodes:
static bool hasNode(const Node *node);
static void forEachNode(const std::function<void(Node *)> &task);
static Project *projectForNode(Node *node);
static Node *nodeForFile(const Utils::FileName &fileName);
void collapseAll();
// for nodes to emit signals, do not call unless you are a node
......
......@@ -203,7 +203,9 @@ QList<Project *> SessionManager::dependencies(const Project *project)
QList<Project *> projects;
foreach (const QString &dep, proDeps) {
if (Project *pro = projectForFile(Utils::FileName::fromString(dep)))
const Utils::FileName fn = Utils::FileName::fromString(dep);
Project *pro = Utils::findOrDefault(d->m_projects, [&fn](Project *p) { return p->projectFilePath() == fn; });
if (pro)
projects += pro;
}
......@@ -624,53 +626,10 @@ QList<Project *> SessionManager::projectOrder(const Project *project)
return result;
}
// node for file returns a randomly selected node if there are multiple
// prefer to use nodesForFile and figure out which node you want
Node *SessionManager::nodeForFile(const Utils::FileName &fileName)
{
Node *node = nullptr;
for (Project *project : d->m_projects) {
if (ProjectNode *projectNode = project->rootProjectNode()) {
projectNode->forEachGenericNode([&](Node *n) {
if (n->filePath() == fileName) {
// prefer file nodes
if (!node || (node->nodeType() != NodeType::File && n->nodeType() == NodeType::File))
node = n;
}
});
}
}
return node;
}
Project *SessionManager::projectForNode(Node *node)
{
if (!node)
return nullptr;
FolderNode *folder = node->asFolderNode();
if (!folder)
folder = node->parentFolderNode();
while (folder && folder->parentFolderNode())
folder = folder->parentFolderNode();
for (Project *pro : d->m_projects) {
if (pro->containerNode() == folder)
return pro;
}
return nullptr;
}
Project *SessionManager::projectForFile(const Utils::FileName &fileName)
{
const QList<Project *> &projectList = projects();
foreach (Project *p, projectList) {
if (p->isKnownFile(fileName))
return p;
}
return nullptr;
return Utils::findOrDefault(SessionManager::projects(),
[&fileName](const Project *p) { return p->isKnownFile(fileName); });
}
void SessionManager::configureEditor(IEditor *editor, const QString &fileName)
......
......@@ -31,9 +31,9 @@
#include <utils/persistentsettings.h>
#include <QDateTime>
#include <QString>
#include <QStringList>
#include <QDateTime>
namespace Core { class IEditor; }
......@@ -43,8 +43,6 @@ class Project;
class Target;
class BuildConfiguration;
class DeployConfiguration;
class Node;
enum class SetActive { Cascade, NoCascade };
class PROJECTEXPLORER_EXPORT SessionManager : public QObject
......@@ -110,10 +108,8 @@ public:
static QVariant value(const QString &name);
// NBS rewrite projectOrder (dependency management)
static QList<Project *> projectOrder(const Project *project = 0);
static QList<Project *> projectOrder(const Project *project = nullptr);
static Project *projectForNode(Node *node);
static Node *nodeForFile(const Utils::FileName &fileName);
static Project *projectForFile(const Utils::FileName &fileName);
static QStringList projectsForSessionName(const QString &session);
......
......@@ -75,13 +75,13 @@ namespace Internal {
static Node *currentEditorNode()
{
Core::IDocument *doc = Core::EditorManager::currentDocument();
return doc ? SessionManager::nodeForFile(doc->filePath()) : 0;
return doc ? ProjectTree::nodeForFile(doc->filePath()) : nullptr;
}
static QbsProject *currentEditorProject()
{
Core::IDocument *doc = Core::EditorManager::currentDocument();
return doc ? qobject_cast<QbsProject *>(SessionManager::projectForFile(doc->filePath())) : 0;
return doc ? qobject_cast<QbsProject *>(SessionManager::projectForFile(doc->filePath())) : nullptr;
}
bool QbsProjectManagerPlugin::initialize(const QStringList &arguments, QString *errorMessage)
......
......@@ -194,8 +194,8 @@ void QmakeManager::buildFile()
{
if (Core::IDocument *currentDocument= Core::EditorManager::currentDocument()) {
const Utils::FileName file = currentDocument->filePath();
Node *n = SessionManager::nodeForFile(file);
FileNode *node = n ? n->asFileNode() : 0;
Node *n = ProjectTree::nodeForFile(file);
FileNode *node = n ? n->asFileNode() : nullptr;
Project *project = SessionManager::projectForFile(file);
if (project && node)
......
......@@ -53,9 +53,9 @@
#include <coreplugin/editormanager/ieditor.h>
#include <projectexplorer/buildmanager.h>
#include <projectexplorer/session.h>
#include <projectexplorer/projectmanager.h>
#include <projectexplorer/projecttree.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
#include <texteditor/texteditoractionhandler.h>
......@@ -414,7 +414,7 @@ void QmakeProjectManagerPlugin::enableBuildFileMenus(const Utils::FileName &file
bool visible = false;
bool enabled = false;
if (Node *node = SessionManager::nodeForFile(file)) {
if (Node *node = ProjectTree::nodeForFile(file)) {
if (Project *project = SessionManager::projectForFile(file)) {
if (const FileNode *fileNode = node->asFileNode()) {
const FileType type = fileNode->fileType();
......
......@@ -40,9 +40,10 @@
#include <coreplugin/vcsmanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/messagebox.h>
#include <projectexplorer/session.h>
#include <projectexplorer/projectnodes.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projecttree.h>
#include <projectexplorer/session.h>
#include <qmakeprojectmanager/qmakenodes.h>
#include <qmakeprojectmanager/qmakeproject.h>
......@@ -327,7 +328,7 @@ Utils::FileName DocumentManager::currentFilePath()
QStringList DocumentManager::isoIconsQmakeVariableValue(const QString &proPath)
{
ProjectExplorer::Node *node = ProjectExplorer::SessionManager::nodeForFile(Utils::FileName::fromString(proPath));
ProjectExplorer::Node *node = ProjectExplorer::ProjectTree::nodeForFile(Utils::FileName::fromString(proPath));
if (!node) {
qCWarning(documentManagerLog) << "No node for .pro:" << proPath;
return QStringList();
......@@ -350,7 +351,7 @@ QStringList DocumentManager::isoIconsQmakeVariableValue(const QString &proPath)
bool DocumentManager::setIsoIconsQmakeVariableValue(const QString &proPath, const QStringList &value)
{
ProjectExplorer::Node *node = ProjectExplorer::SessionManager::nodeForFile(Utils::FileName::fromString(proPath));
ProjectExplorer::Node *node = ProjectExplorer::ProjectTree::nodeForFile(Utils::FileName::fromString(proPath));
if (!node) {
qCWarning(documentManagerLog) << "No node for .pro:" << proPath;
return false;
......@@ -380,7 +381,7 @@ void DocumentManager::findPathToIsoProFile(bool *iconResourceFileAlreadyExists,
{
Utils::FileName qmlFileName = QmlDesignerPlugin::instance()->currentDesignDocument()->fileName();
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::projectForFile(qmlFileName);
ProjectExplorer::Node *node = ProjectExplorer::SessionManager::nodeForFile(qmlFileName)->parentFolderNode();
ProjectExplorer::Node *node = ProjectExplorer::ProjectTree::nodeForFile(qmlFileName)->parentFolderNode();
ProjectExplorer::Node *iconQrcFileNode = nullptr;
while (node && !iconQrcFileNode) {
......@@ -419,11 +420,11 @@ void DocumentManager::findPathToIsoProFile(bool *iconResourceFileAlreadyExists,
*resourceFilePath = project->projectDirectory().toString() + "/" + isoIconsQrcFile;
// We assume that the .pro containing the QML file is an acceptable place to add the .qrc file.
ProjectExplorer::ProjectNode *projectNode = ProjectExplorer::SessionManager::nodeForFile(qmlFileName)->parentProjectNode();
ProjectExplorer::ProjectNode *projectNode = ProjectExplorer::ProjectTree::nodeForFile(qmlFileName)->parentProjectNode();
*resourceFileProPath = projectNode->filePath().toString();
} else {
// We found the QRC file that we want.
QString projectDirectory = ProjectExplorer::SessionManager::projectForNode(iconQrcFileNode)->projectDirectory().toString();
QString projectDirectory = ProjectExplorer::ProjectTree::projectForNode(iconQrcFileNode)->projectDirectory().toString();
*resourceFilePath = projectDirectory + "/" + isoIconsQrcFile;
}
......@@ -432,7 +433,7 @@ void DocumentManager::findPathToIsoProFile(bool *iconResourceFileAlreadyExists,
bool DocumentManager::isoProFileSupportsAddingExistingFiles(const QString &resourceFileProPath)
{
ProjectExplorer::Node *node = ProjectExplorer::SessionManager::nodeForFile(Utils::FileName::fromString(resourceFileProPath));
ProjectExplorer::Node *node = ProjectExplorer::ProjectTree::nodeForFile(Utils::FileName::fromString(resourceFileProPath));
if (!node || !node->parentFolderNode())
return false;
ProjectExplorer::ProjectNode *projectNode = node->parentFolderNode()->asProjectNode();
......@@ -448,7 +449,7 @@ bool DocumentManager::isoProFileSupportsAddingExistingFiles(const QString &resou
bool DocumentManager::addResourceFileToIsoProject(const QString &resourceFileProPath, const QString &resourceFilePath)
{
ProjectExplorer::Node *node = ProjectExplorer::SessionManager::nodeForFile(Utils::FileName::fromString(resourceFileProPath));
ProjectExplorer::Node *node = ProjectExplorer::ProjectTree::nodeForFile(Utils::FileName::fromString(resourceFileProPath));
if (!node || !node->parentFolderNode())
return false;
ProjectExplorer::ProjectNode *projectNode = node->parentFolderNode()->asProjectNode();
......
......@@ -39,9 +39,9 @@
#include <qmljs/qmljspropertyreader.h>
#include <qmljs/qmljsrewriter.h>
#include <qmljstools/qmljsrefactoringchanges.h>
#include <projectexplorer/session.h>
#include <projectexplorer/projectnodes.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectnodes.h>
#include <projectexplorer/projecttree.h>
#include <utils/fileutils.h>
......@@ -192,7 +192,7 @@ public:
if (path == QFileInfo(currentFileName).path()) {
// hack for the common case, next version should use the wizard
ProjectExplorer::Node * oldFileNode =
ProjectExplorer::SessionManager::nodeForFile(Utils::FileName::fromString(currentFileName));
ProjectExplorer::ProjectTree::nodeForFile(Utils::FileName::fromString(currentFileName));
if (oldFileNode) {
ProjectExplorer::FolderNode *containingFolder = oldFileNode->parentFolderNode();
if (containingFolder)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment