From fc963871058c9765709eea483d96eb3b763f510a Mon Sep 17 00:00:00 2001 From: Brian Ferguson Date: Fri, 8 Nov 2013 08:36:43 -0700 Subject: [PATCH] Added IfConditionMode. If 1, will execute the True/False action on every update of the measure. If 0, will only execute the True/False action once until it switches case and back again (like IfActions). --- Library/IfActions.cpp | 27 ++++++++++++++++++++++++--- Library/IfActions.h | 7 ++++++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Library/IfActions.cpp b/Library/IfActions.cpp index 4d910c9b..70b2bd94 100644 --- a/Library/IfActions.cpp +++ b/Library/IfActions.cpp @@ -32,7 +32,8 @@ IfActions::IfActions() : m_AboveCommitted(false), m_BelowCommitted(false), m_EqualCommitted(false), - m_Conditions() + m_Conditions(), + m_ConditionMode(false) { } @@ -54,6 +55,8 @@ void IfActions::ReadOptions(ConfigParser& parser, const WCHAR* section) void IfActions::ReadConditionOptions(ConfigParser& parser, const WCHAR* section) { + m_ConditionMode = parser.ReadBool(section, L"IfConditionMode", false); + std::wstring condition = parser.ReadString(section, L"IfCondition", L""); if (!condition.empty()) { @@ -178,11 +181,23 @@ void IfActions::DoIfActions(Measure& measure, double value) if (result == 1.0f) // "True" { - GetRainmeter().ExecuteCommand(item.tAction.c_str(), measure.GetMeterWindow()); + item.fCommitted = false; + + if (m_ConditionMode || !item.tCommitted) + { + item.tCommitted = true; + GetRainmeter().ExecuteCommand(item.tAction.c_str(), measure.GetMeterWindow()); + } } else if (result == 0.0f) // "False" { - GetRainmeter().ExecuteCommand(item.fAction.c_str(), measure.GetMeterWindow()); + item.tCommitted = false; + + if (m_ConditionMode || !item.fCommitted) + { + item.fCommitted = true; + GetRainmeter().ExecuteCommand(item.fAction.c_str(), measure.GetMeterWindow()); + } } } } @@ -206,4 +221,10 @@ void IfActions::SetState(double value) { m_BelowCommitted = false; } + + for (auto& item : m_Conditions) + { + item.tCommitted = false; + item.fCommitted = false; + } } diff --git a/Library/IfActions.h b/Library/IfActions.h index 76b78fe5..214b3ac3 100644 --- a/Library/IfActions.h +++ b/Library/IfActions.h @@ -34,7 +34,9 @@ public: condition(), tAction(), fAction(), - parseError(false) + parseError(false), + tCommitted(false), + fCommitted(false) { Set(value, trueAction, falseAction); } @@ -50,6 +52,8 @@ public: std::wstring tAction; // IfTrueAction std::wstring fAction; // IfFalseAction bool parseError; + bool tCommitted; + bool fCommitted; }; class IfActions @@ -77,5 +81,6 @@ private: bool m_EqualCommitted; std::vector m_Conditions; + bool m_ConditionMode; }; #endif