forked from qt-creator/qt-creator
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:
@@ -337,27 +337,49 @@ void Qt4Manager::buildFileContextMenu()
|
|||||||
handleSubDirContextMenu(BUILD, true);
|
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)
|
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);
|
QTC_ASSERT(qt4pro, return);
|
||||||
|
|
||||||
if (!qt4pro->activeTarget() ||
|
if (!qt4pro->activeTarget() ||
|
||||||
!qt4pro->activeTarget()->activeBuildConfiguration())
|
!qt4pro->activeTarget()->activeBuildConfiguration())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!m_contextNode || !m_contextFile)
|
if (!contextNode || !contextFile)
|
||||||
isFileBuild = false;
|
isFileBuild = false;
|
||||||
Qt4BuildConfiguration *bc = qobject_cast<Qt4BuildConfiguration *>(qt4pro->activeTarget()->activeBuildConfiguration());
|
Qt4BuildConfiguration *bc = qobject_cast<Qt4BuildConfiguration *>(qt4pro->activeTarget()->activeBuildConfiguration());
|
||||||
if (!bc)
|
if (!bc)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (m_contextNode != 0 && (m_contextNode != qt4pro->rootProjectNode() || isFileBuild))
|
if (contextNode != 0 && (contextNode != qt4pro->rootProjectNode() || isFileBuild))
|
||||||
if (Qt4ProFileNode *profile = qobject_cast<Qt4ProFileNode *>(m_contextNode))
|
if (Qt4ProFileNode *profile = qobject_cast<Qt4ProFileNode *>(contextNode))
|
||||||
bc->setSubNodeBuild(profile);
|
bc->setSubNodeBuild(profile);
|
||||||
|
|
||||||
if (isFileBuild)
|
if (isFileBuild)
|
||||||
bc->setFileNodeBuild(m_contextFile);
|
bc->setFileNodeBuild(contextFile);
|
||||||
if (projectExplorer()->saveModifiedFiles()) {
|
if (projectExplorer()->saveModifiedFiles()) {
|
||||||
const Core::Id buildStep = Core::Id(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
|
const Core::Id buildStep = Core::Id(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
|
||||||
const Core::Id cleanStep = Core::Id(ProjectExplorer::Constants::BUILDSTEPS_CLEAN);
|
const Core::Id cleanStep = Core::Id(ProjectExplorer::Constants::BUILDSTEPS_CLEAN);
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ public slots:
|
|||||||
void rebuildSubDirContextMenu();
|
void rebuildSubDirContextMenu();
|
||||||
void cleanSubDirContextMenu();
|
void cleanSubDirContextMenu();
|
||||||
void buildFileContextMenu();
|
void buildFileContextMenu();
|
||||||
|
void buildFile();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void editorAboutToClose(Core::IEditor *editor);
|
void editorAboutToClose(Core::IEditor *editor);
|
||||||
@@ -110,6 +111,10 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
QList<Qt4Project *> m_projects;
|
QList<Qt4Project *> m_projects;
|
||||||
void handleSubDirContextMenu(Action action, bool isFileBuild);
|
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 addLibrary(const QString &fileName, Internal::ProFileEditorWidget *editor = 0);
|
||||||
void runQMake(ProjectExplorer::Project *p, ProjectExplorer::Node *node);
|
void runQMake(ProjectExplorer::Project *p, ProjectExplorer::Node *node);
|
||||||
|
|
||||||
|
|||||||
@@ -63,8 +63,11 @@
|
|||||||
#include <projectexplorer/projectexplorer.h>
|
#include <projectexplorer/projectexplorer.h>
|
||||||
#include <projectexplorer/target.h>
|
#include <projectexplorer/target.h>
|
||||||
#include <coreplugin/mimedatabase.h>
|
#include <coreplugin/mimedatabase.h>
|
||||||
|
#include <coreplugin/coreconstants.h>
|
||||||
#include <coreplugin/actionmanager/actionmanager.h>
|
#include <coreplugin/actionmanager/actionmanager.h>
|
||||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||||
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
|
#include <coreplugin/editormanager/ieditor.h>
|
||||||
#include <texteditor/texteditoractionhandler.h>
|
#include <texteditor/texteditoractionhandler.h>
|
||||||
#include <texteditor/texteditorconstants.h>
|
#include <texteditor/texteditorconstants.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
@@ -243,15 +246,16 @@ bool Qt4ProjectManagerPlugin::initialize(const QStringList &arguments, QString *
|
|||||||
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_CLEAN);
|
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_CLEAN);
|
||||||
connect(m_cleanSubProjectAction, SIGNAL(triggered()), m_qt4ProjectManager, SLOT(cleanSubDirContextMenu()));
|
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\""),
|
m_buildFileAction = new Utils::ParameterAction(tr("Build File"), tr("Build File \"%1\""),
|
||||||
Utils::ParameterAction::AlwaysEnabled, this);
|
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_Hide);
|
||||||
command->setAttribute(Core::Command::CA_UpdateText);
|
command->setAttribute(Core::Command::CA_UpdateText);
|
||||||
command->setDescription(m_buildFileAction->text());
|
command->setDescription(m_buildFileAction->text());
|
||||||
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+B")));
|
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+B")));
|
||||||
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD);
|
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*)),
|
connect(m_projectExplorer->buildManager(), SIGNAL(buildStateChanged(ProjectExplorer::Project*)),
|
||||||
this, SLOT(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);
|
command = Core::ActionManager::command(TextEditor::Constants::UN_COMMENT_SELECTION);
|
||||||
contextMenu->addAction(command);
|
contextMenu->addAction(command);
|
||||||
|
|
||||||
|
connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
|
||||||
|
this, SLOT(updateBuildFileAction()));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,7 +408,29 @@ void Qt4ProjectManagerPlugin::buildStateChanged(ProjectExplorer::Project *pro)
|
|||||||
if (pro == currentProject) {
|
if (pro == currentProject) {
|
||||||
updateRunQMakeAction();
|
updateRunQMakeAction();
|
||||||
updateContextActions(m_projectExplorer->currentNode(), pro);
|
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)
|
Q_EXPORT_PLUGIN(Qt4ProjectManagerPlugin)
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ private slots:
|
|||||||
void updateRunQMakeAction();
|
void updateRunQMakeAction();
|
||||||
void updateContextActions(ProjectExplorer::Node *node, ProjectExplorer::Project *project);
|
void updateContextActions(ProjectExplorer::Node *node, ProjectExplorer::Project *project);
|
||||||
void buildStateChanged(ProjectExplorer::Project *pro);
|
void buildStateChanged(ProjectExplorer::Project *pro);
|
||||||
|
void updateBuildFileAction();
|
||||||
|
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
void testQmakeOutputParsers_data();
|
void testQmakeOutputParsers_data();
|
||||||
|
|||||||
Reference in New Issue
Block a user