cmakerunconfiguration.cpp 21.7 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
}

QString CMakeRunConfiguration::workingDirectory() const
135
136
137
138
139
{
    return environment().expandVariables(baseWorkingDirectory());
}

QString CMakeRunConfiguration::baseWorkingDirectory() const
dt's avatar
dt committed
140
{
141
142
    if (!m_userWorkingDirectory.isEmpty())
        return m_userWorkingDirectory;
dt's avatar
dt committed
143
144
145
146
    return m_workingDirectory;
}

QStringList CMakeRunConfiguration::commandLineArguments() const
147
148
149
150
151
{
    return environment().expandVariables(baseCommandLineArguments());
}

QStringList CMakeRunConfiguration::baseCommandLineArguments() const
dt's avatar
dt committed
152
{
153
    return Utils::Environment::parseCombinedArgString(m_arguments);
dt's avatar
dt committed
154
155
}

dt's avatar
dt committed
156
157
158
159
160
161
162
QString CMakeRunConfiguration::title() const
{
    return m_title;
}

void CMakeRunConfiguration::setExecutable(const QString &executable)
{
163
    m_buildTarget = executable;
dt's avatar
dt committed
164
165
}

166
void CMakeRunConfiguration::setBaseWorkingDirectory(const QString &wd)
dt's avatar
dt committed
167
{
168
    const QString &oldWorkingDirectory = workingDirectory();
169
170
171
172
173

    m_workingDirectory = wd;

    const QString &newWorkingDirectory = workingDirectory();
    if (oldWorkingDirectory != newWorkingDirectory)
174
        emit baseWorkingDirectoryChanged(newWorkingDirectory);
175
176
177
178
179
180
181
182
183
184
}

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

    m_userWorkingDirectory = wd;

    const QString &newWorkingDirectory = workingDirectory();
    if (oldWorkingDirectory != newWorkingDirectory)
185
        emit baseWorkingDirectoryChanged(newWorkingDirectory);
dt's avatar
dt committed
186
187
}

188
QVariantMap CMakeRunConfiguration::toMap() const
dt's avatar
dt committed
189
{
190
191
    QVariantMap map(ProjectExplorer::LocalApplicationRunConfiguration::toMap());

192
    map.insert(QLatin1String(TARGET_KEY), m_buildTarget);
193
194
195
196
197
    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);
198
    map.insert(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY), Utils::EnvironmentItem::toStringList(m_userEnvironmentChanges));
199
    map.insert(QLatin1String(BASE_ENVIRONMENT_BASE_KEY), m_baseEnvironmentBase);
200

201
    return map;
dt's avatar
dt committed
202
203
}

204
bool CMakeRunConfiguration::fromMap(const QVariantMap &map)
dt's avatar
dt committed
205
{
206
    m_buildTarget = map.value(QLatin1String(TARGET_KEY)).toString();
207
208
209
210
211
    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();
212
    m_userEnvironmentChanges = Utils::EnvironmentItem::fromStringList(map.value(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY)).toStringList());
213
214
215
    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
216
217
}

218
219
220
221
222
223
224
QString CMakeRunConfiguration::defaultDisplayName() const
{
    if (m_title.isEmpty())
        return tr("Run CMake target");
    return m_title + (m_enabled ? "" : tr(" (disabled)"));
}

225
QWidget *CMakeRunConfiguration::createConfigurationWidget()
dt's avatar
dt committed
226
{
227
    return new CMakeRunConfigurationWidget(this);
228
229
}

230
void CMakeRunConfiguration::setCommandLineArguments(const QString &newText)
231
232
{
    m_arguments = newText;
dt's avatar
dt committed
233
234
}

235
236
QString CMakeRunConfiguration::dumperLibrary() const
{
237
    QString qmakePath = ProjectExplorer::DebuggingHelperLibrary::findSystemQt(environment());
dt's avatar
dt committed
238
239
    QString qtInstallData = ProjectExplorer::DebuggingHelperLibrary::qtInstallDataDir(qmakePath);
    QString dhl = ProjectExplorer::DebuggingHelperLibrary::debuggingHelperLibraryByInstallData(qtInstallData);
240
    return dhl;
241
242
}

