From b941e76d921d2f481e6f1b30083ae921ae445b0b Mon Sep 17 00:00:00 2001 From: Daniel Teske Date: Tue, 30 Apr 2013 15:12:48 +0200 Subject: [PATCH] Fix "Build File" to take the current file from the currentEditor() And not use the currentNode() from the project tree. Task-number: QTCREATORBUG-9178 Change-Id: I03be1dd1b0fa00a7c8b44cdbaea276970c870f49 Reviewed-by: Eike Ziller --- .../qt4projectmanager/qt4projectmanager.cpp | 32 +++++++++++++++--- .../qt4projectmanager/qt4projectmanager.h | 5 +++ .../qt4projectmanagerplugin.cpp | 33 +++++++++++++++++-- .../qt4projectmanagerplugin.h | 1 + 4 files changed, 64 insertions(+), 7 deletions(-) diff --git a/src/plugins/qt4projectmanager/qt4projectmanager.cpp b/src/plugins/qt4projectmanager/qt4projectmanager.cpp index 7c063cdcfc4..be93686f5a2 100644 --- a/src/plugins/qt4projectmanager/qt4projectmanager.cpp +++ b/src/plugins/qt4projectmanager/qt4projectmanager.cpp @@ -337,27 +337,49 @@ void Qt4Manager::buildFileContextMenu() handleSubDirContextMenu(BUILD, true); } +void Qt4Manager::buildFile() +{ + if (Core::IEditor *currentEditor = Core::EditorManager::currentEditor()) { + QString file = currentEditor->document()->fileName(); + ProjectExplorer::SessionManager *session = projectExplorer()->session(); + ProjectExplorer::FileNode *node = qobject_cast(session->nodeForFile(file)); + ProjectExplorer::Project *project = session->projectForFile(file); + + if (project && node) + handleSubDirContextMenu(BUILD, true, project, node->projectNode(), node); + + } +} + void Qt4Manager::handleSubDirContextMenu(Qt4Manager::Action action, bool isFileBuild) { - Qt4Project *qt4pro = qobject_cast(m_contextProject); + handleSubDirContextMenu(action, isFileBuild, m_contextProject, m_contextNode, m_contextFile); +} + +void Qt4Manager::handleSubDirContextMenu(Qt4Manager::Action action, bool isFileBuild, + ProjectExplorer::Project *contextProject, + ProjectExplorer::Node *contextNode, + ProjectExplorer::FileNode *contextFile) +{ + Qt4Project *qt4pro = qobject_cast(contextProject); QTC_ASSERT(qt4pro, return); if (!qt4pro->activeTarget() || !qt4pro->activeTarget()->activeBuildConfiguration()) return; - if (!m_contextNode || !m_contextFile) + if (!contextNode || !contextFile) isFileBuild = false; Qt4BuildConfiguration *bc = qobject_cast(qt4pro->activeTarget()->activeBuildConfiguration()); if (!bc) return; - if (m_contextNode != 0 && (m_contextNode != qt4pro->rootProjectNode() || isFileBuild)) - if (Qt4ProFileNode *profile = qobject_cast(m_contextNode)) + if (contextNode != 0 && (contextNode != qt4pro->rootProjectNode() || isFileBuild)) + if (Qt4ProFileNode *profile = qobject_cast(contextNode)) bc->setSubNodeBuild(profile); if (isFileBuild) - bc->setFileNodeBuild(m_contextFile); + bc->setFileNodeBuild(contextFile); if (projectExplorer()->saveModifiedFiles()) { const Core::Id buildStep = Core::Id(ProjectExplorer::Constants::BUILDSTEPS_BUILD); const Core::Id cleanStep = Core::Id(ProjectExplorer::Constants::BUILDSTEPS_CLEAN); diff --git a/src/plugins/qt4projectmanager/qt4projectmanager.h b/src/plugins/qt4projectmanager/qt4projectmanager.h index 7e431f3e14d..14f309a4c01 100644 --- a/src/plugins/qt4projectmanager/qt4projectmanager.h +++ b/src/plugins/qt4projectmanager/qt4projectmanager.h @@ -101,6 +101,7 @@ public slots: void rebuildSubDirContextMenu(); void cleanSubDirContextMenu(); void buildFileContextMenu(); + void buildFile(); private slots: void editorAboutToClose(Core::IEditor *editor); @@ -110,6 +111,10 @@ private slots: private: QList m_projects; void handleSubDirContextMenu(Action action, bool isFileBuild); + void handleSubDirContextMenu(Qt4Manager::Action action, bool isFileBuild, + ProjectExplorer::Project *contextProject, + ProjectExplorer::Node *contextNode, + ProjectExplorer::FileNode *contextFile); void addLibrary(const QString &fileName, Internal::ProFileEditorWidget *editor = 0); void runQMake(ProjectExplorer::Project *p, ProjectExplorer::Node *node); diff --git a/src/plugins/qt4projectmanager/qt4projectmanagerplugin.cpp b/src/plugins/qt4projectmanager/qt4projectmanagerplugin.cpp index 58352173d91..89adb519fe1 100644 --- a/src/plugins/qt4projectmanager/qt4projectmanagerplugin.cpp +++ b/src/plugins/qt4projectmanager/qt4projectmanagerplugin.cpp @@ -63,8 +63,11 @@ #include #include #include +#include #include #include +#include +#include #include #include #include @@ -243,15 +246,16 @@ bool Qt4ProjectManagerPlugin::initialize(const QStringList &arguments, QString * mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_CLEAN); connect(m_cleanSubProjectAction, SIGNAL(triggered()), m_qt4ProjectManager, SLOT(cleanSubDirContextMenu())); + const Core::Context globalcontext(Core::Constants::C_GLOBAL); m_buildFileAction = new Utils::ParameterAction(tr("Build File"), tr("Build File \"%1\""), Utils::ParameterAction::AlwaysEnabled, this); - command = Core::ActionManager::registerAction(m_buildFileAction, Constants::BUILDFILE, projectContext); + command = Core::ActionManager::registerAction(m_buildFileAction, Constants::BUILDFILE, globalcontext); command->setAttribute(Core::Command::CA_Hide); command->setAttribute(Core::Command::CA_UpdateText); command->setDescription(m_buildFileAction->text()); command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+B"))); mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD); - connect(m_buildFileAction, SIGNAL(triggered()), m_qt4ProjectManager, SLOT(buildFileContextMenu())); + connect(m_buildFileAction, SIGNAL(triggered()), m_qt4ProjectManager, SLOT(buildFile())); connect(m_projectExplorer->buildManager(), SIGNAL(buildStateChanged(ProjectExplorer::Project*)), this, SLOT(buildStateChanged(ProjectExplorer::Project*))); @@ -287,6 +291,9 @@ bool Qt4ProjectManagerPlugin::initialize(const QStringList &arguments, QString * command = Core::ActionManager::command(TextEditor::Constants::UN_COMMENT_SELECTION); contextMenu->addAction(command); + connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)), + this, SLOT(updateBuildFileAction())); + return true; } @@ -401,7 +408,29 @@ void Qt4ProjectManagerPlugin::buildStateChanged(ProjectExplorer::Project *pro) if (pro == currentProject) { updateRunQMakeAction(); updateContextActions(m_projectExplorer->currentNode(), pro); + updateBuildFileAction(); } } +void Qt4ProjectManagerPlugin::updateBuildFileAction() +{ + bool visible = false; + bool enabled = false; + + QString file; + if (Core::IEditor *currentEditor = Core::EditorManager::currentEditor()) { + file = currentEditor->document()->fileName(); + ProjectExplorer::SessionManager *session = m_projectExplorer->session(); + ProjectExplorer::Node *node = session->nodeForFile(file); + ProjectExplorer::Project *project = session->projectForFile(file); + m_buildFileAction->setParameter(file); + visible = qobject_cast(project) + && qobject_cast(node->projectNode()); + + enabled = !m_projectExplorer->buildManager()->isBuilding(project); + } + m_buildFileAction->setVisible(visible); + m_buildFileAction->setEnabled(enabled); +} + Q_EXPORT_PLUGIN(Qt4ProjectManagerPlugin) diff --git a/src/plugins/qt4projectmanager/qt4projectmanagerplugin.h b/src/plugins/qt4projectmanager/qt4projectmanagerplugin.h index 991147927d1..4fd1e5dbc29 100644 --- a/src/plugins/qt4projectmanager/qt4projectmanagerplugin.h +++ b/src/plugins/qt4projectmanager/qt4projectmanagerplugin.h @@ -73,6 +73,7 @@ private slots: void updateRunQMakeAction(); void updateContextActions(ProjectExplorer::Node *node, ProjectExplorer::Project *project); void buildStateChanged(ProjectExplorer::Project *pro); + void updateBuildFileAction(); #ifdef WITH_TESTS void testQmakeOutputParsers_data();