customexecutableconfigurationwidget.cpp 6.9 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3 4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
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
12 13 14
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
15
**
16 17 18 19 20 21 22
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
con's avatar
con committed
23
**
hjk's avatar
hjk committed
24
****************************************************************************/
25 26

#include "customexecutableconfigurationwidget.h"
27

28
#include "customexecutablerunconfiguration.h"
29 30 31 32
#include "environmentaspect.h"
#include "project.h"
#include "runconfigurationaspects.h"
#include "target.h"
33

34
#include <coreplugin/variablechooser.h>
35 36 37
#include <utils/detailswidget.h>
#include <utils/pathchooser.h>

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

hjk's avatar
hjk committed
45
using namespace Utils;
46

47
namespace ProjectExplorer {
48 49
namespace Internal {

50
CustomExecutableConfigurationWidget::CustomExecutableConfigurationWidget(CustomExecutableRunConfiguration *rc, ApplyMode mode)
hjk's avatar
hjk committed
51
    : m_runConfiguration(rc)
52
{
hjk's avatar
hjk committed
53
    auto layout = new QFormLayout;
54 55 56
    layout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
    layout->setMargin(0);

hjk's avatar
hjk committed
57
    m_executableChooser = new PathChooser(this);
58
    m_executableChooser->setHistoryCompleter(QLatin1String("Qt.CustomExecutable.History"));
59
    m_executableChooser->setExpectedKind(PathChooser::ExistingCommand);
60
    layout->addRow(tr("Executable:"), m_executableChooser);
61

hjk's avatar
hjk committed
62
    auto argumentsAspect = rc->extraAspect<ArgumentsAspect>();
63 64 65 66 67 68 69 70
    if (mode == InstantApply) {
        argumentsAspect->addToMainConfigurationWidget(this, layout);
    } else {
        m_temporaryArgumentsAspect = argumentsAspect->clone(rc);
        m_temporaryArgumentsAspect->addToMainConfigurationWidget(this, layout);
        connect(m_temporaryArgumentsAspect, &ArgumentsAspect::argumentsChanged,
                this, &CustomExecutableConfigurationWidget::validChanged);
    }
71

hjk's avatar
hjk committed
72
    m_workingDirectory = new PathChooser(this);
73
    m_workingDirectory->setHistoryCompleter(QLatin1String("Qt.WorkingDir.History"));
hjk's avatar
hjk committed
74
    m_workingDirectory->setExpectedKind(PathChooser::Directory);
75
    m_workingDirectory->setBaseFileName(rc->target()->project()->projectDirectory());
76

77 78
    layout->addRow(tr("Working directory:"), m_workingDirectory);

hjk's avatar
hjk committed
79
    auto terminalAspect = rc->extraAspect<TerminalAspect>();
80 81 82 83 84 85 86 87
    if (mode == InstantApply) {
        terminalAspect->addToMainConfigurationWidget(this, layout);
    } else {
        m_temporaryTerminalAspect = terminalAspect->clone(rc);
        m_temporaryTerminalAspect->addToMainConfigurationWidget(this, layout);
        connect(m_temporaryTerminalAspect, &TerminalAspect::useTerminalChanged,
                this, &CustomExecutableConfigurationWidget::validChanged);
    }
88

hjk's avatar
hjk committed
89
    auto vbox = new QVBoxLayout(this);
90 91
    vbox->setMargin(0);

hjk's avatar
hjk committed
92 93
    m_detailsContainer = new DetailsWidget(this);
    m_detailsContainer->setState(DetailsWidget::NoSummary);
94 95
    vbox->addWidget(m_detailsContainer);

hjk's avatar
hjk committed
96
    auto detailsWidget = new QWidget(m_detailsContainer);
97 98 99 100 101
    m_detailsContainer->setWidget(detailsWidget);
    detailsWidget->setLayout(layout);

    changed();

102
    if (mode == InstantApply) {
hjk's avatar
hjk committed
103 104 105 106
        connect(m_executableChooser, &PathChooser::rawPathChanged,
                this, &CustomExecutableConfigurationWidget::executableEdited);
        connect(m_workingDirectory, &PathChooser::rawPathChanged,
                this, &CustomExecutableConfigurationWidget::workingDirectoryEdited);
107
    } else {
hjk's avatar
hjk committed
108 109 110 111
        connect(m_executableChooser, &PathChooser::rawPathChanged,
                this, &CustomExecutableConfigurationWidget::validChanged);
        connect(m_workingDirectory, &PathChooser::rawPathChanged,
                this, &CustomExecutableConfigurationWidget::validChanged);
112
    }
113

hjk's avatar
hjk committed
114 115 116 117
    auto enviromentAspect = rc->extraAspect<EnvironmentAspect>();
    connect(enviromentAspect, &EnvironmentAspect::environmentChanged,
            this, &CustomExecutableConfigurationWidget::environmentWasChanged);
    environmentWasChanged();
118

hjk's avatar
hjk committed
119
    // If we are in InstantApply mode, we keep us in sync with the rc
120 121
    // otherwise we ignore changes to the rc and override them on apply,
    // or keep them on cancel
hjk's avatar
hjk committed
122 123 124 125
    if (mode == InstantApply) {
        connect(m_runConfiguration, &CustomExecutableRunConfiguration::changed,
                this, &CustomExecutableConfigurationWidget::changed);
    }
126 127

    Core::VariableChooser::addSupportForChildWidgets(this, m_runConfiguration->macroExpander());
128 129
}

130 131
CustomExecutableConfigurationWidget::~CustomExecutableConfigurationWidget()
{
132
    delete m_temporaryArgumentsAspect;
133 134 135
    delete m_temporaryTerminalAspect;
}

136 137
void CustomExecutableConfigurationWidget::environmentWasChanged()
{
hjk's avatar
hjk committed
138
    auto aspect = m_runConfiguration->extraAspect<EnvironmentAspect>();
139 140 141 142 143
    QTC_ASSERT(aspect, return);
    m_workingDirectory->setEnvironment(aspect->environment());
    m_executableChooser->setEnvironment(aspect->environment());
}

144 145 146 147 148 149
void CustomExecutableConfigurationWidget::executableEdited()
{
    m_ignoreChange = true;
    m_runConfiguration->setExecutable(m_executableChooser->rawPath());
    m_ignoreChange = false;
}
150

151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
void CustomExecutableConfigurationWidget::workingDirectoryEdited()
{
    m_ignoreChange = true;
    m_runConfiguration->setBaseWorkingDirectory(m_workingDirectory->rawPath());
    m_ignoreChange = false;
}

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

    m_executableChooser->setPath(m_runConfiguration->rawExecutable());
    m_workingDirectory->setPath(m_runConfiguration->baseWorkingDirectory());
}

168 169 170 171
void CustomExecutableConfigurationWidget::apply()
{
    m_ignoreChange = true;
    m_runConfiguration->setExecutable(m_executableChooser->rawPath());
172
    m_runConfiguration->setCommandLineArguments(m_temporaryArgumentsAspect->unexpandedArguments());
173
    m_runConfiguration->setBaseWorkingDirectory(m_workingDirectory->rawPath());
174
    m_runConfiguration->setRunMode(m_temporaryTerminalAspect->runMode());
175 176 177 178 179 180 181 182
    m_ignoreChange = false;
}

bool CustomExecutableConfigurationWidget::isValid() const
{
    return !m_executableChooser->rawPath().isEmpty();
}

183
} // namespace Internal
184
} // namespace ProjectExplorer