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);
|
||||
connect(m_buildFileAction, &QAction::triggered, this, [this] { buildFile(); });
|
||||
|
||||
connect(SessionManager::instance(), &SessionManager::startupProjectChanged,
|
||||
this, &CMakeManager::updateCmakeActions);
|
||||
connect(BuildManager::instance(), &BuildManager::buildStateChanged,
|
||||
this, &CMakeManager::updateCmakeActions);
|
||||
connect(SessionManager::instance(), &SessionManager::startupProjectChanged, this, [this] {
|
||||
updateCmakeActions(ProjectTree::currentNode());
|
||||
});
|
||||
connect(BuildManager::instance(), &BuildManager::buildStateChanged, this, [this] {
|
||||
updateCmakeActions(ProjectTree::currentNode());
|
||||
});
|
||||
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged,
|
||||
this, &CMakeManager::updateBuildFileAction);
|
||||
connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged,
|
||||
this, &CMakeManager::updateCmakeActions);
|
||||
|
||||
updateCmakeActions();
|
||||
updateCmakeActions(ProjectTree::currentNode());
|
||||
}
|
||||
|
||||
void CMakeManager::updateCmakeActions()
|
||||
void CMakeManager::updateCmakeActions(Node *node)
|
||||
{
|
||||
auto project = qobject_cast<CMakeProject *>(SessionManager::startupProject());
|
||||
const bool visible = project && !BuildManager::isBuilding(project);
|
||||
m_runCMakeAction->setVisible(visible);
|
||||
m_clearCMakeCacheAction->setVisible(visible);
|
||||
m_rescanProjectAction->setVisible(visible);
|
||||
enableBuildFileMenus(ProjectTree::currentNode());
|
||||
enableBuildFileMenus(node);
|
||||
}
|
||||
|
||||
void CMakeManager::clearCMakeCache(BuildSystem *buildSystem)
|
||||
|
@@ -44,7 +44,7 @@ public:
|
||||
CMakeManager();
|
||||
|
||||
private:
|
||||
void updateCmakeActions();
|
||||
void updateCmakeActions(ProjectExplorer::Node *node);
|
||||
void clearCMakeCache(ProjectExplorer::BuildSystem *buildSystem);
|
||||
void runCMake(ProjectExplorer::BuildSystem *buildSystem);
|
||||
void rescanProject(ProjectExplorer::BuildSystem *buildSystem);
|
||||
|
@@ -142,9 +142,9 @@ void CMakeProjectPlugin::extensionsInitialized()
|
||||
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();
|
||||
|
||||
// Build Target:
|
||||
|
@@ -27,6 +27,8 @@
|
||||
|
||||
#include <extensionsystem/iplugin.h>
|
||||
|
||||
namespace ProjectExplorer { class Node; }
|
||||
|
||||
namespace CMakeProjectManager {
|
||||
namespace Internal {
|
||||
|
||||
@@ -60,7 +62,7 @@ private:
|
||||
bool initialize(const QStringList &arguments, QString *errorMessage) final;
|
||||
void extensionsInitialized() final;
|
||||
|
||||
void updateContextActions();
|
||||
void updateContextActions(ProjectExplorer::Node *node);
|
||||
|
||||
class CMakeProjectPluginPrivate *d = nullptr;
|
||||
};
|
||||
|
@@ -403,7 +403,7 @@ class ProjectExplorerPluginPrivate : public QObject
|
||||
public:
|
||||
ProjectExplorerPluginPrivate();
|
||||
|
||||
void updateContextMenuActions();
|
||||
void updateContextMenuActions(Node *currentNode);
|
||||
void updateLocationSubMenus();
|
||||
void executeRunConfiguration(RunConfiguration *, Utils::Id mode);
|
||||
QPair<bool, QString> buildSettingsEnabledForSession();
|
||||
@@ -767,10 +767,12 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
||||
});
|
||||
|
||||
ProjectTree *tree = &dd->m_projectTree;
|
||||
connect(tree, &ProjectTree::currentProjectChanged,
|
||||
dd, &ProjectExplorerPluginPrivate::updateContextMenuActions);
|
||||
connect(tree, &ProjectTree::nodeActionsChanged,
|
||||
dd, &ProjectExplorerPluginPrivate::updateContextMenuActions);
|
||||
connect(tree, &ProjectTree::currentProjectChanged, dd, [] {
|
||||
dd->updateContextMenuActions(ProjectTree::currentNode());
|
||||
});
|
||||
connect(tree, &ProjectTree::nodeActionsChanged, dd, [] {
|
||||
dd->updateContextMenuActions(ProjectTree::currentNode());
|
||||
});
|
||||
connect(tree, &ProjectTree::currentNodeChanged,
|
||||
dd, &ProjectExplorerPluginPrivate::updateContextMenuActions);
|
||||
connect(tree, &ProjectTree::currentProjectChanged,
|
||||
@@ -1763,8 +1765,9 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
||||
connect(this, &ProjectExplorerPlugin::settingsChanged,
|
||||
dd, &ProjectExplorerPluginPrivate::updateRunWithoutDeployMenu);
|
||||
|
||||
connect(ICore::instance(), &ICore::newItemDialogStateChanged,
|
||||
dd, &ProjectExplorerPluginPrivate::updateContextMenuActions);
|
||||
connect(ICore::instance(), &ICore::newItemDialogStateChanged, dd, [] {
|
||||
dd->updateContextMenuActions(ProjectTree::currentNode());
|
||||
});
|
||||
|
||||
dd->updateWelcomePage();
|
||||
|
||||
@@ -3257,7 +3260,7 @@ void ProjectExplorerPluginPrivate::invalidateProject(Project *project)
|
||||
updateActions();
|
||||
}
|
||||
|
||||
void ProjectExplorerPluginPrivate::updateContextMenuActions()
|
||||
void ProjectExplorerPluginPrivate::updateContextMenuActions(Node *currentNode)
|
||||
{
|
||||
m_addExistingFilesAction->setEnabled(false);
|
||||
m_addExistingDirectoryAction->setEnabled(false);
|
||||
@@ -3294,8 +3297,6 @@ void ProjectExplorerPluginPrivate::updateContextMenuActions()
|
||||
runMenu->menu()->clear();
|
||||
runMenu->menu()->menuAction()->setVisible(false);
|
||||
|
||||
const Node *currentNode = ProjectTree::currentNode();
|
||||
|
||||
if (currentNode && currentNode->managingProject()) {
|
||||
ProjectNode *pn;
|
||||
if (const ContainerNode *cn = currentNode->asContainerNode())
|
||||
|
@@ -227,7 +227,7 @@ void ProjectTree::setCurrent(Node *node, Project *project)
|
||||
|
||||
if (node != m_currentNode) {
|
||||
m_currentNode = node;
|
||||
emit currentNodeChanged();
|
||||
emit currentNodeChanged(node);
|
||||
}
|
||||
|
||||
if (changedProject) {
|
||||
|
@@ -104,7 +104,7 @@ public:
|
||||
|
||||
signals:
|
||||
void currentProjectChanged(ProjectExplorer::Project *project);
|
||||
void currentNodeChanged();
|
||||
void currentNodeChanged(Node *node);
|
||||
void nodeActionsChanged();
|
||||
|
||||
// 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
|
||||
updateContextActions();
|
||||
updateContextActions(ProjectTree::currentNode());
|
||||
updateReparseQbsAction();
|
||||
updateBuildActions();
|
||||
|
||||
@@ -280,10 +280,9 @@ void QbsProjectManagerPlugin::targetWasAdded(Target *target)
|
||||
this, &QbsProjectManagerPlugin::projectChanged);
|
||||
}
|
||||
|
||||
void QbsProjectManagerPlugin::updateContextActions()
|
||||
void QbsProjectManagerPlugin::updateContextActions(Node *node)
|
||||
{
|
||||
auto project = qobject_cast<Internal::QbsProject *>(ProjectTree::currentProject());
|
||||
const Node *node = ProjectTree::currentNode();
|
||||
bool isEnabled = !BuildManager::isBuilding(project)
|
||||
&& project && project->activeTarget()
|
||||
&& !project->activeTarget()->buildSystem()->isParsing()
|
||||
@@ -369,7 +368,7 @@ void QbsProjectManagerPlugin::projectChanged()
|
||||
updateReparseQbsAction();
|
||||
|
||||
if (!project || project == ProjectTree::currentProject())
|
||||
updateContextActions();
|
||||
updateContextActions(ProjectTree::currentNode());
|
||||
|
||||
if (!project || project == currentEditorProject())
|
||||
updateBuildActions();
|
||||
|
@@ -29,7 +29,10 @@
|
||||
#include <utils/id.h>
|
||||
#include <utils/parameteraction.h>
|
||||
|
||||
namespace ProjectExplorer { class Target; }
|
||||
namespace ProjectExplorer {
|
||||
class Target;
|
||||
class Node;
|
||||
} // namespace ProjectExplorer
|
||||
|
||||
namespace QbsProjectManager {
|
||||
namespace Internal {
|
||||
@@ -72,7 +75,7 @@ private:
|
||||
void reparseCurrentProject();
|
||||
void reparseProject(QbsProject *project);
|
||||
|
||||
void updateContextActions();
|
||||
void updateContextActions(ProjectExplorer::Node *node);
|
||||
void updateReparseQbsAction();
|
||||
void updateBuildActions();
|
||||
|
||||
|
@@ -86,7 +86,7 @@ public:
|
||||
void activeTargetChanged();
|
||||
void updateActions();
|
||||
void updateRunQMakeAction();
|
||||
void updateContextActions();
|
||||
void updateContextActions(Node *node);
|
||||
void buildStateChanged(Project *pro);
|
||||
void updateBuildFileAction();
|
||||
void disableBuildFileMenus();
|
||||
@@ -496,7 +496,7 @@ void QmakeProjectManagerPluginPrivate::activeTargetChanged()
|
||||
void QmakeProjectManagerPluginPrivate::updateActions()
|
||||
{
|
||||
updateRunQMakeAction();
|
||||
updateContextActions();
|
||||
updateContextActions(ProjectTree::currentNode());
|
||||
}
|
||||
|
||||
void QmakeProjectManagerPluginPrivate::updateRunQMakeAction()
|
||||
@@ -515,9 +515,8 @@ void QmakeProjectManagerPluginPrivate::updateRunQMakeAction()
|
||||
m_runQMakeAction->setEnabled(enable);
|
||||
}
|
||||
|
||||
void QmakeProjectManagerPluginPrivate::updateContextActions()
|
||||
void QmakeProjectManagerPluginPrivate::updateContextActions(Node *node)
|
||||
{
|
||||
const Node *node = ProjectTree::currentNode();
|
||||
Project *project = ProjectTree::currentProject();
|
||||
|
||||
const ContainerNode *containerNode = node ? node->asContainerNode() : nullptr;
|
||||
@@ -578,7 +577,7 @@ void QmakeProjectManagerPluginPrivate::buildStateChanged(Project *pro)
|
||||
{
|
||||
if (pro == ProjectTree::currentProject()) {
|
||||
updateRunQMakeAction();
|
||||
updateContextActions();
|
||||
updateContextActions(ProjectTree::currentNode());
|
||||
updateBuildFileAction();
|
||||
}
|
||||
}
|
||||
|
@@ -236,8 +236,7 @@ QmlPreviewPluginPrivate::QmlPreviewPluginPrivate(QmlPreviewPlugin *parent)
|
||||
Core::ActionManager::registerAction(action, "QmlPreview.PreviewFile", Core::Context(Constants::C_PROJECT_TREE)),
|
||||
Constants::G_FILE_OTHER);
|
||||
action->setVisible(false);
|
||||
connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged, action, [action]() {
|
||||
const Node *node = ProjectTree::currentNode();
|
||||
connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged, action, [action](Node *node) {
|
||||
const FileNode *fileNode = node ? node->asFileNode() : nullptr;
|
||||
action->setVisible(fileNode ? fileNode->fileType() == FileType::QML : false);
|
||||
});
|
||||
|
@@ -132,7 +132,7 @@ public:
|
||||
void copyPathContextMenu();
|
||||
void copyUrlContextMenu();
|
||||
|
||||
void updateContextActions();
|
||||
void updateContextActions(Node *node);
|
||||
|
||||
ResourceEditorW * currentEditor() const;
|
||||
|
||||
@@ -368,9 +368,8 @@ void ResourceEditorPluginPrivate::renamePrefixContextMenu()
|
||||
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);
|
||||
m_addPrefix->setEnabled(isResourceNode);
|
||||
m_addPrefix->setVisible(isResourceNode);
|
||||
|
Reference in New Issue
Block a user