243
244
245
QStringList CMakeRunConfiguration::dumperLibraryLocations() const
{
    QString qmakePath = ProjectExplorer::DebuggingHelperLibrary::findSystemQt(environment());
dt's avatar
dt committed
246
    QString qtInstallData = ProjectExplorer::DebuggingHelperLibrary::qtInstallDataDir(qmakePath);
247
    return ProjectExplorer::DebuggingHelperLibrary::locationsByInstallData(qtInstallData);
248
249
}

250
Utils::Environment CMakeRunConfiguration::baseEnvironment() const
251
{
252
    Utils::Environment env;
253
254
255
    if (m_baseEnvironmentBase == CMakeRunConfiguration::CleanEnvironmentBase) {
        // Nothing
    } else  if (m_baseEnvironmentBase == CMakeRunConfiguration::SystemEnvironmentBase) {
256
        env = Utils::Environment::systemEnvironment();
257
    } else  if (m_baseEnvironmentBase == CMakeRunConfiguration::BuildEnvironmentBase) {
Tobias Hunger's avatar
Tobias Hunger committed
258
        env = activeBuildConfiguration()->environment();
259
    }
260
261
262
    return env;
}

263
264
265
266
267
268
269
270
271
272
273
274
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();
}

275
276
277
278
279
280
281
282
283
284
285
286
287
void CMakeRunConfiguration::setBaseEnvironmentBase(BaseEnvironmentBase env)
{
    if (m_baseEnvironmentBase == env)
        return;
    m_baseEnvironmentBase = env;
    emit baseEnvironmentChanged();
}

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

288
Utils::Environment CMakeRunConfiguration::environment() const
289
{
290
    Utils::Environment env = baseEnvironment();
291
292
293
294
    env.modify(userEnvironmentChanges());
    return env;
}

295
QList<Utils::EnvironmentItem> CMakeRunConfiguration::userEnvironmentChanges() const
296
297
298
299
{
    return m_userEnvironmentChanges;
}

300
void CMakeRunConfiguration::setUserEnvironmentChanges(const QList<Utils::EnvironmentItem> &diff)
301
302
303
304
305
306
307
{
    if (m_userEnvironmentChanges != diff) {
        m_userEnvironmentChanges = diff;
        emit userEnvironmentChangesChanged(diff);
    }
}

308
309
ProjectExplorer::ToolChain::ToolChainType CMakeRunConfiguration::toolChainType() const
{
Tobias Hunger's avatar
Tobias Hunger committed
310
311
312
    CMakeBuildConfiguration *bc = activeBuildConfiguration();
    if (!bc)
        return ProjectExplorer::ToolChain::UNKNOWN;
313
    return bc->toolChainType();
314
315
}

316
317
318
319
320
321
void CMakeRunConfiguration::setEnabled(bool b)
{
    if (m_enabled == b)
        return;
    m_enabled = b;
    emit isEnabledChanged(isEnabled());
322
    setDefaultDisplayName(defaultDisplayName());
323
}
324

325
326
327
328
bool CMakeRunConfiguration::isEnabled(ProjectExplorer::BuildConfiguration *bc) const
{
    return m_enabled && LocalApplicationRunConfiguration::isEnabled(bc);
}
329

330
// Configuration widget
331
CMakeRunConfigurationWidget::CMakeRunConfigurationWidget(CMakeRunConfiguration *cmakeRunConfiguration, QWidget *parent)
332
    : QWidget(parent), m_ignoreChange(false), m_cmakeRunConfiguration(cmakeRunConfiguration)
333
334
335
{

    QFormLayout *fl = new QFormLayout();
336
337
    fl->setMargin(0);
    fl->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
338
    QLineEdit *argumentsLineEdit = new QLineEdit();
339
    argumentsLineEdit->setText(Utils::Environment::joinArgumentList(cmakeRunConfiguration->baseCommandLineArguments()));
340
341
342
343
    connect(argumentsLineEdit, SIGNAL(textChanged(QString)),
            this, SLOT(setArguments(QString)));
    fl->addRow(tr("Arguments:"), argumentsLineEdit);

344
    m_workingDirectoryEdit = new Utils::PathChooser();
345
    m_workingDirectoryEdit->setBaseDirectory(m_cmakeRunConfiguration->target()->project()->projectDirectory());
346
    m_workingDirectoryEdit->setPath(m_cmakeRunConfiguration->baseWorkingDirectory());
347
    m_workingDirectoryEdit->setExpectedKind(Utils::PathChooser::Directory);
348
    m_workingDirectoryEdit->setPromptDialogTitle(tr("Select Working Directory"));
349
350
351

    QToolButton *resetButton = new QToolButton();
    resetButton->setToolTip(tr("Reset to default"));
352
    resetButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_RESET)));
