ProjectExplorer: Move ProjectExplorerPlugin::directoryFor etc

... to Node::

It's completely self-contained, and uses less indirections this way.

Change-Id: I2f9274ee46b53b6443f52bc45f620b43d43f529c
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2019-08-02 12:38:45 +02:00
parent aad1df06f0
commit 86d0c7ef66
5 changed files with 56 additions and 68 deletions

View File

@@ -41,6 +41,7 @@
#include <utils/mimetypes/mimetype.h>
#include <utils/pointeralgorithm.h>
#include <utils/qtcassert.h>
#include <utils/stringutils.h>
#include <QFileInfo>
#include <QDir>
@@ -312,6 +313,43 @@ FileType Node::fileTypeForFileName(const Utils::FilePath &file)
Utils::MimeMatchMode::MatchExtension));
}
QString Node::pathOrDirectory(bool dir) const
{
QString location;
const FolderNode *folder = asFolderNode();
if (isVirtualFolderType() && folder) {
// Virtual Folder case
// If there are files directly below or no subfolders, take the folder path
if (!folder->fileNodes().isEmpty() || folder->folderNodes().isEmpty()) {
location = m_filePath.toString();
} else {
// Otherwise we figure out a commonPath from the subfolders
QStringList list;
foreach (FolderNode *f, folder->folderNodes())
list << f->filePath().toString() + QLatin1Char('/');
location = Utils::commonPath(list);
}
QFileInfo fi(location);
while ((!fi.exists() || !fi.isDir()) && !fi.isRoot())
fi.setFile(fi.absolutePath());
location = fi.absoluteFilePath();
} else if (!m_filePath.isEmpty()) {
QFileInfo fi = m_filePath.toFileInfo();
// remove any /suffixes, which e.g. ResourceNode uses
// Note this could be removed again by making path() a true path again
// That requires changes in both the VirtualFolderNode and ResourceNode
while (!fi.exists() && !fi.isRoot())
fi.setFile(fi.absolutePath());
if (dir)
location = fi.isDir() ? fi.absoluteFilePath() : fi.absolutePath();
else
location = fi.absoluteFilePath();
}
return location;
}
/*!
\class ProjectExplorer::FileNode