diff --git a/src/libs/utils/macroexpander.cpp b/src/libs/utils/macroexpander.cpp index 1a279f8ff62..10029b0d629 100644 --- a/src/libs/utils/macroexpander.cpp +++ b/src/libs/utils/macroexpander.cpp @@ -49,6 +49,7 @@ public: QHash m_map; QHash m_prefixMap; QMap m_descriptions; + QString m_displayName; }; } // Internal @@ -320,4 +321,37 @@ QString MacroExpander::variableDescription(const QByteArray &variable) return d->m_descriptions.value(variable); } +QString MacroExpander::displayName() const +{ + return d->m_displayName; +} + +void MacroExpander::setDisplayName(const QString &displayName) +{ + d->m_displayName = displayName; +} + + +class GlobalMacroExpander : public MacroExpander +{ + Q_DECLARE_TR_FUNCTIONS(Utils::MacroExpander) + +public: + GlobalMacroExpander() + { + setDisplayName(tr("Global variables")); + registerPrefix("Env", tr("Access environment variables."), + [](const QString &value) { return QString::fromLocal8Bit(qgetenv(value.toLocal8Bit())); }); + } +}; + +/*! + * Returns the expander for globally registered variables. + */ +MacroExpander *globalMacroExpander() +{ + static GlobalMacroExpander theGlobalExpander; + return &theGlobalExpander; +} + } // namespace Utils diff --git a/src/libs/utils/macroexpander.h b/src/libs/utils/macroexpander.h index 2405659dc54..c2f3efd7c65 100644 --- a/src/libs/utils/macroexpander.h +++ b/src/libs/utils/macroexpander.h @@ -70,6 +70,9 @@ public: QList variables(); QString variableDescription(const QByteArray &variable); + QString displayName() const; + void setDisplayName(const QString &displayName); + private: MacroExpander(const MacroExpander &) Q_DECL_EQ_DELETE; void operator=(const MacroExpander &) Q_DECL_EQ_DELETE; @@ -77,6 +80,8 @@ private: Internal::MacroExpanderPrivate *d; }; +QTCREATOR_UTILS_EXPORT MacroExpander *globalMacroExpander(); + } // namespace Utils #endif // UTILS_MACROEXPANDER_H diff --git a/src/plugins/baremetal/baremetaldeviceconfigurationwidget.cpp b/src/plugins/baremetal/baremetaldeviceconfigurationwidget.cpp index 05d6e8240c0..09bea5e7e07 100644 --- a/src/plugins/baremetal/baremetaldeviceconfigurationwidget.cpp +++ b/src/plugins/baremetal/baremetaldeviceconfigurationwidget.cpp @@ -79,9 +79,9 @@ BareMetalDeviceConfigurationWidget::BareMetalDeviceConfigurationWidget( formLayout->addRow(tr("Init commands:"), m_gdbInitCommandsTextEdit); formLayout->addRow(tr("Reset commands:"), m_gdbResetCommandsTextEdit); - VariableChooser::addVariableSupport(m_gdbResetCommandsTextEdit); - VariableChooser::addVariableSupport(m_gdbInitCommandsTextEdit); - (void)new VariableChooser(this); + auto chooser = new VariableChooser(this); + chooser->addSupportedWidget(m_gdbResetCommandsTextEdit); + chooser->addSupportedWidget(m_gdbInitCommandsTextEdit); connect(m_gdbHostLineEdit, SIGNAL(editingFinished()), SLOT(hostnameChanged())); connect(m_gdbPortSpinBox, SIGNAL(valueChanged(int)), SLOT(portChanged())); diff --git a/src/plugins/baremetal/baremetaldeviceconfigurationwizardpages.cpp b/src/plugins/baremetal/baremetaldeviceconfigurationwizardpages.cpp index f6397032ebd..4c0891c3b1a 100644 --- a/src/plugins/baremetal/baremetaldeviceconfigurationwizardpages.cpp +++ b/src/plugins/baremetal/baremetaldeviceconfigurationwizardpages.cpp @@ -88,9 +88,9 @@ BareMetalDeviceConfigurationWizardSetupPage::BareMetalDeviceConfigurationWizardS connect(m_gdbResetCommandsTextEdit, SIGNAL(textChanged()), SIGNAL(completeChanged())); connect(m_gdbInitCommandsPlainTextEdit, SIGNAL(textChanged()), SIGNAL(completeChanged())); - VariableChooser::addVariableSupport(m_gdbResetCommandsTextEdit); - VariableChooser::addVariableSupport(m_gdbInitCommandsPlainTextEdit); - (void)new VariableChooser(this); + auto chooser = new VariableChooser(this); + chooser->addSupportedWidget(m_gdbResetCommandsTextEdit); + chooser->addSupportedWidget(m_gdbInitCommandsPlainTextEdit); } void BareMetalDeviceConfigurationWizardSetupPage::initializePage() diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp index f37e8c45cc1..a6a44c6bfdc 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp @@ -64,7 +64,6 @@ #include #include #include -#include #include #include diff --git a/src/plugins/coreplugin/coreplugin.pro b/src/plugins/coreplugin/coreplugin.pro index c4b93810d8c..e9f5ef867b9 100644 --- a/src/plugins/coreplugin/coreplugin.pro +++ b/src/plugins/coreplugin/coreplugin.pro @@ -53,7 +53,6 @@ SOURCES += corejsextensions.cpp \ progressmanager/futureprogress.cpp \ statusbarwidget.cpp \ coreplugin.cpp \ - variablemanager.cpp \ modemanager.cpp \ basefilewizard.cpp \ basefilewizardfactory.cpp \ @@ -165,7 +164,6 @@ HEADERS += corejsextensions.h \ core_global.h \ statusbarwidget.h \ coreplugin.h \ - variablemanager.h \ modemanager.h \ basefilewizard.h \ basefilewizardfactory.h \ diff --git a/src/plugins/coreplugin/coreplugin.qbs b/src/plugins/coreplugin/coreplugin.qbs index b96902a1bf9..33cf4ff5133 100644 --- a/src/plugins/coreplugin/coreplugin.qbs +++ b/src/plugins/coreplugin/coreplugin.qbs @@ -100,7 +100,6 @@ QtcPlugin { "textdocument.cpp", "textdocument.h", "toolsettings.cpp", "toolsettings.h", "variablechooser.cpp", "variablechooser.h", - "variablemanager.cpp", "variablemanager.h", "vcsmanager.cpp", "vcsmanager.h", "versiondialog.cpp", "versiondialog.h", "windowsupport.cpp", "windowsupport.h" diff --git a/src/plugins/coreplugin/dialogs/externaltoolconfig.cpp b/src/plugins/coreplugin/dialogs/externaltoolconfig.cpp index 9699b8359b2..d0eb4268dac 100644 --- a/src/plugins/coreplugin/dialogs/externaltoolconfig.cpp +++ b/src/plugins/coreplugin/dialogs/externaltoolconfig.cpp @@ -33,13 +33,13 @@ #include #include +#include #include #include #include #include #include -#include #include #include @@ -410,10 +410,11 @@ ExternalToolConfig::ExternalToolConfig(QWidget *parent) : connect(ui->toolTree->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(handleCurrentChanged(QModelIndex,QModelIndex))); - Core::VariableChooser::addVariableSupport(ui->executable->lineEdit()); - Core::VariableChooser::addVariableSupport(ui->arguments); - Core::VariableChooser::addVariableSupport(ui->workingDirectory->lineEdit()); - Core::VariableChooser::addVariableSupport(ui->inputText); + auto chooser = new VariableChooser(this); + chooser->addSupportedWidget(ui->executable->lineEdit()); + chooser->addSupportedWidget(ui->arguments); + chooser->addSupportedWidget(ui->workingDirectory->lineEdit()); + chooser->addSupportedWidget(ui->inputText); connect(ui->description, SIGNAL(editingFinished()), this, SLOT(updateCurrentItem())); connect(ui->executable, SIGNAL(editingFinished()), this, SLOT(updateCurrentItem())); @@ -441,7 +442,6 @@ ExternalToolConfig::ExternalToolConfig(QWidget *parent) : showInfoForItem(QModelIndex()); - new VariableChooser(this); } ExternalToolConfig::~ExternalToolConfig() @@ -595,5 +595,5 @@ void ExternalToolConfig::addCategory() void ExternalToolConfig::updateEffectiveArguments() { ui->arguments->setToolTip(Utils::QtcProcess::expandMacros(ui->arguments->text(), - globalMacroExpander())); + Utils::globalMacroExpander())); } diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 68fb7c82824..9dc888e991b 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -59,7 +59,6 @@ #include #include #include -#include #include #include @@ -67,6 +66,7 @@ #include #include #include +#include #include #include @@ -87,6 +87,8 @@ #include #include +using namespace Utils; + enum { debugEditorManager=0 }; static const char kCurrentDocumentPrefix[] = "CurrentDocument"; diff --git a/src/plugins/coreplugin/externaltool.cpp b/src/plugins/coreplugin/externaltool.cpp index fc8e3759340..014dc20cdd0 100644 --- a/src/plugins/coreplugin/externaltool.cpp +++ b/src/plugins/coreplugin/externaltool.cpp @@ -33,7 +33,6 @@ #include "actionmanager/actionmanager.h" #include "actionmanager/actioncontainer.h" #include "coreconstants.h" -#include "variablemanager.h" #include #include @@ -41,8 +40,10 @@ #include #include #include -#include + #include +#include +#include #include #include @@ -54,6 +55,7 @@ #include +using namespace Utils; using namespace Core; using namespace Core::Internal; diff --git a/src/plugins/coreplugin/jsexpander.cpp b/src/plugins/coreplugin/jsexpander.cpp index 6e8c95f4045..fe0ec65f175 100644 --- a/src/plugins/coreplugin/jsexpander.cpp +++ b/src/plugins/coreplugin/jsexpander.cpp @@ -30,8 +30,8 @@ #include "jsexpander.h" #include "corejsextensions.h" -#include "variablemanager.h" +#include #include #include @@ -90,7 +90,7 @@ QString JsExpander::evaluate(const QString &expression, QString *errorMessage) JsExpander::JsExpander() { d = new Internal::JsExpanderPrivate; - globalMacroExpander()->registerPrefix("JS", + Utils::globalMacroExpander()->registerPrefix("JS", QCoreApplication::translate("Core::JsExpander", "Evaluate simple Javascript statements.\n" "The statements may not contain '{' nor '}' characters."), diff --git a/src/plugins/coreplugin/locator/executefilter.cpp b/src/plugins/coreplugin/locator/executefilter.cpp index 75cbe0940b0..1d033bdaf5e 100644 --- a/src/plugins/coreplugin/locator/executefilter.cpp +++ b/src/plugins/coreplugin/locator/executefilter.cpp @@ -32,7 +32,7 @@ #include #include -#include +#include #include @@ -91,9 +91,9 @@ void ExecuteFilter::accept(LocatorFilterEntry selection) const p->m_commandHistory.prepend(value); bool found; - QString workingDirectory = globalMacroExpander()->value("CurrentDocument:Path", &found); + QString workingDirectory = Utils::globalMacroExpander()->value("CurrentDocument:Path", &found); if (!found || workingDirectory.isEmpty()) - workingDirectory = globalMacroExpander()->value("CurrentProject:Path", &found); + workingDirectory = Utils::globalMacroExpander()->value("CurrentProject:Path", &found); ExecuteData d; d.workingDirectory = workingDirectory; diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp index df0c4a87037..0cfebe0951a 100644 --- a/src/plugins/coreplugin/mainwindow.cpp +++ b/src/plugins/coreplugin/mainwindow.cpp @@ -45,7 +45,6 @@ #include "outputpanemanager.h" #include "plugindialog.h" #include "vcsmanager.h" -#include "variablemanager.h" #include "versiondialog.h" #include "statusbarmanager.h" #include "id.h" diff --git a/src/plugins/coreplugin/variablechooser.cpp b/src/plugins/coreplugin/variablechooser.cpp index 05d853ef24e..3e3353e4c85 100644 --- a/src/plugins/coreplugin/variablechooser.cpp +++ b/src/plugins/coreplugin/variablechooser.cpp @@ -29,67 +29,36 @@ ****************************************************************************/ #include "variablechooser.h" -#include "variablemanager.h" #include "coreconstants.h" #include // IconButton +#include +#include #include #include +#include +#include #include #include -#include #include #include #include #include #include +#include #include +#include + +using namespace Utils; namespace Core { namespace Internal { -/*! - * \internal - */ class VariableChooserPrivate : public QObject { - Q_OBJECT - public: - VariableChooserPrivate(VariableChooser *parent) - : q(parent), - m_defaultDescription(tr("Select a variable to insert.")), - m_lineEdit(0), - m_textEdit(0), - m_plainTextEdit(0) - { - m_variableList = new QListWidget(q); - m_variableList->setAttribute(Qt::WA_MacSmallSize); - m_variableList->setAttribute(Qt::WA_MacShowFocusRect, false); - foreach (const QByteArray &variable, globalMacroExpander()->variables()) - m_variableList->addItem(QString::fromLatin1(variable)); - - m_variableDescription = new QLabel(q); - m_variableDescription->setText(m_defaultDescription); - m_variableDescription->setMinimumSize(QSize(0, 60)); - m_variableDescription->setAlignment(Qt::AlignLeft|Qt::AlignTop); - m_variableDescription->setWordWrap(true); - m_variableDescription->setAttribute(Qt::WA_MacSmallSize); - - QVBoxLayout *verticalLayout = new QVBoxLayout(q); - verticalLayout->setContentsMargins(3, 3, 3, 12); - verticalLayout->addWidget(m_variableList); - verticalLayout->addWidget(m_variableDescription); - - connect(m_variableList, SIGNAL(currentTextChanged(QString)), - this, SLOT(updateDescription(QString))); - connect(m_variableList, SIGNAL(itemActivated(QListWidgetItem*)), - this, SLOT(handleItemActivated(QListWidgetItem*))); - connect(qApp, SIGNAL(focusChanged(QWidget*,QWidget*)), - this, SLOT(updateCurrentEditor(QWidget*,QWidget*))); - updateCurrentEditor(0, qApp->focusWidget()); - } + VariableChooserPrivate(VariableChooser *parent); void createIconButton() { @@ -97,30 +66,140 @@ public: m_iconButton->setPixmap(QPixmap(QLatin1String(":/core/images/replace.png"))); m_iconButton->setToolTip(tr("Insert variable")); m_iconButton->hide(); - connect(m_iconButton, SIGNAL(clicked()), this, SLOT(updatePositionAndShow())); + connect(m_iconButton.data(), static_cast(&QAbstractButton::clicked), + this, &VariableChooserPrivate::updatePositionAndShow); } -public slots: - void updateDescription(const QString &variable); + void updateDescription(const QModelIndex &index); void updateCurrentEditor(QWidget *old, QWidget *widget); - void handleItemActivated(QListWidgetItem *item); + void handleItemActivated(const QModelIndex &index); void insertVariable(const QString &variable); - void updatePositionAndShow(); + void updatePositionAndShow(bool); -public: QWidget *currentWidget(); +public: VariableChooser *q; - QString m_defaultDescription; + TreeModel m_model; + QPointer m_lineEdit; QPointer m_textEdit; QPointer m_plainTextEdit; QPointer m_iconButton; - QListWidget *m_variableList; + QTreeView *m_variableTree; QLabel *m_variableDescription; + QString m_defaultDescription; + QByteArray m_currentVariableName; // Prevent recursive insertion of currently expanded item }; +class VariableItem : public TreeItem +{ +public: + VariableItem() + {} + + QVariant data(int column, int role) const + { + if (role == Qt::DisplayRole || role == Qt::EditRole) { + if (column == 0) + return m_display; + } + if (role == Qt::ToolTipRole) + return m_description; + + return QVariant(); + } + +public: + QString m_display; + QString m_description; +}; + +class VariableGroupItem : public TreeItem +{ +public: + VariableGroupItem(VariableChooserPrivate *chooser) + : m_chooser(chooser), m_expander(0) + { + setLazy(true); + } + + bool ensureExpander() const + { + if (!m_expander) + m_expander = m_provider(); + return m_expander != 0; + } + + QVariant data(int column, int role) const + { + if (role == Qt::DisplayRole || role == Qt::EditRole) { + if (column == 0 && ensureExpander()) + return m_expander->displayName(); + } + return QVariant(); + } + + void populate() + { + if (ensureExpander()) { + foreach (const QByteArray &variable, m_expander->variables()) { + auto item = new VariableItem; + item->m_display = QString::fromLatin1(variable); + item->m_description = m_expander->variableDescription(variable); + if (variable == m_chooser->m_currentVariableName) + item->setFlags(Qt::ItemIsSelectable); // not ItemIsEnabled + appendChild(item); + } + } + } + +public: + VariableChooserPrivate *m_chooser; // Not owned. + MacroExpanderProvider m_provider; + mutable MacroExpander *m_expander; // Not owned. + QString m_displayName; +}; + +VariableChooserPrivate::VariableChooserPrivate(VariableChooser *parent) + : q(parent), + m_lineEdit(0), + m_textEdit(0), + m_plainTextEdit(0) +{ + m_defaultDescription = VariableChooser::tr("Select a variable to insert."); + + m_variableTree = new QTreeView(q); + m_variableTree->setAttribute(Qt::WA_MacSmallSize); + m_variableTree->setAttribute(Qt::WA_MacShowFocusRect, false); + m_variableTree->setModel(&m_model); + m_variableTree->header()->hide(); + m_variableTree->header()->setStretchLastSection(true); + + m_variableDescription = new QLabel(q); + m_variableDescription->setText(m_defaultDescription); + m_variableDescription->setMinimumSize(QSize(0, 60)); + m_variableDescription->setAlignment(Qt::AlignLeft|Qt::AlignTop); + m_variableDescription->setWordWrap(true); + m_variableDescription->setAttribute(Qt::WA_MacSmallSize); + + QVBoxLayout *verticalLayout = new QVBoxLayout(q); + verticalLayout->setContentsMargins(3, 3, 3, 12); + verticalLayout->addWidget(m_variableTree); + verticalLayout->addWidget(m_variableDescription); + + // connect(m_variableList, &QTreeView::currentChanged, + // this, &VariableChooserPrivate::updateDescription); + connect(m_variableTree, &QTreeView::clicked, + this, &VariableChooserPrivate::updateDescription); + connect(m_variableTree, &QTreeView::activated, + this, &VariableChooserPrivate::handleItemActivated); + connect(qobject_cast(qApp), &QApplication::focusChanged, + this, &VariableChooserPrivate::updateCurrentEditor); + updateCurrentEditor(0, qApp->focusWidget()); +} + } // namespace Internal using namespace Internal; @@ -140,8 +219,7 @@ using namespace Internal; * * The variable chooser monitors focus changes of all children of its parent widget. * When a text control gets focus, the variable chooser checks if it has variable support set, - * either through the addVariableSupport() function or by manually setting the - * custom kVariableSupportProperty on the control. If the control supports variables, + * either through the addVariableSupport() function. If the control supports variables, * a tool button which opens the variable chooser is shown in it while it has focus. * * Supported text controls are QLineEdit, QTextEdit and QPlainTextEdit. @@ -159,13 +237,15 @@ using namespace Internal; */ /*! + * \internal * \variable VariableChooser::kVariableSupportProperty * Property name that is checked for deciding if a widget supports \QC variables. * Can be manually set with * \c{textcontrol->setProperty(VariableChooser::kVariableSupportProperty, true)} * \sa addVariableSupport() */ -const char VariableChooser::kVariableSupportProperty[] = "QtCreator.VariableSupport"; +const char kVariableSupportProperty[] = "QtCreator.VariableSupport"; +const char kVariableNameProperty[] = "QtCreator.VariableName"; /*! * Creates a variable chooser that tracks all children of \a parent for variable support. @@ -179,7 +259,8 @@ VariableChooser::VariableChooser(QWidget *parent) : setWindowTitle(tr("Variables")); setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint); setFocusPolicy(Qt::StrongFocus); - setFocusProxy(d->m_variableList); + setFocusProxy(d->m_variableTree); + addMacroExpanderProvider([]() { return globalMacroExpander(); }); } /*! @@ -191,26 +272,30 @@ VariableChooser::~VariableChooser() delete d; } +void VariableChooser::addMacroExpanderProvider(const MacroExpanderProvider &provider) +{ + auto *item = new VariableGroupItem(d); + item->m_provider = provider; + d->m_model.rootItem()->prependChild(item); +} + /*! * Marks the control as supporting variables. * \sa kVariableSupportProperty */ -void VariableChooser::addVariableSupport(QWidget *textcontrol) +void VariableChooser::addSupportedWidget(QWidget *textcontrol, const QByteArray &ownName) { QTC_ASSERT(textcontrol, return); - textcontrol->setProperty(kVariableSupportProperty, true); + textcontrol->setProperty(kVariableSupportProperty, QVariant::fromValue(this)); + textcontrol->setProperty(kVariableNameProperty, ownName); } /*! * \internal */ -void VariableChooserPrivate::updateDescription(const QString &variable) +void VariableChooserPrivate::updateDescription(const QModelIndex &index) { - if (variable.isNull()) - m_variableDescription->setText(m_defaultDescription); - else - m_variableDescription->setText(globalMacroExpander()->variableDescription(variable.toUtf8()) - + QLatin1String("