353
354
355
356
357

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

358
    fl->addRow(tr("Working directory:"), boxlayout);
359

360
361
362
363
364
    QWidget *debuggerLabelWidget = new QWidget(this);
    QVBoxLayout *debuggerLabelLayout = new QVBoxLayout(debuggerLabelWidget);
    debuggerLabelLayout->setMargin(0);
    debuggerLabelLayout->setSpacing(0);
    debuggerLabelWidget->setLayout(debuggerLabelLayout);
365
    QLabel *debuggerLabel = new QLabel(tr("Debugger:"), this);
366
367
368
    debuggerLabelLayout->addWidget(debuggerLabel);
    debuggerLabelLayout->addStretch(10);

369
    m_debuggerLanguageChooser = new Utils::DebuggerLanguageChooser(this);
370
    fl->addRow(debuggerLabelWidget, m_debuggerLanguageChooser);
371
372
373

    m_debuggerLanguageChooser->setCppChecked(m_cmakeRunConfiguration->useCppDebugger());
    m_debuggerLanguageChooser->setQmlChecked(m_cmakeRunConfiguration->useQmlDebugger());
374
    m_debuggerLanguageChooser->setQmlDebugServerPort(m_cmakeRunConfiguration->qmlDebugServerPort());
375

376
    m_detailsContainer = new Utils::DetailsWidget(this);
377
    m_detailsContainer->setState(Utils::DetailsWidget::NoSummary);
dt's avatar
dt committed
378

379
380
381
    QWidget *m_details = new QWidget(m_detailsContainer);
    m_detailsContainer->setWidget(m_details);
    m_details->setLayout(fl);
dt's avatar
dt committed
382

383
    QVBoxLayout *vbx = new QVBoxLayout(this);
384
385
    vbx->setMargin(0);;
    vbx->addWidget(m_detailsContainer);
386
387
388
389
390
391
392
393

    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);
394

395
396
397
    QWidget *baseEnvironmentWidget = new QWidget;
    QHBoxLayout *baseEnvironmentLayout = new QHBoxLayout(baseEnvironmentWidget);
    baseEnvironmentLayout->setMargin(0);
398
    QLabel *label = new QLabel(tr("Base environment for this runconfiguration:"), this);
399
    baseEnvironmentLayout->addWidget(label);
400
    m_baseEnvironmentComboBox = new QComboBox(this);
401
402
403
404
405
406
407
    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)));
408
409
    baseEnvironmentLayout->addWidget(m_baseEnvironmentComboBox);
    baseEnvironmentLayout->addStretch(10);
410

dt's avatar
dt committed
411
412
    m_environmentWidget = new ProjectExplorer::EnvironmentWidget(this, baseEnvironmentWidget);
    m_environmentWidget->setBaseEnvironment(m_cmakeRunConfiguration->baseEnvironment());
413
    m_environmentWidget->setBaseEnvironmentText(m_cmakeRunConfiguration->baseEnvironmentText());
dt's avatar
dt committed
414
415
416
417
    m_environmentWidget->setUserChanges(m_cmakeRunConfiguration->userEnvironmentChanges());

    vbx->addWidget(m_environmentWidget);

con's avatar
con committed
418
    connect(m_workingDirectoryEdit, SIGNAL(changed(QString)),
419
420
421
422
423
            this, SLOT(setWorkingDirectory()));

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

424
425
426
427
    connect(m_debuggerLanguageChooser, SIGNAL(cppLanguageToggled(bool)),
            this, SLOT(useCppDebuggerToggled(bool)));
    connect(m_debuggerLanguageChooser, SIGNAL(qmlLanguageToggled(bool)),
            this, SLOT(useQmlDebuggerToggled(bool)));
