targetsettingspanel.cpp 18.3 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
Tobias Hunger's avatar
Tobias Hunger committed
2
**
Eike Ziller's avatar
Eike Ziller committed
3
4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
Tobias Hunger's avatar
Tobias Hunger committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
Tobias Hunger's avatar
Tobias Hunger committed
7
**
hjk's avatar
hjk committed
8
9
10
11
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
Eike Ziller's avatar
Eike Ziller committed
12
13
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
Eike Ziller's avatar
Eike Ziller committed
14
** use the contact form at http://www.qt.io/contact-us.
Tobias Hunger's avatar
Tobias Hunger committed
15
16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18
19
20
21
22
23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
hjk's avatar
hjk committed
24
**
Eike Ziller's avatar
Eike Ziller committed
25
26
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
con's avatar
con committed
27
28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
Tobias Hunger's avatar
Tobias Hunger committed
30
31
32

#include "targetsettingspanel.h"

33
#include "buildinfo.h"
Tobias Hunger's avatar
Tobias Hunger committed
34
#include "buildsettingspropertiespage.h"
35
#include "ipotentialkit.h"
36
#include "kitoptionspage.h"
37
#include "panelswidget.h"
Tobias Hunger's avatar
Tobias Hunger committed
38
#include "project.h"
39
#include "projectimporter.h"
Tobias Hunger's avatar
Tobias Hunger committed
40
#include "projectwindow.h"
41
#include "propertiespanel.h"
Tobias Hunger's avatar
Tobias Hunger committed
42
#include "runsettingspropertiespage.h"
43
#include "session.h"
Tobias Hunger's avatar
Tobias Hunger committed
44
45
46
#include "target.h"
#include "targetsettingswidget.h"

47
#include <coreplugin/icore.h>
Tobias Hunger's avatar
Tobias Hunger committed
48
#include <extensionsystem/pluginmanager.h>
Daniel Teske's avatar
Daniel Teske committed
49
#include <projectexplorer/projectexplorer.h>
Tobias Hunger's avatar
Tobias Hunger committed
50
51
#include <projectexplorer/kit.h>
#include <projectexplorer/kitmanager.h>
Daniel Teske's avatar
Daniel Teske committed
52
#include <projectexplorer/buildmanager.h>
53
#include <projectexplorer/buildconfiguration.h>
54
#include <utils/algorithm.h>
Tobias Hunger's avatar
Tobias Hunger committed
55
#include <utils/qtcassert.h>
Tobias Hunger's avatar
Tobias Hunger committed
56

57
#include <QFileDialog>
58
59
60
61
#include <QLabel>
#include <QMenu>
#include <QMessageBox>
#include <QPushButton>
62
63
64
#include <QStackedWidget>
#include <QToolTip>
#include <QVBoxLayout>
Tobias Hunger's avatar
Tobias Hunger committed
65
66


hjk's avatar
hjk committed
67
68
69
70
using namespace Core;

