Qbs: Allow for building products

Change-Id: Id6fcdbdb0c776458eb16c7fc6765046969c2658e
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
Tobias Hunger
2013-06-10 15:40:18 +02:00
parent 4780061471
commit f5d7707188
9 changed files with 143 additions and 21 deletions

View File

@@ -77,6 +77,7 @@ bool QbsProjectManagerPlugin::initialize(const QStringList &arguments, QString *
m_manager = new QbsManager(this);
m_projectExplorer = ProjectExplorer::ProjectExplorerPlugin::instance();
const Core::Context projectContext(::QbsProjectManager::Constants::PROJECT_ID);
const Core::Context globalcontext(Core::Constants::C_GLOBAL);
Q_UNUSED(arguments);
@@ -100,10 +101,8 @@ bool QbsProjectManagerPlugin::initialize(const QStringList &arguments, QString *
// PE Context menu for projects
Core::ActionContainer *mproject =
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_PROJECTCONTEXT);
// <debug>
// Core::ActionContainer *msubproject =
// Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_SUBPROJECTCONTEXT);
// </debug>
Core::ActionContainer *msubproject =
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_SUBPROJECTCONTEXT);
Core::ActionContainer *mfile =
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_FILECONTEXT);
@@ -129,7 +128,6 @@ bool QbsProjectManagerPlugin::initialize(const QStringList &arguments, QString *
mfile->addAction(command, ProjectExplorer::Constants::G_FILE_OTHER);
connect(m_buildFileContextMenu, SIGNAL(triggered()), this, SLOT(buildFileContextMenu()));
const Core::Context globalcontext(Core::Constants::C_GLOBAL);
m_buildFile = new Utils::ParameterAction(tr("Build File"), tr("Build File \"%1\""),
Utils::ParameterAction::AlwaysEnabled, this);
command = Core::ActionManager::registerAction(m_buildFile, Constants::ACTION_BUILD_FILE, globalcontext);
@@ -140,6 +138,22 @@ bool QbsProjectManagerPlugin::initialize(const QStringList &arguments, QString *
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD);
connect(m_buildFile, SIGNAL(triggered()), this, SLOT(buildFile()));
m_buildProductContextMenu = new QAction(tr("Build"), this);
command = Core::ActionManager::registerAction(m_buildProductContextMenu, Constants::ACTION_BUILD_PRODUCT_CONTEXT, projectContext);
command->setAttribute(Core::Command::CA_Hide);
msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
connect(m_buildProductContextMenu, SIGNAL(triggered()), this, SLOT(buildProductContextMenu()));
m_buildProduct = new Utils::ParameterAction(tr("Build Product"), tr("Build Product \"%1\""),
Utils::ParameterAction::AlwaysEnabled, this);
command = Core::ActionManager::registerAction(m_buildProduct, Constants::ACTION_BUILD_PRODUCT, globalcontext);
command->setAttribute(Core::Command::CA_Hide);
command->setAttribute(Core::Command::CA_UpdateText);
command->setDescription(m_buildFile->text());
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+Shift+B")));
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD);
connect(m_buildProduct, SIGNAL(triggered()), this, SLOT(buildProduct()));
// Connect
connect(m_projectExplorer, SIGNAL(currentNodeChanged(ProjectExplorer::Node*,ProjectExplorer::Project*)),
this, SLOT(updateContextActions(ProjectExplorer::Node*,ProjectExplorer::Project*)));
@@ -148,12 +162,12 @@ bool QbsProjectManagerPlugin::initialize(const QStringList &arguments, QString *
this, SLOT(buildStateChanged(ProjectExplorer::Project*)));
connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
this, SLOT(updateBuildFileAction()));
this, SLOT(updateBuildActions()));
// Run initial setup routines
updateContextActions(0, 0);
updateReparseQbsAction();
updateBuildFileAction();
updateBuildActions();
return true;
}
@@ -187,10 +201,12 @@ void QbsProjectManagerPlugin::updateContextActions(ProjectExplorer::Node *node,
bool isBuilding = m_projectExplorer->buildManager()->isBuilding(project);
bool isFile = m_currentProject && node && (node->nodeType() == ProjectExplorer::FileNodeType);
bool isProduct = m_currentProject && node && qobject_cast<QbsProductNode *>(node->projectNode());
bool isFileEnabled = isFile && node->isEnabled();
m_reparseQbsCtx->setEnabled(!isBuilding && m_currentProject && !m_currentProject->isParsing());
m_buildFileContextMenu->setEnabled(isFileEnabled);
m_buildProductContextMenu->setEnabled(isProduct);
}
void QbsProjectManagerPlugin::updateReparseQbsAction()
@@ -200,12 +216,15 @@ void QbsProjectManagerPlugin::updateReparseQbsAction()
&& !m_currentProject->isParsing());
}
void QbsProjectManagerPlugin::updateBuildFileAction()
void QbsProjectManagerPlugin::updateBuildActions()
{
bool visible = false;
bool enabled = false;
bool fileVisible = false;
bool fileEnabled = false;
bool productVisible = false;
bool productEnabled = false;
QString file;
if (Core::IEditor *currentEditor = Core::EditorManager::currentEditor()) {
file = currentEditor->document()->fileName();
ProjectExplorer::SessionManager *session = m_projectExplorer->session();
@@ -214,14 +233,22 @@ void QbsProjectManagerPlugin::updateBuildFileAction()
= qobject_cast<QbsProject *>(session->projectForFile(file));
m_buildFile->setParameter(QFileInfo(file).fileName());
visible = project && node && qobject_cast<QbsBaseProjectNode *>(node->projectNode());
enabled = !m_projectExplorer->buildManager()->isBuilding(project)
fileVisible = project && node && qobject_cast<QbsBaseProjectNode *>(node->projectNode());
fileEnabled = !m_projectExplorer->buildManager()->isBuilding(project)
&& m_currentProject && !m_currentProject->isParsing();
if (QbsProductNode *productNode = qobject_cast<QbsProductNode *>(node->projectNode())) {
productEnabled = true;
productVisible = true;
m_buildProduct->setParameter(productNode->displayName());
}
}
m_buildFile->setEnabled(enabled);
m_buildFile->setVisible(visible);
m_buildFile->setEnabled(fileEnabled);
m_buildFile->setVisible(fileVisible);
m_buildProduct->setEnabled(productEnabled);
m_buildProduct->setVisible(productVisible);
}
void QbsProjectManagerPlugin::activeTargetChanged()
@@ -244,7 +271,7 @@ void QbsProjectManagerPlugin::buildStateChanged(ProjectExplorer::Project *projec
if (project == m_currentProject) {
updateReparseQbsAction();
updateContextActions(m_currentNode, m_currentProject);
updateBuildFileAction();
updateBuildActions();
}
}
@@ -279,6 +306,32 @@ void QbsProjectManagerPlugin::buildFile()
buildFiles(project, QStringList(file));
}
void QbsProjectManagerPlugin::buildProductContextMenu()
{
QTC_ASSERT(m_currentNode, return);
QTC_ASSERT(m_currentProject, return);
buildProducts(m_currentProject, QStringList(m_currentNode->displayName()));
}
void QbsProjectManagerPlugin::buildProduct()
{
QbsProject *project = 0;
QbsProductNode *product = 0;
if (Core::IEditor *currentEditor = Core::EditorManager::currentEditor()) {
const QString file = currentEditor->document()->fileName();
ProjectExplorer::SessionManager *session = m_projectExplorer->session();
project = qobject_cast<QbsProject *>(session->projectForFile(file));
product = qobject_cast<QbsProductNode *>(session->nodeForFile(file)->projectNode());
}
if (!project || !product)
return;
buildProducts(project, QStringList(product->displayName()));
}
void QbsProjectManagerPlugin::buildFiles(QbsProject *project, const QStringList &files)
{
QTC_ASSERT(project, return);
@@ -296,6 +349,7 @@ void QbsProjectManagerPlugin::buildFiles(QbsProject *project, const QStringList
return;
bc->setChangedFiles(files);
bc->setProducts(QStringList());
const Core::Id buildStep = Core::Id(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
@@ -305,6 +359,33 @@ void QbsProjectManagerPlugin::buildFiles(QbsProject *project, const QStringList
bc->setChangedFiles(QStringList());
}
void QbsProjectManagerPlugin::buildProducts(QbsProject *project, const QStringList &products)
{
QTC_ASSERT(project, return);
QTC_ASSERT(!products.isEmpty(), return);
ProjectExplorer::Target *t = project->activeTarget();
if (!t)
return;
QbsBuildConfiguration *bc = qobject_cast<QbsBuildConfiguration *>(t->activeBuildConfiguration());
if (!bc)
return;
ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance();
if (!pe->saveModifiedFiles())
return;
bc->setChangedFiles(QStringList());
bc->setProducts(products);
const Core::Id buildStep = Core::Id(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
const QString name = ProjectExplorer::ProjectExplorerPlugin::displayNameForStepId(buildStep);
pe->buildManager()->buildList(bc->stepList(buildStep), name);
bc->setProducts(QStringList());
}
void QbsProjectManagerPlugin::reparseCurrentProject()
{
if (m_currentProject)