customexecutableconfigurationwidget.cpp 6.11 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** 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
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
23
24
25
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29
30
31
32

#include "customexecutableconfigurationwidget.h"
#include "customexecutablerunconfiguration.h"

33
#include <projectexplorer/environmentaspect.h>
34
35
#include <projectexplorer/target.h>
#include <projectexplorer/project.h>
36
37
38
#include <utils/detailswidget.h>
#include <utils/pathchooser.h>

39
40
41
42
43
44
#include <QCheckBox>
#include <QComboBox>
#include <QFormLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
45

46

47
namespace QtSupport {
48
49
50
51
52
53
54
55
56
57
namespace Internal {

CustomExecutableConfigurationWidget::CustomExecutableConfigurationWidget(CustomExecutableRunConfiguration *rc)
    : m_ignoreChange(false), m_runConfiguration(rc)
{
    QFormLayout *layout = new QFormLayout;
    layout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
    layout->setMargin(0);

    m_executableChooser = new Utils::PathChooser(this);
58
    m_executableChooser->setHistoryCompleter(QLatin1String("Qt.CustomExecutable.History"));
59
    m_executableChooser->setExpectedKind(Utils::PathChooser::Command);
60
    layout->addRow(tr("Executable:"), m_executableChooser);
61
62
63
64
65

    m_commandLineArgumentsLineEdit = new QLineEdit(this);
    m_commandLineArgumentsLineEdit->setMinimumWidth(200); // this shouldn't be fixed here...
    layout->addRow(tr("Arguments:"), m_commandLineArgumentsLineEdit);

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
66
    m_workingDirectory = new Utils::PathChooser(this);
67
    m_workingDirectory->setHistoryCompleter(QLatin1String("WorkingDir.History"));
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
68
    m_workingDirectory->setExpectedKind(Utils::PathChooser::Directory);
69
    m_workingDirectory->setBaseDirectory(rc->target()->project()->projectDirectory());
70

71
72
    layout->addRow(tr("Working directory:"), m_workingDirectory);

73
    m_useTerminalCheck = new QCheckBox(tr("Run in &terminal"), this);
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
    layout->addRow(QString(), m_useTerminalCheck);

    QVBoxLayout *vbox = new QVBoxLayout(this);
    vbox->setMargin(0);

    m_detailsContainer = new Utils::DetailsWidget(this);
    m_detailsContainer->setState(Utils::DetailsWidget::NoSummary);
    vbox->addWidget(m_detailsContainer);

    QWidget *detailsWidget = new QWidget(m_detailsContainer);
    m_detailsContainer->setWidget(detailsWidget);
    detailsWidget->setLayout(layout);

    changed();

    connect(m_executableChooser, SIGNAL(changed(QString)),
            this, SLOT(executableEdited()));
Robert Loehning's avatar
Robert Loehning committed
91
92
    connect(m_commandLineArgumentsLineEdit, SIGNAL(textEdited(QString)),
            this, SLOT(argumentsEdited(QString)));
93
94
95
96
97
    connect(m_workingDirectory, SIGNAL(changed(QString)),
            this, SLOT(workingDirectoryEdited()));
    connect(m_useTerminalCheck, SIGNAL(toggled(bool)),
            this, SLOT(termToggled(bool)));

98
99
100
101
102
103
    ProjectExplorer::EnvironmentAspect *aspect = rc->extraAspect<ProjectExplorer::EnvironmentAspect>();
    if (aspect) {
        connect(aspect, SIGNAL(environmentChanged()), this, SLOT(environmentWasChanged()));
        environmentWasChanged();
    }

104
105
106
    connect(m_runConfiguration, SIGNAL(changed()), this, SLOT(changed()));
}

107
108
109
110
111
112
113
114
115
void CustomExecutableConfigurationWidget::environmentWasChanged()
{
    ProjectExplorer::EnvironmentAspect *aspect
            = m_runConfiguration->extraAspect<ProjectExplorer::EnvironmentAspect>();
    QTC_ASSERT(aspect, return);
    m_workingDirectory->setEnvironment(aspect->environment());
    m_executableChooser->setEnvironment(aspect->environment());
}

116
117
118
119
120
121
122
123
124
void CustomExecutableConfigurationWidget::executableEdited()
{
    m_ignoreChange = true;
    m_runConfiguration->setExecutable(m_executableChooser->rawPath());
    m_ignoreChange = false;
}
void CustomExecutableConfigurationWidget::argumentsEdited(const QString &arguments)
{
    m_ignoreChange = true;
125
    m_runConfiguration->setCommandLineArguments(arguments);
126
127
128
129
130
131
132
133
134
135
136
137
    m_ignoreChange = false;
}
void CustomExecutableConfigurationWidget::workingDirectoryEdited()
{
    m_ignoreChange = true;
    m_runConfiguration->setBaseWorkingDirectory(m_workingDirectory->rawPath());
    m_ignoreChange = false;
}

void CustomExecutableConfigurationWidget::termToggled(bool on)
{
    m_ignoreChange = true;
138
139
    m_runConfiguration->setRunMode(on ? ProjectExplorer::LocalApplicationRunConfiguration::Console
                                      : ProjectExplorer::LocalApplicationRunConfiguration::Gui);
140
141
142
143
144
145
146
147
148
149
    m_ignoreChange = false;
}

void CustomExecutableConfigurationWidget::changed()
{
    // We triggered the change, don't update us
    if (m_ignoreChange)
        return;

    m_executableChooser->setPath(m_runConfiguration->rawExecutable());
150
    m_commandLineArgumentsLineEdit->setText(m_runConfiguration->rawCommandLineArguments());
151
    m_workingDirectory->setPath(m_runConfiguration->baseWorkingDirectory());
152
153
    m_useTerminalCheck->setChecked(m_runConfiguration->runMode()
                                   == ProjectExplorer::LocalApplicationRunConfiguration::Console);
154
155
156
}

} // namespace Internal
157
} // namespace QtSupport