428
429
    connect(m_debuggerLanguageChooser, SIGNAL(qmlDebugServerPortChanged(uint)),
            this, SLOT(qmlDebugServerPortChanged(uint)));
430

431
432
    connect(m_environmentWidget, SIGNAL(userChangesChanged()),
            this, SLOT(userChangesChanged()));
433

434
    connect(m_cmakeRunConfiguration, SIGNAL(baseWorkingDirectoryChanged(QString)),
435
            this, SLOT(workingDirectoryChanged(QString)));
436
437
    connect(m_cmakeRunConfiguration, SIGNAL(baseEnvironmentChanged()),
            this, SLOT(baseEnvironmentChanged()));
438
    connect(m_cmakeRunConfiguration, SIGNAL(userEnvironmentChangesChanged(QList<Utils::EnvironmentItem>)),
439
            this, SLOT(userEnvironmentChangesChanged()));
440
441
442
443
444
445
446
447

}

void CMakeRunConfigurationWidget::setWorkingDirectory()
{
    if (m_ignoreChange)
        return;
    m_ignoreChange = true;
448
    m_cmakeRunConfiguration->setUserWorkingDirectory(m_workingDirectoryEdit->rawPath());
449
450
451
452
453
454
455
456
457
458
459
460
461
    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
462
    m_cmakeRunConfiguration->setUserWorkingDirectory(QString());
463
464
}

465
466
467
468
469
470
471
472
473
474
void CMakeRunConfigurationWidget::useCppDebuggerToggled(bool toggled)
{
    m_cmakeRunConfiguration->setUseCppDebugger(toggled);
}

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

475
476
477
478
479
void CMakeRunConfigurationWidget::qmlDebugServerPortChanged(uint port)
{
    m_cmakeRunConfiguration->setQmlDebugServerPort(port);
}

480
void CMakeRunConfigurationWidget::userChangesChanged()
481
482
483
484
{
    m_cmakeRunConfiguration->setUserEnvironmentChanges(m_environmentWidget->userChanges());
}

485
void CMakeRunConfigurationWidget::baseEnvironmentComboBoxChanged(int index)
486
487
{
    m_ignoreChange = true;
488
    m_cmakeRunConfiguration->setBaseEnvironmentBase(CMakeRunConfiguration::BaseEnvironmentBase(index));
489
490

    m_environmentWidget->setBaseEnvironment(m_cmakeRunConfiguration->baseEnvironment());
491
    m_environmentWidget->setBaseEnvironmentText(m_cmakeRunConfiguration->baseEnvironmentText());
492
493
494
    m_ignoreChange = false;
}

495
496
void CMakeRunConfigurationWidget::baseEnvironmentChanged()
{
497
498
499
    if (m_ignoreChange)
        return;

500
    m_baseEnvironmentComboBox->setCurrentIndex(m_cmakeRunConfiguration->baseEnvironmentBase());
501
    m_environmentWidget->setBaseEnvironment(m_cmakeRunConfiguration->baseEnvironment());
502
    m_environmentWidget->setBaseEnvironmentText(m_cmakeRunConfiguration->baseEnvironmentText());
503
504
505
506
507
508
509
510
511
}

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

void CMakeRunConfigurationWidget::setArguments(const QString &args)
{
512
    m_cmakeRunConfiguration->setCommandLineArguments(args);
dt's avatar
dt committed
513
514
}

dt's avatar
dt committed
515
// Factory
516
517
CMakeRunConfigurationFactory::CMakeRunConfigurationFactory(QObject *parent) :
    ProjectExplorer::IRunConfigurationFactory(parent)
dt's avatar
dt committed
518
519
520
521
522
523
524
{
}

CMakeRunConfigurationFactory::~CMakeRunConfigurationFactory()
{
}

