cmakerunconfiguration.cpp 21.4 KB
Newer Older
1
/**************************************************************************
dt's avatar
dt committed
2
3
4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
dt's avatar
dt committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
dt's avatar
dt committed
8
**
9
** Commercial Usage
dt's avatar
dt committed
10
**
11
12
13
14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
dt's avatar
dt committed
15
**
16
** GNU Lesser General Public License Usage
dt's avatar
dt committed
17
**
18
19
20
21
22
23
** Alternatively, 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.
dt's avatar
dt committed
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
dt's avatar
dt committed
27
**
28
**************************************************************************/
dt's avatar
dt committed
29
30

#include "cmakerunconfiguration.h"
hjk's avatar
hjk committed
31

32
#include "cmakebuildconfiguration.h"
Tobias Hunger's avatar
Tobias Hunger committed
33
#include "cmakeproject.h"
hjk's avatar
hjk committed
34
#include "cmakeprojectconstants.h"
Tobias Hunger's avatar
Tobias Hunger committed
35
#include "cmaketarget.h"
dt's avatar
dt committed
36

37
#include <coreplugin/coreconstants.h>
38
#include <projectexplorer/debugginghelper.h>
hjk's avatar
hjk committed
39
#include <utils/qtcassert.h>
40
#include <utils/debuggerlanguagechooser.h>
41
42
#include <QtGui/QFormLayout>
#include <QtGui/QLineEdit>
43
44
#include <QtGui/QGroupBox>
#include <QtGui/QLabel>
45
#include <QtGui/QComboBox>
46
#include <QtGui/QToolButton>
dt's avatar
dt committed
47
48
49
50

using namespace CMakeProjectManager;
using namespace CMakeProjectManager::Internal;

51
52
53
54
55
56
57
58
59
60
61
62
63
namespace {
const char * const CMAKE_RC_ID("CMakeProjectManager.CMakeRunConfiguration");
const char * const CMAKE_RC_PREFIX("CMakeProjectManager.CMakeRunConfiguration.");

const char * const TARGET_KEY("CMakeProjectManager.CMakeRunConfiguration.Target");
const char * const WORKING_DIRECTORY_KEY("CMakeProjectManager.CMakeRunConfiguration.WorkingDirectory");
const char * const USER_WORKING_DIRECTORY_KEY("CMakeProjectManager.CMakeRunConfiguration.UserWorkingDirectory");
const char * const USE_TERMINAL_KEY("CMakeProjectManager.CMakeRunConfiguration.UseTerminal");
const char * const TITLE_KEY("CMakeProjectManager.CMakeRunConfiguation.Title");
const char * const ARGUMENTS_KEY("CMakeProjectManager.CMakeRunConfiguration.Arguments");
const char * const USER_ENVIRONMENT_CHANGES_KEY("CMakeProjectManager.CMakeRunConfiguration.UserEnvironmentChanges");
const char * const BASE_ENVIRONMENT_BASE_KEY("CMakeProjectManager.BaseEnvironmentBase");

64
QString buildTargetFromId(const QString &id)
dt's avatar
dt committed
65
{
66
67
68
69
    if (!id.startsWith(QLatin1String(CMAKE_RC_PREFIX)))
        return QString();
    return id.mid(QString::fromLatin1(CMAKE_RC_PREFIX).length());
}
70

71
QString idFromBuildTarget(const QString &target)
72
73
{
    return QString::fromLatin1(CMAKE_RC_PREFIX) + target;
dt's avatar
dt committed
74
}
hjk's avatar
hjk committed
75

76
77
} // namespace

Tobias Hunger's avatar
Tobias Hunger committed
78
79
CMakeRunConfiguration::CMakeRunConfiguration(CMakeTarget *parent, const QString &target, const QString &workingDirectory, const QString &title) :
    ProjectExplorer::LocalApplicationRunConfiguration(parent, QString::fromLatin1(CMAKE_RC_PREFIX)),
80
    m_runMode(Gui),
81
    m_buildTarget(target),
82
83
    m_workingDirectory(workingDirectory),
    m_title(title),
84
85
    m_baseEnvironmentBase(CMakeRunConfiguration::BuildEnvironmentBase),
    m_enabled(true)
dt's avatar
dt committed
86
{
87
88
    ctor();
}
dt's avatar
dt committed
89

