runsettingspropertiespage.cpp 14.6 KB
Newer Older
1
/**************************************************************************
con's avatar
con 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).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
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.
15
**
16
** GNU Lesser General Public License Usage
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.
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.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
#include "runsettingspropertiespage.h"
Tobias Hunger's avatar
Tobias Hunger committed
31
32
33
34

#include "buildstepspage.h"
#include "deployconfiguration.h"
#include "deployconfigurationmodel.h"
dt's avatar
dt committed
35
#include "runconfigurationmodel.h"
con's avatar
con committed
36
#include "runconfiguration.h"
Tobias Hunger's avatar
Tobias Hunger committed
37
#include "target.h"
38
#include "project.h"
con's avatar
con committed
39
40
41

#include "ui_runsettingspropertiespage.h"

42
#include <coreplugin/coreconstants.h>
con's avatar
con committed
43
#include <extensionsystem/pluginmanager.h>
hjk's avatar
hjk committed
44
#include <utils/qtcassert.h>
con's avatar
con committed
45
46

#include <QtCore/QPair>
47
#include <QtGui/QInputDialog>
48
#include <QtGui/QMenu>
49
#include <QtGui/QMessageBox>
con's avatar
con committed
50
51
52

namespace ProjectExplorer {
namespace Internal {
hjk's avatar
hjk committed
53

54
struct FactoryAndId
con's avatar
con committed
55
56
{
    ProjectExplorer::IRunConfigurationFactory *factory;
57
    QString id;
con's avatar
con committed
58
};
hjk's avatar
hjk committed
59
60
61

} // namespace Internal
} // namespace ProjectExplorer
con's avatar
con committed
62

63
Q_DECLARE_METATYPE(ProjectExplorer::Internal::FactoryAndId);
con's avatar
con committed
64
65
66
67
68
69
70
71
72

using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;
using ExtensionSystem::PluginManager;

///
/// RunSettingsPanelFactory
///

Tobias Hunger's avatar
Tobias Hunger committed
73
74
75
76
77
QString RunSettingsPanelFactory::id() const
{
    return QLatin1String(RUNSETTINGS_PANEL_ID);
}

con's avatar
con committed
78
79
QString RunSettingsPanelFactory::displayName() const
{
Friedemann Kleint's avatar
Friedemann Kleint committed
80
    return QCoreApplication::translate("RunSettingsPanelFactory", "Run Settings");
con's avatar
con committed
81
82
}

Tobias Hunger's avatar
Tobias Hunger committed
83
bool RunSettingsPanelFactory::supports(Target *target)
con's avatar
con committed
84
{
Tobias Hunger's avatar
Tobias Hunger committed
85
    Q_UNUSED(target);
con's avatar
con committed
86
87
88
    return true;
}

Tobias Hunger's avatar
Tobias Hunger committed
89
90
91
IPropertiesPanel *RunSettingsPanelFactory::createPanel(Target *target)
{
    return new RunSettingsPanel(target);
con's avatar
con committed
92
93
94
95
96
97
}

///
/// RunSettingsPanel
///

Tobias Hunger's avatar
Tobias Hunger committed
98
99
RunSettingsPanel::RunSettingsPanel(Target *target) :
     m_widget(new RunSettingsWidget(target)),
con's avatar
con committed
100
     m_icon(":/projectexplorer/images/RunSettings.png")
con's avatar
con committed
101
102
103
104
105
{
}

RunSettingsPanel::~RunSettingsPanel()
{
106
    delete m_widget;
con's avatar
con committed
107
108
}

109
QString RunSettingsPanel::displayName() const
con's avatar
con committed
110
{
Friedemann Kleint's avatar
Friedemann Kleint committed
111
    return QCoreApplication::translate("RunSettingsPanel", "Run Settings");
con's avatar
con committed
112
113
}

114
QWidget *RunSettingsPanel::widget() const
con's avatar
con committed
115
116
117
118
{
    return m_widget;
}

119
120
121
122
123
QIcon RunSettingsPanel::icon() const
{
    return m_icon;
}

con's avatar
con committed
124
125
126
127
///
/// RunSettingsWidget
///

Tobias Hunger's avatar
Tobias Hunger committed
128
129
RunSettingsWidget::RunSettingsWidget(Target *target)
    : m_target(target),
dt's avatar
dt committed
130
      m_runConfigurationsModel(new RunConfigurationModel(target, this)),
Tobias Hunger's avatar
Tobias Hunger committed
131
      m_deployConfigurationModel(new DeployConfigurationModel(target, this)),
132
      m_runConfigurationWidget(0),
133
      m_runLayout(0),
Tobias Hunger's avatar
Tobias Hunger committed
134
135
136
      m_deployConfigurationWidget(0),
      m_deployLayout(0),
      m_deploySteps(0),
137
      m_ignoreChange(false)
con's avatar
con committed
138
{
Tobias Hunger's avatar
Tobias Hunger committed
139
140
    Q_ASSERT(m_target);

con's avatar
con committed
141
142
    m_ui = new Ui::RunSettingsPropertiesPage;
    m_ui->setupUi(this);
Tobias Hunger's avatar
Tobias Hunger committed
143

144
    // deploy part
145
    m_ui->deployWidget->setContentsMargins(0, 10, 0, 25);
Tobias Hunger's avatar
Tobias Hunger committed
146
147
148
149
150
151
152
153
154
155
    m_deployLayout = new QVBoxLayout(m_ui->deployWidget);
    m_deployLayout->setMargin(0);
    m_deployLayout->setSpacing(5);

    m_ui->deployConfigurationCombo->setModel(m_deployConfigurationModel);
    m_addDeployMenu = new QMenu(m_ui->addDeployToolButton);
    m_ui->addDeployToolButton->setMenu(m_addDeployMenu);

    updateDeployConfiguration(m_target->activeDeployConfiguration());

156
    // Some projects may not support deployment, so we need this:
Tobias Hunger's avatar
Tobias Hunger committed
157
158
    m_ui->addDeployToolButton->setEnabled(m_target->activeDeployConfiguration());
    m_ui->deployConfigurationCombo->setEnabled(m_target->activeDeployConfiguration());
159

Tobias Hunger's avatar
Tobias Hunger committed
160
    m_ui->removeDeployToolButton->setEnabled(m_target->deployConfigurations().count() > 1);
161
    m_ui->renameDeployButton->setEnabled(m_target->activeDeployConfiguration());
Tobias Hunger's avatar
Tobias Hunger committed
162
163
164
165
166
167
168

    connect(m_addDeployMenu, SIGNAL(aboutToShow()),
            this, SLOT(aboutToShowDeployMenu()));
    connect(m_ui->deployConfigurationCombo, SIGNAL(currentIndexChanged(int)),
            this, SLOT(currentDeployConfigurationChanged(int)));
    connect(m_ui->removeDeployToolButton, SIGNAL(clicked(bool)),
            this, SLOT(removeDeployConfiguration()));
169
170
    connect(m_ui->renameDeployButton, SIGNAL(clicked()),
            this, SLOT(renameDeployConfiguration()));
Tobias Hunger's avatar
Tobias Hunger committed
171
172
173
174
175

    connect(m_target, SIGNAL(activeDeployConfigurationChanged(ProjectExplorer::DeployConfiguration*)),
            this, SLOT(activeDeployConfigurationChanged()));

    // run part
176
    m_ui->runWidget->setContentsMargins(0, 10, 0, 25);
177
178
179
180
    m_runLayout = new QVBoxLayout(m_ui->runWidget);
    m_runLayout->setMargin(0);
    m_runLayout->setSpacing(5);

Tobias Hunger's avatar
Tobias Hunger committed
181
182
    m_addRunMenu = new QMenu(m_ui->addRunToolButton);
    m_ui->addRunToolButton->setMenu(m_addRunMenu);
con's avatar
con committed
183
    m_ui->runConfigurationCombo->setModel(m_runConfigurationsModel);
184
    m_ui->runConfigurationCombo->setCurrentIndex(
dt's avatar
dt committed
185
            m_runConfigurationsModel->indexFor(m_target->activeRunConfiguration()).row());
186

Tobias Hunger's avatar
Tobias Hunger committed
187
    m_ui->removeRunToolButton->setEnabled(m_target->runConfigurations().size() > 1);
188
    m_ui->renameRunButton->setEnabled(m_target->activeRunConfiguration());
dt's avatar
dt committed
189

190
    m_runConfigurationWidget = m_target->activeRunConfiguration()->createConfigurationWidget();
191
    m_runLayout->addWidget(m_runConfigurationWidget);
con's avatar
con committed
192

Tobias Hunger's avatar
Tobias Hunger committed
193
    connect(m_addRunMenu, SIGNAL(aboutToShow()),
con's avatar
con committed
194
195
            this, SLOT(aboutToShowAddMenu()));
    connect(m_ui->runConfigurationCombo, SIGNAL(currentIndexChanged(int)),
196
            this, SLOT(currentRunConfigurationChanged(int)));
Tobias Hunger's avatar
Tobias Hunger committed
197
    connect(m_ui->removeRunToolButton, SIGNAL(clicked(bool)),
con's avatar
con committed
198
            this, SLOT(removeRunConfiguration()));
199
200
    connect(m_ui->renameRunButton, SIGNAL(clicked()),
            this, SLOT(renameRunConfiguration()));
Tobias Hunger's avatar
Tobias Hunger committed
201
202

    connect(m_target, SIGNAL(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)),
203
            this, SLOT(activeRunConfigurationChanged()));
204

con's avatar
con committed
205
206
    // TODO: Add support for custom runner configuration widgets once we have some
    /*
207
208
    QList<IRunControlFactory *> runners = PluginManager::instance()->getObjects<IRunControlFactory>();
    foreach (IRunControlFactory * runner, runners) {
con's avatar
con committed
209
        if (runner->canRun(activeRunConfiguration))
210
            m_ui->layout->addWidget(runner->createConfigurationWidget(activeRunConfiguration));
con's avatar
con committed
211
212
213
214
215
216
217
218
219
220
221
    }
    */
}