namespace ProjectExplorer {
namespace Internal {
Tobias Hunger's avatar
Tobias Hunger committed
71

72
73
int TargetSettingsPanelWidget::s_targetSubIndex = -1;

Tobias Hunger's avatar
Tobias Hunger committed
74
75
76
77
78
///
// TargetSettingsWidget
///

TargetSettingsPanelWidget::TargetSettingsPanelWidget(Project *project) :
79
    m_currentTarget(0),
Tobias Hunger's avatar
Tobias Hunger committed
80
    m_project(project),
81
    m_importer(project->createProjectImporter()),
Tobias Hunger's avatar
Tobias Hunger committed
82
    m_selector(0),
83
    m_centralWidget(0),
84
85
    m_changeMenu(0),
    m_duplicateMenu(0),
86
87
    m_lastAction(0),
    m_importAction(0)
Tobias Hunger's avatar
Tobias Hunger committed
88
{
89
90
    Q_ASSERT(m_project);

Tobias Hunger's avatar
Tobias Hunger committed
91
92
93
    m_panelWidgets[0] = 0;
    m_panelWidgets[1] = 0;

94
    m_addMenu = new QMenu(this);
95
    m_targetMenu = new QMenu(this);
96

97
98
99
100
101
    if (m_importer) {
        m_importAction = new QAction(tr("Import existing build..."), this);
        connect(m_importAction, SIGNAL(triggered()), this, SLOT(importTarget()));
    }

102
103
    setFocusPolicy(Qt::NoFocus);

Tobias Hunger's avatar
Tobias Hunger committed
104
105
106
107
    setupUi();

    connect(m_project, SIGNAL(addedTarget(ProjectExplorer::Target*)),
            this, SLOT(targetAdded(ProjectExplorer::Target*)));
108
109
110
    connect(m_project, SIGNAL(removedTarget(ProjectExplorer::Target*)),
            this, SLOT(removedTarget(ProjectExplorer::Target*)));

Tobias Hunger's avatar
Tobias Hunger committed
111
112
    connect(m_project, SIGNAL(activeTargetChanged(ProjectExplorer::Target*)),
            this, SLOT(activeTargetChanged(ProjectExplorer::Target*)));
113

Tobias Hunger's avatar
Tobias Hunger committed
114
    connect(KitManager::instance(), SIGNAL(kitsChanged()),
115
            this, SLOT(updateTargetButtons()));
Tobias Hunger's avatar
Tobias Hunger committed
116
117
118
119
}

TargetSettingsPanelWidget::~TargetSettingsPanelWidget()
{
120
    delete m_importer;
Tobias Hunger's avatar
Tobias Hunger committed
121
122
}

123
124
125
bool TargetSettingsPanelWidget::event(QEvent *event)
{
    if (event->type() == QEvent::StatusTip) {
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
        QAction *act = 0;
        QMenu *menu = 0;
        if (m_addMenu->activeAction()) {
            menu = m_addMenu;
            act = m_addMenu->activeAction();
        } else if (m_changeMenu && m_changeMenu->activeAction()) {
            menu = m_changeMenu;
            act = m_changeMenu->activeAction();
        } else if (m_duplicateMenu && m_duplicateMenu->activeAction()) {
            menu = m_duplicateMenu;
            act = m_duplicateMenu->activeAction();
        } else {
            return QWidget::event(event);
        }

141
142
143
144
145
146
147
        QStatusTipEvent *ev = static_cast<QStatusTipEvent *>(event);
        ev->accept();

        if (act != m_lastAction)
            QToolTip::showText(QPoint(), QString());
        m_lastAction = act;
        if (act) {
148
149
            QRect actionRect = menu->actionGeometry(act);
            actionRect.translate(menu->pos());
150
151
152
153
            QPoint p = QCursor::pos();
            if (!actionRect.contains(p))
                p = actionRect.center();
            p.setY(actionRect.center().y());
154
            QToolTip::showText(p, ev->tip(), menu, menu->actionGeometry(act));
155
156
157
158
159
160
161
162
163
        } else {
            QToolTip::showText(QPoint(), QString());
        }

        return true;
    }
    return QWidget::event(event);
}

Tobias Hunger's avatar
Tobias Hunger committed
164
165
166
167
168
169
170
171
172
173
174
175
176
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);

177
    // no target label:
Tobias Hunger's avatar
Tobias Hunger committed
178
    m_noTargetLabel = new QWidget;
179
    QVBoxLayout *noTargetLayout = new QVBoxLayout(m_noTargetLabel);
Tobias Hunger's avatar
Tobias Hunger committed
180
181
    noTargetLayout->setMargin(0);
    QLabel *label = new QLabel(m_noTargetLabel);
182
    label->setText(tr("No kit defined in this project."));
Tobias Hunger's avatar
Tobias Hunger committed
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
    {
        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);

dt's avatar
dt committed
198
199
200
    // Now set the correct target
    int index = m_targets.indexOf(m_project->activeTarget());
    m_selector->setCurrentIndex(index);
201
    m_selector->setCurrentSubIndex(s_targetSubIndex);
202
    currentTargetChanged(index, m_selector->currentSubIndex());
dt's avatar
dt committed
203
204
205

