Hello,
I'm trying to create a simple toggle button that changes its own font color when clicked. I'm using a global variable to store the state and an @ifset
directive on the button to set the color.
I've set up a two-part system
-
A Toolbar Button (set to "Script Function") that calls a user command.
-
A User Command (also a script) that toggles the global variable and then calls
Toolbar REFRESH
.
The Problem:
The script log confirms that the entire process is working : the button successfully calls the user command, the user command toggles the global variable, and the Toolbar REFRESH
command is sent. However, the button's font color on the toolbar never visually changes.
It seems like there's a timing issue where the refresh command isn't forcing the original button to re-evaluate its @ifset
condition and redraw itself.
Here is the exact code I am using:
1. Toolbar Button Code (Function Type: Script Function)
// This button's only job is to call the user command.
@ifset:GLOBAL:state_MyButtonState
@color:text=128,0,128
@endif
@script jscript
function OnClick(clickData) {
var cmd = DOpus.Create.Command();
cmd.AddLine("ToggleMyButtonVar");
cmd.Run();
}
2. User Command Code (Named: ToggleMyButtonVar
)
@script jscript
function OnClick(clickData) {
// This command toggles the variable and sends the refresh command.
var cmd = DOpus.Create.Command();
cmd.AddLine("Set GLOBALVAR=!toggle:state_MyButtonState");
cmd.AddLine("Toolbar REFRESH");
cmd.Run();
}
What is the correct way to force a button to redraw itself and re-evaluate its @ifset
directive after its state variable has been changed by a script?
Thank you for your help.