2010-02-08 15:50:06 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2010-02-08 15:50:06 +01:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2010-02-08 15:50:06 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2010-02-08 15:50:06 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2010-02-08 15:50:06 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "targetsettingspanel.h"
|
|
|
|
|
|
|
|
|
|
#include "buildsettingspropertiespage.h"
|
|
|
|
|
#include "project.h"
|
|
|
|
|
#include "projectwindow.h"
|
|
|
|
|
#include "runsettingspropertiespage.h"
|
|
|
|
|
#include "target.h"
|
|
|
|
|
#include "targetsettingswidget.h"
|
|
|
|
|
|
|
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2011-10-24 13:10:38 +00:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
|
|
|
|
#include <projectexplorer/buildmanager.h>
|
2010-02-08 15:50:06 +01:00
|
|
|
|
|
|
|
|
#include <QtCore/QCoreApplication>
|
|
|
|
|
#include <QtGui/QLabel>
|
2010-06-29 12:56:08 +02:00
|
|
|
#include <QtGui/QMenu>
|
2010-02-24 17:52:56 +01:00
|
|
|
#include <QtGui/QMessageBox>
|
2010-02-08 15:50:06 +01:00
|
|
|
#include <QtGui/QVBoxLayout>
|
2010-07-13 16:36:37 +02:00
|
|
|
#include <QtGui/QStackedWidget>
|
2011-10-24 13:10:38 +00:00
|
|
|
#include <QtGui/QPushButton>
|
2010-02-08 15:50:06 +01:00
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace ProjectExplorer::Internal;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
// TargetSettingsWidget
|
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
TargetSettingsPanelWidget::TargetSettingsPanelWidget(Project *project) :
|
2010-02-26 13:45:07 +01:00
|
|
|
m_currentTarget(0),
|
2010-02-08 15:50:06 +01:00
|
|
|
m_project(project),
|
|
|
|
|
m_selector(0),
|
|
|
|
|
m_centralWidget(0)
|
|
|
|
|
{
|
2010-03-15 10:52:18 +01:00
|
|
|
Q_ASSERT(m_project);
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
m_panelWidgets[0] = 0;
|
|
|
|
|
m_panelWidgets[1] = 0;
|
|
|
|
|
|
2010-06-29 12:56:08 +02:00
|
|
|
m_addMenu = new QMenu(this);
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
setupUi();
|
|
|
|
|
|
|
|
|
|
connect(m_project, SIGNAL(addedTarget(ProjectExplorer::Target*)),
|
|
|
|
|
this, SLOT(targetAdded(ProjectExplorer::Target*)));
|
2010-03-25 17:27:59 +01:00
|
|
|
connect(m_project, SIGNAL(removedTarget(ProjectExplorer::Target*)),
|
|
|
|
|
this, SLOT(removedTarget(ProjectExplorer::Target*)));
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
connect(m_project, SIGNAL(activeTargetChanged(ProjectExplorer::Target*)),
|
|
|
|
|
this, SLOT(activeTargetChanged(ProjectExplorer::Target*)));
|
2010-12-10 19:02:19 +01:00
|
|
|
|
|
|
|
|
QList<ITargetFactory *> factories =
|
|
|
|
|
ExtensionSystem::PluginManager::instance()->getObjects<ITargetFactory>();
|
|
|
|
|
|
|
|
|
|
foreach (ITargetFactory *fac, factories) {
|
|
|
|
|
connect(fac, SIGNAL(supportedTargetIdsChanged()),
|
|
|
|
|
this, SLOT(updateTargetAddAndRemoveButtons()));
|
|
|
|
|
}
|
2010-02-08 15:50:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TargetSettingsPanelWidget::~TargetSettingsPanelWidget()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TargetSettingsPanelWidget::setupUi()
|
|
|
|
|
{
|
|
|
|
|
QVBoxLayout *viewLayout = new QVBoxLayout(this);
|
|
|
|
|
viewLayout->setMargin(0);
|
|
|
|
|
viewLayout->setSpacing(0);
|
|
|
|
|
|
|
|
|
|
m_selector = new TargetSettingsWidget(this);
|
|
|
|
|
viewLayout->addWidget(m_selector);
|
|
|
|
|
|
|
|
|
|
// Setup our container for the contents:
|
|
|
|
|
m_centralWidget = new QStackedWidget(this);
|
|
|
|
|
m_selector->setCentralWidget(m_centralWidget);
|
|
|
|
|
|
2010-09-14 17:49:11 +02:00
|
|
|
// no target label:
|
2010-02-08 15:50:06 +01:00
|
|
|
m_noTargetLabel = new QWidget;
|
2010-09-14 17:49:11 +02:00
|
|
|
QVBoxLayout *noTargetLayout = new QVBoxLayout(m_noTargetLabel);
|
2010-02-08 15:50:06 +01:00
|
|
|
noTargetLayout->setMargin(0);
|
|
|
|
|
QLabel *label = new QLabel(m_noTargetLabel);
|
|
|
|
|
label->setText(tr("No target defined."));
|
|
|
|
|
{
|
|
|
|
|
QFont f = label->font();
|
|
|
|
|
f.setPointSizeF(f.pointSizeF() * 1.4);
|
|
|
|
|
f.setBold(true);
|
|
|
|
|
label->setFont(f);
|
|
|
|
|
}
|
|
|
|
|
label->setMargin(10);
|
|
|
|
|
label->setAlignment(Qt::AlignTop);
|
|
|
|
|
noTargetLayout->addWidget(label);
|
|
|
|
|
noTargetLayout->addStretch(10);
|
|
|
|
|
m_centralWidget->addWidget(m_noTargetLabel);
|
|
|
|
|
|
|
|
|
|
foreach (Target *t, m_project->targets())
|
|
|
|
|
targetAdded(t);
|
|
|
|
|
|
2010-06-15 14:44:15 +02:00
|
|
|
// Now set the correct target
|
|
|
|
|
int index = m_targets.indexOf(m_project->activeTarget());
|
|
|
|
|
m_selector->setCurrentIndex(index);
|
|
|
|
|
m_selector->setCurrentSubIndex(0);
|
|
|
|
|
|
|
|
|
|
currentTargetChanged(index, 0);
|
|
|
|
|
|
|
|
|
|
connect(m_selector, SIGNAL(currentChanged(int,int)),
|
|
|
|
|
this, SLOT(currentTargetChanged(int,int)));
|
|
|
|
|
|
2010-02-10 17:29:08 +01:00
|
|
|
connect(m_selector, SIGNAL(removeButtonClicked()),
|
|
|
|
|
this, SLOT(removeTarget()));
|
2010-02-08 15:50:06 +01:00
|
|
|
|
2010-06-29 12:56:08 +02:00
|
|
|
m_selector->setAddButtonMenu(m_addMenu);
|
|
|
|
|
connect(m_addMenu, SIGNAL(triggered(QAction*)),
|
|
|
|
|
this, SLOT(addTarget(QAction*)));
|
|
|
|
|
|
2010-03-15 10:52:18 +01:00
|
|
|
updateTargetAddAndRemoveButtons();
|
2010-02-08 15:50:06 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-26 13:45:07 +01:00
|
|
|
void TargetSettingsPanelWidget::currentTargetChanged(int targetIndex, int subIndex)
|
2010-02-08 15:50:06 +01:00
|
|
|
{
|
2010-02-23 14:33:18 +01:00
|
|
|
if (targetIndex < -1 || targetIndex >= m_targets.count())
|
2010-02-08 15:50:06 +01:00
|
|
|
return;
|
|
|
|
|
if (subIndex < -1 || subIndex >= 2)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-03-30 13:23:11 +02:00
|
|
|
if (targetIndex == -1 || subIndex == -1) { // no more targets!
|
|
|
|
|
delete m_panelWidgets[0];
|
|
|
|
|
m_panelWidgets[0] = 0;
|
|
|
|
|
delete m_panelWidgets[1];
|
|
|
|
|
m_panelWidgets[1] = 0;
|
|
|
|
|
|
|
|
|
|
m_centralWidget->setCurrentWidget(m_noTargetLabel);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-26 12:44:55 +01:00
|
|
|
Target *target = m_targets.at(targetIndex);
|
2010-02-08 15:50:06 +01:00
|
|
|
|
|
|
|
|
// Target was not actually changed:
|
2010-02-26 13:45:07 +01:00
|
|
|
if (m_currentTarget == target) {
|
2010-02-23 14:33:18 +01:00
|
|
|
if (m_panelWidgets[subIndex])
|
|
|
|
|
m_centralWidget->setCurrentWidget(m_panelWidgets[subIndex]);
|
|
|
|
|
else
|
|
|
|
|
m_centralWidget->setCurrentWidget(m_noTargetLabel);
|
2010-02-08 15:50:06 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-23 14:33:18 +01:00
|
|
|
// Target has changed:
|
2010-03-30 13:23:11 +02:00
|
|
|
m_currentTarget = target;
|
2010-02-08 15:50:06 +01:00
|
|
|
|
2010-03-26 12:44:55 +01:00
|
|
|
PanelsWidget *buildPanel = new PanelsWidget(m_centralWidget);
|
|
|
|
|
PanelsWidget *runPanel = new PanelsWidget(m_centralWidget);
|
2010-02-08 15:50:06 +01:00
|
|
|
|
2010-03-25 16:16:38 +01:00
|
|
|
foreach (ITargetPanelFactory *panelFactory, ExtensionSystem::PluginManager::instance()->getObjects<ITargetPanelFactory>()) {
|
2010-02-08 15:50:06 +01:00
|
|
|
if (panelFactory->id() == QLatin1String(BUILDSETTINGS_PANEL_ID)) {
|
2011-04-14 13:32:30 +02:00
|
|
|
PropertiesPanel *panel = panelFactory->createPanel(target);
|
2010-02-08 15:50:06 +01:00
|
|
|
buildPanel->addPropertiesPanel(panel);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (panelFactory->id() == QLatin1String(RUNSETTINGS_PANEL_ID)) {
|
2011-04-14 13:32:30 +02:00
|
|
|
PropertiesPanel *panel = panelFactory->createPanel(target);
|
2010-02-08 15:50:06 +01:00
|
|
|
runPanel->addPropertiesPanel(panel);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_centralWidget->addWidget(buildPanel);
|
|
|
|
|
m_centralWidget->addWidget(runPanel);
|
|
|
|
|
|
2010-02-23 14:33:18 +01:00
|
|
|
m_centralWidget->setCurrentWidget(subIndex == 0 ? buildPanel : runPanel);
|
|
|
|
|
|
|
|
|
|
delete m_panelWidgets[0];
|
2010-02-08 15:50:06 +01:00
|
|
|
m_panelWidgets[0] = buildPanel;
|
2010-02-23 14:33:18 +01:00
|
|
|
delete m_panelWidgets[1];
|
2010-02-08 15:50:06 +01:00
|
|
|
m_panelWidgets[1] = runPanel;
|
2010-03-26 12:44:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
m_project->setActiveTarget(target);
|
2010-02-08 15:50:06 +01:00
|
|
|
}
|
|
|
|
|
|
2010-06-29 12:56:08 +02:00
|
|
|
void TargetSettingsPanelWidget::addTarget(QAction *action)
|
2010-02-08 15:50:06 +01:00
|
|
|
{
|
2010-06-29 12:56:08 +02:00
|
|
|
QString id = action->data().toString();
|
2010-12-10 19:02:19 +01:00
|
|
|
Q_ASSERT(!m_project->target(id));
|
2010-12-06 16:15:41 +01:00
|
|
|
QList<ITargetFactory *> factories =
|
|
|
|
|
ExtensionSystem::PluginManager::instance()->getObjects<ITargetFactory>();
|
|
|
|
|
|
|
|
|
|
Target *target = 0;
|
|
|
|
|
foreach (ITargetFactory *fac, factories) {
|
|
|
|
|
if (fac->canCreate(m_project, id)) {
|
|
|
|
|
target = fac->create(m_project, id);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-29 12:56:08 +02:00
|
|
|
if (!target)
|
|
|
|
|
return;
|
|
|
|
|
m_project->addTarget(target);
|
2010-02-08 15:50:06 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-10 17:29:08 +01:00
|
|
|
void TargetSettingsPanelWidget::removeTarget()
|
|
|
|
|
{
|
|
|
|
|
int index = m_selector->currentIndex();
|
2010-02-22 14:42:37 +01:00
|
|
|
Target *t = m_targets.at(index);
|
2011-10-24 13:10:38 +00:00
|
|
|
|
|
|
|
|
ProjectExplorer::BuildManager *bm = ProjectExplorerPlugin::instance()->buildManager();
|
|
|
|
|
if (bm->isBuilding(t)) {
|
|
|
|
|
QMessageBox box;
|
|
|
|
|
QPushButton *closeAnyway = box.addButton(tr("Cancel Build && Remove Target"), QMessageBox::AcceptRole);
|
|
|
|
|
QPushButton *cancelClose = box.addButton(tr("Do Not Remove"), QMessageBox::RejectRole);
|
|
|
|
|
box.setDefaultButton(cancelClose);
|
|
|
|
|
box.setWindowTitle(tr("Remove Target %1?").arg(t->displayName()));
|
|
|
|
|
box.setText(tr("The target <b>%1</b> is currently being built.").arg(t->displayName()));
|
|
|
|
|
box.setInformativeText(tr("Do you want to cancel the build process and remove the Target anyway?"));
|
|
|
|
|
box.exec();
|
|
|
|
|
if (box.clickedButton() != closeAnyway)
|
|
|
|
|
return;
|
|
|
|
|
bm->cancel();
|
|
|
|
|
} else {
|
|
|
|
|
// We don't show the generic message box on removing the target, if we showed the still building one
|
|
|
|
|
int ret = QMessageBox::warning(this, tr("Qt Creator"),
|
|
|
|
|
tr("Do you really want to remove the\n"
|
|
|
|
|
"\"%1\" target?").arg(t->displayName()),
|
|
|
|
|
QMessageBox::Yes | QMessageBox::No,
|
|
|
|
|
QMessageBox::No);
|
|
|
|
|
if (ret != QMessageBox::Yes)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_project->removeTarget(t);
|
|
|
|
|
|
2010-02-10 17:29:08 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
void TargetSettingsPanelWidget::targetAdded(ProjectExplorer::Target *target)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(m_project == target->project());
|
|
|
|
|
Q_ASSERT(m_selector);
|
|
|
|
|
|
2010-02-22 14:42:37 +01:00
|
|
|
for (int pos = 0; pos <= m_targets.count(); ++pos) {
|
|
|
|
|
if (m_targets.count() == pos ||
|
|
|
|
|
m_targets.at(pos)->displayName() > target->displayName()) {
|
|
|
|
|
m_targets.insert(pos, target);
|
|
|
|
|
m_selector->insertTarget(pos, target->displayName());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-15 10:52:18 +01:00
|
|
|
updateTargetAddAndRemoveButtons();
|
2010-02-08 15:50:06 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-25 17:27:59 +01:00
|
|
|
void TargetSettingsPanelWidget::removedTarget(ProjectExplorer::Target *target)
|
2010-02-08 15:50:06 +01:00
|
|
|
{
|
|
|
|
|
Q_ASSERT(m_project == target->project());
|
|
|
|
|
Q_ASSERT(m_selector);
|
|
|
|
|
|
2010-02-22 14:42:37 +01:00
|
|
|
int index(m_targets.indexOf(target));
|
2010-02-08 15:50:06 +01:00
|
|
|
if (index < 0)
|
|
|
|
|
return;
|
2010-02-22 14:42:37 +01:00
|
|
|
m_targets.removeAt(index);
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
m_selector->removeTarget(index);
|
2010-03-15 10:52:18 +01:00
|
|
|
|
|
|
|
|
updateTargetAddAndRemoveButtons();
|
2010-02-08 15:50:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TargetSettingsPanelWidget::activeTargetChanged(ProjectExplorer::Target *target)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(m_project == target->project());
|
|
|
|
|
Q_ASSERT(m_selector);
|
|
|
|
|
|
2010-03-26 12:44:55 +01:00
|
|
|
int index = m_targets.indexOf(target);
|
|
|
|
|
m_selector->setCurrentIndex(index);
|
2010-02-08 15:50:06 +01:00
|
|
|
}
|
2010-03-15 10:52:18 +01:00
|
|
|
|
|
|
|
|
void TargetSettingsPanelWidget::updateTargetAddAndRemoveButtons()
|
|
|
|
|
{
|
|
|
|
|
if (!m_selector)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-06-29 12:56:08 +02:00
|
|
|
m_addMenu->clear();
|
|
|
|
|
|
2010-12-06 16:15:41 +01:00
|
|
|
QList<ITargetFactory *> factories =
|
|
|
|
|
ExtensionSystem::PluginManager::instance()->getObjects<ITargetFactory>();
|
|
|
|
|
|
2010-12-10 19:02:19 +01:00
|
|
|
foreach (ITargetFactory *fac, factories) {
|
|
|
|
|
foreach (const QString &id, fac->supportedTargetIds(m_project)) {
|
|
|
|
|
if (m_project->target(id))
|
|
|
|
|
continue;
|
|
|
|
|
QString displayName = fac->displayNameForId(id);
|
|
|
|
|
QAction *action = new QAction(displayName, m_addMenu);
|
|
|
|
|
action->setData(QVariant(id));
|
|
|
|
|
bool added = false;
|
2011-01-17 14:17:32 +01:00
|
|
|
foreach (QAction *existing, m_addMenu->actions()) {
|
2010-12-10 19:02:19 +01:00
|
|
|
if (existing->text() > action->text()) {
|
|
|
|
|
m_addMenu->insertAction(existing, action);
|
|
|
|
|
added = true;
|
|
|
|
|
}
|
2010-12-06 16:15:41 +01:00
|
|
|
}
|
|
|
|
|
|
2010-12-10 19:02:19 +01:00
|
|
|
if (!added)
|
|
|
|
|
m_addMenu->addAction(action);
|
2010-06-29 12:56:08 +02:00
|
|
|
}
|
|
|
|
|
}
|
2010-12-10 19:02:19 +01:00
|
|
|
|
2010-06-29 12:56:08 +02:00
|
|
|
m_selector->setAddButtonEnabled(!m_addMenu->actions().isEmpty());
|
2010-03-15 10:52:18 +01:00
|
|
|
m_selector->setRemoveButtonEnabled(m_project->targets().count() > 1);
|
|
|
|
|
}
|
2010-10-06 11:15:01 +02:00
|
|
|
|
|
|
|
|
int TargetSettingsPanelWidget::currentSubIndex() const
|
|
|
|
|
{
|
|
|
|
|
return m_selector->currentSubIndex();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TargetSettingsPanelWidget::setCurrentSubIndex(int subIndex)
|
|
|
|
|
{
|
|
|
|
|
m_selector->setCurrentSubIndex(subIndex);
|
|
|
|
|
}
|