forked from qt-creator/qt-creator
Use one common EnvironmentDialog in 3 different places.
Reduce code repetition. Change-Id: I7442c035270a18c79afd82c2111d363fd840df96 Reviewed-by: hjk <hjk@theqtcompany.com> Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <utils/fancylineedit.h>
|
||||
#include <utils/environmentdialog.h>
|
||||
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/variablechooser.h>
|
||||
@@ -393,44 +394,6 @@ void ExternalToolModel::removeTool(const QModelIndex &modelIndex)
|
||||
delete tool;
|
||||
}
|
||||
|
||||
EnvironmentChangesDialog::EnvironmentChangesDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
m_editor(0)
|
||||
{
|
||||
setWindowTitle(tr("Edit Environment Changes"));
|
||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
setModal(true);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
QLabel *label = new QLabel(this);
|
||||
label->setText(tr("Change system environment by assigning one environment variable per line:"));
|
||||
layout->addWidget(label);
|
||||
|
||||
m_editor = new QPlainTextEdit(this);
|
||||
if (Utils::HostOsInfo::isWindowsHost())
|
||||
m_editor->setPlaceholderText(tr("PATH=C:\\dev\\bin;${PATH}"));
|
||||
else
|
||||
m_editor->setPlaceholderText(tr("PATH=/opt/bin:${PATH}"));
|
||||
|
||||
QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
|
||||
|
||||
layout->addWidget(m_editor);
|
||||
layout->addWidget(buttons);
|
||||
|
||||
connect(buttons, &QDialogButtonBox::accepted, this, &EnvironmentChangesDialog::accept);
|
||||
connect(buttons, &QDialogButtonBox::rejected, this, &EnvironmentChangesDialog::reject);
|
||||
}
|
||||
|
||||
QStringList EnvironmentChangesDialog::changes() const
|
||||
{
|
||||
return m_editor->toPlainText().split(QLatin1Char('\n'));
|
||||
}
|
||||
|
||||
void EnvironmentChangesDialog::setChanges(const QStringList &changes)
|
||||
{
|
||||
m_editor->setPlainText(changes.join(QLatin1Char('\n')));
|
||||
}
|
||||
|
||||
// #pragma mark -- ExternalToolConfig
|
||||
|
||||
ExternalToolConfig::ExternalToolConfig(QWidget *parent) :
|
||||
@@ -556,7 +519,7 @@ void ExternalToolConfig::updateItem(const QModelIndex &index)
|
||||
tool->setExecutables(executables);
|
||||
tool->setArguments(ui->arguments->text());
|
||||
tool->setWorkingDirectory(ui->workingDirectory->rawPath());
|
||||
tool->setEnvironment(Utils::EnvironmentItem::fromStringList(m_environment));
|
||||
tool->setEnvironment(m_environment);
|
||||
tool->setOutputHandling((ExternalTool::OutputHandling)ui->outputBehavior->currentIndex());
|
||||
tool->setErrorHandling((ExternalTool::OutputHandling)ui->errorOutputBehavior->currentIndex());
|
||||
tool->setModifiesCurrentDocument(ui->modifiesDocumentCheckbox->checkState());
|
||||
@@ -585,7 +548,7 @@ void ExternalToolConfig::showInfoForItem(const QModelIndex &index)
|
||||
ui->outputBehavior->setCurrentIndex((int)tool->outputHandling());
|
||||
ui->errorOutputBehavior->setCurrentIndex((int)tool->errorHandling());
|
||||
ui->modifiesDocumentCheckbox->setChecked(tool->modifiesCurrentDocument());
|
||||
m_environment = Utils::EnvironmentItem::toStringList(tool->environment());
|
||||
m_environment = tool->environment();
|
||||
|
||||
bool blocked = ui->inputText->blockSignals(true);
|
||||
ui->inputText->setPlainText(tool->input());
|
||||
@@ -649,17 +612,24 @@ void ExternalToolConfig::updateEffectiveArguments()
|
||||
|
||||
void ExternalToolConfig::editEnvironmentChanges()
|
||||
{
|
||||
EnvironmentChangesDialog dialog(ui->environmentLabel);
|
||||
dialog.setChanges(m_environment);
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
m_environment = dialog.changes();
|
||||
updateEnvironmentLabel();
|
||||
}
|
||||
bool ok;
|
||||
const QString placeholderText = Utils::HostOsInfo::isWindowsHost()
|
||||
? tr("PATH=C:\\dev\\bin;${PATH}")
|
||||
: tr("PATH=/opt/bin:${PATH}");
|
||||
const QList<Utils::EnvironmentItem> newItems =
|
||||
Utils::EnvironmentDialog::getEnvironmentItems(&ok, ui->environmentLabel,
|
||||
m_environment,
|
||||
placeholderText);
|
||||
if (!ok)
|
||||
return;
|
||||
|
||||
m_environment = newItems;
|
||||
updateEnvironmentLabel();
|
||||
}
|
||||
|
||||
void ExternalToolConfig::updateEnvironmentLabel()
|
||||
{
|
||||
QString shortSummary = m_environment.join(QLatin1String("; "));
|
||||
QString shortSummary = Utils::EnvironmentItem::toStringList(m_environment).join(QLatin1String("; "));
|
||||
QFontMetrics fm(ui->environmentLabel->font());
|
||||
shortSummary = fm.elidedText(shortSummary, Qt::ElideRight, ui->environmentLabel->width());
|
||||
ui->environmentLabel->setText(shortSummary.isEmpty() ? tr("No changes to apply.") : shortSummary);
|
||||
|
||||
Reference in New Issue
Block a user