    connect(m_selector, SIGNAL(currentChanged(int,int)),
            this, SLOT(currentTargetChanged(int,int)));
206
207
    connect(m_selector, SIGNAL(manageButtonClicked()),
            this, SLOT(openTargetPreferences()));
208
209
    connect(m_selector, SIGNAL(toolTipRequested(QPoint,int)),
            this, SLOT(showTargetToolTip(QPoint,int)));
210
211
    connect(m_selector, SIGNAL(menuShown(int)),
            this, SLOT(menuShown(int)));
Tobias Hunger's avatar
Tobias Hunger committed
212

213
    connect(m_addMenu, SIGNAL(triggered(QAction*)),
214
            this, SLOT(addActionTriggered(QAction*)));
215

216
217
218
219
    m_selector->setAddButtonMenu(m_addMenu);
    m_selector->setTargetMenu(m_targetMenu);

    updateTargetButtons();
Tobias Hunger's avatar
Tobias Hunger committed
220
221
}

222
void TargetSettingsPanelWidget::currentTargetChanged(int targetIndex, int subIndex)
Tobias Hunger's avatar
Tobias Hunger committed
223
{
224
    if (targetIndex < -1 || targetIndex >= m_targets.count())
Tobias Hunger's avatar
Tobias Hunger committed
225
226
227
228
        return;
    if (subIndex < -1 || subIndex >= 2)
        return;

Tobias Hunger's avatar
Tobias Hunger committed
229
    if (targetIndex == -1 || subIndex == -1) { // no more kits!
230
231
232
233
234
235
236
237
238
        delete m_panelWidgets[0];
        m_panelWidgets[0] = 0;
        delete m_panelWidgets[1];
        m_panelWidgets[1] = 0;

        m_centralWidget->setCurrentWidget(m_noTargetLabel);
        return;
    }

239
240
    s_targetSubIndex = subIndex;

241
    Target *target = m_targets.at(targetIndex);
Tobias Hunger's avatar
Tobias Hunger committed
242
243

    // Target was not actually changed:
244
    if (m_currentTarget == target) {
245
246
247
248
        if (m_panelWidgets[subIndex])
            m_centralWidget->setCurrentWidget(m_panelWidgets[subIndex]);
        else
            m_centralWidget->setCurrentWidget(m_noTargetLabel);
Tobias Hunger's avatar
Tobias Hunger committed
249
250
251
        return;
    }

252
    // Target has changed:
253
    m_currentTarget = target;
Tobias Hunger's avatar
Tobias Hunger committed
254

255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
    auto wrapWidgetInPropertiesPanel
            = [](QWidget *widget, const QString &displayName, const QIcon &icon) -> PropertiesPanel *{
                    PropertiesPanel *panel = new PropertiesPanel;
                    QWidget *w = new QWidget();
                    QVBoxLayout *l = new QVBoxLayout(w);
                    l->addWidget(widget);
                    l->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding));
                    l->setContentsMargins(QMargins());
                    panel->setWidget(w);
                    panel->setIcon(icon);
                    panel->setDisplayName(displayName);
                    return panel;
                };

    PropertiesPanel *build = wrapWidgetInPropertiesPanel(new BuildSettingsWidget(target),
                                                         QCoreApplication::translate("BuildSettingsPanel", "Build Settings"),
                                                         QIcon(QLatin1String(":/projectexplorer/images/BuildSettings.png")));
    PropertiesPanel *run= wrapWidgetInPropertiesPanel(new RunSettingsWidget(target),
                                                      RunSettingsWidget::tr("Run Settings"),
                                                      QIcon(QLatin1String(":/projectexplorer/images/RunSettings.png")));

276
277
    PanelsWidget *buildPanel = new PanelsWidget(m_centralWidget);
    PanelsWidget *runPanel = new PanelsWidget(m_centralWidget);
Tobias Hunger's avatar
Tobias Hunger committed
278

279
280
281
    buildPanel->addPropertiesPanel(build);
    runPanel->addPropertiesPanel(run);

Tobias Hunger's avatar
Tobias Hunger committed
282
283
284
    m_centralWidget->addWidget(buildPanel);
    m_centralWidget->addWidget(runPanel);