RunSettingsWidget::~RunSettingsWidget()
{
    delete m_ui;
}

void RunSettingsWidget::aboutToShowAddMenu()
{
Tobias Hunger's avatar
Tobias Hunger committed
222
    m_addRunMenu->clear();
hjk's avatar
hjk committed
223
224
225
    QList<IRunConfigurationFactory *> factories =
        ExtensionSystem::PluginManager::instance()->getObjects<IRunConfigurationFactory>();
    foreach (IRunConfigurationFactory *factory, factories) {
Tobias Hunger's avatar
Tobias Hunger committed
226
        QStringList ids = factory->availableCreationIds(m_target);
227
        foreach (const QString &id, ids) {
Tobias Hunger's avatar
Tobias Hunger committed
228
            QAction *action = m_addRunMenu->addAction(factory->displayNameForId(id));;
229
230
231
            FactoryAndId fai;
            fai.factory = factory;
            fai.id = id;
con's avatar
con committed
232
            QVariant v;
233
            v.setValue(fai);
con's avatar
con committed
234
235
236
237
238
239
240
241
242
243
244
245
            action->setData(v);
            connect(action, SIGNAL(triggered()),
                    this, SLOT(addRunConfiguration()));
        }
    }
}

void RunSettingsWidget::addRunConfiguration()
{
    QAction *act = qobject_cast<QAction *>(sender());
    if (!act)
        return;
246
    FactoryAndId fai = act->data().value<FactoryAndId>();
Tobias Hunger's avatar
Tobias Hunger committed
247
    RunConfiguration *newRC = fai.factory->create(m_target, fai.id);
con's avatar
con committed
248
249
    if (!newRC)
        return;
Tobias Hunger's avatar
Tobias Hunger committed
250
    m_target->addRunConfiguration(newRC);
251
    m_target->setActiveRunConfiguration(newRC);
Tobias Hunger's avatar
Tobias Hunger committed
252
    m_ui->removeRunToolButton->setEnabled(m_target->runConfigurations().size() > 1);
con's avatar
con committed
253
254
255
256
}

