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 <eike.ziller@digia.com>
This commit is contained in:
Daniel Teske
2013-04-30 15:12:48 +02:00
parent 1ca9bab242
commit b941e76d92
4 changed files with 64 additions and 7 deletions

View File

@@ -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<FileNode *>(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<Qt4Project *>(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<Qt4Project *>(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<Qt4BuildConfiguration *>(qt4pro->activeTarget()->activeBuildConfiguration());
if (!bc)
return;
if (m_contextNode != 0 && (m_contextNode != qt4pro->rootProjectNode() || isFileBuild))
if (Qt4ProFileNode *profile = qobject_cast<Qt4ProFileNode *>(m_contextNode))
if (contextNode != 0 && (contextNode != qt4pro->rootProjectNode() || isFileBuild))
if (Qt4ProFileNode *profile = qobject_cast<Qt4ProFileNode *>(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);

View File

@@ -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<Qt4Project *> 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);

View File

@@ -63,8 +63,11 @@
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/target.h>
#include <coreplugin/mimedatabase.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <texteditor/texteditoractionhandler.h>
#include <texteditor/texteditorconstants.h>
#include <utils/hostosinfo.h>
@@ -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<Qt4Project *>(project)
&& qobject_cast<Qt4ProFileNode *>(node->projectNode());
enabled = !m_projectExplorer->buildManager()->isBuilding(project);
}
m_buildFileAction->setVisible(visible);
m_buildFileAction->setEnabled(enabled);
}
Q_EXPORT_PLUGIN(Qt4ProjectManagerPlugin)

View File

@@ -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();