diff --git a/src/libs/utils/namevaluemodel.cpp b/src/libs/utils/namevaluemodel.cpp index 0283bd9ba78..697a6b58117 100644 --- a/src/libs/utils/namevaluemodel.cpp +++ b/src/libs/utils/namevaluemodel.cpp @@ -167,10 +167,16 @@ QVariant NameValueModel::data(const QModelIndex &index, int role) const } QString value = d->m_resultNameValueDictionary.value(resultIterator); if (role == Qt::ToolTipRole && value.length() > 80) { - // Use html to enable text wrapping - value = value.toHtmlEscaped(); - value.prepend(QLatin1String("")); - value.append(QLatin1String("")); + if (currentEntryIsPathList(index)) { + // For path lists, display one entry per line without separator + const QChar sep = Utils::HostOsInfo::pathListSeparator(); + value = value.replace(sep, '\n'); + } else { + // Use html to enable text wrapping + value = value.toHtmlEscaped(); + value.prepend(QLatin1String("")); + value.append(QLatin1String("")); + } } return value; } @@ -437,4 +443,36 @@ void NameValueModel::setUserChanges(const NameValueItems &items) emit userChangesChanged(); } +bool NameValueModel::currentEntryIsPathList(const QModelIndex ¤t) const +{ + if (!current.isValid()) + return false; + + // Look at the name first and check it against some well-known path variables. Extend as needed. + const QString varName = indexToVariable(current); + if (varName.compare("PATH", Utils::HostOsInfo::fileNameCaseSensitivity()) == 0) + return true; + if (Utils::HostOsInfo::isMacHost() && varName == "DYLD_LIBRARY_PATH") + return true; + if (Utils::HostOsInfo::isAnyUnixHost() && varName == "LD_LIBRARY_PATH") + return true; + if (varName == "PKG_CONFIG_DIR") + return true; + if (Utils::HostOsInfo::isWindowsHost() + && QStringList{"INCLUDE", "LIB", "LIBPATH"}.contains(varName)) { + return true; + } + + // Now check the value: If it's a list of strings separated by the platform's path separator + // and at least one of the strings is an existing directory, then that's enough proof for us. + QModelIndex valueIndex = current; + if (valueIndex.column() == 0) + valueIndex = valueIndex.siblingAtColumn(1); + const QStringList entries = data(valueIndex).toString() + .split(Utils::HostOsInfo::pathListSeparator(), Qt::SkipEmptyParts); + if (entries.length() < 2) + return false; + return Utils::anyOf(entries, [](const QString &d) { return QFileInfo(d).isDir(); }); +} + } // namespace Utils diff --git a/src/libs/utils/namevaluemodel.h b/src/libs/utils/namevaluemodel.h index ede319a0138..6e6ddfc1773 100644 --- a/src/libs/utils/namevaluemodel.h +++ b/src/libs/utils/namevaluemodel.h @@ -70,6 +70,7 @@ public: void setBaseNameValueDictionary(const NameValueDictionary &dictionary); NameValueItems userChanges() const; void setUserChanges(const NameValueItems &items); + bool currentEntryIsPathList(const QModelIndex ¤t) const; signals: void userChangesChanged(); diff --git a/src/plugins/projectexplorer/environmentwidget.cpp b/src/plugins/projectexplorer/environmentwidget.cpp index 948bba7d430..078eb2f2a58 100644 --- a/src/plugins/projectexplorer/environmentwidget.cpp +++ b/src/plugins/projectexplorer/environmentwidget.cpp @@ -437,38 +437,6 @@ void EnvironmentWidget::linkActivated(const QString &link) focusIndex(idx); } -bool EnvironmentWidget::currentEntryIsPathList(const QModelIndex ¤t) const -{ - if (!current.isValid()) - return false; - - // Look at the name first and check it against some well-known path variables. Extend as needed. - const QString varName = d->m_model->indexToVariable(current); - if (varName.compare("PATH", Utils::HostOsInfo::fileNameCaseSensitivity()) == 0) - return true; - if (Utils::HostOsInfo::isMacHost() && varName == "DYLD_LIBRARY_PATH") - return true; - if (Utils::HostOsInfo::isAnyUnixHost() && varName == "LD_LIBRARY_PATH") - return true; - if (varName == "PKG_CONFIG_DIR") - return true; - if (Utils::HostOsInfo::isWindowsHost() - && QStringList{"INCLUDE", "LIB", "LIBPATH"}.contains(varName)) { - return true; - } - - // Now check the value: If it's a list of strings separated by the platform's path separator - // and at least one of the strings is an existing directory, then that's enough proof for us. - QModelIndex valueIndex = current; - if (valueIndex.column() == 0) - valueIndex = valueIndex.siblingAtColumn(1); - const QStringList entries = d->m_model->data(valueIndex).toString() - .split(Utils::HostOsInfo::pathListSeparator(), Qt::SkipEmptyParts); - if (entries.length() < 2) - return false; - return Utils::anyOf(entries, [](const QString &d) { return QFileInfo(d).isDir(); }); -} - void EnvironmentWidget::updateButtons() { environmentCurrentIndexChanged(d->m_environmentView->currentIndex()); @@ -477,7 +445,9 @@ void EnvironmentWidget::updateButtons() void EnvironmentWidget::editEnvironmentButtonClicked() { const QModelIndex current = d->m_environmentView->currentIndex(); - if (current.column() == 1 && d->m_type == TypeLocal && currentEntryIsPathList(current)) { + if (current.column() == 1 + && d->m_type == TypeLocal + && d->m_model->currentEntryIsPathList(current)) { PathListDialog dlg(d->m_model->indexToVariable(current), d->m_model->data(current).toString(), this); if (dlg.exec() == QDialog::Accepted) @@ -562,8 +532,9 @@ void EnvironmentWidget::environmentCurrentIndexChanged(const QModelIndex ¤ d->m_toggleButton->setText(tr("Disable")); } if (d->m_appendPathButton) { - d->m_appendPathButton->setEnabled(currentEntryIsPathList(current)); - d->m_prependPathButton->setEnabled(currentEntryIsPathList(current)); + const bool isPathList = d->m_model->currentEntryIsPathList(current); + d->m_appendPathButton->setEnabled(isPathList); + d->m_prependPathButton->setEnabled(isPathList); } } diff --git a/src/plugins/projectexplorer/environmentwidget.h b/src/plugins/projectexplorer/environmentwidget.h index e59d84efbc5..62a91b46ca0 100644 --- a/src/plugins/projectexplorer/environmentwidget.h +++ b/src/plugins/projectexplorer/environmentwidget.h @@ -80,7 +80,6 @@ private: void focusIndex(const QModelIndex &index); void updateButtons(); void linkActivated(const QString &link); - bool currentEntryIsPathList(const QModelIndex ¤t) const; using PathListModifier = std::function; void amendPathList(Utils::NameValueItem::Operation op);