285
286
287
    m_centralWidget->setCurrentWidget(subIndex == 0 ? buildPanel : runPanel);

    delete m_panelWidgets[0];
Tobias Hunger's avatar
Tobias Hunger committed
288
    m_panelWidgets[0] = buildPanel;
289
    delete m_panelWidgets[1];
Tobias Hunger's avatar
Tobias Hunger committed
290
    m_panelWidgets[1] = runPanel;
291

292
    SessionManager::setActiveTarget(m_project, target, SetActive::Cascade);
Tobias Hunger's avatar
Tobias Hunger committed
293
294
}

295
296
297
298
299
300
301
void TargetSettingsPanelWidget::menuShown(int targetIndex)
{
    m_menuTargetIndex = targetIndex;
}

void TargetSettingsPanelWidget::changeActionTriggered(QAction *action)
{
302
    Kit *k = KitManager::find(action->data().value<Id>());
303
    Target *sourceTarget = m_targets.at(m_menuTargetIndex);
304
    Target *newTarget = m_project->cloneTarget(sourceTarget, k);
305
306
307

    if (newTarget) {
        m_project->addTarget(newTarget);
308
        SessionManager::setActiveTarget(m_project, newTarget, SetActive::Cascade);
309
310
311
312
313
314
        m_project->removeTarget(sourceTarget);
    }
}

void TargetSettingsPanelWidget::duplicateActionTriggered(QAction *action)
{
315
    Kit *k = KitManager::find(action->data().value<Id>());
316
    Target *newTarget = m_project->cloneTarget(m_targets.at(m_menuTargetIndex), k);
317
318
319

    if (newTarget) {
        m_project->addTarget(newTarget);
320
        SessionManager::setActiveTarget(m_project, newTarget, SetActive::Cascade);
321
322
323
324
    }
}

void TargetSettingsPanelWidget::addActionTriggered(QAction *action)
Tobias Hunger's avatar
Tobias Hunger committed
325
{
326
    const QVariant data = action->data();
327
328
    if (data.canConvert<Id>()) { // id of kit
        Kit *k = KitManager::find(action->data().value<Id>());
329
        QTC_ASSERT(!m_project->target(k), return);
330

331
        m_project->addTarget(m_project->createTarget(k));
332
333
334
335
336
    } else {
        QTC_ASSERT(data.canConvert<IPotentialKit *>(), return);
        IPotentialKit *potentialKit = data.value<IPotentialKit *>();
        potentialKit->executeFromMenu();
    }
Tobias Hunger's avatar
Tobias Hunger committed
337
338
}

339
void TargetSettingsPanelWidget::removeTarget()
340
{
341
    Target *t = m_targets.at(m_menuTargetIndex);
Daniel Teske's avatar
Daniel Teske committed
342

hjk's avatar
hjk committed
343
    if (BuildManager::isBuilding(t)) {
Daniel Teske's avatar
Daniel Teske committed
344
        QMessageBox box;
Tobias Hunger's avatar
Tobias Hunger committed
345
        QPushButton *closeAnyway = box.addButton(tr("Cancel Build && Remove Kit"), QMessageBox::AcceptRole);
Daniel Teske's avatar
Daniel Teske committed
346
347
        QPushButton *cancelClose = box.addButton(tr("Do Not Remove"), QMessageBox::RejectRole);
        box.setDefaultButton(cancelClose);
Tobias Hunger's avatar
Tobias Hunger committed
348
349
        box.setWindowTitle(tr("Remove Kit %1?").arg(t->displayName()));
        box.setText(tr("The kit <b>%1</b> is currently being built.").arg(t->displayName()));
350
        box.setInformativeText(tr("Do you want to cancel the build process and remove the kit anyway?"));
Daniel Teske's avatar
Daniel Teske committed
351
352
353
        box.exec();
        if (box.clickedButton() != closeAnyway)
            return;
hjk's avatar
hjk committed
354
        BuildManager::cancel();
Daniel Teske's avatar
Daniel Teske committed
355
356
357
358
    } 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"
Tobias Hunger's avatar
Tobias Hunger committed
359
                                          "\"%1\" kit?").arg(t->displayName()),