Tobias Hunger's avatar
Tobias Hunger committed
90
91
CMakeRunConfiguration::CMakeRunConfiguration(CMakeTarget *parent, CMakeRunConfiguration *source) :
    ProjectExplorer::LocalApplicationRunConfiguration(parent, source),
92
    m_runMode(source->m_runMode),
93
    m_buildTarget(source->m_buildTarget),
94
95
96
97
98
    m_workingDirectory(source->m_workingDirectory),
    m_userWorkingDirectory(source->m_userWorkingDirectory),
    m_title(source->m_title),
    m_arguments(source->m_arguments),
    m_userEnvironmentChanges(source->m_userEnvironmentChanges),
99
100
    m_baseEnvironmentBase(source->m_baseEnvironmentBase),
    m_enabled(source->m_enabled)
101
102
{
    ctor();
dt's avatar
dt committed
103
104
}

105
CMakeRunConfiguration::~CMakeRunConfiguration()
dt's avatar
dt committed
106
{
dt's avatar
dt committed
107
108
}

109
void CMakeRunConfiguration::ctor()
dt's avatar
dt committed
110
{
111
    setDefaultDisplayName(defaultDisplayName());
Tobias Hunger's avatar
Tobias Hunger committed
112
}
113

Tobias Hunger's avatar
Tobias Hunger committed
114
115
116
CMakeTarget *CMakeRunConfiguration::cmakeTarget() const
{
    return static_cast<CMakeTarget *>(target());
117
118
}

Tobias Hunger's avatar
Tobias Hunger committed
119
CMakeBuildConfiguration *CMakeRunConfiguration::activeBuildConfiguration() const
120
{
Tobias Hunger's avatar
Tobias Hunger committed
121
    return cmakeTarget()->activeBuildConfiguration();
dt's avatar
dt committed
122
123
124
125
}

QString CMakeRunConfiguration::executable() const
{
126
    return m_buildTarget;
dt's avatar
dt committed
127
128
}

129
ProjectExplorer::LocalApplicationRunConfiguration::RunMode CMakeRunConfiguration::runMode() const
dt's avatar
dt committed
130
{
131
    return m_runMode;
dt's avatar
dt committed
132
133
134
135
}

QString CMakeRunConfiguration::workingDirectory() const
{
136
137
    if (!m_userWorkingDirectory.isEmpty())
        return m_userWorkingDirectory;
dt's avatar
dt committed
138
139
140
141
142
    return m_workingDirectory;
}

QStringList CMakeRunConfiguration::commandLineArguments() const
{
143
    return Utils::Environment::parseCombinedArgString(m_arguments);
dt's avatar
dt committed
144
145
}

dt's avatar
dt committed
146
147
148
149
150
151
152
QString CMakeRunConfiguration::title() const
{
    return m_title;
}

void CMakeRunConfiguration::setExecutable(const QString &executable)
{
153
    m_buildTarget = executable;
dt's avatar
dt committed
154
155
}

156
void CMakeRunConfiguration::setWorkingDirectory(const QString &wd)
dt's avatar
dt committed
157
{
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
    const QString & oldWorkingDirectory = workingDirectory();

    m_workingDirectory = wd;

    const QString &newWorkingDirectory = workingDirectory();
    if (oldWorkingDirectory != newWorkingDirectory)
        emit workingDirectoryChanged(newWorkingDirectory);
}

void CMakeRunConfiguration::setUserWorkingDirectory(const QString &wd)
{
    const QString & oldWorkingDirectory = workingDirectory();

    m_userWorkingDirectory = wd;

    const QString &newWorkingDirectory = workingDirectory();
    if (oldWorkingDirectory != newWorkingDirectory)
        emit workingDirectoryChanged(newWorkingDirectory);
dt's avatar
dt committed
176
177
}

178
QVariantMap CMakeRunConfiguration::toMap() const
dt's avatar
dt committed
179
{
180
181
    QVariantMap map(ProjectExplorer::LocalApplicationRunConfiguration::toMap());

182
    map.insert(QLatin1String(TARGET_KEY), m_buildTarget);
183
184
185
186
187
    map.insert(QLatin1String(WORKING_DIRECTORY_KEY), m_workingDirectory);
    map.insert(QLatin1String(USER_WORKING_DIRECTORY_KEY), m_userWorkingDirectory);
    map.insert(QLatin1String(USE_TERMINAL_KEY), m_runMode == Console);
    map.insert(QLatin1String(TITLE_KEY), m_title);
    map.insert(QLatin1String(ARGUMENTS_KEY), m_arguments);
188
    map.insert(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY), Utils::EnvironmentItem::toStringList(m_userEnvironmentChanges));
