Skip to content

Commit

Permalink
Fixed an outstanding issue when parsing the CURRENTSECTION variable i…
Browse files Browse the repository at this point in the history
…n an action (when executed) using nested syntax
  • Loading branch information
brianferguson committed Jul 2, 2021
1 parent 68a776a commit 427dc87
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 16 deletions.
22 changes: 19 additions & 3 deletions Library/ConfigParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,19 @@ bool ConfigParser::ReplaceMeasures(std::wstring& result)
*/
bool ConfigParser::ParseVariables(std::wstring& str, const VariableType type, Meter* meter)
{
// Since actions are parsed when executed, get the current active
// section in case the current section variable is used.
bool hasCurrentAction = false;
if (m_Skin && (m_CurrentSection->empty() || meter))
{
Section* section = m_Skin->GetCurrentActionSection();
if (section || meter)
{
m_CurrentSection->assign(meter ? meter->GetName() : section->GetName());
hasCurrentAction = true;
}
}

// It is possible for a variable to be reset when calling a custom function in a plugin or lua.
// Copy the result here, and replace it before returning.
std::wstring result = str;
Expand Down Expand Up @@ -966,8 +979,6 @@ bool ConfigParser::ParseVariables(std::wstring& str, const VariableType type, Me

case VariableType::Variable:
{
// Assign current section if available
if (meter) m_CurrentSection->assign(meter->GetName());
const std::wstring* value = GetVariable(val);
if (value)
{
Expand All @@ -976,7 +987,6 @@ bool ConfigParser::ParseVariables(std::wstring& str, const VariableType type, Me
replaced = true;
found = true;
}
if (meter) m_CurrentSection->clear();
}
break;

Expand Down Expand Up @@ -1031,6 +1041,12 @@ bool ConfigParser::ParseVariables(std::wstring& str, const VariableType type, Me
}
}

// Reset the current section
if (hasCurrentAction)
{
m_CurrentSection->clear();
}

str = result;
return replaced;
}
Expand Down
1 change: 1 addition & 0 deletions Library/ConfigParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

class Rainmeter;
class Skin;
class Section;
class Measure;
class Meter;

Expand Down
14 changes: 7 additions & 7 deletions Library/IfActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void IfActions::DoIfActions(Measure& measure, double value)
if (!m_EqualCommitted)
{
m_EqualCommitted = true; // To avoid infinite loop from !Update
GetRainmeter().ExecuteCommand(m_EqualAction.c_str(), measure.GetSkin());
GetRainmeter().ExecuteActionCommand(m_EqualAction.c_str(), &measure);
}
}
else
Expand All @@ -167,7 +167,7 @@ void IfActions::DoIfActions(Measure& measure, double value)
if (!m_AboveCommitted)
{
m_AboveCommitted = true; // To avoid infinite loop from !Update
GetRainmeter().ExecuteCommand(m_AboveAction.c_str(), measure.GetSkin());
GetRainmeter().ExecuteActionCommand(m_AboveAction.c_str(), &measure);
}
}
else
Expand All @@ -184,7 +184,7 @@ void IfActions::DoIfActions(Measure& measure, double value)
if (!m_BelowCommitted)
{
m_BelowCommitted = true; // To avoid infinite loop from !Update
GetRainmeter().ExecuteCommand(m_BelowAction.c_str(), measure.GetSkin());
GetRainmeter().ExecuteActionCommand(m_BelowAction.c_str(), &measure);
}
}
else
Expand Down Expand Up @@ -229,7 +229,7 @@ void IfActions::DoIfActions(Measure& measure, double value)
if (m_ConditionMode || !item.tCommitted)
{
item.tCommitted = true;
GetRainmeter().ExecuteCommand(item.tAction.c_str(), measure.GetSkin());
GetRainmeter().ExecuteActionCommand(item.tAction.c_str(), &measure);
}
}
else if (result == 0.0) // "False"
Expand All @@ -239,7 +239,7 @@ void IfActions::DoIfActions(Measure& measure, double value)
if (m_ConditionMode || !item.fCommitted)
{
item.fCommitted = true;
GetRainmeter().ExecuteCommand(item.fAction.c_str(), measure.GetSkin());
GetRainmeter().ExecuteActionCommand(item.fAction.c_str(), &measure);
}
}
}
Expand Down Expand Up @@ -303,7 +303,7 @@ void IfActions::DoIfActions(Measure& measure, double value)
if (m_MatchMode || !item.tCommitted)
{
item.tCommitted = true;
GetRainmeter().ExecuteCommand(item.tAction.c_str(), measure.GetSkin());
GetRainmeter().ExecuteActionCommand(item.tAction.c_str(), &measure);
}
}
else // Not Match
Expand All @@ -313,7 +313,7 @@ void IfActions::DoIfActions(Measure& measure, double value)
if (m_MatchMode || !item.fCommitted)
{
item.fCommitted = true;
GetRainmeter().ExecuteCommand(item.fAction.c_str(), measure.GetSkin());
GetRainmeter().ExecuteActionCommand(item.fAction.c_str(), &measure);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Library/Measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ void Measure::DoChangeAction(bool execute)
{
if (m_OldValue->IsChanged(newValue, newStringValue))
{
GetRainmeter().ExecuteCommand(m_OnChangeAction.c_str(), m_Skin);
GetRainmeter().ExecuteActionCommand(m_OnChangeAction.c_str(), this);
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion Library/MeterButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ bool MeterButton::MouseUp(POINT pos, bool execute)
{
if (execute && m_Clicked && m_Focus && HitTest2(pos.x, pos.y))
{
GetRainmeter().ExecuteCommand(m_Command.c_str(), m_Skin);
GetRainmeter().ExecuteActionCommand(m_Command.c_str(), this);
}
m_State = BUTTON_STATE_NORMAL;
m_Clicked = false;
Expand Down
18 changes: 18 additions & 0 deletions Library/Rainmeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,24 @@ void Rainmeter::ExecuteCommand(const WCHAR* command, Skin* skin, bool multi)
m_CommandHandler.ExecuteCommand(command, skin, multi);
}

/*
** Runs the given command or bang (sent from an Action)
**
*/
void Rainmeter::ExecuteActionCommand(const WCHAR* command, Section* section)
{
Skin* skin = nullptr;
if (section && (skin = section->GetSkin()))
{
skin->SetCurrentActionSection(section);
m_CommandHandler.ExecuteCommand(command, skin);
skin->ResetCurrentActionSection();
return;
}

m_CommandHandler.ExecuteCommand(command, skin);
}

/*
** Executes command when current processing is done.
**
Expand Down
1 change: 1 addition & 0 deletions Library/Rainmeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class Rainmeter
void ExecuteBang(const WCHAR* bang, std::vector<std::wstring>& args, Skin* skin);
void ExecuteCommand(const WCHAR* command, Skin* skin, bool multi = true);
void DelayedExecuteCommand(const WCHAR* command, Skin* skin = nullptr);
void ExecuteActionCommand(const WCHAR* command, Section* section);

void RefreshAll();

Expand Down
2 changes: 1 addition & 1 deletion Library/Section.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ void Section::DoUpdateAction()
{
if (!m_OnUpdateAction.empty())
{
GetRainmeter().ExecuteCommand(m_OnUpdateAction.c_str(), m_Skin);
GetRainmeter().ExecuteActionCommand(m_OnUpdateAction.c_str(), this);
}
}
16 changes: 13 additions & 3 deletions Library/Skin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Skin::Skin(const std::wstring& folderPath, const std::wstring& file) : m_FolderP
m_MouseOver(false),
m_MouseInputRegistered(false),
m_HasMouseScrollAction(false),
m_CurrentActionSection(nullptr),
m_BackgroundMargins(),
m_DragMargins(),
m_WindowX(1, L'0'),
Expand Down Expand Up @@ -4839,6 +4840,7 @@ LRESULT Skin::OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam)
*/
bool Skin::DoAction(int x, int y, MOUSEACTION action, bool test)
{
Meter* meter = nullptr;
std::wstring command;

// Check if the hitpoint was over some meter
Expand All @@ -4851,6 +4853,7 @@ bool Skin::DoAction(int x, int y, MOUSEACTION action, bool test)
const Mouse& mouse = (*j)->GetMouse();
if (mouse.HasActionCommand(action) && (*j)->HitTest(x, y))
{
meter = (*j);
command = mouse.GetActionCommand(action);
break;
}
Expand All @@ -4868,7 +4871,14 @@ bool Skin::DoAction(int x, int y, MOUSEACTION action, bool test)
{
if (!test)
{
GetRainmeter().ExecuteCommand(command.c_str(), this);
if (meter)
{
GetRainmeter().ExecuteActionCommand(command.c_str(), meter);
}
else
{
GetRainmeter().ExecuteCommand(command.c_str(), this);
}
}

return true;
Expand Down Expand Up @@ -4941,7 +4951,7 @@ bool Skin::DoMoveAction(int x, int y, MOUSEACTION action)
if (!mouse.GetOverAction().empty())
{
UINT currCounter = m_MouseMoveCounter;
GetRainmeter().ExecuteCommand(mouse.GetOverAction().c_str(), this);
GetRainmeter().ExecuteActionCommand(mouse.GetOverAction().c_str(), (*j));
return (currCounter == m_MouseMoveCounter);
}
}
Expand All @@ -4967,7 +4977,7 @@ bool Skin::DoMoveAction(int x, int y, MOUSEACTION action)
const Mouse& mouse = (*j)->GetMouse();
if (!mouse.GetLeaveAction().empty())
{
GetRainmeter().ExecuteCommand(mouse.GetLeaveAction().c_str(), this);
GetRainmeter().ExecuteActionCommand(mouse.GetLeaveAction().c_str(), (*j));
return true;
}
}
Expand Down
6 changes: 6 additions & 0 deletions Library/Skin.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ class Skin : public Group
void SetMouseLeaveEvent(bool cancel);
void SetHasMouseScrollAction() { m_HasMouseScrollAction = true; }

Section* GetCurrentActionSection() { return m_CurrentActionSection; }
void SetCurrentActionSection(Section* section) { m_CurrentActionSection = section; }
void ResetCurrentActionSection() { SetCurrentActionSection(nullptr); }

void MoveWindow(int x, int y);
void MoveSelectedWindow(int dx, int dy);
bool IsSelected() { return m_Selected; }
Expand Down Expand Up @@ -362,6 +366,8 @@ class Skin : public Group
std::wstring m_OnUpdateAction;
std::wstring m_OnWakeAction;

Section* m_CurrentActionSection;

std::wstring m_SkinGroup;
std::wstring m_BackgroundName;
RECT m_BackgroundMargins;
Expand Down

0 comments on commit 427dc87

Please sign in to comment.