diff --git a/src/libs/utils/pathchooser.cpp b/src/libs/utils/pathchooser.cpp index ce2ce044be5..0d0dab0e60c 100644 --- a/src/libs/utils/pathchooser.cpp +++ b/src/libs/utils/pathchooser.cpp @@ -28,6 +28,7 @@ #include "environment.h" #include "optional.h" #include "qtcassert.h" +#include "macroexpander.h" #include "synchronousprocess.h" #include "hostosinfo.h" @@ -174,12 +175,14 @@ public: Environment m_environment; BinaryVersionToolTipEventFilter *m_binaryVersionToolTipEventFilter = nullptr; QList m_buttons; + MacroExpander *m_macroExpander; }; PathChooserPrivate::PathChooserPrivate() : m_hLayout(new QHBoxLayout), m_lineEdit(new FancyLineEdit), - m_acceptingKind(PathChooser::ExistingDirectory) + m_acceptingKind(PathChooser::ExistingDirectory), + m_macroExpander(globalMacroExpander()) { } @@ -187,7 +190,12 @@ QString PathChooserPrivate::expandedPath(const QString &input) const { if (input.isEmpty()) return input; - const QString path = FileName::fromUserInput(m_environment.expandVariables(input)).toString(); + + QString expandedInput = m_environment.expandVariables(input); + if (m_macroExpander) + expandedInput = m_macroExpander->expand(expandedInput); + + const QString path = FileName::fromUserInput(expandedInput).toString(); if (path.isEmpty()) return path; @@ -692,6 +700,11 @@ void PathChooser::setHistoryCompleter(const QString &historyKey, bool restoreLas d->m_lineEdit->setHistoryCompleter(historyKey, restoreLastItemFromHistory); } +void PathChooser::setMacroExpander(MacroExpander *macroExpander) +{ + d->m_macroExpander = macroExpander; +} + QStringList PathChooser::commandVersionArguments() const { return d->m_binaryVersionToolTipEventFilter ? diff --git a/src/libs/utils/pathchooser.h b/src/libs/utils/pathchooser.h index deaaf4f05d7..73939e1bf48 100644 --- a/src/libs/utils/pathchooser.h +++ b/src/libs/utils/pathchooser.h @@ -39,6 +39,7 @@ QT_END_NAMESPACE namespace Utils { class FancyLineEdit; +class MacroExpander; class Environment; class PathChooserPrivate; @@ -135,6 +136,11 @@ public: // Enable a history completer with a history of entries. void setHistoryCompleter(const QString &historyKey, bool restoreLastItemFromHistory = false); + // Sets a macro expander that is used when producing path and fileName. + // By default, the global expander is used. + // nullptr can be passed to disable macro expansion. + void setMacroExpander(MacroExpander *macroExpander); + bool isReadOnly() const; void setReadOnly(bool b);