525
// used to show the list of possible additons to a project, returns a list of ids
Tobias Hunger's avatar
Tobias Hunger committed
526
QStringList CMakeRunConfigurationFactory::availableCreationIds(ProjectExplorer::Target *parent) const
dt's avatar
dt committed
527
{
Tobias Hunger's avatar
Tobias Hunger committed
528
529
    CMakeTarget *t(qobject_cast<CMakeTarget *>(parent));
    if (!t)
dt's avatar
dt committed
530
        return QStringList();
531
    QStringList allIds;
Tobias Hunger's avatar
Tobias Hunger committed
532
    foreach (const QString &buildTarget, t->cmakeProject()->buildTargetTitles())
533
        allIds << idFromBuildTarget(buildTarget);
534
    return allIds;
dt's avatar
dt committed
535
536
}

537
538
// used to translate the ids to names to display to the user
QString CMakeRunConfigurationFactory::displayNameForId(const QString &id) const
dt's avatar
dt committed
539
{
540
    return buildTargetFromId(id);
541
}
dt's avatar
dt committed
542

Tobias Hunger's avatar
Tobias Hunger committed
543
bool CMakeRunConfigurationFactory::canCreate(ProjectExplorer::Target *parent, const QString &id) const
544
{
Tobias Hunger's avatar
Tobias Hunger committed
545
546
    CMakeTarget *t(qobject_cast<CMakeTarget *>(parent));
    if (!t)
547
        return false;
Tobias Hunger's avatar
Tobias Hunger committed
548
    return t->cmakeProject()->hasBuildTarget(buildTargetFromId(id));
dt's avatar
dt committed
549
550
}

Tobias Hunger's avatar
Tobias Hunger committed
551
ProjectExplorer::RunConfiguration *CMakeRunConfigurationFactory::create(ProjectExplorer::Target *parent, const QString &id)
dt's avatar
dt committed
552
{
553
554
    if (!canCreate(parent, id))
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
555
    CMakeTarget *t(static_cast<CMakeTarget *>(parent));
556

557
    const QString title(buildTargetFromId(id));
Tobias Hunger's avatar
Tobias Hunger committed
558
559
    const CMakeBuildTarget &ct = t->cmakeProject()->buildTargetForTitle(title);
    return new CMakeRunConfiguration(t, ct.executable, ct.workingDirectory, ct.title);
560
561
}

Tobias Hunger's avatar
Tobias Hunger committed
562
bool CMakeRunConfigurationFactory::canClone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *source) const
563
{
Tobias Hunger's avatar
Tobias Hunger committed
564
    if (!qobject_cast<CMakeTarget *>(parent))
565
566
567
568
        return false;
    return source->id() == QLatin1String(CMAKE_RC_ID);
}

Tobias Hunger's avatar
Tobias Hunger committed
569
ProjectExplorer::RunConfiguration *CMakeRunConfigurationFactory::clone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration * source)
570
571
572
{
    if (!canClone(parent, source))
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
573
    CMakeTarget *t(static_cast<CMakeTarget *>(parent));
574
    CMakeRunConfiguration *crc(static_cast<CMakeRunConfiguration *>(source));
Tobias Hunger's avatar
Tobias Hunger committed
575
    return new CMakeRunConfiguration(t, crc);
576
577
}

Tobias Hunger's avatar
Tobias Hunger committed
578
bool CMakeRunConfigurationFactory::canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const
579
{
Tobias Hunger's avatar
Tobias Hunger committed
580
    if (!qobject_cast<CMakeTarget *>(parent))
581
582
583
584
585
        return false;
    QString id(ProjectExplorer::idFromMap(map));
    return id.startsWith(QLatin1String(CMAKE_RC_ID));
}

Tobias Hunger's avatar
Tobias Hunger committed
586
ProjectExplorer::RunConfiguration *CMakeRunConfigurationFactory::restore(ProjectExplorer::Target *parent, const QVariantMap &map)
587
588
589
{
    if (!canRestore(parent, map))
        return 0;
Tobias Hunger's avatar
Tobias Hunger committed
590
591
    CMakeTarget *t(static_cast<CMakeTarget *>(parent));
    CMakeRunConfiguration *rc(new CMakeRunConfiguration(t, QString(), QString(), QString()));
592
    if (rc->fromMap(map))
dt's avatar
dt committed
593
        return rc;
594
595
    delete rc;
    return 0;
dt's avatar
dt committed
596
}