") + tr("Current Value: %1").arg(globalMacroExpander()->value(variable.toUtf8()))); + m_variableDescription->setText(m_model.data(index, Qt::ToolTipRole).toString()); } /*! @@ -236,15 +321,16 @@ void VariableChooserPrivate::updateCurrentEditor(QWidget *old, QWidget *widget) } if (!handle) return; + widget->installEventFilter(this); // for intercepting escape key presses QLineEdit *previousLineEdit = m_lineEdit; QWidget *previousWidget = currentWidget(); m_lineEdit = 0; m_textEdit = 0; m_plainTextEdit = 0; - QVariant variablesSupportProperty = widget->property(VariableChooser::kVariableSupportProperty); - bool supportsVariables = (variablesSupportProperty.isValid() - ? variablesSupportProperty.toBool() : false); + QWidget *chooser = widget->property(kVariableSupportProperty).value(); + m_currentVariableName = widget->property(kVariableNameProperty).value(); + bool supportsVariables = chooser == q; if (QLineEdit *lineEdit = qobject_cast(widget)) m_lineEdit = (supportsVariables ? lineEdit : 0); else if (QTextEdit *textEdit = qobject_cast(widget)) @@ -283,7 +369,7 @@ void VariableChooserPrivate::updateCurrentEditor(QWidget *old, QWidget *widget) /*! * \internal */ -void VariableChooserPrivate::updatePositionAndShow() +void VariableChooserPrivate::updatePositionAndShow(bool) { if (QWidget *w = q->parentWidget()) { QPoint parentCenter = w->mapToGlobal(w->geometry().center()); @@ -309,10 +395,9 @@ QWidget *VariableChooserPrivate::currentWidget() /*! * \internal */ -void VariableChooserPrivate::handleItemActivated(QListWidgetItem *item) +void VariableChooserPrivate::handleItemActivated(const QModelIndex &index) { - if (item) - insertVariable(item->text()); + insertVariable(m_model.data(index, Qt::DisplayRole).toString()); } /*! @@ -320,7 +405,7 @@ void VariableChooserPrivate::handleItemActivated(QListWidgetItem *item) */ void VariableChooserPrivate::insertVariable(const QString &variable) { - const QString &text = QLatin1String("%{") + variable + QLatin1Char('}'); + const QString text = QLatin1String("%{") + variable + QLatin1Char('}'); if (m_lineEdit) { m_lineEdit->insert(text); m_lineEdit->activateWindow(); @@ -367,5 +452,3 @@ bool VariableChooser::eventFilter(QObject *, QEvent *event) } } // namespace Internal - -#include "variablechooser.moc" diff --git a/src/plugins/coreplugin/variablechooser.h b/src/plugins/coreplugin/variablechooser.h index e06c2fe795e..dd24550596f 100644 --- a/src/plugins/coreplugin/variablechooser.h +++ b/src/plugins/coreplugin/variablechooser.h @@ -35,10 +35,16 @@ #include +#include + +namespace Utils { class MacroExpander; } + namespace Core { namespace Internal { class VariableChooserPrivate; } +typedef std::function MacroExpanderProvider; + class CORE_EXPORT VariableChooser : public QWidget { Q_OBJECT @@ -47,8 +53,8 @@ public: explicit VariableChooser(QWidget *parent = 0); ~VariableChooser(); - static const char kVariableSupportProperty[]; - static void addVariableSupport(QWidget *textcontrol); + void addMacroExpanderProvider(const MacroExpanderProvider &provider); + void addSupportedWidget(QWidget *textcontrol, const QByteArray &ownName = QByteArray()); protected: void keyPressEvent(QKeyEvent *ke); diff --git a/src/plugins/cpptools/cpptoolsplugin.cpp b/src/plugins/cpptools/cpptoolsplugin.cpp index 757d3c9aca9..3956b5629c1 100644 --- a/src/plugins/cpptools/cpptoolsplugin.cpp +++ b/src/plugins/cpptools/cpptoolsplugin.cpp @@ -51,12 +51,12 @@ #include #include #include -#include #include #include #include #include +#include #include #include @@ -191,7 +191,7 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error) mcpptools->addAction(command); connect(openInNextSplitAction, SIGNAL(triggered()), this, SLOT(switchHeaderSourceInNextSplit())); - Utils::MacroExpander *expander = globalMacroExpander(); + Utils::MacroExpander *expander = Utils::globalMacroExpander(); expander->registerVariable("Cpp:LicenseTemplate", tr("The license template."), [this]() { return CppToolsPlugin::licenseTemplate(); }); diff --git a/src/plugins/debugger/debuggerengine.cpp b/src/plugins/debugger/debuggerengine.cpp index 13db85c5875..c57299016bb 100644 --- a/src/plugins/debugger/debuggerengine.cpp +++ b/src/plugins/debugger/debuggerengine.cpp @@ -60,9 +60,10 @@ #include -#include -#include #include +#include +#include +#include #include @@ -178,7 +179,7 @@ public: connect(action(IntelFlavor), SIGNAL(valueChanged(QVariant)), SLOT(reloadDisassembly())); - globalMacroExpander()->registerFileVariables(PrefixDebugExecutable, + Utils::globalMacroExpander()->registerFileVariables(PrefixDebugExecutable, tr("Debugged executable"), [this]() { return m_startParameters.executable; }); } @@ -1835,7 +1836,7 @@ void DebuggerEngine::validateExecutable(DebuggerStartParameters *sp) SourcePathRegExpMap globalRegExpSourceMap; globalRegExpSourceMap.reserve(options->sourcePathRegExpMap.size()); foreach (auto entry, options->sourcePathRegExpMap) { - const QString expanded = globalMacroExpander()->expandedString(entry.second); + const QString expanded = Utils::globalMacroExpander()->expandedString(entry.second); if (!expanded.isEmpty()) globalRegExpSourceMap.push_back(qMakePair(entry.first, expanded)); } diff --git a/src/plugins/debugger/debuggerengine.h b/src/plugins/debugger/debuggerengine.h index d065ef5ca42..41b3ef23945 100644 --- a/src/plugins/debugger/debuggerengine.h +++ b/src/plugins/debugger/debuggerengine.h @@ -36,7 +36,6 @@ #include "debuggerstartparameters.h" #include "breakpoint.h" // For BreakpointModelId. #include "threaddata.h" // For ThreadId. -#include "coreplugin/variablemanager.h" #include diff --git a/src/plugins/debugger/debuggersourcepathmappingwidget.cpp b/src/plugins/debugger/debuggersourcepathmappingwidget.cpp index e0334ff1fa1..8fcb4a4567d 100644 --- a/src/plugins/debugger/debuggersourcepathmappingwidget.cpp +++ b/src/plugins/debugger/debuggersourcepathmappingwidget.cpp @@ -209,7 +209,6 @@ DebuggerSourcePathMappingWidget::DebuggerSourcePathMappingWidget(QWidget *parent m_sourceLineEdit(new QLineEdit(this)), m_targetChooser(new PathChooser(this)) { - (void)new Core::VariableChooser(this); setTitle(tr("Source Paths Mapping")); setToolTip(tr("

Mappings of source file folders to " "be used in the debugger can be entered here.

" @@ -275,7 +274,9 @@ DebuggerSourcePathMappingWidget::DebuggerSourcePathMappingWidget(QWidget *parent editTargetLabel->setBuddy(m_targetChooser); m_targetChooser->setToolTip(targetToolTip); editLayout->addRow(editTargetLabel, m_targetChooser); - Core::VariableChooser::addVariableSupport(m_targetChooser->lineEdit()); + + auto chooser = new Core::VariableChooser(this); + chooser->addSupportedWidget(m_targetChooser->lineEdit()); // Main layout QVBoxLayout *mainLayout = new QVBoxLayout; diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp index 2c434e39ec2..392e1cc8f84 100644 --- a/src/plugins/debugger/gdb/gdbengine.cpp +++ b/src/plugins/debugger/gdb/gdbengine.cpp @@ -69,8 +69,10 @@ #include #include #include + #include #include +#include #include #include #include diff --git a/src/plugins/debugger/gdb/gdboptionspage.cpp b/src/plugins/debugger/gdb/gdboptionspage.cpp index 90400c52984..d1b14cb3acd 100644 --- a/src/plugins/debugger/gdb/gdboptionspage.cpp +++ b/src/plugins/debugger/gdb/gdboptionspage.cpp @@ -72,8 +72,6 @@ public: GdbOptionsPageWidget::GdbOptionsPageWidget(QWidget *parent) : QWidget(parent) { - (void) new VariableChooser(this); - auto groupBoxGeneral = new QGroupBox(this); groupBoxGeneral->setTitle(GdbOptionsPage::tr("General")); @@ -233,10 +231,11 @@ GdbOptionsPageWidget::GdbOptionsPageWidget(QWidget *parent) "Matching regular expression: ")); */ - VariableChooser::addVariableSupport(textEditCustomDumperCommands); - VariableChooser::addVariableSupport(textEditPostAttachCommands); - VariableChooser::addVariableSupport(textEditStartupCommands); - VariableChooser::addVariableSupport(pathChooserExtraDumperFile->lineEdit()); + auto chooser = new VariableChooser(this); + chooser->addSupportedWidget(textEditCustomDumperCommands); + chooser->addSupportedWidget(textEditPostAttachCommands); + chooser->addSupportedWidget(textEditStartupCommands); + chooser->addSupportedWidget(pathChooserExtraDumperFile->lineEdit()); auto formLayout = new QFormLayout(groupBoxGeneral); formLayout->addRow(labelGdbWatchdogTimeout, spinBoxGdbWatchdogTimeout); diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp index 000e995b2cc..7f0a688f779 100644 --- a/src/plugins/debugger/watchhandler.cpp +++ b/src/plugins/debugger/watchhandler.cpp @@ -897,7 +897,7 @@ QModelIndex WatchModel::parent(const QModelIndex &idx) const if (!grandparent) return QModelIndex(); - const WatchItems &uncles = grandparent->children; + const auto &uncles = grandparent->children; for (int i = 0, n = uncles.size(); i < n; ++i) if (uncles.at(i) == parent) return createIndex(i, 0, (void*) parent); diff --git a/src/plugins/genericprojectmanager/genericmakestep.cpp b/src/plugins/genericprojectmanager/genericmakestep.cpp index 29cb86065f9..95f08b5ea5a 100644 --- a/src/plugins/genericprojectmanager/genericmakestep.cpp +++ b/src/plugins/genericprojectmanager/genericmakestep.cpp @@ -43,7 +43,6 @@ #include #include #include -#include #include #include #include diff --git a/src/plugins/ios/iosbuildstep.cpp b/src/plugins/ios/iosbuildstep.cpp index 2120231b618..a356ce040dc 100644 --- a/src/plugins/ios/iosbuildstep.cpp +++ b/src/plugins/ios/iosbuildstep.cpp @@ -51,7 +51,6 @@ #include #include #include -#include #include #include #include diff --git a/src/plugins/ios/iosdsymbuildstep.cpp b/src/plugins/ios/iosdsymbuildstep.cpp index f379ca99c84..718a9f4a1c6 100644 --- a/src/plugins/ios/iosdsymbuildstep.cpp +++ b/src/plugins/ios/iosdsymbuildstep.cpp @@ -45,7 +45,6 @@ #include #include #include -#include #include #include #include diff --git a/src/plugins/projectexplorer/buildconfiguration.cpp b/src/plugins/projectexplorer/buildconfiguration.cpp index 82387fb9f04..70d9bc690ae 100644 --- a/src/plugins/projectexplorer/buildconfiguration.cpp +++ b/src/plugins/projectexplorer/buildconfiguration.cpp @@ -38,7 +38,6 @@ #include "kit.h" #include "projectmacroexpander.h" -#include #include #include #include diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardexpander.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizardexpander.cpp index c9e50500755..09493a0bb19 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizardexpander.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardexpander.cpp @@ -32,8 +32,7 @@ #include "jsonwizard.h" -#include - +#include #include #include @@ -59,7 +58,7 @@ bool JsonWizardExpander::resolveMacro(const QString &name, QString *ret) return true; } - return Core::globalMacroExpander()->resolveMacro(name, ret); + return Utils::globalMacroExpander()->resolveMacro(name, ret); } } // namespace Internal diff --git a/src/plugins/projectexplorer/localapplicationrunconfiguration.cpp b/src/plugins/projectexplorer/localapplicationrunconfiguration.cpp index 6d198f4e1dd..7cccc5356aa 100644 --- a/src/plugins/projectexplorer/localapplicationrunconfiguration.cpp +++ b/src/plugins/projectexplorer/localapplicationrunconfiguration.cpp @@ -32,8 +32,9 @@ #include "buildconfiguration.h" +#include #include -#include + #include #include @@ -58,7 +59,7 @@ bool FallBackMacroExpander::resolveMacro(const QString &name, QString *ret) return true; } bool found; - *ret = Core::globalMacroExpander()->value(name.toUtf8(), &found); + *ret = Utils::globalMacroExpander()->value(name.toUtf8(), &found); return found; } } // namespace Internal diff --git a/src/plugins/projectexplorer/processstep.cpp b/src/plugins/projectexplorer/processstep.cpp index cd16683b403..7697d999e92 100644 --- a/src/plugins/projectexplorer/processstep.cpp +++ b/src/plugins/projectexplorer/processstep.cpp @@ -35,7 +35,7 @@ #include "target.h" #include "kit.h" -#include +#include #include @@ -82,7 +82,7 @@ bool ProcessStep::init() if (!bc) bc = target()->activeBuildConfiguration(); ProcessParameters *pp = processParameters(); - pp->setMacroExpander(bc ? bc->macroExpander() : Core::globalMacroExpander()); + pp->setMacroExpander(bc ? bc->macroExpander() : Utils::globalMacroExpander()); pp->setEnvironment(bc ? bc->environment() : Utils::Environment::systemEnvironment()); pp->setWorkingDirectory(workingDirectory()); pp->setCommand(m_command); @@ -272,7 +272,7 @@ void ProcessStepConfigWidget::updateDetails() BuildConfiguration *bc = m_step->buildConfiguration(); if (!bc) // iff the step is actually in the deploy list bc = m_step->target()->activeBuildConfiguration(); - param.setMacroExpander(bc ? bc->macroExpander() : Core::globalMacroExpander()); + param.setMacroExpander(bc ? bc->macroExpander() : Utils::globalMacroExpander()); param.setEnvironment(bc ? bc->environment() : Utils::Environment::systemEnvironment()); param.setWorkingDirectory(m_step->workingDirectory()); diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 1f9f9b3ff0c..16a1bb2b97b 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -117,12 +117,13 @@ #include #include #include -#include #include #include #include + #include #include +#include #include #include @@ -1135,7 +1136,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er updateWelcomePage(); - Utils::MacroExpander *expander = globalMacroExpander(); + Utils::MacroExpander *expander = Utils::globalMacroExpander(); expander->registerFileVariables(Constants::VAR_CURRENTPROJECT_PREFIX, tr("Current project's main file"), [this]() -> QString { diff --git a/src/plugins/projectexplorer/projectexplorersettingspage.cpp b/src/plugins/projectexplorer/projectexplorersettingspage.cpp index 73d54580b7f..b2c2ab76d39 100644 --- a/src/plugins/projectexplorer/projectexplorersettingspage.cpp +++ b/src/plugins/projectexplorer/projectexplorersettingspage.cpp @@ -48,8 +48,6 @@ ProjectExplorerSettingsWidget::ProjectExplorerSettingsWidget(QWidget *parent) : QWidget(parent) { m_ui.setupUi(this); - new Core::VariableChooser(this); - Core::VariableChooser::addVariableSupport(m_ui.buildDirectoryEdit); setJomVisible(Utils::HostOsInfo::isWindowsHost()); m_ui.directoryButtonGroup->setId(m_ui.currentDirectoryRadioButton, UseCurrentDirectory); m_ui.directoryButtonGroup->setId(m_ui.directoryRadioButton, UseProjectDirectory); @@ -58,6 +56,9 @@ ProjectExplorerSettingsWidget::ProjectExplorerSettingsWidget(QWidget *parent) : this, SLOT(slotDirectoryButtonGroupChanged())); connect(m_ui.resetButton, SIGNAL(clicked()), this, SLOT(resetDefaultBuildDirectory())); connect(m_ui.buildDirectoryEdit, SIGNAL(textChanged(QString)), this, SLOT(updateResetButton())); + + auto chooser = new Core::VariableChooser(this); + chooser->addSupportedWidget(m_ui.buildDirectoryEdit); } void ProjectExplorerSettingsWidget::setJomVisible(bool v) diff --git a/src/plugins/projectexplorer/projectmacroexpander.cpp b/src/plugins/projectexplorer/projectmacroexpander.cpp index 63c9747c62a..fc98079a5ee 100644 --- a/src/plugins/projectexplorer/projectmacroexpander.cpp +++ b/src/plugins/projectexplorer/projectmacroexpander.cpp @@ -33,7 +33,7 @@ #include "kitinformation.h" #include "projectexplorerconstants.h" -#include +#include #include using namespace ProjectExplorer; @@ -99,7 +99,7 @@ bool ProjectMacroExpander::resolveMacro(const QString &name, QString *ret) { bool found = resolveProjectMacro(name, ret); if (!found) { - QString result = Core::globalMacroExpander()->value(name.toUtf8(), &found); + QString result = Utils::globalMacroExpander()->value(name.toUtf8(), &found); if (ret) *ret = result; } diff --git a/src/plugins/qtsupport/baseqtversion.cpp b/src/plugins/qtsupport/baseqtversion.cpp index b8e7c41588c..93ec6158c38 100644 --- a/src/plugins/qtsupport/baseqtversion.cpp +++ b/src/plugins/qtsupport/baseqtversion.cpp @@ -250,6 +250,9 @@ void BaseQtVersion::setupExpander() // m_expander.registerVariable("Qt:name", // QCoreApplication::translate("QtSupport::QtKitInformation", "The display name of the current Qt version."), // [this]() { return displayName(); }); + + m_expander.setDisplayName( + QCoreApplication::translate("QtSupport::QtKitInformation", "Qt version")); } BaseQtVersion::~BaseQtVersion() @@ -606,7 +609,8 @@ void BaseQtVersion::setAutoDetectionSource(const QString &autodetectionSource) QString BaseQtVersion::displayName() const { - return Utils::expandMacros(m_unexpandedDisplayName, &m_expander); + QString ret = Utils::expandMacros(m_unexpandedDisplayName, &m_expander); + return Utils::expandMacros(ret, Utils::globalMacroExpander()); } QString BaseQtVersion::unexpandedDisplayName() const diff --git a/src/plugins/qtsupport/qtkitinformation.cpp b/src/plugins/qtsupport/qtkitinformation.cpp index 4879ff91acf..278dc7525fd 100644 --- a/src/plugins/qtsupport/qtkitinformation.cpp +++ b/src/plugins/qtsupport/qtkitinformation.cpp @@ -146,6 +146,9 @@ bool QtKitInformation::resolveMacro(const ProjectExplorer::Kit *kit, const QStri } } + if (Utils::globalMacroExpander()->resolveMacro(name, ret)) + return true; + return false; } diff --git a/src/plugins/qtsupport/qtoptionspage.cpp b/src/plugins/qtsupport/qtoptionspage.cpp index 1d5d03e7bab..021645303b0 100644 --- a/src/plugins/qtsupport/qtoptionspage.cpp +++ b/src/plugins/qtsupport/qtoptionspage.cpp @@ -41,6 +41,7 @@ #include #include +#include #include #include #include @@ -192,6 +193,14 @@ QtOptionsPageWidget::QtOptionsPageWidget(QWidget *parent) connect(ProjectExplorer::ToolChainManager::instance(), SIGNAL(toolChainsChanged()), this, SLOT(toolChainsUpdated())); + + auto chooser = new Core::VariableChooser(this); + chooser->addSupportedWidget(m_versionUi->nameEdit, "Qt:name"); + chooser->addMacroExpanderProvider( + [this]() -> Utils::MacroExpander * { + BaseQtVersion *version = currentVersion(); + return version ? version->macroExpander() : 0; + }); } int QtOptionsPageWidget::currentIndex() const diff --git a/src/plugins/qtsupport/qtsupportplugin.cpp b/src/plugins/qtsupport/qtsupportplugin.cpp index 03e7c7b93dc..f344c7045a1 100644 --- a/src/plugins/qtsupport/qtsupportplugin.cpp +++ b/src/plugins/qtsupport/qtsupportplugin.cpp @@ -46,12 +46,12 @@ #include #include -#include #include + #include #include #include - +#include #include @@ -114,7 +114,7 @@ static QString qmakeProperty(const char *propertyName) void QtSupportPlugin::extensionsInitialized() { - Utils::MacroExpander *expander = globalMacroExpander(); + Utils::MacroExpander *expander = Utils::globalMacroExpander(); expander->registerVariable(kHostBins, tr("Full path to the host bin directory of the current project's Qt version."), diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp index c2ce283f413..4430c3b77ec 100644 --- a/src/plugins/texteditor/texteditorplugin.cpp +++ b/src/plugins/texteditor/texteditorplugin.cpp @@ -45,11 +45,11 @@ #include "textmarkregistry.h" #include -#include #include #include #include #include +#include #include #include @@ -147,7 +147,7 @@ void TextEditorPlugin::extensionsInitialized() addAutoReleasedObject(new FindInCurrentFile); addAutoReleasedObject(new FindInOpenFiles); - Utils::MacroExpander *expander = globalMacroExpander(); + Utils::MacroExpander *expander = Utils::globalMacroExpander(); expander->registerVariable(kCurrentDocumentSelection, tr("Selected text within the current document."), diff --git a/src/plugins/vcsbase/vcsplugin.cpp b/src/plugins/vcsbase/vcsplugin.cpp index be47027f24a..c1b42cfe613 100644 --- a/src/plugins/vcsbase/vcsplugin.cpp +++ b/src/plugins/vcsbase/vcsplugin.cpp @@ -39,11 +39,13 @@ #include #include -#include #include + #include #include +#include + #include #include @@ -87,7 +89,7 @@ bool VcsPlugin::initialize(const QStringList &arguments, QString *errorMessage) this, SLOT(slotSettingsChanged())); slotSettingsChanged(); - Utils::MacroExpander *expander = globalMacroExpander(); + Utils::MacroExpander *expander = Utils::globalMacroExpander(); expander->registerVariable(Constants::VAR_VCS_NAME, tr("Name of the version control system in use by the current project."), []() -> QString {