forked from qt-creator/qt-creator
Pass the new node in ProjectTree::currentNodeChanged
Avoids some roundtrips asking for ProjectTree::currentNode() which traverses the project tree every time. Change-Id: I650728eab5a47a7f4760cf88844a4b7106365255 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -130,26 +130,28 @@ CMakeManager::CMakeManager()
|
|||||||
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD);
|
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD);
|
||||||
connect(m_buildFileAction, &QAction::triggered, this, [this] { buildFile(); });
|
connect(m_buildFileAction, &QAction::triggered, this, [this] { buildFile(); });
|
||||||
|
|
||||||
connect(SessionManager::instance(), &SessionManager::startupProjectChanged,
|
connect(SessionManager::instance(), &SessionManager::startupProjectChanged, this, [this] {
|
||||||
this, &CMakeManager::updateCmakeActions);
|
updateCmakeActions(ProjectTree::currentNode());
|
||||||
connect(BuildManager::instance(), &BuildManager::buildStateChanged,
|
});
|
||||||
this, &CMakeManager::updateCmakeActions);
|
connect(BuildManager::instance(), &BuildManager::buildStateChanged, this, [this] {
|
||||||
|
updateCmakeActions(ProjectTree::currentNode());
|
||||||
|
});
|
||||||
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged,
|
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged,
|
||||||
this, &CMakeManager::updateBuildFileAction);
|
this, &CMakeManager::updateBuildFileAction);
|
||||||
connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged,
|
connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged,
|
||||||
this, &CMakeManager::updateCmakeActions);
|
this, &CMakeManager::updateCmakeActions);
|
||||||
|
|
||||||
updateCmakeActions();
|
updateCmakeActions(ProjectTree::currentNode());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMakeManager::updateCmakeActions()
|
void CMakeManager::updateCmakeActions(Node *node)
|
||||||
{
|
{
|
||||||
auto project = qobject_cast<CMakeProject *>(SessionManager::startupProject());
|
auto project = qobject_cast<CMakeProject *>(SessionManager::startupProject());
|
||||||
const bool visible = project && !BuildManager::isBuilding(project);
|
const bool visible = project && !BuildManager::isBuilding(project);
|
||||||
m_runCMakeAction->setVisible(visible);
|
m_runCMakeAction->setVisible(visible);
|
||||||
m_clearCMakeCacheAction->setVisible(visible);
|
m_clearCMakeCacheAction->setVisible(visible);
|
||||||
m_rescanProjectAction->setVisible(visible);
|
m_rescanProjectAction->setVisible(visible);
|
||||||
enableBuildFileMenus(ProjectTree::currentNode());
|
enableBuildFileMenus(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMakeManager::clearCMakeCache(BuildSystem *buildSystem)
|
void CMakeManager::clearCMakeCache(BuildSystem *buildSystem)
|
||||||
|
@@ -44,7 +44,7 @@ public:
|
|||||||
CMakeManager();
|
CMakeManager();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateCmakeActions();
|
void updateCmakeActions(ProjectExplorer::Node *node);
|
||||||
void clearCMakeCache(ProjectExplorer::BuildSystem *buildSystem);
|
void clearCMakeCache(ProjectExplorer::BuildSystem *buildSystem);
|
||||||
void runCMake(ProjectExplorer::BuildSystem *buildSystem);
|
void runCMake(ProjectExplorer::BuildSystem *buildSystem);
|
||||||
void rescanProject(ProjectExplorer::BuildSystem *buildSystem);
|
void rescanProject(ProjectExplorer::BuildSystem *buildSystem);
|
||||||
|
@@ -142,9 +142,9 @@ void CMakeProjectPlugin::extensionsInitialized()
|
|||||||
CMakeToolManager::restoreCMakeTools();
|
CMakeToolManager::restoreCMakeTools();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMakeProjectPlugin::updateContextActions()
|
void CMakeProjectPlugin::updateContextActions(Node *node)
|
||||||
{
|
{
|
||||||
auto targetNode = dynamic_cast<const CMakeTargetNode *>(ProjectTree::currentNode());
|
auto targetNode = dynamic_cast<const CMakeTargetNode *>(node);
|
||||||
const QString targetDisplayName = targetNode ? targetNode->displayName() : QString();
|
const QString targetDisplayName = targetNode ? targetNode->displayName() : QString();
|
||||||
|
|
||||||
// Build Target:
|
// Build Target:
|
||||||
|
@@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
#include <extensionsystem/iplugin.h>
|
#include <extensionsystem/iplugin.h>
|
||||||
|
|
||||||
|
namespace ProjectExplorer { class Node; }
|
||||||
|
|
||||||
namespace CMakeProjectManager {
|
namespace CMakeProjectManager {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -60,7 +62,7 @@ private:
|
|||||||
bool initialize(const QStringList &arguments, QString *errorMessage) final;
|
bool initialize(const QStringList &arguments, QString *errorMessage) final;
|
||||||
void extensionsInitialized() final;
|
void extensionsInitialized() final;
|
||||||
|
|
||||||
void updateContextActions();
|
void updateContextActions(ProjectExplorer::Node *node);
|
||||||
|
|
||||||
class CMakeProjectPluginPrivate *d = nullptr;
|
class CMakeProjectPluginPrivate *d = nullptr;
|
||||||
};
|
};
|
||||||
|
@@ -403,7 +403,7 @@ class ProjectExplorerPluginPrivate : public QObject
|
|||||||
public:
|
public:
|
||||||
ProjectExplorerPluginPrivate();
|
ProjectExplorerPluginPrivate();
|
||||||
|
|
||||||
void updateContextMenuActions();
|
void updateContextMenuActions(Node *currentNode);
|
||||||
void updateLocationSubMenus();
|
void updateLocationSubMenus();
|
||||||
void executeRunConfiguration(RunConfiguration *, Utils::Id mode);
|
void executeRunConfiguration(RunConfiguration *, Utils::Id mode);
|
||||||
QPair<bool, QString> buildSettingsEnabledForSession();
|
QPair<bool, QString> buildSettingsEnabledForSession();
|
||||||
@@ -767,10 +767,12 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
|||||||
});
|
});
|
||||||
|
|
||||||
ProjectTree *tree = &dd->m_projectTree;
|
ProjectTree *tree = &dd->m_projectTree;
|
||||||
connect(tree, &ProjectTree::currentProjectChanged,
|
connect(tree, &ProjectTree::currentProjectChanged, dd, [] {
|
||||||
dd, &ProjectExplorerPluginPrivate::updateContextMenuActions);
|
dd->updateContextMenuActions(ProjectTree::currentNode());
|
||||||
connect(tree, &ProjectTree::nodeActionsChanged,
|
});
|
||||||
dd, &ProjectExplorerPluginPrivate::updateContextMenuActions);
|
connect(tree, &ProjectTree::nodeActionsChanged, dd, [] {
|
||||||
|
dd->updateContextMenuActions(ProjectTree::currentNode());
|
||||||
|
});
|
||||||
connect(tree, &ProjectTree::currentNodeChanged,
|
connect(tree, &ProjectTree::currentNodeChanged,
|
||||||
dd, &ProjectExplorerPluginPrivate::updateContextMenuActions);
|
dd, &ProjectExplorerPluginPrivate::updateContextMenuActions);
|
||||||
connect(tree, &ProjectTree::currentProjectChanged,
|
connect(tree, &ProjectTree::currentProjectChanged,
|
||||||
@@ -1763,8 +1765,9 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
|||||||
connect(this, &ProjectExplorerPlugin::settingsChanged,
|
connect(this, &ProjectExplorerPlugin::settingsChanged,
|
||||||
dd, &ProjectExplorerPluginPrivate::updateRunWithoutDeployMenu);
|
dd, &ProjectExplorerPluginPrivate::updateRunWithoutDeployMenu);
|
||||||
|
|
||||||
connect(ICore::instance(), &ICore::newItemDialogStateChanged,
|
connect(ICore::instance(), &ICore::newItemDialogStateChanged, dd, [] {
|
||||||
dd, &ProjectExplorerPluginPrivate::updateContextMenuActions);
|
dd->updateContextMenuActions(ProjectTree::currentNode());
|
||||||
|
});
|
||||||
|
|
||||||
dd->updateWelcomePage();
|
dd->updateWelcomePage();
|
||||||
|
|
||||||
@@ -3257,7 +3260,7 @@ void ProjectExplorerPluginPrivate::invalidateProject(Project *project)
|
|||||||
updateActions();
|
updateActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectExplorerPluginPrivate::updateContextMenuActions()
|
void ProjectExplorerPluginPrivate::updateContextMenuActions(Node *currentNode)
|
||||||
{
|
{
|
||||||
m_addExistingFilesAction->setEnabled(false);
|
m_addExistingFilesAction->setEnabled(false);
|
||||||
m_addExistingDirectoryAction->setEnabled(false);
|
m_addExistingDirectoryAction->setEnabled(false);
|
||||||
@@ -3294,8 +3297,6 @@ void ProjectExplorerPluginPrivate::updateContextMenuActions()
|
|||||||
runMenu->menu()->clear();
|
runMenu->menu()->clear();
|
||||||
runMenu->menu()->menuAction()->setVisible(false);
|
runMenu->menu()->menuAction()->setVisible(false);
|
||||||
|
|
||||||
const Node *currentNode = ProjectTree::currentNode();
|
|
||||||
|
|
||||||
if (currentNode && currentNode->managingProject()) {
|
if (currentNode && currentNode->managingProject()) {
|
||||||
ProjectNode *pn;
|
ProjectNode *pn;
|
||||||
if (const ContainerNode *cn = currentNode->asContainerNode())
|
if (const ContainerNode *cn = currentNode->asContainerNode())
|
||||||
|
@@ -227,7 +227,7 @@ void ProjectTree::setCurrent(Node *node, Project *project)
|
|||||||
|
|
||||||
if (node != m_currentNode) {
|
if (node != m_currentNode) {
|
||||||
m_currentNode = node;
|
m_currentNode = node;
|
||||||
emit currentNodeChanged();
|
emit currentNodeChanged(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changedProject) {
|
if (changedProject) {
|
||||||
|
@@ -104,7 +104,7 @@ public:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void currentProjectChanged(ProjectExplorer::Project *project);
|
void currentProjectChanged(ProjectExplorer::Project *project);
|
||||||
void currentNodeChanged();
|
void currentNodeChanged(Node *node);
|
||||||
void nodeActionsChanged();
|
void nodeActionsChanged();
|
||||||
|
|
||||||
// Emitted whenever the model needs to send a update signal.
|
// Emitted whenever the model needs to send a update signal.
|
||||||
|
@@ -262,7 +262,7 @@ bool QbsProjectManagerPlugin::initialize(const QStringList &arguments, QString *
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Run initial setup routines
|
// Run initial setup routines
|
||||||
updateContextActions();
|
updateContextActions(ProjectTree::currentNode());
|
||||||
updateReparseQbsAction();
|
updateReparseQbsAction();
|
||||||
updateBuildActions();
|
updateBuildActions();
|
||||||
|
|
||||||
@@ -280,10 +280,9 @@ void QbsProjectManagerPlugin::targetWasAdded(Target *target)
|
|||||||
this, &QbsProjectManagerPlugin::projectChanged);
|
this, &QbsProjectManagerPlugin::projectChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QbsProjectManagerPlugin::updateContextActions()
|
void QbsProjectManagerPlugin::updateContextActions(Node *node)
|
||||||
{
|
{
|
||||||
auto project = qobject_cast<Internal::QbsProject *>(ProjectTree::currentProject());
|
auto project = qobject_cast<Internal::QbsProject *>(ProjectTree::currentProject());
|
||||||
const Node *node = ProjectTree::currentNode();
|
|
||||||
bool isEnabled = !BuildManager::isBuilding(project)
|
bool isEnabled = !BuildManager::isBuilding(project)
|
||||||
&& project && project->activeTarget()
|
&& project && project->activeTarget()
|
||||||
&& !project->activeTarget()->buildSystem()->isParsing()
|
&& !project->activeTarget()->buildSystem()->isParsing()
|
||||||
@@ -369,7 +368,7 @@ void QbsProjectManagerPlugin::projectChanged()
|
|||||||
updateReparseQbsAction();
|
updateReparseQbsAction();
|
||||||
|
|
||||||
if (!project || project == ProjectTree::currentProject())
|
if (!project || project == ProjectTree::currentProject())
|
||||||
updateContextActions();
|
updateContextActions(ProjectTree::currentNode());
|
||||||
|
|
||||||
if (!project || project == currentEditorProject())
|
if (!project || project == currentEditorProject())
|
||||||
updateBuildActions();
|
updateBuildActions();
|
||||||
|
@@ -29,7 +29,10 @@
|
|||||||
#include <utils/id.h>
|
#include <utils/id.h>
|
||||||
#include <utils/parameteraction.h>
|
#include <utils/parameteraction.h>
|
||||||
|
|
||||||
namespace ProjectExplorer { class Target; }
|
namespace ProjectExplorer {
|
||||||
|
class Target;
|
||||||
|
class Node;
|
||||||
|
} // namespace ProjectExplorer
|
||||||
|
|
||||||
namespace QbsProjectManager {
|
namespace QbsProjectManager {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -72,7 +75,7 @@ private:
|
|||||||
void reparseCurrentProject();
|
void reparseCurrentProject();
|
||||||
void reparseProject(QbsProject *project);
|
void reparseProject(QbsProject *project);
|
||||||
|
|
||||||
void updateContextActions();
|
void updateContextActions(ProjectExplorer::Node *node);
|
||||||
void updateReparseQbsAction();
|
void updateReparseQbsAction();
|
||||||
void updateBuildActions();
|
void updateBuildActions();
|
||||||
|
|
||||||
|
@@ -86,7 +86,7 @@ public:
|
|||||||
void activeTargetChanged();
|
void activeTargetChanged();
|
||||||
void updateActions();
|
void updateActions();
|
||||||
void updateRunQMakeAction();
|
void updateRunQMakeAction();
|
||||||
void updateContextActions();
|
void updateContextActions(Node *node);
|
||||||
void buildStateChanged(Project *pro);
|
void buildStateChanged(Project *pro);
|
||||||
void updateBuildFileAction();
|
void updateBuildFileAction();
|
||||||
void disableBuildFileMenus();
|
void disableBuildFileMenus();
|
||||||
@@ -496,7 +496,7 @@ void QmakeProjectManagerPluginPrivate::activeTargetChanged()
|
|||||||
void QmakeProjectManagerPluginPrivate::updateActions()
|
void QmakeProjectManagerPluginPrivate::updateActions()
|
||||||
{
|
{
|
||||||
updateRunQMakeAction();
|
updateRunQMakeAction();
|
||||||
updateContextActions();
|
updateContextActions(ProjectTree::currentNode());
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmakeProjectManagerPluginPrivate::updateRunQMakeAction()
|
void QmakeProjectManagerPluginPrivate::updateRunQMakeAction()
|
||||||
@@ -515,9 +515,8 @@ void QmakeProjectManagerPluginPrivate::updateRunQMakeAction()
|
|||||||
m_runQMakeAction->setEnabled(enable);
|
m_runQMakeAction->setEnabled(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmakeProjectManagerPluginPrivate::updateContextActions()
|
void QmakeProjectManagerPluginPrivate::updateContextActions(Node *node)
|
||||||
{
|
{
|
||||||
const Node *node = ProjectTree::currentNode();
|
|
||||||
Project *project = ProjectTree::currentProject();
|
Project *project = ProjectTree::currentProject();
|
||||||
|
|
||||||
const ContainerNode *containerNode = node ? node->asContainerNode() : nullptr;
|
const ContainerNode *containerNode = node ? node->asContainerNode() : nullptr;
|
||||||
@@ -578,7 +577,7 @@ void QmakeProjectManagerPluginPrivate::buildStateChanged(Project *pro)
|
|||||||
{
|
{
|
||||||
if (pro == ProjectTree::currentProject()) {
|
if (pro == ProjectTree::currentProject()) {
|
||||||
updateRunQMakeAction();
|
updateRunQMakeAction();
|
||||||
updateContextActions();
|
updateContextActions(ProjectTree::currentNode());
|
||||||
updateBuildFileAction();
|
updateBuildFileAction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -236,8 +236,7 @@ QmlPreviewPluginPrivate::QmlPreviewPluginPrivate(QmlPreviewPlugin *parent)
|
|||||||
Core::ActionManager::registerAction(action, "QmlPreview.PreviewFile", Core::Context(Constants::C_PROJECT_TREE)),
|
Core::ActionManager::registerAction(action, "QmlPreview.PreviewFile", Core::Context(Constants::C_PROJECT_TREE)),
|
||||||
Constants::G_FILE_OTHER);
|
Constants::G_FILE_OTHER);
|
||||||
action->setVisible(false);
|
action->setVisible(false);
|
||||||
connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged, action, [action]() {
|
connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged, action, [action](Node *node) {
|
||||||
const Node *node = ProjectTree::currentNode();
|
|
||||||
const FileNode *fileNode = node ? node->asFileNode() : nullptr;
|
const FileNode *fileNode = node ? node->asFileNode() : nullptr;
|
||||||
action->setVisible(fileNode ? fileNode->fileType() == FileType::QML : false);
|
action->setVisible(fileNode ? fileNode->fileType() == FileType::QML : false);
|
||||||
});
|
});
|
||||||
|
@@ -132,7 +132,7 @@ public:
|
|||||||
void copyPathContextMenu();
|
void copyPathContextMenu();
|
||||||
void copyUrlContextMenu();
|
void copyUrlContextMenu();
|
||||||
|
|
||||||
void updateContextActions();
|
void updateContextActions(Node *node);
|
||||||
|
|
||||||
ResourceEditorW * currentEditor() const;
|
ResourceEditorW * currentEditor() const;
|
||||||
|
|
||||||
@@ -368,9 +368,8 @@ void ResourceEditorPluginPrivate::renamePrefixContextMenu()
|
|||||||
node->renamePrefix(prefix, dialog.lang());
|
node->renamePrefix(prefix, dialog.lang());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceEditorPluginPrivate::updateContextActions()
|
void ResourceEditorPluginPrivate::updateContextActions(Node *node)
|
||||||
{
|
{
|
||||||
const Node *node = ProjectTree::currentNode();
|
|
||||||
const bool isResourceNode = dynamic_cast<const ResourceTopLevelNode *>(node);
|
const bool isResourceNode = dynamic_cast<const ResourceTopLevelNode *>(node);
|
||||||
m_addPrefix->setEnabled(isResourceNode);
|
m_addPrefix->setEnabled(isResourceNode);
|
||||||
m_addPrefix->setVisible(isResourceNode);
|
m_addPrefix->setVisible(isResourceNode);
|
||||||
|
Reference in New Issue
Block a user