void RunSettingsWidget::removeRunConfiguration()
{
257
    RunConfiguration *rc = m_target->activeRunConfiguration();
258
    QMessageBox msgBox(QMessageBox::Question, tr("Remove Run Configuration?"),
259
                       tr("Do you really want to delete deploy configuration <b>%1</b>.").arg(rc->displayName()),
260
261
262
263
264
265
                       QMessageBox::Yes|QMessageBox::No, this);
    msgBox.setDefaultButton(QMessageBox::No);
    msgBox.setEscapeButton(QMessageBox::No);
    if (!this || msgBox.exec() == QMessageBox::No)
        return;

Tobias Hunger's avatar
Tobias Hunger committed
266
    m_target->removeRunConfiguration(rc);
Tobias Hunger's avatar
Tobias Hunger committed
267
    m_ui->removeRunToolButton->setEnabled(m_target->runConfigurations().size() > 1);
268
    m_ui->renameRunButton->setEnabled(m_target->activeRunConfiguration());
269
270
271
272
}

void RunSettingsWidget::activeRunConfigurationChanged()
{
273
274
275
276
277
278
279
280
    if (m_ignoreChange)
        return;
    QModelIndex actRc = m_runConfigurationsModel->indexFor(m_target->activeRunConfiguration());
    m_ignoreChange = true;
    m_ui->runConfigurationCombo->setCurrentIndex(actRc.row());
    m_ignoreChange = false;

    delete m_runConfigurationWidget;
281
    m_runConfigurationWidget = m_target->activeRunConfiguration()->createConfigurationWidget();
282
    m_runLayout->addWidget(m_runConfigurationWidget);
con's avatar
con committed
283
284
}