189
    map.insert(QLatin1String(BASE_ENVIRONMENT_BASE_KEY), m_baseEnvironmentBase);
190

191
    return map;
dt's avatar
dt committed
192
193
}

194
bool CMakeRunConfiguration::fromMap(const QVariantMap &map)
dt's avatar
dt committed
195
{
196
    m_buildTarget = map.value(QLatin1String(TARGET_KEY)).toString();
197
198
199
200
201
    m_workingDirectory = map.value(QLatin1String(WORKING_DIRECTORY_KEY)).toString();
    m_userWorkingDirectory = map.value(QLatin1String(USER_WORKING_DIRECTORY_KEY)).toString();
    m_runMode = map.value(QLatin1String(USE_TERMINAL_KEY)).toBool() ? Console : Gui;
    m_title = map.value(QLatin1String(TITLE_KEY)).toString();
    m_arguments = map.value(QLatin1String(ARGUMENTS_KEY)).toString();
202
    m_userEnvironmentChanges = Utils::EnvironmentItem::fromStringList(map.value(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY)).toStringList());
203
204
205
    m_baseEnvironmentBase = static_cast<BaseEnvironmentBase>(map.value(QLatin1String(BASE_ENVIRONMENT_BASE_KEY), static_cast<int>(CMakeRunConfiguration::BuildEnvironmentBase)).toInt());

    return RunConfiguration::fromMap(map);
dt's avatar
dt committed
206
207
}

208
209
210
211
212
213
214
QString CMakeRunConfiguration::defaultDisplayName() const
{
    if (m_title.isEmpty())
        return tr("Run CMake target");
    return m_title + (m_enabled ? "" : tr(" (disabled)"));
}

215
QWidget *CMakeRunConfiguration::createConfigurationWidget()
dt's avatar
dt committed
216
{
217
    return new CMakeRunConfigurationWidget(this);
218
219
220
221
222
}

void CMakeRunConfiguration::setArguments(const QString &newText)
{
    m_arguments = newText;
dt's avatar
dt committed
223
224
}

225
226
QString CMakeRunConfiguration::dumperLibrary() const
{
227
    QString qmakePath = ProjectExplorer::DebuggingHelperLibrary::findSystemQt(environment());
dt's avatar
dt committed
228
229
    QString qtInstallData = ProjectExplorer::DebuggingHelperLibrary::qtInstallDataDir(qmakePath);
    QString dhl = ProjectExplorer::DebuggingHelperLibrary::debuggingHelperLibraryByInstallData(qtInstallData);
230
    return dhl;
231
232
}

233
234
235
QStringList CMakeRunConfiguration::dumperLibraryLocations() const
{
    QString qmakePath = ProjectExplorer::DebuggingHelperLibrary::findSystemQt(environment());
dt's avatar
dt committed
236
237
    QString qtInstallData = ProjectExplorer::DebuggingHelperLibrary::qtInstallDataDir(qmakePath);
    return ProjectExplorer::DebuggingHelperLibrary::debuggingHelperLibraryLocationsByInstallData(qtInstallData);
238
239
}

240
Utils::Environment CMakeRunConfiguration::baseEnvironment() const
241
{
242
    Utils::Environment env;
243
244
245
    if (m_baseEnvironmentBase == CMakeRunConfiguration::CleanEnvironmentBase) {
        // Nothing
    } else  if (m_baseEnvironmentBase == CMakeRunConfiguration::SystemEnvironmentBase) {
246
        env = Utils::Environment::systemEnvironment();
247
    } else  if (m_baseEnvironmentBase == CMakeRunConfiguration::BuildEnvironmentBase) {
Tobias Hunger's avatar
Tobias Hunger committed
248
        env = activeBuildConfiguration()->environment();
249
    }
250
251
252
    return env;
}

253
254
255
256
257
258
259
260
261
262
263
264
QString CMakeRunConfiguration::baseEnvironmentText() const
{
    if (m_baseEnvironmentBase == CMakeRunConfiguration::CleanEnvironmentBase) {
        return tr("Clean Environment");
    } else  if (m_baseEnvironmentBase == CMakeRunConfiguration::SystemEnvironmentBase) {
        return tr("System Environment");
    } else  if (m_baseEnvironmentBase == CMakeRunConfiguration::BuildEnvironmentBase) {
        return tr("Build Environment");
    }
    return QString();
}

