forked from qt-creator/qt-creator
ProjectNodes: Add method to query FileType
Add methods to get the FileType based on filepath or mimetype. Use that method in treescanner. Change-Id: I3de50d7afd8262cc86ae722e7de4ca53921153d2 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -141,29 +141,7 @@ bool TreeScanner::isMimeBinary(const Utils::MimeType &mimeType, const Utils::Fil
|
|||||||
|
|
||||||
FileType TreeScanner::genericFileType(const Utils::MimeType &mimeType, const Utils::FileName &/*fn*/)
|
FileType TreeScanner::genericFileType(const Utils::MimeType &mimeType, const Utils::FileName &/*fn*/)
|
||||||
{
|
{
|
||||||
FileType type = FileType::Unknown;
|
return Node::fileTypeForMimeType(mimeType);
|
||||||
if (mimeType.isValid()) {
|
|
||||||
const QString mt = mimeType.name();
|
|
||||||
if (mt == CppTools::Constants::C_SOURCE_MIMETYPE
|
|
||||||
|| mt == CppTools::Constants::CPP_SOURCE_MIMETYPE
|
|
||||||
|| mt == CppTools::Constants::OBJECTIVE_C_SOURCE_MIMETYPE
|
|
||||||
|| mt == CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE
|
|
||||||
|| mt == CppTools::Constants::QDOC_MIMETYPE
|
|
||||||
|| mt == CppTools::Constants::MOC_MIMETYPE)
|
|
||||||
type = FileType::Source;
|
|
||||||
else if (mt == CppTools::Constants::C_HEADER_MIMETYPE
|
|
||||||
|| mt == CppTools::Constants::CPP_HEADER_MIMETYPE)
|
|
||||||
type = FileType::Header;
|
|
||||||
else if (mt == ProjectExplorer::Constants::FORM_MIMETYPE)
|
|
||||||
type = FileType::Form;
|
|
||||||
else if (mt == ProjectExplorer::Constants::RESOURCE_MIMETYPE)
|
|
||||||
type = FileType::Resource;
|
|
||||||
else if (mt == ProjectExplorer::Constants::SCXML_MIMETYPE)
|
|
||||||
type = FileType::StateChart;
|
|
||||||
else if (mt == ProjectExplorer::Constants::QML_MIMETYPE)
|
|
||||||
type = FileType::QML;
|
|
||||||
}
|
|
||||||
return type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TreeScanner::scanForFiles(FutureInterface *fi, const Utils::FileName& directory, const FileFilter &filter, const FileTypeFactory &factory)
|
void TreeScanner::scanForFiles(FutureInterface *fi, const Utils::FileName& directory, const FileFilter &filter, const FileTypeFactory &factory)
|
||||||
|
|||||||
@@ -36,6 +36,8 @@
|
|||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
|
#include <utils/mimetypes/mimedatabase.h>
|
||||||
|
#include <utils/mimetypes/mimetype.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
@@ -233,6 +235,33 @@ void Node::setParentFolderNode(FolderNode *parentFolder)
|
|||||||
m_parentFolderNode = parentFolder;
|
m_parentFolderNode = parentFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileType Node::fileTypeForMimeType(const Utils::MimeType &mt)
|
||||||
|
{
|
||||||
|
FileType type = FileType::Source;
|
||||||
|
if (mt.isValid()) {
|
||||||
|
const QString mtName = mt.name();
|
||||||
|
if (mtName == Constants::C_HEADER_MIMETYPE
|
||||||
|
|| mtName == Constants::CPP_HEADER_MIMETYPE)
|
||||||
|
type = FileType::Header;
|
||||||
|
else if (mtName == Constants::FORM_MIMETYPE)
|
||||||
|
type = FileType::Form;
|
||||||
|
else if (mtName == Constants::RESOURCE_MIMETYPE)
|
||||||
|
type = FileType::Resource;
|
||||||
|
else if (mtName == Constants::SCXML_MIMETYPE)
|
||||||
|
type = FileType::StateChart;
|
||||||
|
else if (mtName == Constants::QML_MIMETYPE)
|
||||||
|
type = FileType::QML;
|
||||||
|
} else {
|
||||||
|
type = FileType::Unknown;
|
||||||
|
}
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileType Node::fileTypeForFileName(const Utils::FileName &file)
|
||||||
|
{
|
||||||
|
return fileTypeForMimeType(Utils::mimeTypeForFile(file.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\class ProjectExplorer::FileNode
|
\class ProjectExplorer::FileNode
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,8 @@
|
|||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
namespace Utils { class MimeType; }
|
||||||
|
|
||||||
namespace ProjectExplorer {
|
namespace ProjectExplorer {
|
||||||
class RunConfiguration;
|
class RunConfiguration;
|
||||||
class Project;
|
class Project;
|
||||||
@@ -141,6 +143,9 @@ public:
|
|||||||
static bool sortByPath(const Node *a, const Node *b);
|
static bool sortByPath(const Node *a, const Node *b);
|
||||||
void setParentFolderNode(FolderNode *parentFolder);
|
void setParentFolderNode(FolderNode *parentFolder);
|
||||||
|
|
||||||
|
static FileType fileTypeForMimeType(const Utils::MimeType &mt);
|
||||||
|
static FileType fileTypeForFileName(const Utils::FileName &file);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Node(NodeType nodeType, const Utils::FileName &filePath, int line = -1);
|
Node(NodeType nodeType, const Utils::FileName &filePath, int line = -1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user