285
286
287
288
289
290
291
292
void RunSettingsWidget::renameRunConfiguration()
{
    bool ok;
    QString name = QInputDialog::getText(this, tr("Rename..."),
                                         tr("New name for run configuration <b>%1</b>:").
                                            arg(m_target->activeRunConfiguration()->displayName()),
                                         QLineEdit::Normal,
                                         m_target->activeRunConfiguration()->displayName(), &ok);
293
    if (!ok || !this)
294
295
        return;

296
297
298
299
300
301
302
303
    if (!name.isEmpty()) {
        QStringList rcNames;
        foreach (RunConfiguration *rc, m_target->runConfigurations()) {
            if (rc == m_target->activeRunConfiguration())
                continue;
            rcNames.append(rc->displayName());
        }
        name = Project::makeUnique(name, rcNames);
304
305
306
307
    }
    m_target->activeRunConfiguration()->setDisplayName(name);
}

308
void RunSettingsWidget::currentRunConfigurationChanged(int index)
con's avatar
con committed
309
{
310
311
    if (m_ignoreChange)
        return;
dt's avatar
dt committed
312
313
314
315
316
    if (index == -1) {
        delete m_runConfigurationWidget;
        m_runConfigurationWidget = 0;
        return;
    }
317
    RunConfiguration *selectedRunConfiguration =
318
319
320
321
322
            m_runConfigurationsModel->runConfigurationAt(index);

    m_ignoreChange = true;
    m_target->setActiveRunConfiguration(selectedRunConfiguration);
    m_ignoreChange = false;
con's avatar
con committed
323
324
325

    // Update the run configuration configuration widget
    delete m_runConfigurationWidget;
326
    m_runConfigurationWidget = selectedRunConfiguration->createConfigurationWidget();
327
    m_runLayout->addWidget(m_runConfigurationWidget);
328
}
Tobias Hunger's avatar
Tobias Hunger committed
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367

void RunSettingsWidget::currentDeployConfigurationChanged(int index)
{
    if (index == -1)
        updateDeployConfiguration(0);
    else
        m_target->setActiveDeployConfiguration(m_deployConfigurationModel->deployConfigurationAt(index));
}