Daniel Teske's avatar
Daniel Teske committed
360
361
362
363
364
365
366
                                        QMessageBox::Yes | QMessageBox::No,
                                        QMessageBox::No);
        if (ret != QMessageBox::Yes)
            return;
    }

    m_project->removeTarget(t);
367
368
}

369
370
371
372
373
374
375
void TargetSettingsPanelWidget::showTargetToolTip(const QPoint &globalPos, int targetIndex)
{
    QTC_ASSERT(targetIndex >= 0 && targetIndex < m_targets.count(), return);
    Target *target = m_targets.at(targetIndex);
    QToolTip::showText(globalPos, target->kit()->toHtml());
}

376
void TargetSettingsPanelWidget::targetAdded(Target *target)
Tobias Hunger's avatar
Tobias Hunger committed
377
378
379
380
{
    Q_ASSERT(m_project == target->project());
    Q_ASSERT(m_selector);

381
382
383
384
    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);
385
386
387
            m_selector->insertTarget(pos, m_project->hasActiveBuildSettings() ? 0 : 1,
                                     target->displayName());

388
389
390
391
            break;
        }
    }

Tobias Hunger's avatar
Tobias Hunger committed
392
    connect(target, SIGNAL(displayNameChanged()), this, SLOT(renameTarget()));
393
    updateTargetButtons();
Tobias Hunger's avatar
Tobias Hunger committed
394
395
}

396
void TargetSettingsPanelWidget::removedTarget(Target *target)
Tobias Hunger's avatar
Tobias Hunger committed
397
398
399
400
{
    Q_ASSERT(m_project == target->project());
    Q_ASSERT(m_selector);

401
    int index(m_targets.indexOf(target));
Tobias Hunger's avatar
Tobias Hunger committed
402
403
    if (index < 0)
        return;
404
405
    m_targets.removeAt(index);

Tobias Hunger's avatar
Tobias Hunger committed
406
    m_selector->removeTarget(index);
407

408
    updateTargetButtons();
Tobias Hunger's avatar
Tobias Hunger committed
409
410
}

411
void TargetSettingsPanelWidget::activeTargetChanged(Target *target)
Tobias Hunger's avatar
Tobias Hunger committed
412
413
414
{
    Q_ASSERT(m_selector);

415
416
    int index = m_targets.indexOf(target);
    m_selector->setCurrentIndex(index);
Tobias Hunger's avatar
Tobias Hunger committed
417
}
418

419
420
421
422
void TargetSettingsPanelWidget::createAction(Kit *k, QMenu *menu)
{
    QAction *action = new QAction(k->displayName(), menu);
    action->setData(QVariant::fromValue(k->id()));
423
    QString statusTip = QLatin1String("<html><body>");
424
425
426
    QString errorMessage;
    if (!m_project->supportsKit(k, &errorMessage)) {
        action->setEnabled(false);
427
        statusTip += errorMessage;
428
    }
429
430
431
    statusTip += k->toHtml();
    action->setStatusTip(statusTip);

432
433
434
435
    menu->addAction(action);
}