265
266
267
268
269
270
271
272
273
274
275
276
277
void CMakeRunConfiguration::setBaseEnvironmentBase(BaseEnvironmentBase env)
{
    if (m_baseEnvironmentBase == env)
        return;
    m_baseEnvironmentBase = env;
    emit baseEnvironmentChanged();
}

CMakeRunConfiguration::BaseEnvironmentBase CMakeRunConfiguration::baseEnvironmentBase() const
{
    return m_baseEnvironmentBase;
}

278
Utils::Environment CMakeRunConfiguration::environment() const
279
{
280
    Utils::Environment env = baseEnvironment();
281
282
283
284
    env.modify(userEnvironmentChanges());
    return env;
}

285
QList<Utils::EnvironmentItem> CMakeRunConfiguration::userEnvironmentChanges() const
286
287
288
289
{
    return m_userEnvironmentChanges;
}

290
void CMakeRunConfiguration::setUserEnvironmentChanges(const QList<Utils::EnvironmentItem> &diff)
291
292
293
294
295
296
297
{
    if (m_userEnvironmentChanges != diff) {
        m_userEnvironmentChanges = diff;
        emit userEnvironmentChangesChanged(diff);
    }
}

298
299
ProjectExplorer::ToolChain::ToolChainType CMakeRunConfiguration::toolChainType() const
{
Tobias Hunger's avatar
Tobias Hunger committed
300
301
302
    CMakeBuildConfiguration *bc = activeBuildConfiguration();
    if (!bc)
        return ProjectExplorer::ToolChain::UNKNOWN;
303
    return bc->toolChainType();
304
305
}

306
307
308
309
310
311
void CMakeRunConfiguration::setEnabled(bool b)
{
    if (m_enabled == b)
        return;
    m_enabled = b;
    emit isEnabledChanged(isEnabled());
312
    setDefaultDisplayName(defaultDisplayName());
313
}
314

315
316
317
318
bool CMakeRunConfiguration::isEnabled(ProjectExplorer::BuildConfiguration *bc) const
{
    return m_enabled && LocalApplicationRunConfiguration::isEnabled(bc);
}
319

320
// Configuration widget
321
CMakeRunConfigurationWidget::CMakeRunConfigurationWidget(CMakeRunConfiguration *cmakeRunConfiguration, QWidget *parent)
322
    : QWidget(parent), m_ignoreChange(false), m_cmakeRunConfiguration(cmakeRunConfiguration)
323
324
325
{

    QFormLayout *fl = new QFormLayout();
326
327
    fl->setMargin(0);
    fl->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
328
    QLineEdit *argumentsLineEdit = new QLineEdit();
329
    argumentsLineEdit->setText(Utils::Environment::joinArgumentList(cmakeRunConfiguration->commandLineArguments()));
330
331
332
333
    connect(argumentsLineEdit, SIGNAL(textChanged(QString)),
            this, SLOT(setArguments(QString)));
    fl->addRow(tr("Arguments:"), argumentsLineEdit);

334
    m_workingDirectoryEdit = new Utils::PathChooser();
335
    m_workingDirectoryEdit->setBaseDirectory(m_cmakeRunConfiguration->target()->project()->projectDirectory());
336
    m_workingDirectoryEdit->setPath(m_cmakeRunConfiguration->workingDirectory());
337
    m_workingDirectoryEdit->setExpectedKind(Utils::PathChooser::Directory);
338
    m_workingDirectoryEdit->setPromptDialogTitle(tr("Select Working Directory"));
339
340
341

    QToolButton *resetButton = new QToolButton();
    resetButton->setToolTip(tr("Reset to default"));
342
    resetButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_RESET)));
343
344
345
346
347

    QHBoxLayout *boxlayout = new QHBoxLayout();
    boxlayout->addWidget(m_workingDirectoryEdit);
    boxlayout->addWidget(resetButton);

348
    fl->addRow(tr("Working directory:"), boxlayout);
349

350
351
352
353
354
    QWidget *debuggerLabelWidget = new QWidget(this);
    QVBoxLayout *debuggerLabelLayout = new QVBoxLayout(debuggerLabelWidget);
    debuggerLabelLayout->setMargin(0);
    debuggerLabelLayout->setSpacing(0);
    debuggerLabelWidget->setLayout(debuggerLabelLayout);