void RunSettingsWidget::aboutToShowDeployMenu()
{
    m_addDeployMenu->clear();
    DeployConfigurationFactory *factory = m_target->deployConfigurationFactory();
    QStringList ids = factory->availableCreationIds(m_target);
    foreach (const QString &id, ids) {
        QAction *action = m_addDeployMenu->addAction(factory->displayNameForId(id));;
        action->setData(QVariant(id));
        connect(action, SIGNAL(triggered()),
                this, SLOT(addDeployConfiguration()));
    }
}

void RunSettingsWidget::addDeployConfiguration()
{
    QAction *act = qobject_cast<QAction *>(sender());
    if (!act)
        return;
    QString id = act->data().toString();
    DeployConfiguration *newDc = m_target->deployConfigurationFactory()->create(m_target, id);
    if (!newDc)
        return;
    m_target->addDeployConfiguration(newDc);
    m_target->setActiveDeployConfiguration(newDc);
    m_ui->removeDeployToolButton->setEnabled(m_target->deployConfigurations().size() > 1);
}

void RunSettingsWidget::removeDeployConfiguration()
{
    DeployConfiguration *dc = m_target->activeDeployConfiguration();
368
    QMessageBox msgBox(QMessageBox::Question, tr("Remove Deploy Configuration?"),
369
                       tr("Do you really want to delete deploy configuration <b>%1</b>.").arg(dc->displayName()),
370
371
372
373
374
375
                       QMessageBox::Yes|QMessageBox::No, this);
    msgBox.setDefaultButton(QMessageBox::No);
    msgBox.setEscapeButton(QMessageBox::No);
    if (!this || msgBox.exec() == QMessageBox::No)
        return;

Tobias Hunger's avatar
Tobias Hunger committed
376
377
378
379
380
381
382
383
384
    m_target->removeDeployConfiguration(dc);
    m_ui->removeDeployToolButton->setEnabled(m_target->deployConfigurations().size() > 1);
}

void RunSettingsWidget::activeDeployConfigurationChanged()
{
    updateDeployConfiguration(m_target->activeDeployConfiguration());
}

385
386
387
388
389
390
391
392
void RunSettingsWidget::renameDeployConfiguration()
{
    bool ok;
    QString name = QInputDialog::getText(this, tr("Rename..."),
                                         tr("New name for deploy configuration <b>%1</b>:").
                                            arg(m_target->activeDeployConfiguration()->displayName()),
                                         QLineEdit::Normal,
                                         m_target->activeDeployConfiguration()->displayName(), &ok);
393
    if (!ok || !this)
394
395
        return;

396
397
398
399
400
401
402
403
    if (!name.isEmpty()) {
        QStringList dcNames;
        foreach (DeployConfiguration *dc, m_target->deployConfigurations()) {
            if (dc == m_target->activeDeployConfiguration())
                continue;
            dcNames.append(dc->displayName());
        }
        name = Project::makeUnique(name, dcNames);
404
405
406
407
    }
    m_target->activeDeployConfiguration()->setDisplayName(name);
}

Tobias Hunger's avatar
Tobias Hunger committed
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
void RunSettingsWidget::updateDeployConfiguration(DeployConfiguration *dc)
{
    delete m_deployConfigurationWidget;
    m_deployConfigurationWidget = 0;
    delete m_deploySteps;
    m_deploySteps = 0;

    m_ui->deployConfigurationCombo->setCurrentIndex(-1);

    if (!dc)
        return;

    QModelIndex actDc = m_deployConfigurationModel->indexFor(dc);
    m_ui->deployConfigurationCombo->setCurrentIndex(actDc.row());

    m_deployConfigurationWidget = dc->configurationWidget();
    if (m_deployConfigurationWidget) {
        m_deployConfigurationWidget->init(dc);
        m_deployLayout->addWidget(m_deployConfigurationWidget);
    }

    m_deploySteps = new BuildStepListWidget;
    m_deploySteps->init(dc->stepList());
    m_deployLayout->addWidget(m_deploySteps);
}