forked from qt-creator/qt-creator
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:
@@ -66,7 +66,7 @@ void PxNodeUtilities::setDiagramSceneController(qmt::DiagramSceneController *dia
|
||||
QString PxNodeUtilities::calcRelativePath(const ProjectExplorer::Node *node,
|
||||
const QString &anchorFolder)
|
||||
{
|
||||
const QString nodePath = node->isFileNodeType()
|
||||
const QString nodePath = node->asFileNode()
|
||||
? node->filePath().toFileInfo().path()
|
||||
: node->filePath().toString();
|
||||
|
||||
|
@@ -39,7 +39,7 @@ NimProjectNode::NimProjectNode(NimProject &project,
|
||||
|
||||
bool NimProjectNode::supportsAction(ProjectAction action, const Node *node) const
|
||||
{
|
||||
if (node->isFileNodeType()) {
|
||||
if (node->asFileNode()) {
|
||||
return action == ProjectAction::Rename
|
||||
|| action == ProjectAction::RemoveFile;
|
||||
}
|
||||
|
@@ -201,7 +201,7 @@ static QVector<FolderNode *> renamableFolderNodes(const Utils::FileName &before,
|
||||
{
|
||||
QVector<FolderNode *> folderNodes;
|
||||
ProjectTree::forEachNode([&](Node *node) {
|
||||
if (node->isFileNodeType()
|
||||
if (node->asFileNode()
|
||||
&& node->filePath() == before
|
||||
&& node->parentFolderNode()
|
||||
&& node->parentFolderNode()->canRenameFile(before.toString(), after.toString())) {
|
||||
@@ -532,7 +532,7 @@ static QVector<FolderNode *> removableFolderNodes(const Utils::FileName &filePat
|
||||
{
|
||||
QVector<FolderNode *> folderNodes;
|
||||
ProjectTree::forEachNode([&](Node *node) {
|
||||
if (node->isFileNodeType()
|
||||
if (node->asFileNode()
|
||||
&& node->filePath() == filePath
|
||||
&& node->parentFolderNode()
|
||||
&& node->parentFolderNode()->supportsAction(RemoveFile, node)) {
|
||||
|
@@ -1460,7 +1460,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
||||
|
||||
connect(dd->m_filePropertiesAction, &QAction::triggered, this, []() {
|
||||
const Node *currentNode = ProjectTree::findCurrentNode();
|
||||
QTC_ASSERT(currentNode && currentNode->isFileNodeType(), return);
|
||||
QTC_ASSERT(currentNode && currentNode->asFileNode(), return);
|
||||
DocumentManager::showFilePropertiesDialog(currentNode->filePath());
|
||||
});
|
||||
connect(dd->m_removeFileAction, &QAction::triggered,
|
||||
@@ -3507,7 +3507,7 @@ void ProjectExplorerPluginPrivate::openTerminalHere(const EnvironmentGetter &env
|
||||
void ProjectExplorerPluginPrivate::removeFile()
|
||||
{
|
||||
const Node *currentNode = ProjectTree::findCurrentNode();
|
||||
QTC_ASSERT(currentNode && currentNode->isFileNodeType(), return);
|
||||
QTC_ASSERT(currentNode && currentNode->asFileNode(), return);
|
||||
|
||||
const Utils::FileName filePath = currentNode->filePath();
|
||||
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
|
||||
if (currentNode != ProjectTree::findCurrentNode()) {
|
||||
currentNode = ProjectTreeWidget::nodeForFile(filePath);
|
||||
QTC_ASSERT(currentNode && currentNode->isFileNodeType(), return);
|
||||
QTC_ASSERT(currentNode && currentNode->asFileNode(), return);
|
||||
}
|
||||
|
||||
// remove from project
|
||||
@@ -3542,7 +3542,7 @@ void ProjectExplorerPluginPrivate::removeFile()
|
||||
void ProjectExplorerPluginPrivate::duplicateFile()
|
||||
{
|
||||
Node *currentNode = ProjectTree::findCurrentNode();
|
||||
QTC_ASSERT(currentNode && currentNode->isFileNodeType(), return);
|
||||
QTC_ASSERT(currentNode && currentNode->asFileNode(), return);
|
||||
|
||||
FileNode *fileNode = currentNode->asFileNode();
|
||||
QString filePath = currentNode->filePath().toString();
|
||||
@@ -3573,7 +3573,7 @@ void ProjectExplorerPluginPrivate::duplicateFile()
|
||||
void ProjectExplorerPluginPrivate::deleteFile()
|
||||
{
|
||||
Node *currentNode = ProjectTree::findCurrentNode();
|
||||
QTC_ASSERT(currentNode && currentNode->isFileNodeType(), return);
|
||||
QTC_ASSERT(currentNode && currentNode->asFileNode(), return);
|
||||
|
||||
FileNode *fileNode = currentNode->asFileNode();
|
||||
|
||||
|
@@ -165,7 +165,7 @@ Node::~Node() = default;
|
||||
|
||||
NodeType Node::nodeType() const
|
||||
{
|
||||
if (isFileNodeType())
|
||||
if (asFileNode())
|
||||
return NodeType::File;
|
||||
if (isFolderNodeType())
|
||||
return NodeType::Folder;
|
||||
|
@@ -112,7 +112,6 @@ public:
|
||||
|
||||
virtual ~Node();
|
||||
|
||||
virtual bool isFileNodeType() const { return false; }
|
||||
virtual bool isFolderNodeType() const { return false; }
|
||||
virtual bool isProjectNodeType() const { return false; }
|
||||
virtual bool isVirtualFolderType() const { return false; }
|
||||
@@ -199,8 +198,6 @@ public:
|
||||
FileNode *asFileNode() final { return this; }
|
||||
const FileNode *asFileNode() const final { return this; }
|
||||
|
||||
bool isFileNodeType() const final { return true; }
|
||||
|
||||
static QList<FileNode *>
|
||||
scanForFiles(const Utils::FileName &directory,
|
||||
const std::function<FileNode *(const Utils::FileName &fileName)> factory,
|
||||
|
@@ -341,7 +341,7 @@ void ProjectTree::showContextMenu(ProjectTreeWidget *focus, const QPoint &global
|
||||
contextMenu = Core::ActionManager::actionContainer(Constants::M_SUBPROJECTCONTEXT)->menu();
|
||||
} else if (node->isVirtualFolderType() || node->isFolderNodeType()) {
|
||||
contextMenu = Core::ActionManager::actionContainer(Constants::M_FOLDERCONTEXT)->menu();
|
||||
} else if (node->isFileNodeType()) {
|
||||
} else if (node->asFileNode()) {
|
||||
contextMenu = Core::ActionManager::actionContainer(Constants::M_FILECONTEXT)->menu();
|
||||
}
|
||||
|
||||
@@ -425,7 +425,7 @@ Node *ProjectTree::nodeForFile(const FileName &fileName)
|
||||
projectNode->forEachGenericNode([&](Node *n) {
|
||||
if (n->filePath() == fileName) {
|
||||
// prefer file nodes
|
||||
if (!node || (!node->isFileNodeType() && n->isFileNodeType()))
|
||||
if (!node || (!node->asFileNode() && n->asFileNode()))
|
||||
node = n;
|
||||
}
|
||||
});
|
||||
|
@@ -524,7 +524,7 @@ void ProjectTreeWidget::showContextMenu(const QPoint &pos)
|
||||
void ProjectTreeWidget::openItem(const QModelIndex &mainIndex)
|
||||
{
|
||||
Node *node = m_model->nodeForIndex(mainIndex);
|
||||
if (!node || !node->isFileNodeType())
|
||||
if (!node || !node->asFileNode())
|
||||
return;
|
||||
IEditor *editor = EditorManager::openEditor(node->filePath().toString());
|
||||
if (editor && node->line() >= 0)
|
||||
|
@@ -618,7 +618,7 @@ bool PythonProjectNode::showInSimpleTree() const
|
||||
|
||||
bool PythonProjectNode::supportsAction(ProjectAction action, const Node *node) const
|
||||
{
|
||||
if (node->isFileNodeType()) {
|
||||
if (node->asFileNode()) {
|
||||
return action == ProjectAction::Rename
|
||||
|| action == ProjectAction::RemoveFile;
|
||||
}
|
||||
|
@@ -223,7 +223,7 @@ static bool supportsNodeAction(ProjectAction action, const Node *node)
|
||||
};
|
||||
|
||||
if (action == RemoveFile || action == Rename) {
|
||||
if (node->isFileNodeType())
|
||||
if (node->asFileNode())
|
||||
return !Utils::contains(project->qbsProject().buildSystemFiles(), equalsNodeFilePath);
|
||||
}
|
||||
|
||||
|
@@ -286,7 +286,7 @@ void QbsProjectManagerPlugin::updateContextActions()
|
||||
&& project && !project->isParsing()
|
||||
&& 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 auto subproject = dynamic_cast<const QbsProjectNode *>(node);
|
||||
bool isSubproject = project && subproject && subproject != project->rootProjectNode();
|
||||
|
@@ -171,7 +171,7 @@ bool QmakePriFileNode::addFiles(const QStringList &filePaths, QStringList *notAd
|
||||
if (!pri)
|
||||
return false;
|
||||
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) {
|
||||
for (const Node *parent = n->parentFolderNode(); parent;
|
||||
|
@@ -298,7 +298,7 @@ void QmlPreviewPlugin::setFileLoader(QmlPreviewFileLoader fileLoader)
|
||||
void QmlPreviewPlugin::previewCurrentFile()
|
||||
{
|
||||
const Node *currentNode = ProjectTree::findCurrentNode();
|
||||
if (!currentNode || !currentNode->isFileNodeType()
|
||||
if (!currentNode || !currentNode->asFileNode()
|
||||
|| currentNode->asFileNode()->fileType() != FileType::QML)
|
||||
return;
|
||||
|
||||
|
@@ -64,7 +64,7 @@ bool QmlProjectNode::supportsAction(ProjectAction action, const Node *node) cons
|
||||
return true;
|
||||
QTC_ASSERT(node, return false);
|
||||
|
||||
if (action == Rename && node->isFileNodeType()) {
|
||||
if (action == Rename && node->asFileNode()) {
|
||||
const FileNode *fileNode = node->asFileNode();
|
||||
QTC_ASSERT(fileNode, return false);
|
||||
return fileNode->fileType() != FileType::Project;
|
||||
|
Reference in New Issue
Block a user