forked from qt-creator/qt-creator
MacroExpander: Allow registering local expansions
This allows a MacroExpander also to describe an expansion it can do which was restricted to the global VariableManager only. The global is now just a thin (unneeded) wrapper about new "standard" functionality. Change-Id: Ida7ca70cf3d319eae4220ea8d12f3dd1c0d4042c Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
@@ -30,15 +30,294 @@
|
||||
|
||||
#include "macroexpander.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
#include <QMap>
|
||||
|
||||
namespace Utils {
|
||||
namespace Internal {
|
||||
|
||||
MacroExpander::MacroExpander(const MacroExpander::Resolver &resolver)
|
||||
: m_resolver(resolver)
|
||||
{}
|
||||
const char kFilePathPostfix[] = ":FilePath";
|
||||
const char kPathPostfix[] = ":Path";
|
||||
const char kFileNamePostfix[] = ":FileName";
|
||||
const char kFileBaseNamePostfix[] = ":FileBaseName";
|
||||
|
||||
class MacroExpanderPrivate
|
||||
{
|
||||
public:
|
||||
QHash<QByteArray, MacroExpander::StringFunction> m_map;
|
||||
QHash<QByteArray, MacroExpander::PrefixFunction> m_prefixMap;
|
||||
QMap<QByteArray, QString> m_descriptions;
|
||||
};
|
||||
|
||||
} // Internal
|
||||
|
||||
using namespace Internal;
|
||||
|
||||
/*!
|
||||
\class Utils::MacroExpander
|
||||
\brief The MacroExpander class manages \QC wide variables, that a user
|
||||
can enter into many string settings. The variables are replaced by an actual value when the string
|
||||
is used, similar to how environment variables are expanded by a shell.
|
||||
|
||||
\section1 Variables
|
||||
|
||||
Variable names can be basically any string without dollar sign and braces,
|
||||
though it is recommended to only use 7-bit ASCII without special characters and whitespace.
|
||||
|
||||
If there are several variables that contain different aspects of the same object,
|
||||
it is convention to give them the same prefix, followed by a colon and a postfix
|
||||
that describes the aspect.
|
||||
Examples of this are \c{CurrentDocument:FilePath} and \c{CurrentDocument:Selection}.
|
||||
|
||||
When the variable manager is requested to replace variables in a string, it looks for
|
||||
variable names enclosed in %{ and }, like %{CurrentDocument:FilePath}.
|
||||
|
||||
Environment variables are accessible using the %{Env:...} notation.
|
||||
For example, to access the SHELL environment variable, use %{Env:SHELL}.
|
||||
|
||||
\note The names of the variables are stored as QByteArray. They are typically
|
||||
7-bit-clean. In cases where this is not possible, UTF-8 encoding is
|
||||
assumed.
|
||||
|
||||
\section1 Providing Variable Values
|
||||
|
||||
Plugins can register variables together with a description through registerVariable().
|
||||
A typical setup is to register variables in the Plugin::initialize() function.
|
||||
|
||||
\code
|
||||
bool MyPlugin::initialize(const QStringList &arguments, QString *errorString)
|
||||
{
|
||||
[...]
|
||||
MacroExpander::registerVariable(
|
||||
"MyVariable",
|
||||
tr("The current value of whatever I want."));
|
||||
[]() -> QString {
|
||||
QString value;
|
||||
// do whatever is necessary to retrieve the value
|
||||
[...]
|
||||
return value;
|
||||
}
|
||||
);
|
||||
[...]
|
||||
}
|
||||
\endcode
|
||||
|
||||
|
||||
For variables that refer to a file, you should use the convenience function
|
||||
MacroExpander::registerFileVariables().
|
||||
The functions take a variable prefix, like \c MyFileVariable,
|
||||
and automatically handle standardized postfixes like \c{:FilePath},
|
||||
\c{:Path} and \c{:FileBaseName}, resulting in the combined variables, such as
|
||||
\c{MyFileVariable:FilePath}.
|
||||
|
||||
\section1 Providing and Expanding Parametrized Strings
|
||||
|
||||
Though it is possible to just ask the variable manager for the value of some variable in your
|
||||
code, the preferred use case is to give the user the possibility to parametrize strings, for
|
||||
example for settings.
|
||||
|
||||
(If you ever think about doing the former, think twice. It is much more efficient
|
||||
to just ask the plugin that provides the variable value directly, without going through
|
||||
string conversions, and through the variable manager which will do a large scale poll. To be
|
||||
more concrete, using the example from the Providing Variable Values section: instead of
|
||||
calling \c{MacroExpander::value("MyVariable")}, it is much more efficient to just ask directly
|
||||
with \c{MyPlugin::variableValue()}.)
|
||||
|
||||
\section2 User Interface
|
||||
|
||||
If the string that you want to parametrize is settable by the user, through a QLineEdit or
|
||||
QTextEdit derived class, you should add a variable chooser to your UI, which allows adding
|
||||
variables to the string by browsing through a list. See Core::VariableChooser for more
|
||||
details.
|
||||
|
||||
\section2 Expanding Strings
|
||||
|
||||
Expanding variable values in strings is done by "macro expanders".
|
||||
Utils::AbstractMacroExpander is the base class for these, and the variable manager
|
||||
provides an implementation that expands \QC variables through
|
||||
MacroExpander::macroExpander().
|
||||
|
||||
There are several different ways to expand a string, covering the different use cases,
|
||||
listed here sorted by relevance:
|
||||
\list
|
||||
\li Using MacroExpander::expandedString(). This is the most comfortable way to get a string
|
||||
with variable values expanded, but also the least flexible one. If this is sufficient for
|
||||
you, use it.
|
||||
\li Using the Utils::expandMacros() functions. These take a string and a macro expander (for which
|
||||
you would use the one provided by the variable manager). Mostly the same as
|
||||
MacroExpander::expandedString(), but also has a variant that does the replacement inline
|
||||
instead of returning a new string.
|
||||
\li Using Utils::QtcProcess::expandMacros(). This expands the string while conforming to the
|
||||
quoting rules of the platform it is run on. Use this function with the variable manager's
|
||||
macro expander if your string will be passed as a command line parameter string to an
|
||||
external command.
|
||||
\li Writing your own macro expander that nests the variable manager's macro expander. And then
|
||||
doing one of the above. This allows you to expand additional "local" variables/macros,
|
||||
that do not come from the variable manager.
|
||||
\endlist
|
||||
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \internal
|
||||
*/
|
||||
MacroExpander::MacroExpander()
|
||||
{
|
||||
d = new MacroExpanderPrivate;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \internal
|
||||
*/
|
||||
MacroExpander::~MacroExpander()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \internal
|
||||
*/
|
||||
bool MacroExpander::resolveMacro(const QString &name, QString *ret)
|
||||
{
|
||||
return m_resolver(name, ret);
|
||||
bool found;
|
||||
*ret = value(name.toUtf8(), &found);
|
||||
return found;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the value of the given \a variable. If \a found is given, it is
|
||||
* set to true if the variable has a value at all, false if not.
|
||||
*/
|
||||
QString MacroExpander::value(const QByteArray &variable, bool *found)
|
||||
{
|
||||
StringFunction sf = d->m_map.value(variable);
|
||||
if (sf) {
|
||||
if (found)
|
||||
*found = true;
|
||||
return sf();
|
||||
}
|
||||
|
||||
for (auto it = d->m_prefixMap.constBegin(); it != d->m_prefixMap.constEnd(); ++it) {
|
||||
if (variable.startsWith(it.key())) {
|
||||
PrefixFunction pf = it.value();
|
||||
if (found)
|
||||
*found = true;
|
||||
return pf(QString::fromUtf8(variable.mid(it.key().count())));
|
||||
}
|
||||
}
|
||||
if (found)
|
||||
*found = false;
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns \a stringWithVariables with all variables replaced by their values.
|
||||
* See the MacroExpander overview documentation for other ways to expand variables.
|
||||
*
|
||||
* \sa MacroExpander
|
||||
* \sa macroExpander()
|
||||
*/
|
||||
QString MacroExpander::expandedString(const QString &stringWithVariables)
|
||||
{
|
||||
return Utils::expandMacros(stringWithVariables, this);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Makes the given string-valued \a prefix known to the variable manager,
|
||||
* together with a localized \a description.
|
||||
*
|
||||
* The \a value PrefixFunction will be called and gets the full variable name
|
||||
* with the prefix stripped as input.
|
||||
*
|
||||
* \sa registerVariables(), registerIntVariable(), registerFileVariables()
|
||||
*/
|
||||
void MacroExpander::registerPrefix(const QByteArray &prefix, const QString &description,
|
||||
const MacroExpander::PrefixFunction &value)
|
||||
{
|
||||
QByteArray tmp = prefix;
|
||||
if (!tmp.endsWith(':'))
|
||||
tmp.append(':');
|
||||
d->m_descriptions.insert(tmp + "<value>", description);
|
||||
d->m_prefixMap.insert(tmp, value);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Makes the given string-valued \a variable known to the variable manager,
|
||||
* together with a localized \a description.
|
||||
*
|
||||
* \sa registerFileVariables(), registerIntVariable(), registerPrefix()
|
||||
*/
|
||||
void MacroExpander::registerVariable(const QByteArray &variable,
|
||||
const QString &description, const StringFunction &value)
|
||||
{
|
||||
d->m_descriptions.insert(variable, description);
|
||||
d->m_map.insert(variable, value);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Makes the given integral-valued \a variable known to the variable manager,
|
||||
* together with a localized \a description.
|
||||
*
|
||||
* \sa registerVariable(), registerFileVariables(), registerPrefix()
|
||||
*/
|
||||
void MacroExpander::registerIntVariable(const QByteArray &variable,
|
||||
const QString &description, const MacroExpander::IntFunction &value)
|
||||
{
|
||||
const MacroExpander::IntFunction valuecopy = value; // do not capture a reference in a lambda
|
||||
registerVariable(variable, description,
|
||||
[valuecopy]() { return QString::number(valuecopy ? valuecopy() : 0); });
|
||||
}
|
||||
|
||||
/*!
|
||||
* Convenience function to register several variables with the same \a prefix, that have a file
|
||||
* as a value. Takes the prefix and registers variables like \c{prefix:FilePath} and
|
||||
* \c{prefix:Path}, with descriptions that start with the given \a heading.
|
||||
* For example \c{registerFileVariables("CurrentDocument", tr("Current Document"))} registers
|
||||
* variables such as \c{CurrentDocument:FilePath} with description
|
||||
* "Current Document: Full path including file name."
|
||||
*
|
||||
* \sa registerVariable(), registerIntVariable(), registerPrefix()
|
||||
*/
|
||||
void MacroExpander::registerFileVariables(const QByteArray &prefix,
|
||||
const QString &heading, const StringFunction &base)
|
||||
{
|
||||
registerVariable(prefix + kFilePathPostfix,
|
||||
QCoreApplication::translate("Utils::MacroExpander", "%1: Full path including file name.").arg(heading),
|
||||
[base]() -> QString { QString tmp = base(); return tmp.isEmpty() ? QString() : QFileInfo(tmp).filePath(); });
|
||||
|
||||
registerVariable(prefix + kPathPostfix,
|
||||
QCoreApplication::translate("Utils::MacroExpander", "%1: Full path excluding file name.").arg(heading),
|
||||
[base]() -> QString { QString tmp = base(); return tmp.isEmpty() ? QString() : QFileInfo(tmp).path(); });
|
||||
|
||||
registerVariable(prefix + kFileNamePostfix,
|
||||
QCoreApplication::translate("Utils::MacroExpander", "%1: File name without path.").arg(heading),
|
||||
[base]() -> QString { QString tmp = base(); return tmp.isEmpty() ? QString() : QFileInfo(tmp).fileName(); });
|
||||
|
||||
registerVariable(prefix + kFileBaseNamePostfix,
|
||||
QCoreApplication::translate("Utils::MacroExpander", "%1: File base name without path and suffix.").arg(heading),
|
||||
[base]() -> QString { QString tmp = base(); return tmp.isEmpty() ? QString() : QFileInfo(tmp).baseName(); });
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns all registered variable names.
|
||||
*
|
||||
* \sa registerVariable()
|
||||
* \sa registerFileVariables()
|
||||
*/
|
||||
QList<QByteArray> MacroExpander::variables()
|
||||
{
|
||||
return d->m_descriptions.keys();
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the description that was registered for the \a variable.
|
||||
*/
|
||||
QString MacroExpander::variableDescription(const QByteArray &variable)
|
||||
{
|
||||
return d->m_descriptions.value(variable);
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
@@ -37,17 +37,44 @@
|
||||
|
||||
namespace Utils {
|
||||
|
||||
namespace Internal { class MacroExpanderPrivate; }
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT MacroExpander : public AbstractMacroExpander
|
||||
{
|
||||
public:
|
||||
typedef std::function<bool(const QString &name, QString *ret)> Resolver;
|
||||
|
||||
explicit MacroExpander(const Resolver &resolver);
|
||||
explicit MacroExpander();
|
||||
~MacroExpander();
|
||||
|
||||
bool resolveMacro(const QString &name, QString *ret);
|
||||
|
||||
QString value(const QByteArray &variable, bool *found = 0);
|
||||
|
||||
QString expandedString(const QString &stringWithVariables);
|
||||
|
||||
typedef std::function<QString(QString)> PrefixFunction;
|
||||
typedef std::function<QString()> StringFunction;
|
||||
typedef std::function<int()> IntFunction;
|
||||
|
||||
void registerPrefix(const QByteArray &prefix,
|
||||
const QString &description, const PrefixFunction &value);
|
||||
|
||||
void registerVariable(const QByteArray &variable,
|
||||
const QString &description, const StringFunction &value);
|
||||
|
||||
void registerIntVariable(const QByteArray &variable,
|
||||
const QString &description, const IntFunction &value);
|
||||
|
||||
void registerFileVariables(const QByteArray &prefix,
|
||||
const QString &heading, const StringFunction &value);
|
||||
|
||||
QList<QByteArray> variables();
|
||||
QString variableDescription(const QByteArray &variable);
|
||||
|
||||
private:
|
||||
Resolver m_resolver;
|
||||
MacroExpander(const MacroExpander &) Q_DECL_EQ_DELETE;
|
||||
void operator=(const MacroExpander &) Q_DECL_EQ_DELETE;
|
||||
|
||||
Internal::MacroExpanderPrivate *d;
|
||||
};
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
@@ -595,5 +595,5 @@ void ExternalToolConfig::addCategory()
|
||||
void ExternalToolConfig::updateEffectiveArguments()
|
||||
{
|
||||
ui->arguments->setToolTip(Utils::QtcProcess::expandMacros(ui->arguments->text(),
|
||||
Core::VariableManager::macroExpander()));
|
||||
globalMacroExpander()));
|
||||
}
|
||||
|
||||
@@ -483,20 +483,20 @@ void EditorManagerPrivate::init()
|
||||
d->m_openEditorsFactory = new OpenEditorsViewFactory();
|
||||
ExtensionSystem::PluginManager::addObject(d->m_openEditorsFactory);
|
||||
|
||||
VariableManager::registerFileVariables(kCurrentDocumentPrefix, tr("Current document"),
|
||||
globalMacroExpander()->registerFileVariables(kCurrentDocumentPrefix, tr("Current document"),
|
||||
[]() -> QString {
|
||||
IDocument *document = EditorManager::currentDocument();
|
||||
return document ? document->filePath() : QString();
|
||||
});
|
||||
|
||||
VariableManager::registerIntVariable(kCurrentDocumentXPos,
|
||||
globalMacroExpander()->registerIntVariable(kCurrentDocumentXPos,
|
||||
tr("X-coordinate of the current editor's upper left corner, relative to screen."),
|
||||
[]() -> int {
|
||||
IEditor *editor = EditorManager::currentEditor();
|
||||
return editor ? editor->widget()->mapToGlobal(QPoint(0, 0)).x() : 0;
|
||||
});
|
||||
|
||||
VariableManager::registerIntVariable(kCurrentDocumentYPos,
|
||||
globalMacroExpander()->registerIntVariable(kCurrentDocumentYPos,
|
||||
tr("Y-coordinate of the current editor's upper left corner, relative to screen."),
|
||||
[]() -> int {
|
||||
IEditor *editor = EditorManager::currentEditor();
|
||||
|
||||
@@ -550,10 +550,12 @@ bool ExternalToolRunner::resolve()
|
||||
m_resolvedExecutable.clear();
|
||||
m_resolvedArguments.clear();
|
||||
m_resolvedWorkingDirectory.clear();
|
||||
|
||||
Utils::MacroExpander *expander = globalMacroExpander();
|
||||
{ // executable
|
||||
QStringList expandedExecutables; /* for error message */
|
||||
foreach (const QString &executable, m_tool->executables()) {
|
||||
QString expanded = Core::VariableManager::expandedString(executable);
|
||||
QString expanded = expander->expandedString(executable);
|
||||
expandedExecutables << expanded;
|
||||
m_resolvedExecutable =
|
||||
Utils::Environment::systemEnvironment().searchInPath(expanded);
|
||||
@@ -574,14 +576,13 @@ bool ExternalToolRunner::resolve()
|
||||
}
|
||||
}
|
||||
{ // arguments
|
||||
m_resolvedArguments = Utils::QtcProcess::expandMacros(m_tool->arguments(),
|
||||
Core::VariableManager::macroExpander());
|
||||
m_resolvedArguments = Utils::QtcProcess::expandMacros(m_tool->arguments(), expander);
|
||||
}
|
||||
{ // input
|
||||
m_resolvedInput = Core::VariableManager::expandedString(m_tool->input());
|
||||
m_resolvedInput = expander->expandedString(m_tool->input());
|
||||
}
|
||||
{ // working directory
|
||||
m_resolvedWorkingDirectory = Core::VariableManager::expandedString(m_tool->workingDirectory());
|
||||
m_resolvedWorkingDirectory = expander->expandedString(m_tool->workingDirectory());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ QString JsExpander::evaluate(const QString &expression, QString *errorMessage)
|
||||
JsExpander::JsExpander()
|
||||
{
|
||||
d = new Internal::JsExpanderPrivate;
|
||||
VariableManager::registerPrefix("JS",
|
||||
globalMacroExpander()->registerPrefix("JS",
|
||||
QCoreApplication::translate("Core::JsExpander",
|
||||
"Evaluate simple Javascript statements.\n"
|
||||
"The statements may not contain '{' nor '}' characters."),
|
||||
|
||||
@@ -91,9 +91,9 @@ void ExecuteFilter::accept(LocatorFilterEntry selection) const
|
||||
p->m_commandHistory.prepend(value);
|
||||
|
||||
bool found;
|
||||
QString workingDirectory = Core::VariableManager::value("CurrentDocument:Path", &found);
|
||||
QString workingDirectory = globalMacroExpander()->value("CurrentDocument:Path", &found);
|
||||
if (!found || workingDirectory.isEmpty())
|
||||
workingDirectory = Core::VariableManager::value("CurrentProject:Path", &found);
|
||||
workingDirectory = globalMacroExpander()->value("CurrentProject:Path", &found);
|
||||
|
||||
ExecuteData d;
|
||||
d.workingDirectory = workingDirectory;
|
||||
|
||||
@@ -120,8 +120,7 @@ MainWindow::MainWindow() :
|
||||
m_editorManager(0),
|
||||
m_externalToolManager(0),
|
||||
m_progressManager(new ProgressManagerPrivate),
|
||||
m_variableManager(new VariableManager),
|
||||
m_jsExpander(new JsExpander), // must be initialized after the VariableManager
|
||||
m_jsExpander(new JsExpander),
|
||||
m_vcsManager(new VcsManager),
|
||||
m_statusBarManager(0),
|
||||
m_modeManager(0),
|
||||
@@ -305,8 +304,6 @@ MainWindow::~MainWindow()
|
||||
|
||||
delete m_helpManager;
|
||||
m_helpManager = 0;
|
||||
delete m_variableManager;
|
||||
m_variableManager = 0;
|
||||
delete m_jsExpander;
|
||||
m_jsExpander = 0;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,6 @@ class ProgressManager;
|
||||
class NavigationWidget;
|
||||
class RightPaneWidget;
|
||||
class SettingsDatabase;
|
||||
class VariableManager;
|
||||
class VcsManager;
|
||||
|
||||
namespace Internal {
|
||||
@@ -174,7 +173,6 @@ private:
|
||||
ExternalToolManager *m_externalToolManager;
|
||||
MessageManager *m_messageManager;
|
||||
ProgressManagerPrivate *m_progressManager;
|
||||
VariableManager *m_variableManager;
|
||||
JsExpander *m_jsExpander;
|
||||
VcsManager *m_vcsManager;
|
||||
StatusBarManager *m_statusBarManager;
|
||||
|
||||
@@ -67,7 +67,7 @@ public:
|
||||
m_variableList = new QListWidget(q);
|
||||
m_variableList->setAttribute(Qt::WA_MacSmallSize);
|
||||
m_variableList->setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||
foreach (const QByteArray &variable, VariableManager::variables())
|
||||
foreach (const QByteArray &variable, globalMacroExpander()->variables())
|
||||
m_variableList->addItem(QString::fromLatin1(variable));
|
||||
|
||||
m_variableDescription = new QLabel(q);
|
||||
@@ -209,8 +209,8 @@ void VariableChooserPrivate::updateDescription(const QString &variable)
|
||||
if (variable.isNull())
|
||||
m_variableDescription->setText(m_defaultDescription);
|
||||
else
|
||||
m_variableDescription->setText(VariableManager::variableDescription(variable.toUtf8())
|
||||
+ QLatin1String("<p>") + tr("Current Value: %1").arg(VariableManager::value(variable.toUtf8())));
|
||||
m_variableDescription->setText(globalMacroExpander()->variableDescription(variable.toUtf8())
|
||||
+ QLatin1String("<p>") + tr("Current Value: %1").arg(globalMacroExpander()->value(variable.toUtf8())));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -30,312 +30,27 @@
|
||||
|
||||
#include "variablemanager.h"
|
||||
|
||||
#include <utils/stringutils.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QFileInfo>
|
||||
#include <QMap>
|
||||
#include <QDebug>
|
||||
|
||||
static const char kFilePathPostfix[] = ":FilePath";
|
||||
static const char kPathPostfix[] = ":Path";
|
||||
static const char kFileNamePostfix[] = ":FileName";
|
||||
static const char kFileBaseNamePostfix[] = ":FileBaseName";
|
||||
using namespace Utils;
|
||||
|
||||
namespace Core {
|
||||
|
||||
class VMMapExpander : public Utils::AbstractMacroExpander
|
||||
class GlobalMacroExpander : public MacroExpander
|
||||
{
|
||||
public:
|
||||
virtual bool resolveMacro(const QString &name, QString *ret)
|
||||
GlobalMacroExpander()
|
||||
{
|
||||
bool found;
|
||||
*ret = Core::VariableManager::value(name.toUtf8(), &found);
|
||||
return found;
|
||||
registerPrefix("Env", QCoreApplication::translate("Core::VariableManager", "Access environment variables."),
|
||||
[](const QString &value) { return QString::fromLocal8Bit(qgetenv(value.toLocal8Bit())); });
|
||||
}
|
||||
};
|
||||
|
||||
class VariableManagerPrivate
|
||||
MacroExpander *globalMacroExpander()
|
||||
{
|
||||
public:
|
||||
QHash<QByteArray, VariableManager::StringFunction> m_map;
|
||||
QHash<QByteArray, VariableManager::PrefixFunction> m_prefixMap;
|
||||
VMMapExpander m_macroExpander;
|
||||
QMap<QByteArray, QString> m_descriptions;
|
||||
};
|
||||
|
||||
/*!
|
||||
\class Core::VariableManager
|
||||
\brief The VariableManager class manages \QC wide variables, that a user
|
||||
can enter into many string settings. The variables are replaced by an actual value when the string
|
||||
is used, similar to how environment variables are expanded by a shell.
|
||||
|
||||
\section1 Variables
|
||||
|
||||
Variable names can be basically any string without dollar sign and braces,
|
||||
though it is recommended to only use 7-bit ASCII without special characters and whitespace.
|
||||
|
||||
If there are several variables that contain different aspects of the same object,
|
||||
it is convention to give them the same prefix, followed by a colon and a postfix
|
||||
that describes the aspect.
|
||||
Examples of this are \c{CurrentDocument:FilePath} and \c{CurrentDocument:Selection}.
|
||||
|
||||
When the variable manager is requested to replace variables in a string, it looks for
|
||||
variable names enclosed in %{ and }, like %{CurrentDocument:FilePath}.
|
||||
|
||||
Environment variables are accessible using the %{Env:...} notation.
|
||||
For example, to access the SHELL environment variable, use %{Env:SHELL}.
|
||||
|
||||
\note The names of the variables are stored as QByteArray. They are typically
|
||||
7-bit-clean. In cases where this is not possible, UTF-8 encoding is
|
||||
assumed.
|
||||
|
||||
\section1 Providing Variable Values
|
||||
|
||||
Plugins can register variables together with a description through registerVariable().
|
||||
A typical setup is to register variables in the Plugin::initialize() function.
|
||||
|
||||
\code
|
||||
bool MyPlugin::initialize(const QStringList &arguments, QString *errorString)
|
||||
{
|
||||
[...]
|
||||
VariableManager::registerVariable(
|
||||
"MyVariable",
|
||||
tr("The current value of whatever I want."));
|
||||
[]() -> QString {
|
||||
QString value;
|
||||
// do whatever is necessary to retrieve the value
|
||||
[...]
|
||||
return value;
|
||||
}
|
||||
);
|
||||
[...]
|
||||
}
|
||||
\endcode
|
||||
|
||||
|
||||
For variables that refer to a file, you should use the convenience function
|
||||
VariableManager::registerFileVariables().
|
||||
The functions take a variable prefix, like \c MyFileVariable,
|
||||
and automatically handle standardized postfixes like \c{:FilePath},
|
||||
\c{:Path} and \c{:FileBaseName}, resulting in the combined variables, such as
|
||||
\c{MyFileVariable:FilePath}.
|
||||
|
||||
\section1 Providing and Expanding Parametrized Strings
|
||||
|
||||
Though it is possible to just ask the variable manager for the value of some variable in your
|
||||
code, the preferred use case is to give the user the possibility to parametrize strings, for
|
||||
example for settings.
|
||||
|
||||
(If you ever think about doing the former, think twice. It is much more efficient
|
||||
to just ask the plugin that provides the variable value directly, without going through
|
||||
string conversions, and through the variable manager which will do a large scale poll. To be
|
||||
more concrete, using the example from the Providing Variable Values section: instead of
|
||||
calling \c{VariableManager::value("MyVariable")}, it is much more efficient to just ask directly
|
||||
with \c{MyPlugin::variableValue()}.)
|
||||
|
||||
\section2 User Interface
|
||||
|
||||
If the string that you want to parametrize is settable by the user, through a QLineEdit or
|
||||
QTextEdit derived class, you should add a variable chooser to your UI, which allows adding
|
||||
variables to the string by browsing through a list. See Core::VariableChooser for more
|
||||
details.
|
||||
|
||||
\section2 Expanding Strings
|
||||
|
||||
Expanding variable values in strings is done by "macro expanders".
|
||||
Utils::AbstractMacroExpander is the base class for these, and the variable manager
|
||||
provides an implementation that expands \QC variables through
|
||||
VariableManager::macroExpander().
|
||||
|
||||
There are several different ways to expand a string, covering the different use cases,
|
||||
listed here sorted by relevance:
|
||||
\list
|
||||
\li Using VariableManager::expandedString(). This is the most comfortable way to get a string
|
||||
with variable values expanded, but also the least flexible one. If this is sufficient for
|
||||
you, use it.
|
||||
\li Using the Utils::expandMacros() functions. These take a string and a macro expander (for which
|
||||
you would use the one provided by the variable manager). Mostly the same as
|
||||
VariableManager::expandedString(), but also has a variant that does the replacement inline
|
||||
instead of returning a new string.
|
||||
\li Using Utils::QtcProcess::expandMacros(). This expands the string while conforming to the
|
||||
quoting rules of the platform it is run on. Use this function with the variable manager's
|
||||
macro expander if your string will be passed as a command line parameter string to an
|
||||
external command.
|
||||
\li Writing your own macro expander that nests the variable manager's macro expander. And then
|
||||
doing one of the above. This allows you to expand additional "local" variables/macros,
|
||||
that do not come from the variable manager.
|
||||
\endlist
|
||||
|
||||
*/
|
||||
|
||||
static VariableManagerPrivate *d;
|
||||
|
||||
/*!
|
||||
* \internal
|
||||
*/
|
||||
VariableManager::VariableManager()
|
||||
{
|
||||
d = new VariableManagerPrivate;
|
||||
|
||||
registerPrefix("Env", QCoreApplication::translate("Core::VariableManager", "Access environment variables."),
|
||||
[](const QString &value)
|
||||
{ return QString::fromLocal8Bit(qgetenv(value.toLocal8Bit())); });
|
||||
}
|
||||
|
||||
/*!
|
||||
* \internal
|
||||
*/
|
||||
VariableManager::~VariableManager()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the value of the given \a variable. If \a found is given, it is
|
||||
* set to true if the variable has a value at all, false if not.
|
||||
*/
|
||||
QString VariableManager::value(const QByteArray &variable, bool *found)
|
||||
{
|
||||
StringFunction sf = d->m_map.value(variable);
|
||||
if (sf) {
|
||||
if (found)
|
||||
*found = true;
|
||||
return sf();
|
||||
}
|
||||
|
||||
for (auto it = d->m_prefixMap.constBegin(); it != d->m_prefixMap.constEnd(); ++it) {
|
||||
if (variable.startsWith(it.key())) {
|
||||
PrefixFunction pf = it.value();
|
||||
if (found)
|
||||
*found = true;
|
||||
return pf(QString::fromUtf8(variable.mid(it.key().count())));
|
||||
}
|
||||
}
|
||||
if (found)
|
||||
*found = false;
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns \a stringWithVariables with all variables replaced by their values.
|
||||
* See the VariableManager overview documentation for other ways to expand variables.
|
||||
*
|
||||
* \sa VariableManager
|
||||
* \sa macroExpander()
|
||||
*/
|
||||
QString VariableManager::expandedString(const QString &stringWithVariables)
|
||||
{
|
||||
return Utils::expandMacros(stringWithVariables, macroExpander());
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns a macro expander that is used to expand all variables from the variable manager
|
||||
* in a string.
|
||||
* See the VariableManager overview documentation for other ways to expand variables.
|
||||
*
|
||||
* \sa VariableManager
|
||||
* \sa expandedString()
|
||||
*/
|
||||
Utils::AbstractMacroExpander *VariableManager::macroExpander()
|
||||
{
|
||||
return &d->m_macroExpander;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Makes the given string-valued \a prefix known to the variable manager,
|
||||
* together with a localized \a description.
|
||||
*
|
||||
* The \a value PrefixFunction will be called and gets the full variable name
|
||||
* with the prefix stripped as input.
|
||||
*
|
||||
* \sa registerVariables(), registerIntVariable(), registerFileVariables()
|
||||
*/
|
||||
void VariableManager::registerPrefix(const QByteArray &prefix, const QString &description,
|
||||
const VariableManager::PrefixFunction &value)
|
||||
{
|
||||
QByteArray tmp = prefix;
|
||||
if (!tmp.endsWith(':'))
|
||||
tmp.append(':');
|
||||
d->m_descriptions.insert(tmp + "<value>", description);
|
||||
d->m_prefixMap.insert(tmp, value);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Makes the given string-valued \a variable known to the variable manager,
|
||||
* together with a localized \a description.
|
||||
*
|
||||
* \sa registerFileVariables(), registerIntVariable(), registerPrefix()
|
||||
*/
|
||||
void VariableManager::registerVariable(const QByteArray &variable,
|
||||
const QString &description, const StringFunction &value)
|
||||
{
|
||||
d->m_descriptions.insert(variable, description);
|
||||
d->m_map.insert(variable, value);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Makes the given integral-valued \a variable known to the variable manager,
|
||||
* together with a localized \a description.
|
||||
*
|
||||
* \sa registerVariable(), registerFileVariables(), registerPrefix()
|
||||
*/
|
||||
void VariableManager::registerIntVariable(const QByteArray &variable,
|
||||
const QString &description, const VariableManager::IntFunction &value)
|
||||
{
|
||||
const VariableManager::IntFunction valuecopy = value; // do not capture a reference in a lambda
|
||||
registerVariable(variable, description,
|
||||
[valuecopy]() { return QString::number(valuecopy ? valuecopy() : 0); });
|
||||
}
|
||||
|
||||
/*!
|
||||
* Convenience function to register several variables with the same \a prefix, that have a file
|
||||
* as a value. Takes the prefix and registers variables like \c{prefix:FilePath} and
|
||||
* \c{prefix:Path}, with descriptions that start with the given \a heading.
|
||||
* For example \c{registerFileVariables("CurrentDocument", tr("Current Document"))} registers
|
||||
* variables such as \c{CurrentDocument:FilePath} with description
|
||||
* "Current Document: Full path including file name."
|
||||
*
|
||||
* \sa registerVariable(), registerIntVariable(), registerPrefix()
|
||||
*/
|
||||
void VariableManager::registerFileVariables(const QByteArray &prefix,
|
||||
const QString &heading, const StringFunction &base)
|
||||
{
|
||||
registerVariable(prefix + kFilePathPostfix,
|
||||
QCoreApplication::translate("Core::VariableManager", "%1: Full path including file name.").arg(heading),
|
||||
[base]() -> QString { QString tmp = base(); return tmp.isEmpty() ? QString() : QFileInfo(tmp).filePath(); });
|
||||
|
||||
registerVariable(prefix + kPathPostfix,
|
||||
QCoreApplication::translate("Core::VariableManager", "%1: Full path excluding file name.").arg(heading),
|
||||
[base]() -> QString { QString tmp = base(); return tmp.isEmpty() ? QString() : QFileInfo(tmp).path(); });
|
||||
|
||||
registerVariable(prefix + kFileNamePostfix,
|
||||
QCoreApplication::translate("Core::VariableManager", "%1: File name without path.").arg(heading),
|
||||
[base]() -> QString { QString tmp = base(); return tmp.isEmpty() ? QString() : QFileInfo(tmp).fileName(); });
|
||||
|
||||
registerVariable(prefix + kFileBaseNamePostfix,
|
||||
QCoreApplication::translate("Core::VariableManager", "%1: File base name without path and suffix.").arg(heading),
|
||||
[base]() -> QString { QString tmp = base(); return tmp.isEmpty() ? QString() : QFileInfo(tmp).baseName(); });
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns all registered variable names.
|
||||
*
|
||||
* \sa registerVariable()
|
||||
* \sa registerFileVariables()
|
||||
*/
|
||||
QList<QByteArray> VariableManager::variables()
|
||||
{
|
||||
return d->m_descriptions.keys();
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the description that was registered for the \a variable.
|
||||
*/
|
||||
QString VariableManager::variableDescription(const QByteArray &variable)
|
||||
{
|
||||
return d->m_descriptions.value(variable);
|
||||
static MacroExpander theGlobalExpander;
|
||||
return &theGlobalExpander;
|
||||
}
|
||||
|
||||
} // namespace Core
|
||||
|
||||
@@ -33,50 +33,11 @@
|
||||
|
||||
#include "core_global.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QString>
|
||||
|
||||
namespace Utils { class AbstractMacroExpander; }
|
||||
#include <utils/macroexpander.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
namespace Internal { class MainWindow; }
|
||||
|
||||
class CORE_EXPORT VariableManager
|
||||
{
|
||||
public:
|
||||
static QString value(const QByteArray &variable, bool *found = 0);
|
||||
|
||||
static QString expandedString(const QString &stringWithVariables);
|
||||
static Utils::AbstractMacroExpander *macroExpander();
|
||||
|
||||
typedef std::function<QString(QString)> PrefixFunction;
|
||||
typedef std::function<QString()> StringFunction;
|
||||
typedef std::function<int()> IntFunction;
|
||||
|
||||
static void registerPrefix(const QByteArray &prefix,
|
||||
const QString &description, const PrefixFunction &value);
|
||||
|
||||
static void registerVariable(const QByteArray &variable,
|
||||
const QString &description, const StringFunction &value);
|
||||
|
||||
static void registerIntVariable(const QByteArray &variable,
|
||||
const QString &description, const IntFunction &value);
|
||||
|
||||
static void registerFileVariables(const QByteArray &prefix,
|
||||
const QString &heading, const StringFunction &value);
|
||||
|
||||
static QList<QByteArray> variables();
|
||||
static QString variableDescription(const QByteArray &variable);
|
||||
|
||||
private:
|
||||
VariableManager();
|
||||
~VariableManager();
|
||||
|
||||
friend class Core::Internal::MainWindow;
|
||||
};
|
||||
CORE_EXPORT Utils::MacroExpander *globalMacroExpander();
|
||||
|
||||
} // namespace Core
|
||||
|
||||
|
||||
@@ -191,12 +191,13 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
|
||||
mcpptools->addAction(command);
|
||||
connect(openInNextSplitAction, SIGNAL(triggered()), this, SLOT(switchHeaderSourceInNextSplit()));
|
||||
|
||||
Core::VariableManager::registerVariable("Cpp:LicenseTemplate",
|
||||
tr("The license template."),
|
||||
[this]() { return CppToolsPlugin::licenseTemplate(); });
|
||||
Core::VariableManager::registerFileVariables("Cpp:LicenseTemplatePath",
|
||||
tr("The configured path to the license template"),
|
||||
[this]() { return CppToolsPlugin::licenseTemplatePath().toString(); });
|
||||
Utils::MacroExpander *expander = globalMacroExpander();
|
||||
expander->registerVariable("Cpp:LicenseTemplate",
|
||||
tr("The license template."),
|
||||
[this]() { return CppToolsPlugin::licenseTemplate(); });
|
||||
expander->registerFileVariables("Cpp:LicenseTemplatePath",
|
||||
tr("The configured path to the license template"),
|
||||
[this]() { return CppToolsPlugin::licenseTemplatePath().toString(); });
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ public:
|
||||
connect(action(IntelFlavor), SIGNAL(valueChanged(QVariant)),
|
||||
SLOT(reloadDisassembly()));
|
||||
|
||||
VariableManager::registerFileVariables(PrefixDebugExecutable,
|
||||
globalMacroExpander()->registerFileVariables(PrefixDebugExecutable,
|
||||
tr("Debugged executable"),
|
||||
[this]() { return m_startParameters.executable; });
|
||||
}
|
||||
@@ -1835,7 +1835,7 @@ void DebuggerEngine::validateExecutable(DebuggerStartParameters *sp)
|
||||
SourcePathRegExpMap globalRegExpSourceMap;
|
||||
globalRegExpSourceMap.reserve(options->sourcePathRegExpMap.size());
|
||||
foreach (auto entry, options->sourcePathRegExpMap) {
|
||||
const QString expanded = VariableManager::expandedString(entry.second);
|
||||
const QString expanded = globalMacroExpander()->expandedString(entry.second);
|
||||
if (!expanded.isEmpty())
|
||||
globalRegExpSourceMap.push_back(qMakePair(entry.first, expanded));
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <projectexplorer/abi.h>
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/macroexpander.h>
|
||||
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
|
||||
@@ -302,18 +302,15 @@ KitConfigWidget *DebuggerKitInformation::createConfigWidget(Kit *k) const
|
||||
return new Internal::DebuggerKitConfigWidget(k, this);
|
||||
}
|
||||
|
||||
AbstractMacroExpander *DebuggerKitInformation::createMacroExpander(const Kit *k) const
|
||||
bool DebuggerKitInformation::resolveMacro(const Kit *kit, const QString &name, QString *ret) const
|
||||
{
|
||||
return new MacroExpander([k, this](const QString &name, QString *ret) -> bool {
|
||||
const DebuggerItem *item = DebuggerKitInformation::debugger(k);
|
||||
const DebuggerItem *item = debugger(kit);
|
||||
if (name == QLatin1String("Debugger:engineType")) {
|
||||
*ret = item ? item->engineTypeName() : tr("none");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name == QLatin1String("Debugger:engineType")) {
|
||||
*ret = item ? item->engineTypeName() : tr("none");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
KitInformation::ItemList DebuggerKitInformation::toUserOutput(const Kit *k) const
|
||||
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
static bool isValidDebugger(const ProjectExplorer::Kit *k);
|
||||
|
||||
ProjectExplorer::KitConfigWidget *createConfigWidget(ProjectExplorer::Kit *k) const;
|
||||
Utils::AbstractMacroExpander *createMacroExpander(const ProjectExplorer::Kit *k) const;
|
||||
bool resolveMacro(const ProjectExplorer::Kit *kit, const QString &name, QString *ret) const;
|
||||
|
||||
ItemList toUserOutput(const ProjectExplorer::Kit *k) const;
|
||||
|
||||
|
||||
@@ -3334,7 +3334,7 @@ bool boolSetting(int code)
|
||||
QString stringSetting(int code)
|
||||
{
|
||||
QString raw = theDebuggerCore->m_debuggerSettings->item(code)->value().toString();
|
||||
return VariableManager::expandedString(raw);
|
||||
return globalMacroExpander()->expandedString(raw);
|
||||
}
|
||||
|
||||
QStringList stringListSetting(int code)
|
||||
|
||||
@@ -4402,7 +4402,7 @@ void GdbEngine::abortDebugger()
|
||||
void GdbEngine::resetInferior()
|
||||
{
|
||||
if (!startParameters().commandsForReset.isEmpty()) {
|
||||
QByteArray substitutedCommands = VariableManager::expandedString(
|
||||
QByteArray substitutedCommands = globalMacroExpander()->expandedString(
|
||||
QString::fromLatin1(startParameters().commandsForReset)).toLatin1();
|
||||
foreach (QByteArray command, substitutedCommands.split('\n')) {
|
||||
command = command.trimmed();
|
||||
@@ -4453,7 +4453,7 @@ void GdbEngine::handleInferiorPrepared()
|
||||
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
|
||||
|
||||
if (!sp.commandsAfterConnect.isEmpty()) {
|
||||
QByteArray substitutedCommands = VariableManager::expandedString(QString::fromLatin1(sp.commandsAfterConnect)).toLatin1();
|
||||
QByteArray substitutedCommands = globalMacroExpander()->expandedString(QString::fromLatin1(sp.commandsAfterConnect)).toLatin1();
|
||||
foreach (QByteArray command, substitutedCommands.split('\n')) {
|
||||
postCommand(command);
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ bool JsonWizardExpander::resolveMacro(const QString &name, QString *ret)
|
||||
return true;
|
||||
}
|
||||
|
||||
return Core::VariableManager::macroExpander()->resolveMacro(name, ret);
|
||||
return Core::globalMacroExpander()->resolveMacro(name, ret);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -36,8 +36,8 @@
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/macroexpander.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/stringutils.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFileInfo>
|
||||
@@ -66,29 +66,24 @@ namespace ProjectExplorer {
|
||||
// KitMacroExpander:
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
class KitMacroExpander : public AbstractMacroExpander
|
||||
class KitMacroExpander : public MacroExpander
|
||||
{
|
||||
public:
|
||||
KitMacroExpander(const QList<AbstractMacroExpander *> &children) :
|
||||
m_childExpanders(children)
|
||||
{ }
|
||||
~KitMacroExpander() { qDeleteAll(m_childExpanders); }
|
||||
KitMacroExpander(Kit *kit) : m_kit(kit) {}
|
||||
|
||||
bool resolveMacro(const QString &name, QString *ret);
|
||||
bool resolveMacro(const QString &name, QString *ret)
|
||||
{
|
||||
foreach (KitInformation *ki, KitManager::kitInformation())
|
||||
if (ki->resolveMacro(m_kit, name, ret))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
QList<AbstractMacroExpander *> m_childExpanders;
|
||||
Kit *m_kit;
|
||||
};
|
||||
|
||||
bool KitMacroExpander::resolveMacro(const QString &name, QString *ret)
|
||||
{
|
||||
foreach (AbstractMacroExpander *expander, m_childExpanders) {
|
||||
if (expander->resolveMacro(name, ret))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// KitPrivate
|
||||
// -------------------------------------------------------------------------
|
||||
@@ -107,27 +102,15 @@ public:
|
||||
m_hasWarning(false),
|
||||
m_hasValidityInfo(false),
|
||||
m_mustNotify(false),
|
||||
m_macroExpander(0)
|
||||
m_macroExpander(k)
|
||||
{
|
||||
if (!id.isValid())
|
||||
m_id = Id::fromString(QUuid::createUuid().toString());
|
||||
|
||||
m_unexpandedDisplayName = QCoreApplication::translate("ProjectExplorer::Kit", "Unnamed");
|
||||
m_iconPath = FileName::fromLatin1(":///DESKTOP///");
|
||||
|
||||
QList<AbstractMacroExpander *> expanders;
|
||||
foreach (const KitInformation *ki, KitManager::kitInformation()) {
|
||||
AbstractMacroExpander *tmp = ki->createMacroExpander(k);
|
||||
if (tmp)
|
||||
expanders.append(tmp);
|
||||
}
|
||||
|
||||
m_macroExpander = new KitMacroExpander(expanders);
|
||||
}
|
||||
|
||||
~KitPrivate()
|
||||
{ delete m_macroExpander; }
|
||||
|
||||
QString m_unexpandedDisplayName;
|
||||
QString m_fileSystemFriendlyName;
|
||||
QString m_autoDetectionSource;
|
||||
@@ -145,7 +128,7 @@ public:
|
||||
QHash<Core::Id, QVariant> m_data;
|
||||
QSet<Core::Id> m_sticky;
|
||||
QSet<Core::Id> m_mutable;
|
||||
AbstractMacroExpander *m_macroExpander;
|
||||
KitMacroExpander m_macroExpander;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
@@ -317,7 +300,7 @@ QString Kit::unexpandedDisplayName() const
|
||||
|
||||
QString Kit::displayName() const
|
||||
{
|
||||
return Utils::expandMacros(unexpandedDisplayName(), macroExpander());
|
||||
return Utils::expandMacros(d->m_unexpandedDisplayName, &d->m_macroExpander);
|
||||
}
|
||||
|
||||
static QString candidateName(const QString &name, const QString &postfix)
|
||||
@@ -682,8 +665,7 @@ bool Kit::hasFeatures(const FeatureSet &features) const
|
||||
|
||||
AbstractMacroExpander *Kit::macroExpander() const
|
||||
{
|
||||
QTC_CHECK(d->m_macroExpander);
|
||||
return d->m_macroExpander;
|
||||
return &d->m_macroExpander;
|
||||
}
|
||||
|
||||
void Kit::kitUpdated()
|
||||
|
||||
@@ -129,9 +129,8 @@ public:
|
||||
Core::FeatureSet availableFeatures() const;
|
||||
bool hasFeatures(const Core::FeatureSet &features) const;
|
||||
|
||||
Utils::AbstractMacroExpander *macroExpander() const;
|
||||
|
||||
private:
|
||||
Utils::AbstractMacroExpander *macroExpander() const;
|
||||
void setSdkProvided(bool sdkProvided);
|
||||
|
||||
~Kit();
|
||||
|
||||
@@ -589,6 +589,14 @@ Core::FeatureSet KitInformation::availableFeatures(const Kit *k) const
|
||||
return Core::FeatureSet();
|
||||
}
|
||||
|
||||
bool KitInformation::resolveMacro(const Kit *kit, const QString &name, QString *ret) const
|
||||
{
|
||||
Q_UNUSED(kit);
|
||||
Q_UNUSED(name);
|
||||
Q_UNUSED(ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
void KitInformation::notifyAboutUpdate(Kit *k)
|
||||
{
|
||||
if (k)
|
||||
|
||||
@@ -99,8 +99,7 @@ public:
|
||||
virtual QString displayNameForPlatform(const Kit *k, const QString &platform) const;
|
||||
virtual Core::FeatureSet availableFeatures(const Kit *k) const;
|
||||
|
||||
virtual Utils::AbstractMacroExpander *createMacroExpander(const Kit *k) const
|
||||
{ Q_UNUSED(k); return 0; }
|
||||
virtual bool resolveMacro(const Kit *kit, const QString &name, QString *ret) const;
|
||||
|
||||
protected:
|
||||
void setId(Core::Id id) { m_id = id; }
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
#include <QDir>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
|
||||
namespace Internal {
|
||||
|
||||
class FallBackMacroExpander : public Utils::AbstractMacroExpander
|
||||
@@ -59,7 +58,7 @@ bool FallBackMacroExpander::resolveMacro(const QString &name, QString *ret)
|
||||
return true;
|
||||
}
|
||||
bool found;
|
||||
*ret = Core::VariableManager::value(name.toUtf8(), &found);
|
||||
*ret = Core::globalMacroExpander()->value(name.toUtf8(), &found);
|
||||
return found;
|
||||
}
|
||||
} // namespace Internal
|
||||
|
||||
@@ -82,7 +82,7 @@ bool ProcessStep::init()
|
||||
if (!bc)
|
||||
bc = target()->activeBuildConfiguration();
|
||||
ProcessParameters *pp = processParameters();
|
||||
pp->setMacroExpander(bc ? bc->macroExpander() : Core::VariableManager::macroExpander());
|
||||
pp->setMacroExpander(bc ? bc->macroExpander() : Core::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::VariableManager::macroExpander());
|
||||
param.setMacroExpander(bc ? bc->macroExpander() : Core::globalMacroExpander());
|
||||
param.setEnvironment(bc ? bc->environment() : Utils::Environment::systemEnvironment());
|
||||
|
||||
param.setWorkingDirectory(m_step->workingDirectory());
|
||||
|
||||
@@ -1135,7 +1135,8 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
||||
|
||||
updateWelcomePage();
|
||||
|
||||
VariableManager::registerFileVariables(Constants::VAR_CURRENTPROJECT_PREFIX,
|
||||
Utils::MacroExpander *expander = globalMacroExpander();
|
||||
expander->registerFileVariables(Constants::VAR_CURRENTPROJECT_PREFIX,
|
||||
tr("Current project's main file"),
|
||||
[this]() -> QString {
|
||||
QString projectFilePath;
|
||||
@@ -1145,51 +1146,51 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
||||
return projectFilePath;
|
||||
});
|
||||
|
||||
VariableManager::registerVariable(Constants::VAR_CURRENTPROJECT_BUILDPATH,
|
||||
expander->registerVariable(Constants::VAR_CURRENTPROJECT_BUILDPATH,
|
||||
tr("Full build path of the current project's active build configuration."),
|
||||
[]() -> QString {
|
||||
BuildConfiguration *bc = activeBuildConfiguration();
|
||||
return bc ? bc->buildDirectory().toUserOutput() : QString();
|
||||
});
|
||||
|
||||
VariableManager::registerVariable(Constants::VAR_CURRENTPROJECT_NAME,
|
||||
expander->registerVariable(Constants::VAR_CURRENTPROJECT_NAME,
|
||||
tr("The current project's name."),
|
||||
[]() { return variableValue(Constants::VAR_CURRENTPROJECT_NAME); });
|
||||
|
||||
VariableManager::registerVariable(Constants::VAR_CURRENTKIT_NAME,
|
||||
expander->registerVariable(Constants::VAR_CURRENTKIT_NAME,
|
||||
tr("The currently active kit's name."),
|
||||
[]() { return variableValue(Constants::VAR_CURRENTKIT_NAME); });
|
||||
|
||||
VariableManager::registerVariable(Constants::VAR_CURRENTKIT_FILESYSTEMNAME,
|
||||
expander->registerVariable(Constants::VAR_CURRENTKIT_FILESYSTEMNAME,
|
||||
tr("The currently active kit's name in a filesystem friendly version."),
|
||||
[]() { return variableValue(Constants::VAR_CURRENTKIT_FILESYSTEMNAME); });
|
||||
|
||||
VariableManager::registerVariable(Constants::VAR_CURRENTKIT_ID,
|
||||
expander->registerVariable(Constants::VAR_CURRENTKIT_ID,
|
||||
tr("The currently active kit's id."),
|
||||
[]() { return variableValue(Constants::VAR_CURRENTKIT_ID); });
|
||||
|
||||
VariableManager::registerVariable(Constants::VAR_CURRENTDEVICE_HOSTADDRESS,
|
||||
expander->registerVariable(Constants::VAR_CURRENTDEVICE_HOSTADDRESS,
|
||||
tr("The host address of the device in the currently active kit."),
|
||||
[]() { return variableValue(Constants::VAR_CURRENTDEVICE_HOSTADDRESS); });
|
||||
|
||||
VariableManager::registerVariable(Constants::VAR_CURRENTDEVICE_SSHPORT,
|
||||
expander->registerVariable(Constants::VAR_CURRENTDEVICE_SSHPORT,
|
||||
tr("The SSH port of the device in the currently active kit."),
|
||||
[]() { return variableValue(Constants::VAR_CURRENTDEVICE_SSHPORT); });
|
||||
|
||||
VariableManager::registerVariable(Constants::VAR_CURRENTDEVICE_USERNAME,
|
||||
expander->registerVariable(Constants::VAR_CURRENTDEVICE_USERNAME,
|
||||
tr("The username with which to log into the device in the currently active kit."),
|
||||
[]() { return variableValue(Constants::VAR_CURRENTDEVICE_USERNAME); });
|
||||
|
||||
VariableManager::registerVariable(Constants::VAR_CURRENTDEVICE_PRIVATEKEYFILE,
|
||||
expander->registerVariable(Constants::VAR_CURRENTDEVICE_PRIVATEKEYFILE,
|
||||
tr("The private key file with which to authenticate when logging into the device "
|
||||
"in the currently active kit."),
|
||||
[]() { return variableValue(Constants::VAR_CURRENTDEVICE_PRIVATEKEYFILE); });
|
||||
|
||||
VariableManager::registerVariable(Constants::VAR_CURRENTBUILD_NAME,
|
||||
expander->registerVariable(Constants::VAR_CURRENTBUILD_NAME,
|
||||
tr("The currently active build configuration's name."),
|
||||
[]() { return variableValue(Constants::VAR_CURRENTBUILD_NAME); });
|
||||
|
||||
VariableManager::registerVariable(Constants::VAR_CURRENTBUILD_TYPE,
|
||||
expander->registerVariable(Constants::VAR_CURRENTBUILD_TYPE,
|
||||
tr("The currently active build configuration's type."),
|
||||
[&]() -> QString {
|
||||
if (BuildConfiguration *bc = activeBuildConfiguration()) {
|
||||
@@ -1202,11 +1203,11 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
||||
return tr("unknown");
|
||||
});
|
||||
|
||||
VariableManager::registerFileVariables(Constants::VAR_CURRENTSESSION_PREFIX,
|
||||
expander->registerFileVariables(Constants::VAR_CURRENTSESSION_PREFIX,
|
||||
tr("File where current session is saved."),
|
||||
[]() { return SessionManager::sessionNameToFileName(SessionManager::activeSession()).toString(); });
|
||||
|
||||
VariableManager::registerVariable(Constants::VAR_CURRENTSESSION_NAME,
|
||||
expander->registerVariable(Constants::VAR_CURRENTSESSION_NAME,
|
||||
tr("Name of current session."),
|
||||
[]() { return SessionManager::activeSession(); });
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ bool ProjectMacroExpander::resolveMacro(const QString &name, QString *ret)
|
||||
{
|
||||
bool found = resolveProjectMacro(name, ret);
|
||||
if (!found) {
|
||||
QString result = Core::VariableManager::value(name.toUtf8(), &found);
|
||||
QString result = Core::globalMacroExpander()->value(name.toUtf8(), &found);
|
||||
if (ret)
|
||||
*ret = result;
|
||||
}
|
||||
|
||||
@@ -192,9 +192,10 @@ BaseQtVersion::BaseQtVersion(const BaseQtVersion &other) :
|
||||
m_linguistCommand(other.m_linguistCommand),
|
||||
m_qmlsceneCommand(other.m_qmlsceneCommand),
|
||||
m_qmlviewerCommand(other.m_qmlviewerCommand),
|
||||
m_qtAbis(other.m_qtAbis),
|
||||
m_expander(0)
|
||||
{ }
|
||||
m_qtAbis(other.m_qtAbis)
|
||||
{
|
||||
setupExpander();
|
||||
}
|
||||
|
||||
BaseQtVersion::BaseQtVersion()
|
||||
: m_id(-1), m_isAutodetected(false),
|
||||
@@ -228,12 +229,31 @@ void BaseQtVersion::ctor(const FileName &qmakePath)
|
||||
m_hasQtAbis = false;
|
||||
m_qtVersionString.clear();
|
||||
m_sourcePath.clear();
|
||||
m_expander = 0;
|
||||
setupExpander();
|
||||
}
|
||||
|
||||
void BaseQtVersion::setupExpander()
|
||||
{
|
||||
m_expander.registerVariable("Qt:version",
|
||||
QCoreApplication::translate("QtSupport::QtKitInformation", "The version string of the current Qt version."),
|
||||
[this]() { return qtVersionString(); });
|
||||
|
||||
m_expander.registerVariable("Qt:type",
|
||||
QCoreApplication::translate("QtSupport::QtKitInformation", "The type of the current Qt version."),
|
||||
[this]() { return type(); });
|
||||
|
||||
m_expander.registerVariable("Qt:mkspec",
|
||||
QCoreApplication::translate("QtSupport::QtKitInformation", "The mkspec of the current Qt version."),
|
||||
[this]() { return mkspec().toUserOutput(); });
|
||||
|
||||
// FIXME: Re-enable once we can detect expansion loops.
|
||||
// m_expander.registerVariable("Qt:name",
|
||||
// QCoreApplication::translate("QtSupport::QtKitInformation", "The display name of the current Qt version."),
|
||||
// [this]() { return displayName(); });
|
||||
}
|
||||
|
||||
BaseQtVersion::~BaseQtVersion()
|
||||
{
|
||||
delete m_expander;
|
||||
}
|
||||
|
||||
QString BaseQtVersion::defaultUnexpandedDisplayName(const FileName &qmakePath, bool fromPath)
|
||||
@@ -586,7 +606,7 @@ void BaseQtVersion::setAutoDetectionSource(const QString &autodetectionSource)
|
||||
|
||||
QString BaseQtVersion::displayName() const
|
||||
{
|
||||
return Utils::expandMacros(unexpandedDisplayName(), macroExpander());
|
||||
return Utils::expandMacros(m_unexpandedDisplayName, &m_expander);
|
||||
}
|
||||
|
||||
QString BaseQtVersion::unexpandedDisplayName() const
|
||||
@@ -894,15 +914,6 @@ void BaseQtVersion::parseMkSpec(ProFileEvaluator *evaluator) const
|
||||
m_mkspecValues.insert(ns, evaluator->value(ns));
|
||||
}
|
||||
|
||||
AbstractMacroExpander *BaseQtVersion::createMacroExpander() const
|
||||
{
|
||||
return new MacroExpander([this](const QString &name, QString *ret) -> bool {
|
||||
if (name == QLatin1String("Qt:name"))
|
||||
return false;
|
||||
return QtKitInformation::resolveQtMacro(this, name, ret);
|
||||
});
|
||||
}
|
||||
|
||||
FileName BaseQtVersion::mkspec() const
|
||||
{
|
||||
updateMkspec();
|
||||
@@ -1112,11 +1123,9 @@ QStringList BaseQtVersion::qtConfigValues() const
|
||||
return m_qtConfigValues;
|
||||
}
|
||||
|
||||
AbstractMacroExpander *BaseQtVersion::macroExpander() const
|
||||
MacroExpander *BaseQtVersion::macroExpander() const
|
||||
{
|
||||
if (!m_expander)
|
||||
m_expander = createMacroExpander();
|
||||
return m_expander;
|
||||
return &m_expander;
|
||||
}
|
||||
|
||||
QList<HeaderPath> BaseQtVersion::systemHeaderPathes(const Kit *k) const
|
||||
|
||||
@@ -34,17 +34,14 @@
|
||||
#include "qtsupport_global.h"
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/macroexpander.h>
|
||||
|
||||
#include <projectexplorer/abi.h>
|
||||
|
||||
#include <QStringList>
|
||||
#include <QVariantMap>
|
||||
|
||||
namespace Utils {
|
||||
class Environment;
|
||||
class AbstractMacroExpander;
|
||||
} // namespace Utils
|
||||
|
||||
namespace Utils { class Environment; }
|
||||
namespace Core { class FeatureSet; }
|
||||
|
||||
namespace ProjectExplorer {
|
||||
@@ -226,7 +223,7 @@ public:
|
||||
QStringList configValues() const;
|
||||
QStringList qtConfigValues() const;
|
||||
|
||||
Utils::AbstractMacroExpander *macroExpander() const; // owned by the Qt version
|
||||
Utils::MacroExpander *macroExpander() const; // owned by the Qt version
|
||||
|
||||
protected:
|
||||
BaseQtVersion();
|
||||
@@ -246,14 +243,11 @@ protected:
|
||||
void ensureMkSpecParsed() const;
|
||||
virtual void parseMkSpec(ProFileEvaluator *) const;
|
||||
|
||||
// Create the macro expander. This pointer will be cached by the Qt version (which will take
|
||||
// ownership).
|
||||
virtual Utils::AbstractMacroExpander *createMacroExpander() const;
|
||||
|
||||
private:
|
||||
void setAutoDetectionSource(const QString &autodetectionSource);
|
||||
static int getUniqueId();
|
||||
void ctor(const Utils::FileName &qmakePath);
|
||||
void setupExpander();
|
||||
void updateSourcePath() const;
|
||||
void updateVersionInfo() const;
|
||||
enum Binaries { QmlViewer, QmlScene, Designer, Linguist, Uic };
|
||||
@@ -303,7 +297,7 @@ private:
|
||||
|
||||
mutable QList<ProjectExplorer::Abi> m_qtAbis;
|
||||
|
||||
mutable Utils::AbstractMacroExpander *m_expander;
|
||||
mutable Utils::MacroExpander m_expander;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -38,28 +38,13 @@
|
||||
#include <projectexplorer/kitinformationmacroexpander.h>
|
||||
|
||||
#include <utils/buildablehelperlibrary.h>
|
||||
#include <utils/macroexpander.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
|
||||
namespace QtSupport {
|
||||
namespace Internal {
|
||||
|
||||
class QtKitInformationMacroExpander : public ProjectExplorer::KitInformationMacroExpander
|
||||
{
|
||||
public:
|
||||
QtKitInformationMacroExpander(const ProjectExplorer::Kit *k) :
|
||||
ProjectExplorer::KitInformationMacroExpander(k)
|
||||
{ }
|
||||
|
||||
bool resolveMacro(const QString &name, QString *ret)
|
||||
{
|
||||
return QtKitInformation::resolveQtMacro(QtKitInformation::qtVersion(kit()), name, ret);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
QtKitInformation::QtKitInformation()
|
||||
{
|
||||
@@ -71,26 +56,6 @@ QtKitInformation::QtKitInformation()
|
||||
this, SLOT(kitsWereLoaded()));
|
||||
}
|
||||
|
||||
bool QtKitInformation::resolveQtMacro(const BaseQtVersion *version, const QString &name, QString *ret)
|
||||
{
|
||||
const QString noInfo = QCoreApplication::translate("QtSupport::QtKitInformation", "none");
|
||||
|
||||
if (name == QLatin1String("Qt:version")) {
|
||||
*ret = version ? version->qtVersionString() : noInfo;
|
||||
return true;
|
||||
} else if (name == QLatin1String("Qt:name")) {
|
||||
*ret = version ? version->displayName() : noInfo;
|
||||
return true;
|
||||
} else if (name == QLatin1String("Qt:type")) {
|
||||
*ret = version ? version->type() : noInfo;
|
||||
return true;
|
||||
} else if (name == QLatin1String("Qt:mkspec")) {
|
||||
*ret = version ? version->mkspec().toUserOutput() : noInfo;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QVariant QtKitInformation::defaultValue(ProjectExplorer::Kit *k) const
|
||||
{
|
||||
Q_UNUSED(k);
|
||||
@@ -167,9 +132,21 @@ ProjectExplorer::IOutputParser *QtKitInformation::createOutputParser(const Proje
|
||||
return 0;
|
||||
}
|
||||
|
||||
Utils::AbstractMacroExpander *QtKitInformation::createMacroExpander(const ProjectExplorer::Kit *k) const
|
||||
bool QtKitInformation::resolveMacro(const ProjectExplorer::Kit *kit, const QString &name, QString *ret) const
|
||||
{
|
||||
return new Internal::QtKitInformationMacroExpander(k);
|
||||
if (BaseQtVersion *version = qtVersion(kit)) {
|
||||
MacroExpander *expander = version->macroExpander();
|
||||
if (expander->resolveMacro(name, ret))
|
||||
return true;
|
||||
|
||||
// FIXME: Handle in version expander once we can detect loops.
|
||||
if (name == QLatin1String("Qt:name")) {
|
||||
*ret = version->displayName();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Core::Id QtKitInformation::id()
|
||||
|
||||
@@ -38,6 +38,8 @@
|
||||
#include <coreplugin/featureprovider.h>
|
||||
#include <projectexplorer/kitinformation.h>
|
||||
|
||||
namespace Utils { class MacroExpander; }
|
||||
|
||||
namespace QtSupport {
|
||||
|
||||
class QTSUPPORT_EXPORT QtKitInformation : public ProjectExplorer::KitInformation
|
||||
@@ -61,9 +63,7 @@ public:
|
||||
void addToEnvironment(const ProjectExplorer::Kit *k, Utils::Environment &env) const;
|
||||
ProjectExplorer::IOutputParser *createOutputParser(const ProjectExplorer::Kit *k) const;
|
||||
|
||||
Utils::AbstractMacroExpander *createMacroExpander(const ProjectExplorer::Kit *k) const;
|
||||
|
||||
static bool resolveQtMacro(const BaseQtVersion *version, const QString &name, QString *ret);
|
||||
bool resolveMacro(const ProjectExplorer::Kit *kit, const QString &name, QString *ret) const;
|
||||
|
||||
static Core::Id id();
|
||||
static int qtVersionId(const ProjectExplorer::Kit *k);
|
||||
|
||||
@@ -114,11 +114,13 @@ static QString qmakeProperty(const char *propertyName)
|
||||
|
||||
void QtSupportPlugin::extensionsInitialized()
|
||||
{
|
||||
VariableManager::registerVariable(kHostBins,
|
||||
Utils::MacroExpander *expander = globalMacroExpander();
|
||||
|
||||
expander->registerVariable(kHostBins,
|
||||
tr("Full path to the host bin directory of the current project's Qt version."),
|
||||
[]() { return qmakeProperty("QT_HOST_BINS"); });
|
||||
|
||||
VariableManager::registerVariable(kInstallBins,
|
||||
expander->registerVariable(kInstallBins,
|
||||
tr("Full path to the target bin directory of the current project's Qt version."
|
||||
" You probably want %1 instead.").arg(QString::fromLatin1(kHostBins)),
|
||||
[]() { return qmakeProperty("QT_INSTALL_BINS"); });
|
||||
|
||||
@@ -147,7 +147,9 @@ void TextEditorPlugin::extensionsInitialized()
|
||||
addAutoReleasedObject(new FindInCurrentFile);
|
||||
addAutoReleasedObject(new FindInOpenFiles);
|
||||
|
||||
VariableManager::registerVariable(kCurrentDocumentSelection,
|
||||
Utils::MacroExpander *expander = globalMacroExpander();
|
||||
|
||||
expander->registerVariable(kCurrentDocumentSelection,
|
||||
tr("Selected text within the current document."),
|
||||
[]() -> QString {
|
||||
QString value;
|
||||
@@ -158,35 +160,35 @@ void TextEditorPlugin::extensionsInitialized()
|
||||
return value;
|
||||
});
|
||||
|
||||
VariableManager::registerIntVariable(kCurrentDocumentRow,
|
||||
expander->registerIntVariable(kCurrentDocumentRow,
|
||||
tr("Line number of the text cursor position in current document (starts with 1)."),
|
||||
[]() -> int {
|
||||
BaseTextEditor *editor = BaseTextEditor::currentTextEditor();
|
||||
return editor ? editor->currentLine() : 0;
|
||||
});
|
||||
|
||||
VariableManager::registerIntVariable(kCurrentDocumentColumn,
|
||||
expander->registerIntVariable(kCurrentDocumentColumn,
|
||||
tr("Column number of the text cursor position in current document (starts with 0)."),
|
||||
[]() -> int {
|
||||
BaseTextEditor *editor = BaseTextEditor::currentTextEditor();
|
||||
return editor ? editor->currentColumn() : 0;
|
||||
});
|
||||
|
||||
VariableManager::registerIntVariable(kCurrentDocumentRowCount,
|
||||
expander->registerIntVariable(kCurrentDocumentRowCount,
|
||||
tr("Number of lines visible in current document."),
|
||||
[]() -> int {
|
||||
BaseTextEditor *editor = BaseTextEditor::currentTextEditor();
|
||||
return editor ? editor->rowCount() : 0;
|
||||
});
|
||||
|
||||
VariableManager::registerIntVariable(kCurrentDocumentColumnCount,
|
||||
expander->registerIntVariable(kCurrentDocumentColumnCount,
|
||||
tr("Number of columns visible in current document."),
|
||||
[]() -> int {
|
||||
BaseTextEditor *editor = BaseTextEditor::currentTextEditor();
|
||||
return editor ? editor->columnCount() : 0;
|
||||
});
|
||||
|
||||
VariableManager::registerIntVariable(kCurrentDocumentFontSize,
|
||||
expander->registerIntVariable(kCurrentDocumentFontSize,
|
||||
tr("Current document's font size in points."),
|
||||
[]() -> int {
|
||||
BaseTextEditor *editor = BaseTextEditor::currentTextEditor();
|
||||
|
||||
@@ -87,7 +87,8 @@ bool VcsPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
||||
this, SLOT(slotSettingsChanged()));
|
||||
slotSettingsChanged();
|
||||
|
||||
VariableManager::registerVariable(Constants::VAR_VCS_NAME,
|
||||
Utils::MacroExpander *expander = globalMacroExpander();
|
||||
expander->registerVariable(Constants::VAR_VCS_NAME,
|
||||
tr("Name of the version control system in use by the current project."),
|
||||
[]() -> QString {
|
||||
IVersionControl *vc = 0;
|
||||
@@ -96,7 +97,7 @@ bool VcsPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
||||
return vc ? vc->displayName() : QString();
|
||||
});
|
||||
|
||||
VariableManager::registerVariable(Constants::VAR_VCS_TOPIC,
|
||||
expander->registerVariable(Constants::VAR_VCS_TOPIC,
|
||||
tr("The current version control topic (branch or tag) identification of the current project."),
|
||||
[]() -> QString {
|
||||
IVersionControl *vc = 0;
|
||||
@@ -106,7 +107,7 @@ bool VcsPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
||||
return vc ? vc->vcsTopic(topLevel) : QString();
|
||||
});
|
||||
|
||||
VariableManager::registerVariable(Constants::VAR_VCS_TOPLEVELPATH,
|
||||
expander->registerVariable(Constants::VAR_VCS_TOPLEVELPATH,
|
||||
tr("The top level path to the repository the current project is in."),
|
||||
[]() -> QString {
|
||||
if (Project *project = ProjectExplorerPlugin::currentProject())
|
||||
|
||||
Reference in New Issue
Block a user