forked from qt-creator/qt-creator
ProjectExplorer: Replace Node::setNodeType by virtual functions
Not the usual direction of change, but currently there are several systems to identify or invoke node functionality. Virtual functions are likely to stay in this context, so this here attempts to help consolidation by reducing the influence of the node type flags, hopefully leading to full removal by making remaining functionality available through the other mechanisms (virtual functions, asFooNode() 'casts', less so the FileType flag). Change-Id: I12a17ce30b3c8883995b29b4720408020ee0fa3e Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -66,21 +66,9 @@ 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)
|
||||||
{
|
{
|
||||||
QString nodePath;
|
const QString nodePath = node->isFileNodeType()
|
||||||
|
? node->filePath().toFileInfo().path()
|
||||||
switch (node->nodeType()) {
|
: node->filePath().toString();
|
||||||
case ProjectExplorer::NodeType::File:
|
|
||||||
{
|
|
||||||
QFileInfo fileInfo = node->filePath().toFileInfo();
|
|
||||||
nodePath = fileInfo.path();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ProjectExplorer::NodeType::Folder:
|
|
||||||
case ProjectExplorer::NodeType::VirtualFolder:
|
|
||||||
case ProjectExplorer::NodeType::Project:
|
|
||||||
nodePath = node->filePath().toString();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return qmt::NameController::calcRelativePath(nodePath, anchorFolder);
|
return qmt::NameController::calcRelativePath(nodePath, anchorFolder);
|
||||||
}
|
}
|
||||||
|
@@ -39,18 +39,16 @@ NimProjectNode::NimProjectNode(NimProject &project,
|
|||||||
|
|
||||||
bool NimProjectNode::supportsAction(ProjectAction action, const Node *node) const
|
bool NimProjectNode::supportsAction(ProjectAction action, const Node *node) const
|
||||||
{
|
{
|
||||||
switch (node->nodeType()) {
|
if (node->isFileNodeType()) {
|
||||||
case NodeType::File:
|
|
||||||
return action == ProjectAction::Rename
|
return action == ProjectAction::Rename
|
||||||
|| action == ProjectAction::RemoveFile;
|
|| action == ProjectAction::RemoveFile;
|
||||||
case NodeType::Folder:
|
}
|
||||||
case NodeType::Project:
|
if (node->isFolderNodeType() || node->isProjectNodeType()) {
|
||||||
return action == ProjectAction::AddNewFile
|
return action == ProjectAction::AddNewFile
|
||||||
|| action == ProjectAction::RemoveFile
|
|| action == ProjectAction::RemoveFile
|
||||||
|| action == ProjectAction::AddExistingFile;
|
|| action == ProjectAction::AddExistingFile;
|
||||||
default:
|
|
||||||
return ProjectNode::supportsAction(action, node);
|
|
||||||
}
|
}
|
||||||
|
return ProjectNode::supportsAction(action, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NimProjectNode::addFiles(const QStringList &filePaths, QStringList *)
|
bool NimProjectNode::addFiles(const QStringList &filePaths, QStringList *)
|
||||||
|
@@ -201,7 +201,8 @@ static QVector<FolderNode *> renamableFolderNodes(const Utils::FileName &before,
|
|||||||
{
|
{
|
||||||
QVector<FolderNode *> folderNodes;
|
QVector<FolderNode *> folderNodes;
|
||||||
ProjectTree::forEachNode([&](Node *node) {
|
ProjectTree::forEachNode([&](Node *node) {
|
||||||
if (node->nodeType() == NodeType::File && node->filePath() == before
|
if (node->isFileNodeType()
|
||||||
|
&& node->filePath() == before
|
||||||
&& node->parentFolderNode()
|
&& node->parentFolderNode()
|
||||||
&& node->parentFolderNode()->canRenameFile(before.toString(), after.toString())) {
|
&& node->parentFolderNode()->canRenameFile(before.toString(), after.toString())) {
|
||||||
folderNodes.append(node->parentFolderNode());
|
folderNodes.append(node->parentFolderNode());
|
||||||
@@ -531,7 +532,8 @@ static QVector<FolderNode *> removableFolderNodes(const Utils::FileName &filePat
|
|||||||
{
|
{
|
||||||
QVector<FolderNode *> folderNodes;
|
QVector<FolderNode *> folderNodes;
|
||||||
ProjectTree::forEachNode([&](Node *node) {
|
ProjectTree::forEachNode([&](Node *node) {
|
||||||
if (node->nodeType() == NodeType::File && node->filePath() == filePath
|
if (node->isFileNodeType()
|
||||||
|
&& node->filePath() == filePath
|
||||||
&& node->parentFolderNode()
|
&& node->parentFolderNode()
|
||||||
&& node->parentFolderNode()->supportsAction(RemoveFile, node)) {
|
&& node->parentFolderNode()->supportsAction(RemoveFile, node)) {
|
||||||
folderNodes.append(node->parentFolderNode());
|
folderNodes.append(node->parentFolderNode());
|
||||||
|
@@ -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->nodeType() == NodeType::File, return);
|
QTC_ASSERT(currentNode && currentNode->isFileNodeType(), return);
|
||||||
DocumentManager::showFilePropertiesDialog(currentNode->filePath());
|
DocumentManager::showFilePropertiesDialog(currentNode->filePath());
|
||||||
});
|
});
|
||||||
connect(dd->m_removeFileAction, &QAction::triggered,
|
connect(dd->m_removeFileAction, &QAction::triggered,
|
||||||
@@ -2324,7 +2324,7 @@ static QString pathOrDirectoryFor(const Node *node, bool dir)
|
|||||||
Utils::FileName path = node->filePath();
|
Utils::FileName path = node->filePath();
|
||||||
QString location;
|
QString location;
|
||||||
const FolderNode *folder = node->asFolderNode();
|
const FolderNode *folder = node->asFolderNode();
|
||||||
if (node->nodeType() == NodeType::VirtualFolder && folder) {
|
if (node->isVirtualFolderType() && folder) {
|
||||||
// Virtual Folder case
|
// Virtual Folder case
|
||||||
// If there are files directly below or no subfolders, take the folder path
|
// If there are files directly below or no subfolders, take the folder path
|
||||||
if (!folder->fileNodes().isEmpty() || folder->folderNodes().isEmpty()) {
|
if (!folder->fileNodes().isEmpty() || folder->folderNodes().isEmpty()) {
|
||||||
@@ -3207,12 +3207,12 @@ void ProjectExplorerPluginPrivate::updateContextMenuActions()
|
|||||||
// Also handles ProjectNode
|
// Also handles ProjectNode
|
||||||
m_addNewFileAction->setEnabled(supports(AddNewFile)
|
m_addNewFileAction->setEnabled(supports(AddNewFile)
|
||||||
&& !ICore::isNewItemDialogRunning());
|
&& !ICore::isNewItemDialogRunning());
|
||||||
m_addNewSubprojectAction->setEnabled(currentNode->nodeType() == NodeType::Project
|
m_addNewSubprojectAction->setEnabled(currentNode->isProjectNodeType()
|
||||||
&& supports(AddSubProject)
|
&& supports(AddSubProject)
|
||||||
&& !ICore::isNewItemDialogRunning());
|
&& !ICore::isNewItemDialogRunning());
|
||||||
m_addExistingProjectsAction->setEnabled(currentNode->nodeType() == NodeType::Project
|
m_addExistingProjectsAction->setEnabled(currentNode->isProjectNodeType()
|
||||||
&& supports(AddExistingProject));
|
&& supports(AddExistingProject));
|
||||||
m_removeProjectAction->setEnabled(currentNode->nodeType() == NodeType::Project
|
m_removeProjectAction->setEnabled(currentNode->isProjectNodeType()
|
||||||
&& supports(RemoveSubProject));
|
&& supports(RemoveSubProject));
|
||||||
m_addExistingFilesAction->setEnabled(supports(AddExistingFile));
|
m_addExistingFilesAction->setEnabled(supports(AddExistingFile));
|
||||||
m_addExistingDirectoryAction->setEnabled(supports(AddExistingDirectory));
|
m_addExistingDirectoryAction->setEnabled(supports(AddExistingDirectory));
|
||||||
@@ -3338,7 +3338,7 @@ void ProjectExplorerPluginPrivate::addNewSubproject()
|
|||||||
QTC_ASSERT(currentNode, return);
|
QTC_ASSERT(currentNode, return);
|
||||||
QString location = directoryFor(currentNode);
|
QString location = directoryFor(currentNode);
|
||||||
|
|
||||||
if (currentNode->nodeType() == NodeType::Project
|
if (currentNode->isProjectNodeType()
|
||||||
&& currentNode->supportsAction(AddSubProject, currentNode)) {
|
&& currentNode->supportsAction(AddSubProject, currentNode)) {
|
||||||
QVariantMap map;
|
QVariantMap map;
|
||||||
map.insert(QLatin1String(Constants::PREFERRED_PROJECT_NODE), QVariant::fromValue(currentNode));
|
map.insert(QLatin1String(Constants::PREFERRED_PROJECT_NODE), QVariant::fromValue(currentNode));
|
||||||
@@ -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->nodeType() == NodeType::File, return);
|
QTC_ASSERT(currentNode && currentNode->isFileNodeType(), 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->nodeType() == NodeType::File, return);
|
QTC_ASSERT(currentNode && currentNode->isFileNodeType(), 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->nodeType() == NodeType::File, return);
|
QTC_ASSERT(currentNode && currentNode->isFileNodeType(), 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->nodeType() == NodeType::File, return);
|
QTC_ASSERT(currentNode && currentNode->isFileNodeType(), return);
|
||||||
|
|
||||||
FileNode *fileNode = currentNode->asFileNode();
|
FileNode *fileNode = currentNode->asFileNode();
|
||||||
|
|
||||||
|
@@ -165,7 +165,16 @@ Node::~Node() = default;
|
|||||||
|
|
||||||
NodeType Node::nodeType() const
|
NodeType Node::nodeType() const
|
||||||
{
|
{
|
||||||
return m_nodeType;
|
if (isFileNodeType())
|
||||||
|
return NodeType::File;
|
||||||
|
if (isFolderNodeType())
|
||||||
|
return NodeType::Folder;
|
||||||
|
if (isProjectNodeType())
|
||||||
|
return NodeType::Project;
|
||||||
|
if (isVirtualFolderType())
|
||||||
|
return NodeType::VirtualFolder;
|
||||||
|
QTC_CHECK(false);
|
||||||
|
return NodeType::File;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Node::priority() const
|
int Node::priority() const
|
||||||
@@ -308,11 +317,6 @@ FileType Node::fileTypeForFileName(const Utils::FileName &file)
|
|||||||
Utils::MimeMatchMode::MatchExtension));
|
Utils::MimeMatchMode::MatchExtension));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::setNodeType(NodeType nodeType)
|
|
||||||
{
|
|
||||||
m_nodeType = nodeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\class ProjectExplorer::FileNode
|
\class ProjectExplorer::FileNode
|
||||||
|
|
||||||
@@ -434,7 +438,6 @@ QString FileNode::displayName() const
|
|||||||
*/
|
*/
|
||||||
FolderNode::FolderNode(const Utils::FileName &folderPath)
|
FolderNode::FolderNode(const Utils::FileName &folderPath)
|
||||||
{
|
{
|
||||||
setNodeType(NodeType::Folder);
|
|
||||||
setFilePath(folderPath);
|
setFilePath(folderPath);
|
||||||
setPriority(DefaultFolderPriority);
|
setPriority(DefaultFolderPriority);
|
||||||
setListInProject(false);
|
setListInProject(false);
|
||||||
@@ -793,7 +796,6 @@ bool FolderNode::showWhenEmpty() const
|
|||||||
VirtualFolderNode::VirtualFolderNode(const Utils::FileName &folderPath) :
|
VirtualFolderNode::VirtualFolderNode(const Utils::FileName &folderPath) :
|
||||||
FolderNode(folderPath)
|
FolderNode(folderPath)
|
||||||
{
|
{
|
||||||
setNodeType(NodeType::VirtualFolder);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString VirtualFolderNode::addFileFilter() const
|
QString VirtualFolderNode::addFileFilter() const
|
||||||
@@ -819,7 +821,6 @@ QString VirtualFolderNode::addFileFilter() const
|
|||||||
ProjectNode::ProjectNode(const Utils::FileName &projectFilePath) :
|
ProjectNode::ProjectNode(const Utils::FileName &projectFilePath) :
|
||||||
FolderNode(projectFilePath)
|
FolderNode(projectFilePath)
|
||||||
{
|
{
|
||||||
setNodeType(NodeType::Project);
|
|
||||||
setPriority(DefaultProjectPriority);
|
setPriority(DefaultProjectPriority);
|
||||||
setListInProject(true);
|
setListInProject(true);
|
||||||
setDisplayName(projectFilePath.fileName());
|
setDisplayName(projectFilePath.fileName());
|
||||||
@@ -930,7 +931,6 @@ void FolderNode::handleSubTreeChanged(FolderNode *node)
|
|||||||
ContainerNode::ContainerNode(Project *project)
|
ContainerNode::ContainerNode(Project *project)
|
||||||
: FolderNode(project->projectDirectory()), m_project(project)
|
: FolderNode(project->projectDirectory()), m_project(project)
|
||||||
{
|
{
|
||||||
setNodeType(NodeType::Project);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ContainerNode::displayName() const
|
QString ContainerNode::displayName() const
|
||||||
|
@@ -112,6 +112,11 @@ public:
|
|||||||
|
|
||||||
virtual ~Node();
|
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; }
|
||||||
|
|
||||||
NodeType nodeType() const;
|
NodeType nodeType() const;
|
||||||
int priority() const;
|
int priority() const;
|
||||||
|
|
||||||
@@ -165,7 +170,6 @@ protected:
|
|||||||
Node(const Node &other) = delete;
|
Node(const Node &other) = delete;
|
||||||
bool operator=(const Node &other) = delete;
|
bool operator=(const Node &other) = delete;
|
||||||
|
|
||||||
void setNodeType(NodeType nodeType);
|
|
||||||
void setFilePath(const Utils::FileName &filePath);
|
void setFilePath(const Utils::FileName &filePath);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -173,7 +177,6 @@ private:
|
|||||||
Utils::FileName m_filePath;
|
Utils::FileName m_filePath;
|
||||||
int m_line = -1;
|
int m_line = -1;
|
||||||
int m_priority = DefaultPriority;
|
int m_priority = DefaultPriority;
|
||||||
NodeType m_nodeType = NodeType::File;
|
|
||||||
|
|
||||||
enum NodeFlag : quint16 {
|
enum NodeFlag : quint16 {
|
||||||
FlagNone = 0,
|
FlagNone = 0,
|
||||||
@@ -196,6 +199,8 @@ 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,
|
||||||
@@ -216,6 +221,8 @@ public:
|
|||||||
QString displayName() const override;
|
QString displayName() const override;
|
||||||
QIcon icon() const;
|
QIcon icon() const;
|
||||||
|
|
||||||
|
bool isFolderNodeType() const override { return true; }
|
||||||
|
|
||||||
Node *findNode(const std::function<bool(Node *)> &filter);
|
Node *findNode(const std::function<bool(Node *)> &filter);
|
||||||
QList<Node *> findNodes(const std::function<bool(Node *)> &filter);
|
QList<Node *> findNodes(const std::function<bool(Node *)> &filter);
|
||||||
|
|
||||||
@@ -313,6 +320,9 @@ class PROJECTEXPLORER_EXPORT VirtualFolderNode : public FolderNode
|
|||||||
public:
|
public:
|
||||||
explicit VirtualFolderNode(const Utils::FileName &folderPath);
|
explicit VirtualFolderNode(const Utils::FileName &folderPath);
|
||||||
|
|
||||||
|
bool isFolderNodeType() const override { return false; }
|
||||||
|
bool isVirtualFolderType() const override { return true; }
|
||||||
|
|
||||||
void setAddFileFilter(const QString &filter) { m_addFileFilter = filter; }
|
void setAddFileFilter(const QString &filter) { m_addFileFilter = filter; }
|
||||||
QString addFileFilter() const override;
|
QString addFileFilter() const override;
|
||||||
|
|
||||||
@@ -334,6 +344,9 @@ public:
|
|||||||
return Utils::nullopt;
|
return Utils::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isFolderNodeType() const override { return false; }
|
||||||
|
bool isProjectNodeType() const override { return true; }
|
||||||
|
|
||||||
bool addFiles(const QStringList &filePaths, QStringList *notAdded = nullptr) override;
|
bool addFiles(const QStringList &filePaths, QStringList *notAdded = nullptr) override;
|
||||||
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = nullptr) override;
|
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = nullptr) override;
|
||||||
bool deleteFiles(const QStringList &filePaths) override;
|
bool deleteFiles(const QStringList &filePaths) override;
|
||||||
@@ -368,6 +381,9 @@ public:
|
|||||||
QString displayName() const final;
|
QString displayName() const final;
|
||||||
bool supportsAction(ProjectAction action, const Node *node) const final;
|
bool supportsAction(ProjectAction action, const Node *node) const final;
|
||||||
|
|
||||||
|
bool isFolderNodeType() const override { return false; }
|
||||||
|
bool isProjectNodeType() const override { return true; }
|
||||||
|
|
||||||
ContainerNode *asContainerNode() final { return this; }
|
ContainerNode *asContainerNode() final { return this; }
|
||||||
const ContainerNode *asContainerNode() const final { return this; }
|
const ContainerNode *asContainerNode() const final { return this; }
|
||||||
|
|
||||||
|
@@ -333,26 +333,16 @@ void ProjectTree::showContextMenu(ProjectTreeWidget *focus, const QPoint &global
|
|||||||
|
|
||||||
if (!node) {
|
if (!node) {
|
||||||
contextMenu = Core::ActionManager::actionContainer(Constants::M_SESSIONCONTEXT)->menu();
|
contextMenu = Core::ActionManager::actionContainer(Constants::M_SESSIONCONTEXT)->menu();
|
||||||
} else {
|
} else if (node->isProjectNodeType()) {
|
||||||
switch (node->nodeType()) {
|
if ((node->parentFolderNode() && node->parentFolderNode()->asContainerNode())
|
||||||
case NodeType::Project: {
|
|| node->asContainerNode())
|
||||||
if ((node->parentFolderNode() && node->parentFolderNode()->asContainerNode())
|
contextMenu = Core::ActionManager::actionContainer(Constants::M_PROJECTCONTEXT)->menu();
|
||||||
|| node->asContainerNode())
|
else
|
||||||
contextMenu = Core::ActionManager::actionContainer(Constants::M_PROJECTCONTEXT)->menu();
|
contextMenu = Core::ActionManager::actionContainer(Constants::M_SUBPROJECTCONTEXT)->menu();
|
||||||
else
|
} else if (node->isVirtualFolderType() || node->isFolderNodeType()) {
|
||||||
contextMenu = Core::ActionManager::actionContainer(Constants::M_SUBPROJECTCONTEXT)->menu();
|
contextMenu = Core::ActionManager::actionContainer(Constants::M_FOLDERCONTEXT)->menu();
|
||||||
break;
|
} else if (node->isFileNodeType()) {
|
||||||
}
|
contextMenu = Core::ActionManager::actionContainer(Constants::M_FILECONTEXT)->menu();
|
||||||
case NodeType::VirtualFolder:
|
|
||||||
case NodeType::Folder:
|
|
||||||
contextMenu = Core::ActionManager::actionContainer(Constants::M_FOLDERCONTEXT)->menu();
|
|
||||||
break;
|
|
||||||
case NodeType::File:
|
|
||||||
contextMenu = Core::ActionManager::actionContainer(Constants::M_FILECONTEXT)->menu();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
qWarning("ProjectExplorerPlugin::showContextMenu - Missing handler for node type");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contextMenu && contextMenu->actions().count() > 0) {
|
if (contextMenu && contextMenu->actions().count() > 0) {
|
||||||
@@ -435,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->nodeType() != NodeType::File && n->nodeType() == NodeType::File))
|
if (!node || (!node->isFileNodeType() && n->isFileNodeType()))
|
||||||
node = n;
|
node = n;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -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->nodeType() != NodeType::File)
|
if (!node || !node->isFileNodeType())
|
||||||
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)
|
||||||
|
@@ -171,7 +171,7 @@ BestNodeSelector::BestNodeSelector(const QString &commonDirectory, const QString
|
|||||||
void BestNodeSelector::inspect(AddNewTree *tree, bool isContextNode)
|
void BestNodeSelector::inspect(AddNewTree *tree, bool isContextNode)
|
||||||
{
|
{
|
||||||
FolderNode *node = tree->node();
|
FolderNode *node = tree->node();
|
||||||
if (node->nodeType() == NodeType::Project) {
|
if (node->isProjectNodeType()) {
|
||||||
if (static_cast<ProjectNode *>(node)->deploysFolder(m_commonDirectory)) {
|
if (static_cast<ProjectNode *>(node)->deploysFolder(m_commonDirectory)) {
|
||||||
m_deploys = true;
|
m_deploys = true;
|
||||||
m_deployText += tree->displayName() + QLatin1Char('\n');
|
m_deployText += tree->displayName() + QLatin1Char('\n');
|
||||||
|
@@ -623,18 +623,16 @@ QString PythonProjectNode::addFileFilter() const
|
|||||||
|
|
||||||
bool PythonProjectNode::supportsAction(ProjectAction action, const Node *node) const
|
bool PythonProjectNode::supportsAction(ProjectAction action, const Node *node) const
|
||||||
{
|
{
|
||||||
switch (node->nodeType()) {
|
if (node->isFileNodeType()) {
|
||||||
case NodeType::File:
|
|
||||||
return action == ProjectAction::Rename
|
return action == ProjectAction::Rename
|
||||||
|| action == ProjectAction::RemoveFile;
|
|| action == ProjectAction::RemoveFile;
|
||||||
case NodeType::Folder:
|
}
|
||||||
case NodeType::Project:
|
if (node->isFolderNodeType() || node->isProjectNodeType()) {
|
||||||
return action == ProjectAction::AddNewFile
|
return action == ProjectAction::AddNewFile
|
||||||
|| action == ProjectAction::RemoveFile
|
|| action == ProjectAction::RemoveFile
|
||||||
|| action == ProjectAction::AddExistingFile;
|
|| action == ProjectAction::AddExistingFile;
|
||||||
default:
|
|
||||||
return ProjectNode::supportsAction(action, node);
|
|
||||||
}
|
}
|
||||||
|
return ProjectNode::supportsAction(action, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PythonProjectNode::addFiles(const QStringList &filePaths, QStringList *)
|
bool PythonProjectNode::addFiles(const QStringList &filePaths, QStringList *)
|
||||||
|
@@ -223,7 +223,7 @@ static bool supportsNodeAction(ProjectAction action, const Node *node)
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (action == RemoveFile || action == Rename) {
|
if (action == RemoveFile || action == Rename) {
|
||||||
if (node->nodeType() == ProjectExplorer::NodeType::File)
|
if (node->isFileNodeType())
|
||||||
return !Utils::contains(project->qbsProject().buildSystemFiles(), equalsNodeFilePath);
|
return !Utils::contains(project->qbsProject().buildSystemFiles(), equalsNodeFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -286,7 +286,7 @@ void QbsProjectManagerPlugin::updateContextActions()
|
|||||||
&& project && !project->isParsing()
|
&& project && !project->isParsing()
|
||||||
&& node && node->isEnabled();
|
&& node && node->isEnabled();
|
||||||
|
|
||||||
bool isFile = project && node && (node->nodeType() == NodeType::File);
|
const bool isFile = project && node && node->isFileNodeType();
|
||||||
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();
|
||||||
|
@@ -112,7 +112,7 @@ bool QmakePriFileNode::supportsAction(ProjectAction action, const Node *node) co
|
|||||||
return !(pro && pro->knowsFile(node->filePath()));
|
return !(pro && pro->knowsFile(node->filePath()));
|
||||||
|
|
||||||
bool addExistingFiles = true;
|
bool addExistingFiles = true;
|
||||||
if (node->nodeType() == NodeType::VirtualFolder) {
|
if (node->isVirtualFolderType()) {
|
||||||
// A virtual folder, we do what the projectexplorer does
|
// A virtual folder, we do what the projectexplorer does
|
||||||
const FolderNode *folder = node->asFolderNode();
|
const FolderNode *folder = node->asFolderNode();
|
||||||
if (folder) {
|
if (folder) {
|
||||||
@@ -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->nodeType() == NodeType::File && filePaths.contains(n->filePath().toString());
|
return n->isFileNodeType() && 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;
|
||||||
|
@@ -398,7 +398,7 @@ void DocumentManager::findPathToIsoProFile(bool *iconResourceFileAlreadyExists,
|
|||||||
qCDebug(documentManagerLog) << "Checking" << node->displayName()
|
qCDebug(documentManagerLog) << "Checking" << node->displayName()
|
||||||
<< "(" << node << static_cast<int>(node->nodeType()) << ")";
|
<< "(" << node << static_cast<int>(node->nodeType()) << ")";
|
||||||
|
|
||||||
if (node->nodeType() == ProjectExplorer::NodeType::VirtualFolder && node->displayName() == "Resources") {
|
if (node->isVirtualFolderType() && node->displayName() == "Resources") {
|
||||||
auto virtualFolderNode = dynamic_cast<ProjectExplorer::VirtualFolderNode*>(node);
|
auto virtualFolderNode = dynamic_cast<ProjectExplorer::VirtualFolderNode*>(node);
|
||||||
|
|
||||||
for (int subFolderIndex = 0; subFolderIndex < virtualFolderNode->folderNodes().size() && !iconQrcFileNode; ++subFolderIndex) {
|
for (int subFolderIndex = 0; subFolderIndex < virtualFolderNode->folderNodes().size() && !iconQrcFileNode; ++subFolderIndex) {
|
||||||
@@ -408,8 +408,7 @@ void DocumentManager::findPathToIsoProFile(bool *iconResourceFileAlreadyExists,
|
|||||||
<< subFolderNode << static_cast<int>(subFolderNode->nodeType())
|
<< subFolderNode << static_cast<int>(subFolderNode->nodeType())
|
||||||
<< ") is" << isoIconsQrcFile;
|
<< ") is" << isoIconsQrcFile;
|
||||||
|
|
||||||
if (subFolderNode->nodeType() == ProjectExplorer::NodeType::Folder
|
if (subFolderNode->isFolderNodeType() && subFolderNode->displayName() == isoIconsQrcFile) {
|
||||||
&& subFolderNode->displayName() == isoIconsQrcFile) {
|
|
||||||
qCDebug(documentManagerLog) << "Found" << isoIconsQrcFile << "in" << virtualFolderNode->filePath();
|
qCDebug(documentManagerLog) << "Found" << isoIconsQrcFile << "in" << virtualFolderNode->filePath();
|
||||||
|
|
||||||
iconQrcFileNode = subFolderNode;
|
iconQrcFileNode = subFolderNode;
|
||||||
|
@@ -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->nodeType() != NodeType::File
|
if (!currentNode || !currentNode->isFileNodeType()
|
||||||
|| currentNode->asFileNode()->fileType() != FileType::QML)
|
|| currentNode->asFileNode()->fileType() != FileType::QML)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@@ -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->nodeType() == NodeType::File) {
|
if (action == Rename && node->isFileNodeType()) {
|
||||||
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;
|
||||||
|
Reference in New Issue
Block a user