From 4579b7c59e3e12ccb49efab6eb7c17d304c69af0 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Wed, 15 Oct 2014 09:59:55 +0200 Subject: [PATCH] MacroExpander: Add variables for date and time The expander is used in the wizards, and being able to specify timestamps is something many people requested at devdays. Change-Id: If227f9c48d0b5f409d22233af8c43ae376f343f9 Reviewed-by: Eike Ziller --- src/plugins/coreplugin/coreplugin.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/plugins/coreplugin/coreplugin.cpp b/src/plugins/coreplugin/coreplugin.cpp index 45ca675556a..a63d533e059 100644 --- a/src/plugins/coreplugin/coreplugin.cpp +++ b/src/plugins/coreplugin/coreplugin.cpp @@ -43,6 +43,7 @@ #include #include +#include #include #include @@ -113,6 +114,24 @@ bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage) m_findPlugin->initialize(arguments, errorMessage); m_locator->initialize(this, arguments, errorMessage); + Utils::MacroExpander *expander = Utils::globalMacroExpander(); + expander->registerVariable("CurrentDate:ISO", tr("The current date (ISO)."), + []() { return QDate::currentDate().toString(Qt::ISODate); }); + expander->registerVariable("CurrentTime:ISO", tr("The current time (ISO)."), + []() { return QTime::currentTime().toString(Qt::ISODate); }); + expander->registerVariable("CurrentDate:RFC", tr("The current date (RFC2822)."), + []() { return QDate::currentDate().toString(Qt::RFC2822Date); }); + expander->registerVariable("CurrentTime:RFC", tr("The current time (RFC2822)."), + []() { return QTime::currentTime().toString(Qt::RFC2822Date); }); + expander->registerVariable("CurrentDate:Locale", tr("The current date (Locale)."), + []() { return QDate::currentDate().toString(Qt::DefaultLocaleShortDate); }); + expander->registerVariable("CurrentTime:Locale", tr("The current time (Locale)."), + []() { return QTime::currentTime().toString(Qt::DefaultLocaleShortDate); }); + expander->registerPrefix("CurrentDate:", tr("The current date (QDate formatstring)"), + [](const QString &fmt) { return QDate::currentDate().toString(fmt); }); + expander->registerPrefix("CurrentTime:", tr("The current time (QTime formatstring)"), + [](const QString &fmt) { return QTime::currentTime().toString(fmt); }); + return success; }