forked from qt-creator/qt-creator
ProjectExplorer: Ensure environment from aspect is always up to date
Otherwise our (intential) delay when updating the environment from the text edit can lead to surprises for the user. Fixes: QTCREATORBUG-31052 Change-Id: Iaba8c496094ad95d8c099c67c0805317f32a2936 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -73,21 +73,14 @@ NameValueItemsWidget::NameValueItemsWidget(QWidget *parent)
|
||||
layout->addWidget(m_editor);
|
||||
layout->addWidget(new QLabel(helpText, this));
|
||||
|
||||
const auto checkForItemChange = [this] {
|
||||
const EnvironmentItems newItems = environmentItems();
|
||||
if (newItems != m_originalItems) {
|
||||
m_originalItems = newItems;
|
||||
emit userChangedItems(newItems);
|
||||
}
|
||||
};
|
||||
const auto timer = new QTimer(this);
|
||||
timer->setSingleShot(true);
|
||||
timer->setInterval(1000);
|
||||
connect(m_editor, &QPlainTextEdit::textChanged, timer, qOverload<>(&QTimer::start));
|
||||
connect(timer, &QTimer::timeout, this, checkForItemChange);
|
||||
connect(m_editor, &Internal::TextEditHelper::lostFocus, this, [timer, checkForItemChange] {
|
||||
connect(timer, &QTimer::timeout, this, &NameValueItemsWidget::forceUpdateCheck);
|
||||
connect(m_editor, &Internal::TextEditHelper::lostFocus, this, [this, timer] {
|
||||
timer->stop();
|
||||
checkForItemChange();
|
||||
forceUpdateCheck();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -159,6 +152,15 @@ bool NameValueItemsWidget::editVariable(const QString &name, Selection selection
|
||||
return false;
|
||||
}
|
||||
|
||||
void NameValueItemsWidget::forceUpdateCheck()
|
||||
{
|
||||
const EnvironmentItems newItems = environmentItems();
|
||||
if (newItems != m_originalItems) {
|
||||
m_originalItems = newItems;
|
||||
emit userChangedItems(newItems);
|
||||
}
|
||||
}
|
||||
|
||||
NameValuesDialog::NameValuesDialog(const QString &windowTitle, QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
|
@@ -29,6 +29,8 @@ public:
|
||||
enum class Selection { Name, Value };
|
||||
bool editVariable(const QString &name, Selection selection);
|
||||
|
||||
void forceUpdateCheck();
|
||||
|
||||
signals:
|
||||
void userChangedItems(const EnvironmentItems &items);
|
||||
|
||||
|
@@ -69,7 +69,7 @@ void EnvironmentAspect::setUserEnvironmentChanges(const Utils::EnvironmentItems
|
||||
Utils::Environment EnvironmentAspect::environment() const
|
||||
{
|
||||
Environment env = modifiedBaseEnvironment();
|
||||
env.modify(m_userChanges);
|
||||
env.modify(userEnvironmentChanges());
|
||||
return env;
|
||||
}
|
||||
|
||||
@@ -165,4 +165,9 @@ Environment EnvironmentAspect::BaseEnvironment::unmodifiedBaseEnvironment() cons
|
||||
return getter ? getter() : Environment();
|
||||
}
|
||||
|
||||
Utils::EnvironmentItems EnvironmentAspect::userEnvironmentChanges() const
|
||||
{
|
||||
emit userChangesUpdateRequested();
|
||||
return m_userChanges;
|
||||
}
|
||||
} // namespace ProjectExplorer
|
||||
|
@@ -32,7 +32,7 @@ public:
|
||||
int baseEnvironmentBase() const;
|
||||
void setBaseEnvironmentBase(int base);
|
||||
|
||||
Utils::EnvironmentItems userEnvironmentChanges() const { return m_userChanges; }
|
||||
Utils::EnvironmentItems userEnvironmentChanges() const;
|
||||
void setUserEnvironmentChanges(const Utils::EnvironmentItems &diff);
|
||||
|
||||
int addSupportedBaseEnvironment(const QString &displayName,
|
||||
@@ -68,6 +68,7 @@ signals:
|
||||
void baseEnvironmentChanged();
|
||||
void userEnvironmentChangesChanged(const Utils::EnvironmentItems &diff);
|
||||
void environmentChanged();
|
||||
void userChangesUpdateRequested() const;
|
||||
|
||||
protected:
|
||||
void fromMap(const Utils::Store &map) override;
|
||||
|
@@ -26,6 +26,10 @@ EnvironmentAspectWidget::EnvironmentAspectWidget(EnvironmentAspect *aspect)
|
||||
{
|
||||
QTC_CHECK(m_aspect);
|
||||
|
||||
connect(m_aspect, &EnvironmentAspect::userChangesUpdateRequested, this, [this] {
|
||||
m_environmentWidget->forceUpdateCheck();
|
||||
});
|
||||
|
||||
setContentsMargins(0, 0, 0, 0);
|
||||
auto topLayout = new QVBoxLayout(this);
|
||||
topLayout->setContentsMargins(0, 0, 0, 25);
|
||||
|
@@ -332,6 +332,7 @@ void EnvironmentWidget::setBaseEnvironmentText(const QString &text)
|
||||
|
||||
Utils::EnvironmentItems EnvironmentWidget::userChanges() const
|
||||
{
|
||||
forceUpdateCheck();
|
||||
return d->m_model->userChanges();
|
||||
}
|
||||
|
||||
@@ -352,6 +353,11 @@ void EnvironmentWidget::expand()
|
||||
d->m_detailsContainer->setState(Utils::DetailsWidget::Expanded);
|
||||
}
|
||||
|
||||
void EnvironmentWidget::forceUpdateCheck() const
|
||||
{
|
||||
d->m_editor.forceUpdateCheck();
|
||||
}
|
||||
|
||||
void EnvironmentWidget::updateSummaryText()
|
||||
{
|
||||
// The summary is redundant with the text edit, so we hide it on expansion.
|
||||
|
@@ -38,6 +38,8 @@ public:
|
||||
|
||||
void expand();
|
||||
|
||||
void forceUpdateCheck() const;
|
||||
|
||||
signals:
|
||||
void userChangesChanged();
|
||||
void detailsVisibleChanged(bool visible);
|
||||
|
Reference in New Issue
Block a user