355
    QLabel *debuggerLabel = new QLabel(tr("Debugger:"), this);
356
357
358
    debuggerLabelLayout->addWidget(debuggerLabel);
    debuggerLabelLayout->addStretch(10);

359
    m_debuggerLanguageChooser = new Utils::DebuggerLanguageChooser(this);
360
    fl->addRow(debuggerLabelWidget, m_debuggerLanguageChooser);
361
362
363

    m_debuggerLanguageChooser->setCppChecked(m_cmakeRunConfiguration->useCppDebugger());
    m_debuggerLanguageChooser->setQmlChecked(m_cmakeRunConfiguration->useQmlDebugger());
364
    m_debuggerLanguageChooser->setQmlDebugServerPort(m_cmakeRunConfiguration->qmlDebugServerPort());
365

366
    m_detailsContainer = new Utils::DetailsWidget(this);
367
    m_detailsContainer->setState(Utils::DetailsWidget::NoSummary);
dt's avatar
dt committed
368

369
370
371
    QWidget *m_details = new QWidget(m_detailsContainer);
    m_detailsContainer->setWidget(m_details);
    m_details->setLayout(fl);
dt's avatar
dt committed
372

373
    QVBoxLayout *vbx = new QVBoxLayout(this);
374
375
    vbx->setMargin(0);;
    vbx->addWidget(m_detailsContainer);
376
377
378
379
380
381
382
383

    QLabel *environmentLabel = new QLabel(this);
    environmentLabel->setText(tr("Run Environment"));
    QFont f = environmentLabel->font();
    f.setBold(true);
    f.setPointSizeF(f.pointSizeF() *1.2);
    environmentLabel->setFont(f);
    vbx->addWidget(environmentLabel);
384

385
386
387
    QWidget *baseEnvironmentWidget = new QWidget;
    QHBoxLayout *baseEnvironmentLayout = new QHBoxLayout(baseEnvironmentWidget);
    baseEnvironmentLayout->setMargin(0);
388
    QLabel *label = new QLabel(tr("Base environment for this runconfiguration:"), this);
389
    baseEnvironmentLayout->addWidget(label);
390
    m_baseEnvironmentComboBox = new QComboBox(this);
391
392
393
394
395
396
397
    m_baseEnvironmentComboBox->addItems(QStringList()
                                        << tr("Clean Environment")
                                        << tr("System Environment")
                                        << tr("Build Environment"));
    m_baseEnvironmentComboBox->setCurrentIndex(m_cmakeRunConfiguration->baseEnvironmentBase());
    connect(m_baseEnvironmentComboBox, SIGNAL(currentIndexChanged(int)),
            this, SLOT(baseEnvironmentComboBoxChanged(int)));
398
399
    baseEnvironmentLayout->addWidget(m_baseEnvironmentComboBox);
    baseEnvironmentLayout->addStretch(10);
400

dt's avatar
dt committed
401
402
    m_environmentWidget = new ProjectExplorer::EnvironmentWidget(this, baseEnvironmentWidget);
    m_environmentWidget->setBaseEnvironment(m_cmakeRunConfiguration->baseEnvironment());
403
    m_environmentWidget->setBaseEnvironmentText(m_cmakeRunConfiguration->baseEnvironmentText());
dt's avatar
dt committed
404
405
406
407
    m_environmentWidget->setUserChanges(m_cmakeRunConfiguration->userEnvironmentChanges());

    vbx->addWidget(m_environmentWidget);

con's avatar
con committed
408
    connect(m_workingDirectoryEdit, SIGNAL(changed(QString)),
409
410
411
412
413
            this, SLOT(setWorkingDirectory()));

    connect(resetButton, SIGNAL(clicked()),
            this, SLOT(resetWorkingDirectory()));

414
415
416
417
    connect(m_debuggerLanguageChooser, SIGNAL(cppLanguageToggled(bool)),
            this, SLOT(useCppDebuggerToggled(bool)));
    connect(m_debuggerLanguageChooser, SIGNAL(qmlLanguageToggled(bool)),
            this, SLOT(useQmlDebuggerToggled(bool)));
418
419
    connect(m_debuggerLanguageChooser, SIGNAL(qmlDebugServerPortChanged(uint)),
            this, SLOT(qmlDebugServerPortChanged(uint)));
