forked from qt-creator/qt-creator
ProjectNodes: Handle supported actions one-by-one
Getting the full list for a node can get quite expensive e.g. in cases of recursive calls of QMakeProjectManager::findPriFile. However, the FlatModel needs to decide quickly on whether an item is editable to potentially allow renaming. So split up QList<Actions> supportedActions() into individual bool supportsAction(action) calls and make sure Rename is not on the critical path. Task-number: QTCREATORBUG-17953 Change-Id: I31841847f8aa7d7b94c63d76ce71efb1c930fa69 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -42,9 +42,3 @@ bool AutotoolsProjectNode::showInSimpleTree() const
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ProjectAction> AutotoolsProjectNode::supportedActions(Node *node) const
|
|
||||||
{
|
|
||||||
Q_UNUSED(node);
|
|
||||||
return QList<ProjectAction>();
|
|
||||||
}
|
|
||||||
|
@@ -51,7 +51,6 @@ public:
|
|||||||
AutotoolsProjectNode(const Utils::FileName &projectDirectory);
|
AutotoolsProjectNode(const Utils::FileName &projectDirectory);
|
||||||
|
|
||||||
bool showInSimpleTree() const override;
|
bool showInSimpleTree() const override;
|
||||||
QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -56,12 +56,6 @@ bool CMakeInputsNode::showInSimpleTree() const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ProjectExplorer::ProjectAction> CMakeInputsNode::supportedActions(ProjectExplorer::Node *node) const
|
|
||||||
{
|
|
||||||
Q_UNUSED(node);
|
|
||||||
return QList<ProjectExplorer::ProjectAction>();
|
|
||||||
}
|
|
||||||
|
|
||||||
CMakeListsNode::CMakeListsNode(const Utils::FileName &cmakeListPath) :
|
CMakeListsNode::CMakeListsNode(const Utils::FileName &cmakeListPath) :
|
||||||
ProjectExplorer::ProjectNode(cmakeListPath)
|
ProjectExplorer::ProjectNode(cmakeListPath)
|
||||||
{
|
{
|
||||||
@@ -80,12 +74,6 @@ bool CMakeListsNode::showInSimpleTree() const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ProjectExplorer::ProjectAction> CMakeListsNode::supportedActions(ProjectExplorer::Node *node) const
|
|
||||||
{
|
|
||||||
Q_UNUSED(node);
|
|
||||||
return QList<ProjectExplorer::ProjectAction>();
|
|
||||||
}
|
|
||||||
|
|
||||||
CMakeProjectNode::CMakeProjectNode(const Utils::FileName &directory) :
|
CMakeProjectNode::CMakeProjectNode(const Utils::FileName &directory) :
|
||||||
ProjectExplorer::ProjectNode(directory)
|
ProjectExplorer::ProjectNode(directory)
|
||||||
{
|
{
|
||||||
@@ -103,12 +91,6 @@ QString CMakeProjectNode::tooltip() const
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ProjectExplorer::ProjectAction> CMakeProjectNode::supportedActions(ProjectExplorer::Node *node) const
|
|
||||||
{
|
|
||||||
Q_UNUSED(node);
|
|
||||||
return QList<ProjectExplorer::ProjectAction>();
|
|
||||||
}
|
|
||||||
|
|
||||||
CMakeTargetNode::CMakeTargetNode(const Utils::FileName &directory) :
|
CMakeTargetNode::CMakeTargetNode(const Utils::FileName &directory) :
|
||||||
ProjectExplorer::ProjectNode(directory)
|
ProjectExplorer::ProjectNode(directory)
|
||||||
{
|
{
|
||||||
@@ -126,12 +108,6 @@ QString CMakeTargetNode::tooltip() const
|
|||||||
return m_tooltip;
|
return m_tooltip;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ProjectExplorer::ProjectAction> CMakeTargetNode::supportedActions(ProjectExplorer::Node *node) const
|
|
||||||
{
|
|
||||||
Q_UNUSED(node);
|
|
||||||
return QList<ProjectExplorer::ProjectAction>();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMakeTargetNode::setTargetInformation(const QList<Utils::FileName> &artifacts,
|
void CMakeTargetNode::setTargetInformation(const QList<Utils::FileName> &artifacts,
|
||||||
const QString &type)
|
const QString &type)
|
||||||
{
|
{
|
||||||
|
@@ -28,8 +28,6 @@
|
|||||||
#include <projectexplorer/projectnodes.h>
|
#include <projectexplorer/projectnodes.h>
|
||||||
|
|
||||||
namespace CMakeProjectManager {
|
namespace CMakeProjectManager {
|
||||||
class CMakeProject;
|
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class CMakeInputsNode : public ProjectExplorer::ProjectNode
|
class CMakeInputsNode : public ProjectExplorer::ProjectNode
|
||||||
@@ -40,7 +38,6 @@ public:
|
|||||||
static Utils::FileName inputsPathFromCMakeListsPath(const Utils::FileName &cmakeLists);
|
static Utils::FileName inputsPathFromCMakeListsPath(const Utils::FileName &cmakeLists);
|
||||||
|
|
||||||
bool showInSimpleTree() const final;
|
bool showInSimpleTree() const final;
|
||||||
QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const final;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CMakeListsNode : public ProjectExplorer::ProjectNode
|
class CMakeListsNode : public ProjectExplorer::ProjectNode
|
||||||
@@ -49,7 +46,6 @@ public:
|
|||||||
CMakeListsNode(const Utils::FileName &cmakeListPath);
|
CMakeListsNode(const Utils::FileName &cmakeListPath);
|
||||||
|
|
||||||
bool showInSimpleTree() const final;
|
bool showInSimpleTree() const final;
|
||||||
QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const final;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CMakeProjectNode : public ProjectExplorer::ProjectNode
|
class CMakeProjectNode : public ProjectExplorer::ProjectNode
|
||||||
@@ -59,7 +55,6 @@ public:
|
|||||||
|
|
||||||
bool showInSimpleTree() const final;
|
bool showInSimpleTree() const final;
|
||||||
QString tooltip() const final;
|
QString tooltip() const final;
|
||||||
QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const final;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CMakeTargetNode : public ProjectExplorer::ProjectNode
|
class CMakeTargetNode : public ProjectExplorer::ProjectNode
|
||||||
@@ -71,7 +66,6 @@ public:
|
|||||||
|
|
||||||
bool showInSimpleTree() const final;
|
bool showInSimpleTree() const final;
|
||||||
QString tooltip() const final;
|
QString tooltip() const final;
|
||||||
QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const final;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_tooltip;
|
QString m_tooltip;
|
||||||
|
@@ -78,16 +78,14 @@ bool GenericProjectNode::showInSimpleTree() const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ProjectAction> GenericProjectNode::supportedActions(Node *node) const
|
bool GenericProjectNode::supportsAction(ProjectAction action, Node *node) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(node);
|
Q_UNUSED(node);
|
||||||
return {
|
return action == AddNewFile
|
||||||
AddNewFile,
|
|| action == AddExistingFile
|
||||||
AddExistingFile,
|
|| action == AddExistingDirectory
|
||||||
AddExistingDirectory,
|
|| action == RemoveFile
|
||||||
RemoveFile,
|
|| action == Rename;
|
||||||
Rename
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GenericProjectNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
|
bool GenericProjectNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
|
||||||
|
@@ -44,8 +44,7 @@ public:
|
|||||||
explicit GenericProjectNode(GenericProject *project);
|
explicit GenericProjectNode(GenericProject *project);
|
||||||
|
|
||||||
bool showInSimpleTree() const override;
|
bool showInSimpleTree() const override;
|
||||||
|
bool supportsAction(ProjectExplorer::ProjectAction action, Node *node) const override;
|
||||||
QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const override;
|
|
||||||
|
|
||||||
bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0) override;
|
bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0) override;
|
||||||
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0) override;
|
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0) override;
|
||||||
|
@@ -37,23 +37,19 @@ NimProjectNode::NimProjectNode(NimProject &project,
|
|||||||
, m_project(project)
|
, m_project(project)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
QList<ProjectAction> NimProjectNode::supportedActions(Node *node) const
|
bool NimProjectNode::supportsAction(ProjectAction action, Node *node) const
|
||||||
{
|
{
|
||||||
static const QList<ProjectAction> fileActions = {ProjectAction::Rename,
|
|
||||||
ProjectAction::RemoveFile
|
|
||||||
};
|
|
||||||
static const QList<ProjectAction> folderActions = {ProjectAction::AddNewFile,
|
|
||||||
ProjectAction::RemoveFile,
|
|
||||||
ProjectAction::AddExistingFile
|
|
||||||
};
|
|
||||||
switch (node->nodeType()) {
|
switch (node->nodeType()) {
|
||||||
case NodeType::File:
|
case NodeType::File:
|
||||||
return fileActions;
|
return action == ProjectAction::Rename
|
||||||
|
|| action == ProjectAction::RemoveFile;
|
||||||
case NodeType::Folder:
|
case NodeType::Folder:
|
||||||
case NodeType::Project:
|
case NodeType::Project:
|
||||||
return folderActions;
|
return action == ProjectAction::AddNewFile
|
||||||
|
|| action == ProjectAction::RemoveFile
|
||||||
|
|| action == ProjectAction::AddExistingFile;
|
||||||
default:
|
default:
|
||||||
return ProjectNode::supportedActions(node);
|
return ProjectNode::supportsAction(action, node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -38,7 +38,7 @@ class NimProjectNode : public ProjectExplorer::ProjectNode
|
|||||||
public:
|
public:
|
||||||
NimProjectNode(NimProject &project, const Utils::FileName &projectFilePath);
|
NimProjectNode(NimProject &project, const Utils::FileName &projectFilePath);
|
||||||
|
|
||||||
QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const override;
|
bool supportsAction(ProjectExplorer::ProjectAction action, Node *node) const override;
|
||||||
bool addFiles(const QStringList &filePaths, QStringList *) override;
|
bool addFiles(const QStringList &filePaths, QStringList *) override;
|
||||||
bool removeFiles(const QStringList &filePaths, QStringList *) override;
|
bool removeFiles(const QStringList &filePaths, QStringList *) override;
|
||||||
bool deleteFiles(const QStringList &) override;
|
bool deleteFiles(const QStringList &) override;
|
||||||
|
@@ -2938,8 +2938,6 @@ void ProjectExplorerPluginPrivate::updateContextMenuActions()
|
|||||||
Node *currentNode = ProjectTree::currentNode();
|
Node *currentNode = ProjectTree::currentNode();
|
||||||
|
|
||||||
if (currentNode && currentNode->managingProject()) {
|
if (currentNode && currentNode->managingProject()) {
|
||||||
QList<ProjectAction> actions = currentNode->supportedActions(currentNode);
|
|
||||||
|
|
||||||
ProjectNode *pn;
|
ProjectNode *pn;
|
||||||
if (ContainerNode *cn = currentNode->asContainerNode())
|
if (ContainerNode *cn = currentNode->asContainerNode())
|
||||||
pn = cn->rootProjectNode();
|
pn = cn->rootProjectNode();
|
||||||
@@ -2967,56 +2965,61 @@ void ProjectExplorerPluginPrivate::updateContextMenuActions()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto supports = [currentNode](ProjectAction action) {
|
||||||
|
return currentNode->supportsAction(action, currentNode);
|
||||||
|
};
|
||||||
|
|
||||||
if (currentNode->asFolderNode()) {
|
if (currentNode->asFolderNode()) {
|
||||||
// Also handles ProjectNode
|
// Also handles ProjectNode
|
||||||
m_addNewFileAction->setEnabled(actions.contains(AddNewFile)
|
m_addNewFileAction->setEnabled(currentNode->supportsAction(AddNewFile, currentNode)
|
||||||
&& !ICore::isNewItemDialogRunning());
|
&& !ICore::isNewItemDialogRunning());
|
||||||
m_addNewSubprojectAction->setEnabled(currentNode->nodeType() == NodeType::Project
|
m_addNewSubprojectAction->setEnabled(currentNode->nodeType() == NodeType::Project
|
||||||
&& actions.contains(AddSubProject)
|
&& supports(AddSubProject)
|
||||||
&& !ICore::isNewItemDialogRunning());
|
&& !ICore::isNewItemDialogRunning());
|
||||||
m_removeProjectAction->setEnabled(currentNode->nodeType() == NodeType::Project
|
m_removeProjectAction->setEnabled(currentNode->nodeType() == NodeType::Project
|
||||||
&& actions.contains(RemoveSubProject));
|
&& supports(RemoveSubProject));
|
||||||
m_addExistingFilesAction->setEnabled(actions.contains(AddExistingFile));
|
m_addExistingFilesAction->setEnabled(supports(AddExistingFile));
|
||||||
m_addExistingDirectoryAction->setEnabled(actions.contains(AddExistingDirectory));
|
m_addExistingDirectoryAction->setEnabled(supports(AddExistingDirectory));
|
||||||
m_renameFileAction->setEnabled(actions.contains(Rename));
|
m_renameFileAction->setEnabled(supports(Rename));
|
||||||
} else if (currentNode->asFileNode()) {
|
} else if (currentNode->asFileNode()) {
|
||||||
// Enable and show remove / delete in magic ways:
|
// Enable and show remove / delete in magic ways:
|
||||||
// If both are disabled show Remove
|
// If both are disabled show Remove
|
||||||
// If both are enabled show both (can't happen atm)
|
// If both are enabled show both (can't happen atm)
|
||||||
// If only removeFile is enabled only show it
|
// If only removeFile is enabled only show it
|
||||||
// If only deleteFile is enable only show it
|
// If only deleteFile is enable only show it
|
||||||
bool enableRemove = actions.contains(RemoveFile);
|
bool enableRemove = supports(RemoveFile);
|
||||||
m_removeFileAction->setEnabled(enableRemove);
|
m_removeFileAction->setEnabled(enableRemove);
|
||||||
bool enableDelete = actions.contains(EraseFile);
|
bool enableDelete = supports(EraseFile);
|
||||||
m_deleteFileAction->setEnabled(enableDelete);
|
m_deleteFileAction->setEnabled(enableDelete);
|
||||||
m_deleteFileAction->setVisible(enableDelete);
|
m_deleteFileAction->setVisible(enableDelete);
|
||||||
|
|
||||||
m_removeFileAction->setVisible(!enableDelete || enableRemove);
|
m_removeFileAction->setVisible(!enableDelete || enableRemove);
|
||||||
m_renameFileAction->setEnabled(actions.contains(Rename));
|
m_renameFileAction->setEnabled(supports(Rename));
|
||||||
const bool currentNodeIsTextFile = isTextFile(
|
const bool currentNodeIsTextFile = isTextFile(
|
||||||
ProjectTree::currentNode()->filePath().toString());
|
ProjectTree::currentNode()->filePath().toString());
|
||||||
m_diffFileAction->setEnabled(isDiffServiceAvailable()
|
m_diffFileAction->setEnabled(isDiffServiceAvailable()
|
||||||
&& currentNodeIsTextFile && TextEditor::TextDocument::currentTextDocument());
|
&& currentNodeIsTextFile && TextEditor::TextDocument::currentTextDocument());
|
||||||
|
|
||||||
m_duplicateFileAction->setVisible(actions.contains(DuplicateFile));
|
m_duplicateFileAction->setVisible(supports(DuplicateFile));
|
||||||
m_duplicateFileAction->setEnabled(actions.contains(DuplicateFile));
|
m_duplicateFileAction->setEnabled(supports(DuplicateFile));
|
||||||
|
|
||||||
EditorManager::populateOpenWithMenu(m_openWithMenu,
|
EditorManager::populateOpenWithMenu(m_openWithMenu,
|
||||||
ProjectTree::currentNode()->filePath().toString());
|
ProjectTree::currentNode()->filePath().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actions.contains(HidePathActions)) {
|
if (supports(HidePathActions)) {
|
||||||
m_openTerminalHere->setVisible(false);
|
m_openTerminalHere->setVisible(false);
|
||||||
m_showInGraphicalShell->setVisible(false);
|
m_showInGraphicalShell->setVisible(false);
|
||||||
m_searchOnFileSystem->setVisible(false);
|
m_searchOnFileSystem->setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actions.contains(HideFileActions)) {
|
if (supports(HideFileActions)) {
|
||||||
m_deleteFileAction->setVisible(false);
|
m_deleteFileAction->setVisible(false);
|
||||||
m_removeFileAction->setVisible(false);
|
m_removeFileAction->setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actions.contains(HideFolderActions)) {
|
if (supports(HideFolderActions)) {
|
||||||
m_addNewFileAction->setVisible(false);
|
m_addNewFileAction->setVisible(false);
|
||||||
m_addNewSubprojectAction->setVisible(false);
|
m_addNewSubprojectAction->setVisible(false);
|
||||||
m_removeProjectAction->setVisible(false);
|
m_removeProjectAction->setVisible(false);
|
||||||
@@ -3052,8 +3055,7 @@ void ProjectExplorerPluginPrivate::addNewSubproject()
|
|||||||
QString location = directoryFor(currentNode);
|
QString location = directoryFor(currentNode);
|
||||||
|
|
||||||
if (currentNode->nodeType() == NodeType::Project
|
if (currentNode->nodeType() == NodeType::Project
|
||||||
&& currentNode->supportedActions(
|
&& currentNode->supportsAction(AddSubProject, currentNode)) {
|
||||||
currentNode).contains(AddSubProject)) {
|
|
||||||
QVariantMap map;
|
QVariantMap map;
|
||||||
map.insert(QLatin1String(Constants::PREFERRED_PROJECT_NODE), QVariant::fromValue(currentNode));
|
map.insert(QLatin1String(Constants::PREFERRED_PROJECT_NODE), QVariant::fromValue(currentNode));
|
||||||
Project *project = ProjectTree::currentProject();
|
Project *project = ProjectTree::currentProject();
|
||||||
|
@@ -145,7 +145,7 @@ Qt::ItemFlags FlatModel::flags(const QModelIndex &index) const
|
|||||||
if (Node *node = nodeForIndex(index)) {
|
if (Node *node = nodeForIndex(index)) {
|
||||||
if (!node->asProjectNode()) {
|
if (!node->asProjectNode()) {
|
||||||
// either folder or file node
|
// either folder or file node
|
||||||
if (node->supportedActions(node).contains(Rename))
|
if (node->supportsAction(Rename, node))
|
||||||
f = f | Qt::ItemIsEditable;
|
f = f | Qt::ItemIsEditable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -215,14 +215,9 @@ bool Node::isEnabled() const
|
|||||||
return parent ? parent->isEnabled() : true;
|
return parent ? parent->isEnabled() : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ProjectAction> Node::supportedActions(Node *node) const
|
bool Node::supportsAction(ProjectAction, Node *) const
|
||||||
{
|
{
|
||||||
if (FolderNode *folder = parentFolderNode()) {
|
return false;
|
||||||
QList<ProjectAction> list = folder->supportedActions(node);
|
|
||||||
list.append(InheritedFromParent);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::setEnabled(bool enabled)
|
void Node::setEnabled(bool enabled)
|
||||||
@@ -364,6 +359,14 @@ QList<FileNode *> FileNode::scanForFiles(const Utils::FileName &directory,
|
|||||||
return scanForFilesRecursively(directory, factory, visited, future, 0.0, 1000000.0);
|
return scanForFilesRecursively(directory, factory, visited, future, 0.0, 1000000.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FileNode::supportsAction(ProjectAction action, Node *node) const
|
||||||
|
{
|
||||||
|
if (action == InheritedFromParent)
|
||||||
|
return true;
|
||||||
|
FolderNode *parentFolder = parentFolderNode();
|
||||||
|
return parentFolder && parentFolder->supportsAction(action, node);
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\class ProjectExplorer::FolderNode
|
\class ProjectExplorer::FolderNode
|
||||||
|
|
||||||
@@ -593,6 +596,14 @@ QString FolderNode::addFileFilter() const
|
|||||||
return parentFolderNode()->addFileFilter();
|
return parentFolderNode()->addFileFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FolderNode::supportsAction(ProjectAction action, Node *node) const
|
||||||
|
{
|
||||||
|
if (action == InheritedFromParent)
|
||||||
|
return true;
|
||||||
|
FolderNode *parentFolder = parentFolderNode();
|
||||||
|
return parentFolder && parentFolder->supportsAction(action, node);
|
||||||
|
}
|
||||||
|
|
||||||
bool FolderNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
|
bool FolderNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
|
||||||
{
|
{
|
||||||
ProjectNode *pn = managingProject();
|
ProjectNode *pn = managingProject();
|
||||||
@@ -812,11 +823,10 @@ QString ContainerNode::displayName() const
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ProjectAction> ContainerNode::supportedActions(Node *node) const
|
bool ContainerNode::supportsAction(ProjectAction action, Node *node) const
|
||||||
{
|
{
|
||||||
if (Node *rootNode = m_project->rootProjectNode())
|
Node *rootNode = m_project->rootProjectNode();
|
||||||
return rootNode->supportedActions(node);
|
return rootNode && rootNode->supportsAction(action, node);
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectNode *ContainerNode::rootProjectNode() const
|
ProjectNode *ContainerNode::rootProjectNode() const
|
||||||
|
@@ -130,7 +130,7 @@ public:
|
|||||||
virtual QString tooltip() const;
|
virtual QString tooltip() const;
|
||||||
bool isEnabled() const;
|
bool isEnabled() const;
|
||||||
|
|
||||||
virtual QList<ProjectAction> supportedActions(Node *node) const;
|
virtual bool supportsAction(ProjectAction action, Node *node) const;
|
||||||
|
|
||||||
void setEnabled(bool enabled);
|
void setEnabled(bool enabled);
|
||||||
void setAbsoluteFilePathAndLine(const Utils::FileName &filePath, int line);
|
void setAbsoluteFilePathAndLine(const Utils::FileName &filePath, int line);
|
||||||
@@ -179,6 +179,7 @@ public:
|
|||||||
static QList<FileNode *> scanForFiles(const Utils::FileName &directory,
|
static QList<FileNode *> scanForFiles(const Utils::FileName &directory,
|
||||||
const std::function<FileNode *(const Utils::FileName &fileName)> factory,
|
const std::function<FileNode *(const Utils::FileName &fileName)> factory,
|
||||||
QFutureInterface<QList<FileNode *>> *future = nullptr);
|
QFutureInterface<QList<FileNode *>> *future = nullptr);
|
||||||
|
bool supportsAction(ProjectAction action, Node *node) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FileType m_fileType;
|
FileType m_fileType;
|
||||||
@@ -225,6 +226,8 @@ public:
|
|||||||
|
|
||||||
virtual QString addFileFilter() const;
|
virtual QString addFileFilter() const;
|
||||||
|
|
||||||
|
bool supportsAction(ProjectAction action, Node *node) const override;
|
||||||
|
|
||||||
virtual bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0);
|
virtual bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0);
|
||||||
virtual bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0);
|
virtual bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0);
|
||||||
virtual bool deleteFiles(const QStringList &filePaths);
|
virtual bool deleteFiles(const QStringList &filePaths);
|
||||||
@@ -309,7 +312,7 @@ public:
|
|||||||
ContainerNode(Project *project);
|
ContainerNode(Project *project);
|
||||||
|
|
||||||
QString displayName() const final;
|
QString displayName() const final;
|
||||||
QList<ProjectAction> supportedActions(Node *node) const final;
|
bool supportsAction(ProjectAction action, Node *node) const final;
|
||||||
|
|
||||||
ContainerNode *asContainerNode() final { return this; }
|
ContainerNode *asContainerNode() final { return this; }
|
||||||
const ContainerNode *asContainerNode() const final { return this; }
|
const ContainerNode *asContainerNode() const final { return this; }
|
||||||
|
@@ -240,8 +240,7 @@ static inline AddNewTree *buildAddProjectTree(ProjectNode *root, const QString &
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const QList<ProjectAction> &list = root->supportedActions(root);
|
if (root->supportsAction(AddSubProject, root) && !root->supportsAction(InheritedFromParent, root)) {
|
||||||
if (list.contains(AddSubProject) && !list.contains(InheritedFromParent)) {
|
|
||||||
if (projectPath.isEmpty() || root->canAddSubProject(projectPath)) {
|
if (projectPath.isEmpty() || root->canAddSubProject(projectPath)) {
|
||||||
FolderNode::AddNewInformation info = root->addNewInformation(QStringList() << projectPath, contextNode);
|
FolderNode::AddNewInformation info = root->addNewInformation(QStringList() << projectPath, contextNode);
|
||||||
auto item = new AddNewTree(root, children, info);
|
auto item = new AddNewTree(root, children, info);
|
||||||
@@ -265,8 +264,7 @@ static inline AddNewTree *buildAddFilesTree(FolderNode *root, const QStringList
|
|||||||
children.append(child);
|
children.append(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QList<ProjectAction> &list = root->supportedActions(root);
|
if (root->supportsAction(AddNewFile, root) && !root->supportsAction(InheritedFromParent, root)) {
|
||||||
if (list.contains(AddNewFile) && !list.contains(InheritedFromParent)) {
|
|
||||||
FolderNode::AddNewInformation info = root->addNewInformation(files, contextNode);
|
FolderNode::AddNewInformation info = root->addNewInformation(files, contextNode);
|
||||||
auto item = new AddNewTree(root, children, info);
|
auto item = new AddNewTree(root, children, info);
|
||||||
selector->inspect(item, root == contextNode);
|
selector->inspect(item, root == contextNode);
|
||||||
|
@@ -122,11 +122,7 @@ public:
|
|||||||
PythonProjectNode(PythonProject *project);
|
PythonProjectNode(PythonProject *project);
|
||||||
|
|
||||||
bool showInSimpleTree() const override;
|
bool showInSimpleTree() const override;
|
||||||
|
|
||||||
QList<ProjectAction> supportedActions(Node *node) const override;
|
|
||||||
|
|
||||||
QString addFileFilter() const override;
|
QString addFileFilter() const override;
|
||||||
|
|
||||||
bool renameFile(const QString &filePath, const QString &newFilePath) override;
|
bool renameFile(const QString &filePath, const QString &newFilePath) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -655,13 +651,6 @@ bool PythonProjectNode::showInSimpleTree() const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ProjectAction> PythonProjectNode::supportedActions(Node *node) const
|
|
||||||
{
|
|
||||||
Q_UNUSED(node);
|
|
||||||
//return { AddNewFile, AddExistingFile, AddExistingDirectory, RemoveFile, Rename };
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
QString PythonProjectNode::addFileFilter() const
|
QString PythonProjectNode::addFileFilter() const
|
||||||
{
|
{
|
||||||
return QLatin1String("*.py");
|
return QLatin1String("*.py");
|
||||||
|
@@ -45,6 +45,8 @@
|
|||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
|
|
||||||
|
using namespace ProjectExplorer;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// Helpers:
|
// Helpers:
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
@@ -223,26 +225,23 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static QList<ProjectExplorer::ProjectAction> supportedNodeActions(ProjectExplorer::Node *node,
|
static bool supportsNodeAction(ProjectAction action, Node *node)
|
||||||
bool managesFiles)
|
|
||||||
{
|
{
|
||||||
QList<ProjectExplorer::ProjectAction> actions;
|
|
||||||
const QbsProject * const project = parentQbsProjectNode(node)->project();
|
const QbsProject * const project = parentQbsProjectNode(node)->project();
|
||||||
if (!project->isProjectEditable())
|
if (!project->isProjectEditable())
|
||||||
return actions;
|
return false;
|
||||||
if (managesFiles)
|
|
||||||
actions << ProjectExplorer::AddNewFile << ProjectExplorer::AddExistingFile;
|
|
||||||
|
|
||||||
auto equalsNodeFilePath = [node](const QString &str)
|
auto equalsNodeFilePath = [node](const QString &str)
|
||||||
{
|
{
|
||||||
return str == node->filePath().toString();
|
return str == node->filePath().toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
if (node->nodeType() == ProjectExplorer::NodeType::File
|
if (action == RemoveFile || action == Rename) {
|
||||||
&& !Utils::contains(project->qbsProject().buildSystemFiles(), equalsNodeFilePath)) {
|
if (node->nodeType() == ProjectExplorer::NodeType::File)
|
||||||
actions << ProjectExplorer::RemoveFile << ProjectExplorer::Rename;
|
return !Utils::contains(project->qbsProject().buildSystemFiles(), equalsNodeFilePath);
|
||||||
}
|
}
|
||||||
return actions;
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
@@ -271,9 +270,9 @@ QbsFolderNode::QbsFolderNode(const Utils::FileName &folderPath, ProjectExplorer:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ProjectExplorer::ProjectAction> QbsFolderNode::supportedActions(ProjectExplorer::Node *node) const
|
bool QbsFolderNode::supportsAction(ProjectAction action, Node *node) const
|
||||||
{
|
{
|
||||||
return supportedNodeActions(node, false);
|
return supportsNodeAction(action, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -289,12 +288,6 @@ bool QbsBaseProjectNode::showInSimpleTree() const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ProjectExplorer::ProjectAction> QbsBaseProjectNode::supportedActions(ProjectExplorer::Node *node) const
|
|
||||||
{
|
|
||||||
Q_UNUSED(node);
|
|
||||||
return QList<ProjectExplorer::ProjectAction>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
// QbsGroupNode:
|
// QbsGroupNode:
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
@@ -309,9 +302,12 @@ QbsGroupNode::QbsGroupNode(const qbs::GroupData &grp, const QString &productPath
|
|||||||
m_qbsGroupData = grp;
|
m_qbsGroupData = grp;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ProjectExplorer::ProjectAction> QbsGroupNode::supportedActions(ProjectExplorer::Node *node) const
|
bool QbsGroupNode::supportsAction(ProjectAction action, Node *node) const
|
||||||
{
|
{
|
||||||
return supportedNodeActions(node, true);
|
if (action == AddNewFile || action == AddExistingFile)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return supportsNodeAction(action, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QbsGroupNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
|
bool QbsGroupNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
|
||||||
@@ -388,9 +384,12 @@ bool QbsProductNode::showInSimpleTree() const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ProjectExplorer::ProjectAction> QbsProductNode::supportedActions(ProjectExplorer::Node *node) const
|
bool QbsProductNode::supportsAction(ProjectAction action, Node *node) const
|
||||||
{
|
{
|
||||||
return supportedNodeActions(node, true);
|
if (action == AddNewFile || action == AddExistingFile)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return supportsNodeAction(action, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QbsProductNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
|
bool QbsProductNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
|
||||||
|
@@ -55,7 +55,7 @@ public:
|
|||||||
const QString &displayName);
|
const QString &displayName);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<ProjectExplorer::ProjectAction> supportedActions(ProjectExplorer::Node *node) const override;
|
bool supportsAction(ProjectExplorer::ProjectAction action, Node *node) const final;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -70,10 +70,6 @@ public:
|
|||||||
explicit QbsBaseProjectNode(const Utils::FileName &absoluteFilePath);
|
explicit QbsBaseProjectNode(const Utils::FileName &absoluteFilePath);
|
||||||
|
|
||||||
bool showInSimpleTree() const override;
|
bool showInSimpleTree() const override;
|
||||||
|
|
||||||
QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const override;
|
|
||||||
private:
|
|
||||||
friend class QbsGroupNode;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
@@ -85,7 +81,7 @@ class QbsGroupNode : public QbsBaseProjectNode
|
|||||||
public:
|
public:
|
||||||
QbsGroupNode(const qbs::GroupData &grp, const QString &productPath);
|
QbsGroupNode(const qbs::GroupData &grp, const QString &productPath);
|
||||||
|
|
||||||
QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const override;
|
bool supportsAction(ProjectExplorer::ProjectAction action, Node *node) const final;
|
||||||
bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0) override;
|
bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0) override;
|
||||||
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0) override;
|
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0) override;
|
||||||
bool renameFile(const QString &filePath, const QString &newFilePath) override;
|
bool renameFile(const QString &filePath, const QString &newFilePath) override;
|
||||||
@@ -107,7 +103,7 @@ public:
|
|||||||
explicit QbsProductNode(const qbs::ProductData &prd);
|
explicit QbsProductNode(const qbs::ProductData &prd);
|
||||||
|
|
||||||
bool showInSimpleTree() const override;
|
bool showInSimpleTree() const override;
|
||||||
QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const override;
|
bool supportsAction(ProjectExplorer::ProjectAction action, Node *node) const final;
|
||||||
bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0) override;
|
bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0) override;
|
||||||
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0) override;
|
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0) override;
|
||||||
bool renameFile(const QString &filePath, const QString &newFilePath) override;
|
bool renameFile(const QString &filePath, const QString &newFilePath) override;
|
||||||
|
@@ -74,9 +74,13 @@ QmakeProFileNode *QmakePriFileNode::proFileNode() const
|
|||||||
return m_qmakeProFileNode;
|
return m_qmakeProFileNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ProjectAction> QmakePriFileNode::supportedActions(Node *node) const
|
bool QmakePriFileNode::supportsAction(ProjectAction action, Node *node) const
|
||||||
{
|
{
|
||||||
QList<ProjectAction> actions;
|
if (action == Rename || action == DuplicateFile) {
|
||||||
|
FileNode *fileNode = node->asFileNode();
|
||||||
|
return (fileNode && fileNode->fileType() != FileType::Project)
|
||||||
|
|| dynamic_cast<ResourceEditor::ResourceTopLevelNode *>(node);
|
||||||
|
}
|
||||||
|
|
||||||
const FolderNode *folderNode = this;
|
const FolderNode *folderNode = this;
|
||||||
const QmakeProFileNode *proFileNode;
|
const QmakeProFileNode *proFileNode;
|
||||||
@@ -93,12 +97,12 @@ QList<ProjectAction> QmakePriFileNode::supportedActions(Node *node) const
|
|||||||
// TODO: Some of the file types don't make much sense for aux
|
// TODO: Some of the file types don't make much sense for aux
|
||||||
// projects (e.g. cpp). It'd be nice if the "add" action could
|
// projects (e.g. cpp). It'd be nice if the "add" action could
|
||||||
// work on a subset of the file types according to project type.
|
// work on a subset of the file types according to project type.
|
||||||
|
if (action == AddNewFile)
|
||||||
actions << AddNewFile;
|
return true;
|
||||||
if (pro && pro->knowsFile(node->filePath()))
|
if (action == EraseFile)
|
||||||
actions << EraseFile;
|
return pro && pro->knowsFile(node->filePath());
|
||||||
else
|
if (action == RemoveFile)
|
||||||
actions << RemoveFile;
|
return !(pro && pro->knowsFile(node->filePath()));
|
||||||
|
|
||||||
bool addExistingFiles = true;
|
bool addExistingFiles = true;
|
||||||
if (node->nodeType() == NodeType::VirtualFolder) {
|
if (node->nodeType() == NodeType::VirtualFolder) {
|
||||||
@@ -115,31 +119,26 @@ QList<ProjectAction> QmakePriFileNode::supportedActions(Node *node) const
|
|||||||
|
|
||||||
addExistingFiles = addExistingFiles && !deploysFolder(node->filePath().toString());
|
addExistingFiles = addExistingFiles && !deploysFolder(node->filePath().toString());
|
||||||
|
|
||||||
if (addExistingFiles)
|
if (action == AddExistingFile || action == AddExistingDirectory)
|
||||||
actions << AddExistingFile << AddExistingDirectory;
|
return addExistingFiles;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ProjectType::SubDirsTemplate:
|
case ProjectType::SubDirsTemplate:
|
||||||
actions << AddSubProject << RemoveSubProject;
|
if (action == AddSubProject || action == RemoveSubProject)
|
||||||
|
return true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileNode *fileNode = node->asFileNode();
|
if (action == HasSubProjectRunConfigurations) {
|
||||||
if ((fileNode && fileNode->fileType() != FileType::Project)
|
|
||||||
|| dynamic_cast<ResourceEditor::ResourceTopLevelNode *>(node)) {
|
|
||||||
actions << Rename;
|
|
||||||
actions << DuplicateFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
Target *target = m_project->activeTarget();
|
Target *target = m_project->activeTarget();
|
||||||
QmakeRunConfigurationFactory *factory = QmakeRunConfigurationFactory::find(target);
|
QmakeRunConfigurationFactory *factory = QmakeRunConfigurationFactory::find(target);
|
||||||
if (factory && !factory->runConfigurationsForNode(target, node).isEmpty())
|
return factory && !factory->runConfigurationsForNode(target, node).isEmpty();
|
||||||
actions << HasSubProjectRunConfigurations;
|
}
|
||||||
|
|
||||||
return actions;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QmakePriFileNode::canAddSubProject(const QString &proFilePath) const
|
bool QmakePriFileNode::canAddSubProject(const QString &proFilePath) const
|
||||||
|
@@ -47,7 +47,7 @@ public:
|
|||||||
QmakePriFile *priFile() const;
|
QmakePriFile *priFile() const;
|
||||||
|
|
||||||
// ProjectNode interface
|
// ProjectNode interface
|
||||||
QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const override;
|
bool supportsAction(ProjectExplorer::ProjectAction action, Node *node) const override;
|
||||||
|
|
||||||
bool showInSimpleTree() const override { return false; }
|
bool showInSimpleTree() const override { return false; }
|
||||||
|
|
||||||
|
@@ -438,7 +438,7 @@ bool DocumentManager::isoProFileSupportsAddingExistingFiles(const QString &resou
|
|||||||
ProjectExplorer::ProjectNode *projectNode = node->parentFolderNode()->asProjectNode();
|
ProjectExplorer::ProjectNode *projectNode = node->parentFolderNode()->asProjectNode();
|
||||||
if (!projectNode)
|
if (!projectNode)
|
||||||
return false;
|
return false;
|
||||||
if (!projectNode->supportedActions(projectNode).contains(ProjectExplorer::AddExistingFile)) {
|
if (!projectNode->supportsAction(ProjectExplorer::AddExistingFile, projectNode)) {
|
||||||
qCWarning(documentManagerLog) << "Project" << projectNode->displayName() << "does not support adding existing files";
|
qCWarning(documentManagerLog) << "Project" << projectNode->displayName() << "does not support adding existing files";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -57,15 +57,17 @@ bool QmlProjectNode::showInSimpleTree() const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ProjectAction> QmlProjectNode::supportedActions(Node *node) const
|
bool QmlProjectNode::supportsAction(ProjectAction action, Node *node) const
|
||||||
{
|
{
|
||||||
QList<ProjectAction> actions = {AddNewFile, EraseFile};
|
if (action == AddNewFile || action == EraseFile)
|
||||||
if (node->nodeType() == NodeType::File) {
|
return true;
|
||||||
|
|
||||||
|
if (action == Rename && node->nodeType() == NodeType::File) {
|
||||||
FileNode *fileNode = static_cast<FileNode *>(node);
|
FileNode *fileNode = static_cast<FileNode *>(node);
|
||||||
if (fileNode->fileType() != FileType::Project)
|
return fileNode->fileType() != FileType::Project;
|
||||||
actions.append(Rename);
|
|
||||||
}
|
}
|
||||||
return actions;
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QmlProjectNode::addFiles(const QStringList &filePaths, QStringList * /*notAdded*/)
|
bool QmlProjectNode::addFiles(const QStringList &filePaths, QStringList * /*notAdded*/)
|
||||||
|
@@ -38,13 +38,11 @@ class QmlProjectNode : public ProjectExplorer::ProjectNode
|
|||||||
public:
|
public:
|
||||||
QmlProjectNode(QmlProject *project);
|
QmlProjectNode(QmlProject *project);
|
||||||
|
|
||||||
virtual bool showInSimpleTree() const override;
|
bool showInSimpleTree() const override;
|
||||||
|
bool supportsAction(ProjectExplorer::ProjectAction action, Node *node) const override;
|
||||||
virtual QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const override;
|
bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0) override;
|
||||||
|
bool deleteFiles(const QStringList &filePaths) override;
|
||||||
virtual bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0) override;
|
bool renameFile(const QString &filePath, const QString &newFilePath) override;
|
||||||
virtual bool deleteFiles(const QStringList &filePaths) override;
|
|
||||||
virtual bool renameFile(const QString &filePath, const QString &newFilePath) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QmlProject *m_project;
|
QmlProject *m_project;
|
||||||
|
@@ -338,8 +338,8 @@ void ResourceEditorPlugin::updateContextActions()
|
|||||||
|
|
||||||
if (isResourceNode) {
|
if (isResourceNode) {
|
||||||
FolderNode *parent = node ? node->parentFolderNode() : 0;
|
FolderNode *parent = node ? node->parentFolderNode() : 0;
|
||||||
enableRename = parent && parent->supportedActions(node).contains(Rename);
|
enableRename = parent && parent->supportsAction(Rename, node);
|
||||||
enableRemove = parent && parent->supportedActions(node).contains(RemoveFile);
|
enableRemove = parent && parent->supportsAction(RemoveFile, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_renameResourceFile->setEnabled(isResourceNode && enableRename);
|
m_renameResourceFile->setEnabled(isResourceNode && enableRename);
|
||||||
|
@@ -160,7 +160,7 @@ public:
|
|||||||
ResourceTopLevelNode *topLevel, ResourceFolderNode *prefixNode);
|
ResourceTopLevelNode *topLevel, ResourceFolderNode *prefixNode);
|
||||||
|
|
||||||
QString displayName() const final;
|
QString displayName() const final;
|
||||||
QList<ProjectAction> supportedActions(Node *node) const final;
|
bool supportsAction(ProjectAction, Node *node) const final;
|
||||||
bool addFiles(const QStringList &filePaths, QStringList *notAdded) final;
|
bool addFiles(const QStringList &filePaths, QStringList *notAdded) final;
|
||||||
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved) final;
|
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved) final;
|
||||||
bool renameFile(const QString &filePath, const QString &newFilePath) final;
|
bool renameFile(const QString &filePath, const QString &newFilePath) final;
|
||||||
@@ -199,17 +199,15 @@ SimpleResourceFolderNode::SimpleResourceFolderNode(const QString &afolderName, c
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ProjectAction> SimpleResourceFolderNode::supportedActions(Node *) const
|
bool SimpleResourceFolderNode::supportsAction(ProjectAction action, Node *) const
|
||||||
{
|
{
|
||||||
return {
|
return action == AddNewFile
|
||||||
AddNewFile,
|
|| action == AddExistingFile
|
||||||
AddExistingFile,
|
|| action == AddExistingDirectory
|
||||||
AddExistingDirectory,
|
|| action == RemoveFile
|
||||||
RemoveFile,
|
|| action == DuplicateFile
|
||||||
DuplicateFile,
|
|| action == Rename // Note: only works for the filename, works akwardly for relative file paths
|
||||||
Rename, // Note: only works for the filename, works akwardly for relative file paths
|
|| action == InheritedFromParent; // Do not add to list of projects when adding new file
|
||||||
InheritedFromParent // Do not add to list of projects when adding new file
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SimpleResourceFolderNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
|
bool SimpleResourceFolderNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
|
||||||
@@ -387,11 +385,15 @@ QString ResourceTopLevelNode::addFileFilter() const
|
|||||||
return QLatin1String("*.png; *.jpg; *.gif; *.svg; *.ico; *.qml; *.qml.ui");
|
return QLatin1String("*.png; *.jpg; *.gif; *.svg; *.ico; *.qml; *.qml.ui");
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ProjectAction> ResourceTopLevelNode::supportedActions(Node *node) const
|
bool ResourceTopLevelNode::supportsAction(ProjectAction action, Node *node) const
|
||||||
{
|
{
|
||||||
if (node != this)
|
if (node != this)
|
||||||
return {};
|
return false;
|
||||||
return {AddNewFile, AddExistingFile, AddExistingDirectory, HidePathActions, Rename};
|
return action == AddNewFile
|
||||||
|
|| action == AddExistingFile
|
||||||
|
|| action == AddExistingDirectory
|
||||||
|
|| action == HidePathActions
|
||||||
|
|| action == Rename;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ResourceTopLevelNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
|
bool ResourceTopLevelNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
|
||||||
@@ -504,25 +506,23 @@ ResourceFolderNode::~ResourceFolderNode()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ProjectAction> ResourceFolderNode::supportedActions(Node *node) const
|
bool ResourceFolderNode::supportsAction(ProjectAction action, Node *node) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(node)
|
Q_UNUSED(node)
|
||||||
QList<ProjectAction> actions = {
|
|
||||||
AddNewFile,
|
|
||||||
AddExistingFile,
|
|
||||||
AddExistingDirectory,
|
|
||||||
RemoveFile,
|
|
||||||
DuplicateFile,
|
|
||||||
Rename, // Note: only works for the filename, works akwardly for relative file paths
|
|
||||||
HidePathActions, // hides open terminal etc.
|
|
||||||
};
|
|
||||||
|
|
||||||
|
if (action == InheritedFromParent) {
|
||||||
// if the prefix is '/' (without lang) hide this node in add new dialog,
|
// if the prefix is '/' (without lang) hide this node in add new dialog,
|
||||||
// as the ResouceTopLevelNode is always shown for the '/' prefix
|
// as the ResouceTopLevelNode is always shown for the '/' prefix
|
||||||
if (m_prefix == QLatin1String("/") && m_lang.isEmpty())
|
return m_prefix == QLatin1String("/") && m_lang.isEmpty();
|
||||||
actions << InheritedFromParent;
|
}
|
||||||
|
|
||||||
return actions;
|
return action == AddNewFile
|
||||||
|
|| action == AddExistingFile
|
||||||
|
|| action == AddExistingDirectory
|
||||||
|
|| action == RemoveFile
|
||||||
|
|| action == DuplicateFile
|
||||||
|
|| action == Rename // Note: only works for the filename, works akwardly for relative file paths
|
||||||
|
|| action == HidePathActions; // hides open terminal etc.
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ResourceFolderNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
|
bool ResourceFolderNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
|
||||||
@@ -674,12 +674,11 @@ QString ResourceFileNode::qrcPath() const
|
|||||||
return m_qrcPath;
|
return m_qrcPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ProjectAction> ResourceFileNode::supportedActions(Node *node) const
|
bool ResourceFileNode::supportsAction(ProjectAction action, Node *node) const
|
||||||
{
|
{
|
||||||
QList<ProjectAction> actions = parentFolderNode()->supportedActions(node);
|
if (action == HidePathActions)
|
||||||
actions.removeOne(HidePathActions);
|
return false;
|
||||||
return actions;
|
return parentFolderNode()->supportsAction(action, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // ResourceEditor
|
} // ResourceEditor
|
||||||
|
@@ -41,7 +41,7 @@ public:
|
|||||||
|
|
||||||
QString addFileFilter() const override;
|
QString addFileFilter() const override;
|
||||||
|
|
||||||
QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const override;
|
bool supportsAction(ProjectExplorer::ProjectAction action, Node *node) const override;
|
||||||
bool addFiles(const QStringList &filePaths, QStringList *notAdded) override;
|
bool addFiles(const QStringList &filePaths, QStringList *notAdded) override;
|
||||||
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved) override;
|
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved) override;
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ public:
|
|||||||
ResourceFolderNode(const QString &prefix, const QString &lang, ResourceTopLevelNode *parent);
|
ResourceFolderNode(const QString &prefix, const QString &lang, ResourceTopLevelNode *parent);
|
||||||
~ResourceFolderNode() override;
|
~ResourceFolderNode() override;
|
||||||
|
|
||||||
QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const override;
|
bool supportsAction(ProjectExplorer::ProjectAction action, Node *node) const override;
|
||||||
|
|
||||||
QString displayName() const override;
|
QString displayName() const override;
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ public:
|
|||||||
|
|
||||||
QString displayName() const override;
|
QString displayName() const override;
|
||||||
QString qrcPath() const;
|
QString qrcPath() const;
|
||||||
QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const override;
|
bool supportsAction(ProjectExplorer::ProjectAction action, Node *node) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_qrcPath;
|
QString m_qrcPath;
|
||||||
|
Reference in New Issue
Block a user