add '$this' feature to lambda functions

fix large size on startup
fix invalid key parsing
This commit is contained in:
arcan1s 2015-09-03 00:30:10 +03:00
parent 6689bea9a7
commit 7218defe19
9 changed files with 29 additions and 18 deletions

View File

@ -150,8 +150,6 @@ Item {
font.pointSize: plasmoid.configuration.fontSize font.pointSize: plasmoid.configuration.fontSize
font.weight: general.fontWeight[plasmoid.configuration.fontWeight] font.weight: general.fontWeight[plasmoid.configuration.fontWeight]
text: plasmoid.configuration.text
PlasmaCore.ToolTipArea { PlasmaCore.ToolTipArea {
height: tooltip.height height: tooltip.height
width: tooltip.width width: tooltip.width
@ -233,8 +231,6 @@ Item {
awKeys.setPopupEnabled(plasmoid.configuration.notify) awKeys.setPopupEnabled(plasmoid.configuration.notify)
awKeys.setTranslateStrings(plasmoid.configuration.translateStrings) awKeys.setTranslateStrings(plasmoid.configuration.translateStrings)
awKeys.setWrapNewLines(plasmoid.configuration.wrapNewLines) awKeys.setWrapNewLines(plasmoid.configuration.wrapNewLines)
needTextUpdate(plasmoid.configuration.text)
} }
function action_checkUpdates() { function action_checkUpdates() {

View File

@ -1 +1 @@
singleton general general.qml singleton general 1.0 general.qml

View File

@ -724,10 +724,11 @@ void AWKeys::editItem(const QString type)
} }
void AWKeys::dataUpdate() const void AWKeys::dataUpdate()
{ {
qCDebug(LOG_AW); qCDebug(LOG_AW);
calculateLambdas();
emit(needTextToBeUpdated(parsePattern())); emit(needTextToBeUpdated(parsePattern()));
if (toolTip != nullptr) emit(toolTip->updateData(values)); if (toolTip != nullptr) emit(toolTip->updateData(values));
} }
@ -877,17 +878,15 @@ void AWKeys::addKeyToCache(const QString type, const QString key)
} }
QString AWKeys::parsePattern() const void AWKeys::calculateLambdas()
{ {
qCDebug(LOG_AW); qCDebug(LOG_AW);
QString parsed = pattern;
parsed.replace(QString("$$"), QString("$\\$\\"));
// lambdas
foreach(QString key, foundLambdas) foreach(QString key, foundLambdas)
parsed.replace(QString("${{%1}}").arg(key), [this](QString key) { values[key] = [this](QString key) {
QScriptEngine engine; QScriptEngine engine;
// apply $this values
key.replace(QString("$this"), values[key]);
foreach(QString lambdaKey, foundKeys) foreach(QString lambdaKey, foundKeys)
key.replace(QString("$%1").arg(lambdaKey), values[lambdaKey]); key.replace(QString("$%1").arg(lambdaKey), values[lambdaKey]);
qCInfo(LOG_AW) << "Expression" << key; qCInfo(LOG_AW) << "Expression" << key;
@ -898,7 +897,20 @@ QString AWKeys::parsePattern() const
return QString(); return QString();
} else } else
return result.toString(); return result.toString();
}(key)); }(key);
}
QString AWKeys::parsePattern() const
{
qCDebug(LOG_AW);
QString parsed = pattern;
parsed.replace(QString("$$"), QString("$\\$\\"));
// lambdas
foreach(QString key, foundLambdas)
parsed.replace(QString("${{%1}}").arg(key), values[key]);
// main keys // main keys
foreach(QString key, foundKeys) foreach(QString key, foundKeys)

View File

@ -70,13 +70,14 @@ signals:
void needToBeUpdated(); void needToBeUpdated();
private slots: private slots:
void dataUpdate() const; void dataUpdate();
void loadKeysFromCache(); void loadKeysFromCache();
void reinitKeys(); void reinitKeys();
private: private:
// methods // methods
void addKeyToCache(const QString type, const QString key = QString("")); void addKeyToCache(const QString type, const QString key = QString(""));
void calculateLambdas();
QString parsePattern() const; QString parsePattern() const;
float temperature(const float temp, const QString units) const; float temperature(const float temp, const QString units) const;
// get methods // get methods

View File

@ -1,3 +1,2 @@
module org.kde.plasma.private.awesomewidget module org.kde.plasma.private.awesomewidget
plugin awplugin plugin awplugin

View File

@ -174,6 +174,10 @@ private:
} }
} }
// sort items
std::sort(items.begin(), items.end(), [](const T *lhs, const T *rhs){
return lhs->number() < rhs->number();
});
return items; return items;
}; };

View File

@ -1 +1 @@
singleton general general.qml singleton general 1.0 general.qml

View File

@ -1,3 +1,2 @@
module org.kde.plasma.private.desktoppanel module org.kde.plasma.private.desktoppanel
plugin dpplugin plugin dpplugin

View File

@ -533,7 +533,7 @@ QString ExtendedSysMon::buildString(const QString current, const QString value,
qCDebug(LOG_ESM) << "Strip after" << s; qCDebug(LOG_ESM) << "Strip after" << s;
int index = value.indexOf(current); int index = value.indexOf(current);
if ((index == -1) || ((index + s + 1) > value.count())) if ((current.isEmpty()) || ((index + s + 1) > value.count()))
return QString("%1").arg(value.left(s), s, QLatin1Char(' ')); return QString("%1").arg(value.left(s), s, QLatin1Char(' '));
else else
return QString("%1").arg(value.mid(index + 1, s), s, QLatin1Char(' ')); return QString("%1").arg(value.mid(index + 1, s), s, QLatin1Char(' '));