ProjectExplorer: Merge Node::isFileNodeType and asFileNode

They were identifying the same set of nodes.

Change-Id: I3316cbc434ff740547bcf0baf9e5f1544f6e3f56
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2019-02-28 17:19:18 +01:00
parent 89c9eed127
commit 729c74379a
14 changed files with 19 additions and 22 deletions

View File

@@ -66,7 +66,7 @@ void PxNodeUtilities::setDiagramSceneController(qmt::DiagramSceneController *dia
QString PxNodeUtilities::calcRelativePath(const ProjectExplorer::Node *node, QString PxNodeUtilities::calcRelativePath(const ProjectExplorer::Node *node,
const QString &anchorFolder) const QString &anchorFolder)
{ {
const QString nodePath = node->isFileNodeType() const QString nodePath = node->asFileNode()
? node->filePath().toFileInfo().path() ? node->filePath().toFileInfo().path()
: node->filePath().toString(); : node->filePath().toString();

View File

@@ -39,7 +39,7 @@ NimProjectNode::NimProjectNode(NimProject &project,
bool NimProjectNode::supportsAction(ProjectAction action, const Node *node) const bool NimProjectNode::supportsAction(ProjectAction action, const Node *node) const
{ {
if (node->isFileNodeType()) { if (node->asFileNode()) {
return action == ProjectAction::Rename return action == ProjectAction::Rename
|| action == ProjectAction::RemoveFile; || action == ProjectAction::RemoveFile;
} }

View File

@@ -201,7 +201,7 @@ static QVector<FolderNode *> renamableFolderNodes(const Utils::FileName &before,
{ {
QVector<FolderNode *> folderNodes; QVector<FolderNode *> folderNodes;
ProjectTree::forEachNode([&](Node *node) { ProjectTree::forEachNode([&](Node *node) {
if (node->isFileNodeType() if (node->asFileNode()
&& node->filePath() == before && node->filePath() == before
&& node->parentFolderNode() && node->parentFolderNode()
&& node->parentFolderNode()->canRenameFile(before.toString(), after.toString())) { && node->parentFolderNode()->canRenameFile(before.toString(), after.toString())) {
@@ -532,7 +532,7 @@ static QVector<FolderNode *> removableFolderNodes(const Utils::FileName &filePat
{ {
QVector<FolderNode *> folderNodes; QVector<FolderNode *> folderNodes;
ProjectTree::forEachNode([&](Node *node) { ProjectTree::forEachNode([&](Node *node) {
if (node->isFileNodeType() if (node->asFileNode()
&& node->filePath() == filePath && node->filePath() == filePath
&& node->parentFolderNode() && node->parentFolderNode()
&& node->parentFolderNode()->supportsAction(RemoveFile, node)) { && node->parentFolderNode()->supportsAction(RemoveFile, node)) {

View File

@@ -1460,7 +1460,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
connect(dd->m_filePropertiesAction, &QAction::triggered, this, []() { connect(dd->m_filePropertiesAction, &QAction::triggered, this, []() {
const Node *currentNode = ProjectTree::findCurrentNode(); const Node *currentNode = ProjectTree::findCurrentNode();
QTC_ASSERT(currentNode && currentNode->isFileNodeType(), return); QTC_ASSERT(currentNode && currentNode->asFileNode(), return);
DocumentManager::showFilePropertiesDialog(currentNode->filePath()); DocumentManager::showFilePropertiesDialog(currentNode->filePath());
}); });
connect(dd->m_removeFileAction, &QAction::triggered, connect(dd->m_removeFileAction, &QAction::triggered,
@@ -3507,7 +3507,7 @@ void ProjectExplorerPluginPrivate::openTerminalHere(const EnvironmentGetter &env
void ProjectExplorerPluginPrivate::removeFile() void ProjectExplorerPluginPrivate::removeFile()
{ {
const Node *currentNode = ProjectTree::findCurrentNode(); const Node *currentNode = ProjectTree::findCurrentNode();
QTC_ASSERT(currentNode && currentNode->isFileNodeType(), return); QTC_ASSERT(currentNode && currentNode->asFileNode(), return);
const Utils::FileName filePath = currentNode->filePath(); const Utils::FileName filePath = currentNode->filePath();
Utils::RemoveFileDialog removeFileDialog(filePath.toString(), ICore::mainWindow()); Utils::RemoveFileDialog removeFileDialog(filePath.toString(), ICore::mainWindow());
@@ -3518,7 +3518,7 @@ void ProjectExplorerPluginPrivate::removeFile()
// Re-read the current node, in case the project is re-parsed while the dialog is open // Re-read the current node, in case the project is re-parsed while the dialog is open
if (currentNode != ProjectTree::findCurrentNode()) { if (currentNode != ProjectTree::findCurrentNode()) {
currentNode = ProjectTreeWidget::nodeForFile(filePath); currentNode = ProjectTreeWidget::nodeForFile(filePath);
QTC_ASSERT(currentNode && currentNode->isFileNodeType(), return); QTC_ASSERT(currentNode && currentNode->asFileNode(), return);
} }
// remove from project // remove from project
@@ -3542,7 +3542,7 @@ void ProjectExplorerPluginPrivate::removeFile()
void ProjectExplorerPluginPrivate::duplicateFile() void ProjectExplorerPluginPrivate::duplicateFile()
{ {
Node *currentNode = ProjectTree::findCurrentNode(); Node *currentNode = ProjectTree::findCurrentNode();
QTC_ASSERT(currentNode && currentNode->isFileNodeType(), return); QTC_ASSERT(currentNode && currentNode->asFileNode(), return);
FileNode *fileNode = currentNode->asFileNode(); FileNode *fileNode = currentNode->asFileNode();
QString filePath = currentNode->filePath().toString(); QString filePath = currentNode->filePath().toString();
@@ -3573,7 +3573,7 @@ void ProjectExplorerPluginPrivate::duplicateFile()
void ProjectExplorerPluginPrivate::deleteFile() void ProjectExplorerPluginPrivate::deleteFile()
{ {
Node *currentNode = ProjectTree::findCurrentNode(); Node *currentNode = ProjectTree::findCurrentNode();
QTC_ASSERT(currentNode && currentNode->isFileNodeType(), return); QTC_ASSERT(currentNode && currentNode->asFileNode(), return);
FileNode *fileNode = currentNode->asFileNode(); FileNode *fileNode = currentNode->asFileNode();

View File

@@ -165,7 +165,7 @@ Node::~Node() = default;
NodeType Node::nodeType() const NodeType Node::nodeType() const
{ {
if (isFileNodeType()) if (asFileNode())
return NodeType::File; return NodeType::File;
if (isFolderNodeType()) if (isFolderNodeType())
return NodeType::Folder; return NodeType::Folder;

View File

@@ -112,7 +112,6 @@ public:
virtual ~Node(); virtual ~Node();
virtual bool isFileNodeType() const { return false; }
virtual bool isFolderNodeType() const { return false; } virtual bool isFolderNodeType() const { return false; }
virtual bool isProjectNodeType() const { return false; } virtual bool isProjectNodeType() const { return false; }
virtual bool isVirtualFolderType() const { return false; } virtual bool isVirtualFolderType() const { return false; }
@@ -199,8 +198,6 @@ public:
FileNode *asFileNode() final { return this; } FileNode *asFileNode() final { return this; }
const FileNode *asFileNode() const final { return this; } const FileNode *asFileNode() const final { return this; }
bool isFileNodeType() const final { return true; }
static QList<FileNode *> static QList<FileNode *>
scanForFiles(const Utils::FileName &directory, scanForFiles(const Utils::FileName &directory,
const std::function<FileNode *(const Utils::FileName &fileName)> factory, const std::function<FileNode *(const Utils::FileName &fileName)> factory,

View File

@@ -341,7 +341,7 @@ void ProjectTree::showContextMenu(ProjectTreeWidget *focus, const QPoint &global
contextMenu = Core::ActionManager::actionContainer(Constants::M_SUBPROJECTCONTEXT)->menu(); contextMenu = Core::ActionManager::actionContainer(Constants::M_SUBPROJECTCONTEXT)->menu();
} else if (node->isVirtualFolderType() || node->isFolderNodeType()) { } else if (node->isVirtualFolderType() || node->isFolderNodeType()) {
contextMenu = Core::ActionManager::actionContainer(Constants::M_FOLDERCONTEXT)->menu(); contextMenu = Core::ActionManager::actionContainer(Constants::M_FOLDERCONTEXT)->menu();
} else if (node->isFileNodeType()) { } else if (node->asFileNode()) {
contextMenu = Core::ActionManager::actionContainer(Constants::M_FILECONTEXT)->menu(); contextMenu = Core::ActionManager::actionContainer(Constants::M_FILECONTEXT)->menu();
} }
@@ -425,7 +425,7 @@ Node *ProjectTree::nodeForFile(const FileName &fileName)
projectNode->forEachGenericNode([&](Node *n) { projectNode->forEachGenericNode([&](Node *n) {
if (n->filePath() == fileName) { if (n->filePath() == fileName) {
// prefer file nodes // prefer file nodes
if (!node || (!node->isFileNodeType() && n->isFileNodeType())) if (!node || (!node->asFileNode() && n->asFileNode()))
node = n; node = n;
} }
}); });

View File

@@ -524,7 +524,7 @@ void ProjectTreeWidget::showContextMenu(const QPoint &pos)
void ProjectTreeWidget::openItem(const QModelIndex &mainIndex) void ProjectTreeWidget::openItem(const QModelIndex &mainIndex)
{ {
Node *node = m_model->nodeForIndex(mainIndex); Node *node = m_model->nodeForIndex(mainIndex);
if (!node || !node->isFileNodeType()) if (!node || !node->asFileNode())
return; return;
IEditor *editor = EditorManager::openEditor(node->filePath().toString()); IEditor *editor = EditorManager::openEditor(node->filePath().toString());
if (editor && node->line() >= 0) if (editor && node->line() >= 0)

View File

@@ -618,7 +618,7 @@ bool PythonProjectNode::showInSimpleTree() const
bool PythonProjectNode::supportsAction(ProjectAction action, const Node *node) const bool PythonProjectNode::supportsAction(ProjectAction action, const Node *node) const
{ {
if (node->isFileNodeType()) { if (node->asFileNode()) {
return action == ProjectAction::Rename return action == ProjectAction::Rename
|| action == ProjectAction::RemoveFile; || action == ProjectAction::RemoveFile;
} }

View File

@@ -223,7 +223,7 @@ static bool supportsNodeAction(ProjectAction action, const Node *node)
}; };
if (action == RemoveFile || action == Rename) { if (action == RemoveFile || action == Rename) {
if (node->isFileNodeType()) if (node->asFileNode())
return !Utils::contains(project->qbsProject().buildSystemFiles(), equalsNodeFilePath); return !Utils::contains(project->qbsProject().buildSystemFiles(), equalsNodeFilePath);
} }

View File

@@ -286,7 +286,7 @@ void QbsProjectManagerPlugin::updateContextActions()
&& project && !project->isParsing() && project && !project->isParsing()
&& node && node->isEnabled(); && node && node->isEnabled();
const bool isFile = project && node && node->isFileNodeType(); const bool isFile = project && node && node->asFileNode();
const bool isProduct = project && node && dynamic_cast<const QbsProductNode *>(node); const bool isProduct = project && node && dynamic_cast<const QbsProductNode *>(node);
const auto subproject = dynamic_cast<const QbsProjectNode *>(node); const auto subproject = dynamic_cast<const QbsProjectNode *>(node);
bool isSubproject = project && subproject && subproject != project->rootProjectNode(); bool isSubproject = project && subproject && subproject != project->rootProjectNode();

View File

@@ -171,7 +171,7 @@ bool QmakePriFileNode::addFiles(const QStringList &filePaths, QStringList *notAd
if (!pri) if (!pri)
return false; return false;
QList<Node *> matchingNodes = findNodes([filePaths](const Node *n) { QList<Node *> matchingNodes = findNodes([filePaths](const Node *n) {
return n->isFileNodeType() && filePaths.contains(n->filePath().toString()); return n->asFileNode() && filePaths.contains(n->filePath().toString());
}); });
matchingNodes = filtered(matchingNodes, [](const Node *n) { matchingNodes = filtered(matchingNodes, [](const Node *n) {
for (const Node *parent = n->parentFolderNode(); parent; for (const Node *parent = n->parentFolderNode(); parent;

View File

@@ -298,7 +298,7 @@ void QmlPreviewPlugin::setFileLoader(QmlPreviewFileLoader fileLoader)
void QmlPreviewPlugin::previewCurrentFile() void QmlPreviewPlugin::previewCurrentFile()
{ {
const Node *currentNode = ProjectTree::findCurrentNode(); const Node *currentNode = ProjectTree::findCurrentNode();
if (!currentNode || !currentNode->isFileNodeType() if (!currentNode || !currentNode->asFileNode()
|| currentNode->asFileNode()->fileType() != FileType::QML) || currentNode->asFileNode()->fileType() != FileType::QML)
return; return;

View File

@@ -64,7 +64,7 @@ bool QmlProjectNode::supportsAction(ProjectAction action, const Node *node) cons
return true; return true;
QTC_ASSERT(node, return false); QTC_ASSERT(node, return false);
if (action == Rename && node->isFileNodeType()) { if (action == Rename && node->asFileNode()) {
const FileNode *fileNode = node->asFileNode(); const FileNode *fileNode = node->asFileNode();
QTC_ASSERT(fileNode, return false); QTC_ASSERT(fileNode, return false);
return fileNode->fileType() != FileType::Project; return fileNode->fileType() != FileType::Project;