summaryrefslogtreecommitdiff
path: root/src/plugins/projectexplorer/environmentwidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/projectexplorer/environmentwidget.cpp')
-rw-r--r--src/plugins/projectexplorer/environmentwidget.cpp97
1 files changed, 37 insertions, 60 deletions
diff --git a/src/plugins/projectexplorer/environmentwidget.cpp b/src/plugins/projectexplorer/environmentwidget.cpp
index 1a6e424960..04d68dd42d 100644
--- a/src/plugins/projectexplorer/environmentwidget.cpp
+++ b/src/plugins/projectexplorer/environmentwidget.cpp
@@ -30,11 +30,12 @@
#include <utils/detailswidget.h>
#include <utils/environment.h>
-#include <utils/environmentmodel.h>
#include <utils/environmentdialog.h>
+#include <utils/environmentmodel.h>
#include <utils/headerviewstretcher.h>
#include <utils/hostosinfo.h>
#include <utils/itemviews.h>
+#include <utils/namevaluevalidator.h>
#include <utils/tooltip/tooltip.h>
#include <QDir>
@@ -51,48 +52,6 @@
namespace ProjectExplorer {
-class EnvironmentValidator : public QValidator
-{
- Q_OBJECT
-public:
- EnvironmentValidator(QWidget *parent, Utils::EnvironmentModel *model, QTreeView *view,
- const QModelIndex &index) :
- QValidator(parent), m_model(model), m_view(view), m_index(index)
- {
- m_hideTipTimer.setInterval(2000);
- m_hideTipTimer.setSingleShot(true);
- connect(&m_hideTipTimer, &QTimer::timeout,
- this, [](){Utils::ToolTip::hide();});
- }
-
- QValidator::State validate(QString &in, int &pos) const override
- {
- Q_UNUSED(pos)
- QModelIndex idx = m_model->variableToIndex(in);
- if (idx.isValid() && idx != m_index)
- return QValidator::Intermediate;
- Utils::ToolTip::hide();
- m_hideTipTimer.stop();
- return QValidator::Acceptable;
- }
-
- void fixup(QString &input) const override
- {
- Q_UNUSED(input)
-
- QPoint pos = m_view->mapToGlobal(m_view->visualRect(m_index).topLeft());
- pos -= Utils::ToolTip::offsetFromPosition();
- Utils::ToolTip::show(pos, tr("Variable already exists."));
- m_hideTipTimer.start();
- // do nothing
- }
-private:
- Utils::EnvironmentModel *m_model;
- QTreeView *m_view;
- QModelIndex m_index;
- mutable QTimer m_hideTipTimer;
-};
-
class EnvironmentDelegate : public QStyledItemDelegate
{
public:
@@ -108,7 +67,8 @@ public:
return w;
if (auto edit = qobject_cast<QLineEdit *>(w))
- edit->setValidator(new EnvironmentValidator(edit, m_model, m_view, index));
+ edit->setValidator(new Utils::NameValueValidator(
+ edit, m_model, m_view, index, EnvironmentWidget::tr("Variable already exists.")));
return w;
}
private:
@@ -134,6 +94,7 @@ public:
QPushButton *m_addButton;
QPushButton *m_resetButton;
QPushButton *m_unsetButton;
+ QPushButton *m_toggleButton;
QPushButton *m_batchEditButton;
QPushButton *m_appendPathButton = nullptr;
QPushButton *m_prependPathButton = nullptr;
@@ -162,13 +123,13 @@ EnvironmentWidget::EnvironmentWidget(QWidget *parent, Type type, QWidget *additi
details->setVisible(false);
auto vbox2 = new QVBoxLayout(details);
- vbox2->setMargin(0);
+ vbox2->setContentsMargins(0, 0, 0, 0);
if (additionalDetailsWidget)
vbox2->addWidget(additionalDetailsWidget);
auto horizontalLayout = new QHBoxLayout();
- horizontalLayout->setMargin(0);
+ horizontalLayout->setContentsMargins(0, 0, 0, 0);
auto tree = new Utils::TreeView(this);
connect(tree, &QAbstractItemView::activated,
tree, [tree](const QModelIndex &idx) { tree->edit(idx); });
@@ -206,6 +167,13 @@ EnvironmentWidget::EnvironmentWidget(QWidget *parent, Type type, QWidget *additi
d->m_unsetButton->setText(tr("&Unset"));
buttonLayout->addWidget(d->m_unsetButton);
+ d->m_toggleButton = new QPushButton(tr("Disable"), this);
+ buttonLayout->addWidget(d->m_toggleButton);
+ connect(d->m_toggleButton, &QPushButton::clicked, this, [this] {
+ d->m_model->toggleVariable(d->m_environmentView->currentIndex());
+ updateButtons();
+ });
+
if (type == TypeLocal) {
d->m_appendPathButton = new QPushButton(this);
d->m_appendPathButton->setEnabled(false);
@@ -301,12 +269,12 @@ void EnvironmentWidget::setBaseEnvironmentText(const QString &text)
updateSummaryText();
}
-QList<Utils::EnvironmentItem> EnvironmentWidget::userChanges() const
+Utils::EnvironmentItems EnvironmentWidget::userChanges() const
{
return d->m_model->userChanges();
}
-void EnvironmentWidget::setUserChanges(const QList<Utils::EnvironmentItem> &list)
+void EnvironmentWidget::setUserChanges(const Utils::EnvironmentItems &list)
{
d->m_model->setUserChanges(list);
updateSummaryText();
@@ -320,17 +288,26 @@ void EnvironmentWidget::setOpenTerminalFunc(const EnvironmentWidget::OpenTermina
void EnvironmentWidget::updateSummaryText()
{
- QList<Utils::EnvironmentItem> list = d->m_model->userChanges();
+ Utils::EnvironmentItems list = d->m_model->userChanges();
Utils::EnvironmentItem::sort(&list);
QString text;
foreach (const Utils::EnvironmentItem &item, list) {
if (item.name != Utils::EnvironmentModel::tr("<VARIABLE>")) {
text.append(QLatin1String("<br>"));
- if (item.operation == Utils::EnvironmentItem::Unset)
+ switch (item.operation) {
+ case Utils::EnvironmentItem::Unset:
text.append(tr("Unset <a href=\"%1\"><b>%1</b></a>").arg(item.name.toHtmlEscaped()));
- else
+ break;
+ case Utils::EnvironmentItem::SetEnabled:
+ case Utils::EnvironmentItem::Append:
+ case Utils::EnvironmentItem::Prepend:
text.append(tr("Set <a href=\"%1\"><b>%1</b></a> to <b>%2</b>").arg(item.name.toHtmlEscaped(), item.value.toHtmlEscaped()));
+ break;
+ case Utils::EnvironmentItem::SetDisabled:
+ text.append(tr("Set <a href=\"%1\"><b>%1</b></a> to <b>%2</b> [disabled]").arg(item.name.toHtmlEscaped(), item.value.toHtmlEscaped()));
+ break;
+ }
}
}
@@ -455,14 +432,12 @@ void EnvironmentWidget::prependPathButtonClicked()
void EnvironmentWidget::batchEditEnvironmentButtonClicked()
{
- const QList<Utils::EnvironmentItem> changes = d->m_model->userChanges();
+ const Utils::EnvironmentItems changes = d->m_model->userChanges();
- bool ok;
- const QList<Utils::EnvironmentItem> newChanges = Utils::EnvironmentDialog::getEnvironmentItems(&ok, this, changes);
- if (!ok)
- return;
+ const auto newChanges = Utils::EnvironmentDialog::getEnvironmentItems(this, changes);
- d->m_model->setUserChanges(newChanges);
+ if (newChanges)
+ d->m_model->setUserChanges(*newChanges);
}
void EnvironmentWidget::environmentCurrentIndexChanged(const QModelIndex &current)
@@ -471,13 +446,17 @@ void EnvironmentWidget::environmentCurrentIndexChanged(const QModelIndex &curren
d->m_editButton->setEnabled(true);
const QString &name = d->m_model->indexToVariable(current);
bool modified = d->m_model->canReset(name) && d->m_model->changes(name);
- bool unset = d->m_model->canUnset(name);
+ bool unset = d->m_model->isUnset(name);
d->m_resetButton->setEnabled(modified || unset);
d->m_unsetButton->setEnabled(!unset);
+ d->m_toggleButton->setEnabled(!unset);
+ d->m_toggleButton->setText(d->m_model->isEnabled(name) ? tr("Disable") : tr("Enable"));
} else {
d->m_editButton->setEnabled(false);
d->m_resetButton->setEnabled(false);
d->m_unsetButton->setEnabled(false);
+ d->m_toggleButton->setEnabled(false);
+ d->m_toggleButton->setText(tr("Disable"));
}
if (d->m_appendPathButton) {
d->m_appendPathButton->setEnabled(currentEntryIsPathList(current));
@@ -491,5 +470,3 @@ void EnvironmentWidget::invalidateCurrentIndex()
}
} // namespace ProjectExplorer
-
-#include "environmentwidget.moc"