420

421
422
    connect(m_environmentWidget, SIGNAL(userChangesChanged()),
            this, SLOT(userChangesChanged()));
423

424
425
    connect(m_cmakeRunConfiguration, SIGNAL(workingDirectoryChanged(QString)),
            this, SLOT(workingDirectoryChanged(QString)));
426
427
    connect(m_cmakeRunConfiguration, SIGNAL(baseEnvironmentChanged()),
            this, SLOT(baseEnvironmentChanged()));
428
    connect(m_cmakeRunConfiguration, SIGNAL(userEnvironmentChangesChanged(QList<Utils::EnvironmentItem>)),
429
            this, SLOT(userEnvironmentChangesChanged()));
430
431
432
433
434
435
436
437

}

void CMakeRunConfigurationWidget::setWorkingDirectory()
{
    if (m_ignoreChange)
        return;
    m_ignoreChange = true;
438
    m_cmakeRunConfiguration->setUserWorkingDirectory(m_workingDirectoryEdit->rawPath());
439
440
441
442
443
444
445
446
447
448
449
450
451
    m_ignoreChange = false;
}

void CMakeRunConfigurationWidget::workingDirectoryChanged(const QString &workingDirectory)
{
    if (!m_ignoreChange)
        m_workingDirectoryEdit->setPath(workingDirectory);
}

void CMakeRunConfigurationWidget::resetWorkingDirectory()
{
    // This emits a signal connected to workingDirectoryChanged()
    // that sets the m_workingDirectoryEdit
452
    m_cmakeRunConfiguration->setUserWorkingDirectory(QString());
453
454
}

455
456
457
458
459
460
461
462
463
464
void CMakeRunConfigurationWidget::useCppDebuggerToggled(bool toggled)
{
    m_cmakeRunConfiguration->setUseCppDebugger(toggled);
}

void CMakeRunConfigurationWidget::useQmlDebuggerToggled(bool toggled)
{
    m_cmakeRunConfiguration->setUseQmlDebugger(toggled);
}

465
466
467
468
469
void CMakeRunConfigurationWidget::qmlDebugServerPortChanged(uint port)
{
    m_cmakeRunConfiguration->setQmlDebugServerPort(port);
}

470
void CMakeRunConfigurationWidget::userChangesChanged()
471
472
473
474
{
    m_cmakeRunConfiguration->setUserEnvironmentChanges(m_environmentWidget->userChanges());
}

475
void CMakeRunConfigurationWidget::baseEnvironmentComboBoxChanged(int index)
476
477
{
    m_ignoreChange = true;
478
    m_cmakeRunConfiguration->setBaseEnvironmentBase(CMakeRunConfiguration::BaseEnvironmentBase(index));
479
480

    m_environmentWidget->setBaseEnvironment(m_cmakeRunConfiguration->baseEnvironment());
481
    m_environmentWidget->setBaseEnvironmentText(m_cmakeRunConfiguration->baseEnvironmentText());
482
483
484
    m_ignoreChange = false;
}

485
486
void CMakeRunConfigurationWidget::baseEnvironmentChanged()
{
487
488
489
    if (m_ignoreChange)
        return;

490
    m_baseEnvironmentComboBox->setCurrentIndex(m_cmakeRunConfiguration->baseEnvironmentBase());
491
    m_environmentWidget->setBaseEnvironment(m_cmakeRunConfiguration->baseEnvironment());
492
    m_environmentWidget->setBaseEnvironmentText(m_cmakeRunConfiguration->baseEnvironmentText());
493
494
495
496
497
498
499
500
501
502
}

void CMakeRunConfigurationWidget::userEnvironmentChangesChanged()
{
    m_environmentWidget->setUserChanges(m_cmakeRunConfiguration->userEnvironmentChanges());
}

void CMakeRunConfigurationWidget::setArguments(const QString &args)
{
    m_cmakeRunConfiguration->setArguments(args);
dt's avatar
dt committed
503
504
}

dt's avatar
dt committed
505
// Factory
506
507
CMakeRunConfigurationFactory::CMakeRunConfigurationFactory(QObject *parent) :
    ProjectExplorer::IRunConfigurationFactory(parent)
dt's avatar
dt committed
508
509
510
511
512
513
514
{
}

CMakeRunConfigurationFactory::~CMakeRunConfigurationFactory()
{
}

