forked from qt-creator/qt-creator
ProjectNodes: add listInProject() to Node
Add a setter/getter for listInProject to Node and make the project list all nodes with this property set in Project::files. Task-number: QTCREATORBUG-18132 Change-Id: I334e627856d1bc0d033e13c5d629f6657d8d7fee Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -531,8 +531,8 @@ void CMakeProject::createGeneratedCodeModelSupport()
|
|||||||
= Utils::transform<QSet>(factories, [](const ExtraCompilerFactory *f) { return f->sourceTag(); });
|
= Utils::transform<QSet>(factories, [](const ExtraCompilerFactory *f) { return f->sourceTag(); });
|
||||||
|
|
||||||
// Find all files generated by any of the extra compilers, in a rather crude way.
|
// Find all files generated by any of the extra compilers, in a rather crude way.
|
||||||
const QStringList fileList = files(SourceFiles, [&fileExtensions](const FileNode *fn) {
|
const QStringList fileList = files(SourceFiles, [&fileExtensions](const Node *n) {
|
||||||
const QString fp = fn->filePath().toString();
|
const QString fp = n->filePath().toString();
|
||||||
const int pos = fp.lastIndexOf('.');
|
const int pos = fp.lastIndexOf('.');
|
||||||
return pos >= 0 && fileExtensions.contains(fp.mid(pos + 1));
|
return pos >= 0 && fileExtensions.contains(fp.mid(pos + 1));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -168,8 +168,8 @@ bool NimProject::supportsKit(Kit *k, QString *errorMessage) const
|
|||||||
|
|
||||||
FileNameList NimProject::nimFiles() const
|
FileNameList NimProject::nimFiles() const
|
||||||
{
|
{
|
||||||
const QStringList nim = files(AllFiles, [](const ProjectExplorer::FileNode *fn) {
|
const QStringList nim = files(AllFiles, [](const ProjectExplorer::Node *n) {
|
||||||
return fn->filePath().endsWith(".nim");
|
return n->filePath().endsWith(".nim");
|
||||||
});
|
});
|
||||||
return Utils::transform(nim, [](const QString &fp) { return Utils::FileName::fromString(fp); });
|
return Utils::transform(nim, [](const QString &fp) { return Utils::FileName::fromString(fp); });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -548,7 +548,7 @@ Project::RestoreResult Project::restoreSettings(QString *errorMessage)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QStringList Project::files(Project::FilesMode fileMode,
|
QStringList Project::files(Project::FilesMode fileMode,
|
||||||
const std::function<bool (const FileNode *)> &filter) const
|
const std::function<bool(const Node *)> &filter) const
|
||||||
{
|
{
|
||||||
QStringList result;
|
QStringList result;
|
||||||
|
|
||||||
@@ -556,17 +556,19 @@ QStringList Project::files(Project::FilesMode fileMode,
|
|||||||
return result;
|
return result;
|
||||||
|
|
||||||
QSet<QString> alreadySeen;
|
QSet<QString> alreadySeen;
|
||||||
rootProjectNode()->forEachNode([&](const FileNode *fn) {
|
rootProjectNode()->forEachGenericNode([&](const Node *n) {
|
||||||
const QString path = fn->filePath().toString();
|
const QString path = n->filePath().toString();
|
||||||
const int count = alreadySeen.count();
|
const int count = alreadySeen.count();
|
||||||
alreadySeen.insert(path);
|
alreadySeen.insert(path);
|
||||||
if (count == alreadySeen.count())
|
if (count == alreadySeen.count())
|
||||||
return; // skip duplicates
|
return; // skip duplicates
|
||||||
if (filter && !filter(fn))
|
if (!n->listInProject())
|
||||||
|
return;
|
||||||
|
if (filter && !filter(n))
|
||||||
return;
|
return;
|
||||||
if ((fileMode == AllFiles)
|
if ((fileMode == AllFiles)
|
||||||
|| (fileMode == SourceFiles && !fn->isGenerated())
|
|| (fileMode == SourceFiles && !n->isGenerated())
|
||||||
|| (fileMode == GeneratedFiles && fn->isGenerated()))
|
|| (fileMode == GeneratedFiles && n->isGenerated()))
|
||||||
result.append(path);
|
result.append(path);
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ namespace ProjectExplorer {
|
|||||||
class BuildInfo;
|
class BuildInfo;
|
||||||
class ContainerNode;
|
class ContainerNode;
|
||||||
class EditorConfiguration;
|
class EditorConfiguration;
|
||||||
class FileNode;
|
|
||||||
class NamedWidget;
|
class NamedWidget;
|
||||||
|
class Node;
|
||||||
class ProjectImporter;
|
class ProjectImporter;
|
||||||
class ProjectNode;
|
class ProjectNode;
|
||||||
class ProjectPrivate;
|
class ProjectPrivate;
|
||||||
@@ -133,7 +133,7 @@ public:
|
|||||||
AllFiles = SourceFiles | GeneratedFiles
|
AllFiles = SourceFiles | GeneratedFiles
|
||||||
};
|
};
|
||||||
QStringList files(FilesMode fileMode,
|
QStringList files(FilesMode fileMode,
|
||||||
const std::function<bool(const FileNode *)> &filter = {}) const;
|
const std::function<bool(const Node *)> &filter = {}) const;
|
||||||
virtual QStringList filesGeneratedFrom(const QString &sourceFile) const;
|
virtual QStringList filesGeneratedFrom(const QString &sourceFile) const;
|
||||||
|
|
||||||
static QString makeUnique(const QString &preferredName, const QStringList &usedNames);
|
static QString makeUnique(const QString &preferredName, const QStringList &usedNames);
|
||||||
|
|||||||
@@ -127,6 +127,11 @@ void Node::setPriority(int p)
|
|||||||
m_priority = p;
|
m_priority = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Node::setListInProject(bool l)
|
||||||
|
{
|
||||||
|
m_flags.setFlag(FlagListInProject, l);
|
||||||
|
}
|
||||||
|
|
||||||
void Node::setIsGenerated(bool g)
|
void Node::setIsGenerated(bool g)
|
||||||
{
|
{
|
||||||
m_flags.setFlag(FlagIsGenerated, g);
|
m_flags.setFlag(FlagIsGenerated, g);
|
||||||
@@ -153,6 +158,14 @@ int Node::priority() const
|
|||||||
return m_priority;
|
return m_priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns \c true if the Node should be listed as part of the projects file list.
|
||||||
|
*/
|
||||||
|
bool Node::listInProject() const
|
||||||
|
{
|
||||||
|
return m_flags.testFlag(FlagListInProject);
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
The project that owns and manages the node. It is the first project in the list
|
The project that owns and manages the node. It is the first project in the list
|
||||||
of ancestors.
|
of ancestors.
|
||||||
@@ -291,6 +304,7 @@ FileNode::FileNode(const Utils::FileName &filePath,
|
|||||||
bool generated, int line) : Node(NodeType::File, filePath, line),
|
bool generated, int line) : Node(NodeType::File, filePath, line),
|
||||||
m_fileType(fileType)
|
m_fileType(fileType)
|
||||||
{
|
{
|
||||||
|
setListInProject(true);
|
||||||
setIsGenerated(generated);
|
setIsGenerated(generated);
|
||||||
if (fileType == FileType::Project)
|
if (fileType == FileType::Project)
|
||||||
setPriority(DefaultProjectFilePriority);
|
setPriority(DefaultProjectFilePriority);
|
||||||
@@ -303,6 +317,7 @@ FileNode *FileNode::clone() const
|
|||||||
auto fn = new FileNode(filePath(), fileType(), isGenerated(), line());
|
auto fn = new FileNode(filePath(), fileType(), isGenerated(), line());
|
||||||
fn->setEnabled(isEnabled());
|
fn->setEnabled(isEnabled());
|
||||||
fn->setPriority(priority());
|
fn->setPriority(priority());
|
||||||
|
fn->setListInProject(listInProject());
|
||||||
return fn;
|
return fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -390,6 +405,7 @@ FolderNode::FolderNode(const Utils::FileName &folderPath, NodeType nodeType, con
|
|||||||
m_displayName(displayName)
|
m_displayName(displayName)
|
||||||
{
|
{
|
||||||
setPriority(DefaultFolderPriority);
|
setPriority(DefaultFolderPriority);
|
||||||
|
setListInProject(false);
|
||||||
setIsGenerated(false);
|
setIsGenerated(false);
|
||||||
if (m_displayName.isEmpty())
|
if (m_displayName.isEmpty())
|
||||||
m_displayName = folderPath.toUserOutput();
|
m_displayName = folderPath.toUserOutput();
|
||||||
|
|||||||
@@ -129,6 +129,7 @@ public:
|
|||||||
virtual QString displayName() const;
|
virtual QString displayName() const;
|
||||||
virtual QString tooltip() const;
|
virtual QString tooltip() const;
|
||||||
bool isEnabled() const;
|
bool isEnabled() const;
|
||||||
|
bool listInProject() const;
|
||||||
bool isGenerated() const;
|
bool isGenerated() const;
|
||||||
|
|
||||||
virtual bool supportsAction(ProjectAction action, Node *node) const;
|
virtual bool supportsAction(ProjectAction action, Node *node) const;
|
||||||
@@ -155,6 +156,7 @@ protected:
|
|||||||
Node(NodeType nodeType, const Utils::FileName &filePath, int line = -1);
|
Node(NodeType nodeType, const Utils::FileName &filePath, int line = -1);
|
||||||
|
|
||||||
void setPriority(int priority);
|
void setPriority(int priority);
|
||||||
|
void setListInProject(bool l);
|
||||||
void setIsGenerated(bool g);
|
void setIsGenerated(bool g);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -167,6 +169,7 @@ private:
|
|||||||
FlagNone = 0,
|
FlagNone = 0,
|
||||||
FlagIsEnabled = 1 << 0,
|
FlagIsEnabled = 1 << 0,
|
||||||
FlagIsGenerated = 1 << 1,
|
FlagIsGenerated = 1 << 1,
|
||||||
|
FlagListInProject = 1 << 2,
|
||||||
};
|
};
|
||||||
using NodeFlags = QFlags<NodeFlag>;
|
using NodeFlags = QFlags<NodeFlag>;
|
||||||
NodeFlags m_flags = FlagIsEnabled;
|
NodeFlags m_flags = FlagIsEnabled;
|
||||||
|
|||||||
@@ -84,10 +84,13 @@ ModelManagerInterface::ProjectInfo ModelManager::defaultProjectInfoForProject(
|
|||||||
Constants::QMLTYPES_MIMETYPE,
|
Constants::QMLTYPES_MIMETYPE,
|
||||||
Constants::QMLUI_MIMETYPE };
|
Constants::QMLUI_MIMETYPE };
|
||||||
projectInfo.sourceFiles = project->files(Project::SourceFiles,
|
projectInfo.sourceFiles = project->files(Project::SourceFiles,
|
||||||
[&qmlTypeNames](const FileNode *fn) {
|
[&qmlTypeNames](const Node *n) {
|
||||||
|
if (const FileNode *fn = n->asFileNode()) {
|
||||||
return fn->fileType() == FileType::QML
|
return fn->fileType() == FileType::QML
|
||||||
&& qmlTypeNames.contains(Utils::mimeTypeForFile(fn->filePath().toString(),
|
&& qmlTypeNames.contains(Utils::mimeTypeForFile(fn->filePath().toString(),
|
||||||
MimeMatchMode::MatchExtension).name());
|
MimeMatchMode::MatchExtension).name());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
activeTarget = project->activeTarget();
|
activeTarget = project->activeTarget();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user