void TargetSettingsPanelWidget::updateTargetButtons()
436
437
438
439
{
    if (!m_selector)
        return;

440
    m_addMenu->clear();
441
    m_targetMenu->clear();
442

443
    if (m_importAction)
444
        m_addMenu->addAction(m_importAction);
445
446
447
448
449
450
451
452
    const QList<IPotentialKit *> potentialKits
            = ExtensionSystem::PluginManager::getObjects<IPotentialKit>();
    foreach (IPotentialKit *potentialKit, potentialKits) {
        if (!potentialKit->isEnabled())
            continue;
        QAction *action = new QAction(potentialKit->displayName(), m_addMenu);
        action->setData(QVariant::fromValue(potentialKit));
        m_addMenu->addAction(action);
453
    }
454
455
    if (!m_addMenu->actions().isEmpty())
        m_addMenu->addSeparator();
456

457
458
459
    m_changeMenu = m_targetMenu->addMenu(tr("Change Kit"));
    m_duplicateMenu = m_targetMenu->addMenu(tr("Copy to Kit"));
    QAction *removeAction = m_targetMenu->addAction(tr("Remove Kit"));
460

461
462
    if (m_project->targets().size() < 2)
        removeAction->setEnabled(false);
Tobias Hunger's avatar
Tobias Hunger committed
463

464
465
466
467
468
    connect(m_changeMenu, &QMenu::triggered,
            this, &TargetSettingsPanelWidget::changeActionTriggered);
    connect(m_duplicateMenu, &QMenu::triggered,
            this, &TargetSettingsPanelWidget::duplicateActionTriggered);
    connect(removeAction, &QAction::triggered, this, &TargetSettingsPanelWidget::removeTarget);
469

470
    foreach (Kit *k, KitManager::sortKits(KitManager::kits())) {
471
472
473
474
475
        if (m_project->target(k))
            continue;
        createAction(k, m_addMenu);
        createAction(k, m_changeMenu);
        createAction(k, m_duplicateMenu);
476
    }
477
478
479
480
481
    if (m_changeMenu->actions().isEmpty())
        m_changeMenu->setEnabled(false);
    if (m_duplicateMenu->actions().isEmpty())
        m_duplicateMenu->setEnabled(false);

482
    m_selector->setAddButtonEnabled(!m_addMenu->actions().isEmpty());
483
}
484

Tobias Hunger's avatar
Tobias Hunger committed
485
486
487
488
489
490
491
492
493
494
495
void TargetSettingsPanelWidget::renameTarget()
{
    Target *t = qobject_cast<Target *>(sender());
    if (!t)
        return;
    const int pos = m_targets.indexOf(t);
    if (pos < 0)
        return;
    m_selector->renameTarget(pos, t->displayName());
}

496
497
void TargetSettingsPanelWidget::openTargetPreferences()
{
498
499
    int targetIndex = m_selector->currentIndex();
    if (targetIndex >= 0 && targetIndex < m_targets.size()) {
500
        if (KitOptionsPage *page = ExtensionSystem::PluginManager::getObject<KitOptionsPage>())
501
502
            page->showKit(m_targets.at(targetIndex)->kit());
    }
503
    ICore::showOptionsDialog(Constants::KITS_SETTINGS_PAGE_ID, this);
504
505
}

506
507
void TargetSettingsPanelWidget::importTarget()
{
508
    QString toImport = QFileDialog::getExistingDirectory(this, tr("Import directory"), m_project->projectDirectory().toString());
509
510
511
512
513
514
515
516
517
518
519
520
521
522
    importTarget(Utils::FileName::fromString(toImport));
}

void TargetSettingsPanelWidget::importTarget(const Utils::FileName &path)
{
    if (!m_importer)
        return;

    Target *target = 0;
    BuildConfiguration *bc = 0;
    QList<BuildInfo *> toImport = m_importer->import(path, false);
    foreach (BuildInfo *info, toImport) {
        target = m_project->target(info->kitId);
        if (!target) {
523
            target = m_project->createTarget(KitManager::find(info->kitId));
524
525
526
527
528
529
            m_project->addTarget(target);
        }
        bc = info->factory()->create(target, info);
        QTC_ASSERT(bc, continue);
        target->addBuildConfiguration(bc);
    }
530
531
532

    SessionManager::setActiveTarget(m_project, target, SetActive::Cascade);

533
    if (target && bc)
534
        SessionManager::setActiveBuildConfiguration(target, bc, SetActive::Cascade);
535
536
537
538

    qDeleteAll(toImport);
}

539
540
541
542
543
544
545
546
547
int TargetSettingsPanelWidget::currentSubIndex() const
{
    return m_selector->currentSubIndex();
}

void TargetSettingsPanelWidget::setCurrentSubIndex(int subIndex)
{
    m_selector->setCurrentSubIndex(subIndex);
}
hjk's avatar
hjk committed
548
549
550

} // namespace Internal
} // namespace ProjectExplorer