515
// used to show the list of possible additons to a project, returns a list of ids
Tobias Hunger's avatar
Tobias Hunger committed
516
QStringList CMakeRunConfigurationFactory::availableCreationIds(ProjectExplorer::Target *parent) const
dt's avatar
dt committed
517
{
Tobias Hunger's avatar
Tobias Hunger committed
518
519
    CMakeTarget *t(qobject_cast<CMakeTarget *>(parent));
    if (!t)
dt's avatar
dt committed
520
        return QStringList();
521
    QStringList allIds;
Tobias Hunger's avatar
Tobias Hunger committed
522
    foreach (const QString &buildTarget, t->cmakeProject()->buildTargetTitles())
523
        allIds << idFromBuildTarget(buildTarget);
524
    return allIds;
dt's avatar
dt committed
525
526
}

527
528
// used to translate the ids to names to display to the user
QString CMakeRunConfigurationFactory::displayNameForId(const QString &id) const
dt's avatar
dt committed
529
{
530
    return buildTargetFromId(id);
531
}
dt's avatar
dt committed
532

Tobias Hunger's avatar
Tobias Hunger committed
533
bool CMakeRunConfigurationFactory::canCreate(ProjectExplorer::Target *parent, const QString &id) const
534
{
Tobias Hunger's avatar
Tobias Hunger committed
535
536
    CMakeTarget *t(qobject_cast<CMakeTarget *>(parent));
    if (!t)
537
        return false;
Tobias Hunger's avatar
Tobias Hunger committed
538
    return t->cmakeProject()->hasBuildTarget(buildTargetFromId(id));
dt's avatar
dt committed
539
540
}

Tobias Hunger's avatar
Tobias Hunger committed
541
ProjectExplorer::RunConfiguration *CMakeRunConfigurationFactory::create(ProjectExplorer::Target *parent, const QString &id)
dt's avatar
dt committed
542
{
543
544
    if (!canCreate(parent, id))
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
545
    CMakeTarget *t(static_cast<CMakeTarget *>(parent));
546

547
    const QString title(buildTargetFromId(id));
Tobias Hunger's avatar
Tobias Hunger committed
548
549
    const CMakeBuildTarget &ct = t->cmakeProject()->buildTargetForTitle(title);
    return new CMakeRunConfiguration(t, ct.executable, ct.workingDirectory, ct.title);
550
551
}

Tobias Hunger's avatar
Tobias Hunger committed
552
bool CMakeRunConfigurationFactory::canClone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *source) const
553
{
Tobias Hunger's avatar
Tobias Hunger committed
554
    if (!qobject_cast<CMakeTarget *>(parent))
555
556
557
558
        return false;
    return source->id() == QLatin1String(CMAKE_RC_ID);
}

Tobias Hunger's avatar
Tobias Hunger committed
559
ProjectExplorer::RunConfiguration *CMakeRunConfigurationFactory::clone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration * source)
560
561
562
{
    if (!canClone(parent, source))
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
563
    CMakeTarget *t(static_cast<CMakeTarget *>(parent));
564
    CMakeRunConfiguration *crc(static_cast<CMakeRunConfiguration *>(source));
Tobias Hunger's avatar
Tobias Hunger committed
565
    return new CMakeRunConfiguration(t, crc);
566
567
}

Tobias Hunger's avatar
Tobias Hunger committed
568
bool CMakeRunConfigurationFactory::canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const
569
{
Tobias Hunger's avatar
Tobias Hunger committed
570
    if (!qobject_cast<CMakeTarget *>(parent))
571
572
573
574
575
        return false;
    QString id(ProjectExplorer::idFromMap(map));
    return id.startsWith(QLatin1String(CMAKE_RC_ID));
}

Tobias Hunger's avatar
Tobias Hunger committed
576
ProjectExplorer::RunConfiguration *CMakeRunConfigurationFactory::restore(ProjectExplorer::Target *parent, const QVariantMap &map)
577
578
579
{
    if (!canRestore(parent, map))
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
580
581
    CMakeTarget *t(static_cast<CMakeTarget *>(parent));
    CMakeRunConfiguration *rc(new CMakeRunConfiguration(t, QString(), QString(), QString()));
582
    if (rc->fromMap(map))
dt's avatar
dt committed
583
        return rc;
584
585
    delete rc;
    return 0;
dt's avatar
dt committed
586
}