Command: UpdateButtons (force icon/toggle-status refresh)

UpdateButtons - A script command for updating all button-icons and toggle-states to reflect values in global/local variables.

The script below is probably obsolete, please read on:
The method Command.UpdateToggle() seems to have an effect on refreshing icons as well, not just on the toggle state.
So a very simple usercommand seems to do the job quite nicely (to be able to update buttons by dopusrt.exe from an external application e.g.).

<?xml version="1.0"?>
<button backcol="none" display="icon" textcol="none">
	<label>UpdateButtons2</label>
	<tip>Update all button icons and toggle states</tip>
	<icon1>#usercommand</icon1>
	<function type="script">
		<instruction>@script jscript</instruction>
		<instruction>function OnClick(data){</instruction>
		<instruction>	var cmd = DOpus.NewCommand();</instruction>
		<instruction>	cmd.UpdateToggle();</instruction>
		<instruction>}</instruction>
	</function>
</button>

(Note: Adding @toggle:update to a normal, non-script command should also achieve the same thing, without the need for any script or user command, at least in theory. I'm not sure if that existed at the time this was written. --Leo)

The downloadable script maybe still be useful as an example on how to find specific toolbars or how to handle them in scripting.

Description:
I found out that toggling a toolbar by script or button helps to make icons and toggle-states update, so I did this.
Normally buttons are updated only right after switching tabs or between listers, so this allows to run any command and forcing
a button refresh at the same time. It updates all buttons in every open lister. This is experimental so your mileage may vary. o)

Parameters:
none

Usage:
Just call "UpdateButtons" from a button/hotkey or script. You should have some buttons making use of variables to change
their icon and "pressed" appearance. If you just want to try, use code like this to test for a variable "Script.UpdateButtons.Test".

<?xml version="1.0"?>
<button backcol="none" display="both" textcol="none">
	<label>UpdateButtons-Test</label>
	<icon1>#newcommand</icon1>
	<function type="normal">
		<instruction>@toggle:if $glob:Script.UpdateButtons.Test</instruction>
		<instruction>@icon:importexport,$glob:Script.UpdateButtons.Test</instruction>
	</function>
</button>

Installation:
To install the command, download the *.js.txt file below and drag it to Preferences / Toolbars / Scripts.

Download:

This doesn't work for me because I'm using a button group, which means there's a second toolbar in one line with my default toolbar. The command to toggle this toolbar is Toolbar "Testbuttons" STATE=top LINE=0,808 TOGGLE. Your script loads these two toolbars in two lines.

You don't need a script to immediately update Buttons. The following code works reliable for me using only internal commands. Save this as a user command named UpdateButtons.

User command UpdateButtons

Toolbar SAVESET=quiet NAME=UpdateButtons
Toolbar LOADSET=replace NAME=UpdateButtons
Delete NORECYCLE QUIET "/dopusdata\Toolbar Sets\UpdateButtons.ots"

Mhh, your button group should not lead to problems, I also use those, but I noticed the script-side toolbar object does not match the builtin toolbar command regarding options/toolbar states, so that maybe what's causing the glitch. Could you post screenshot of the failing columns? I'd like to nail this down.

The script has the advantage of supporting all opened listers, it does not create additional files and it does not toggle all of the bars.

But anyway, I'm glad to see there is another solution, in this thread Refresh toolbar button Leo told, there is no command to update buttons. Well he's right, there is no command, but obviously there are ways to update buttons nonetheless, which is good! o)

Thank you! o)

No problems with columns here. I think you mean toolbars:

My Standard toolbars (1 Button Group)



After applying your script command:


Two Button Groups:


After applying your script command:

Did you test my version? It updates the icon of a test button on all opened listers for me.

That's true but I think that doesn't hurt for a command that is triggered by a button click. It's fast and you don't see any flickering or such.

I fixed the code, to just toggle the very last toolbar in the very first encountered toolbar group. That does not mix up the toolbars anymore in some conditions.

While fixing things, I got suspicious on the Command.UpdateToggle() method, which I added from the beginning to also update the toggle-state.
It turned out, it also updates the icon, so toggling single toolbars or toolbar sets is not required at all. o)

@Leo, Jon, Greg
In case this is by design, please consider updating the docs, so the next enthusiast can spend time on something more useful! o))

I'll updae the final script nonetheless, it probably serves as an example on how to act on toolbars or finding a specific one.

Thanks! o)

Confirmed working fine now!

To be true, the internal command version I posted doesn't really work when saved as a user command (I'm sure it worked at the first try). It works if the command is directly written to a button but when saved as a user command it's different. It will update only buttons then that are placed on a different toolbar than the button from which the user command was started. :confused:

I guess you tried the 3 lines of usercomand instead of the 80 lines script? o)

I tried both your script command and my user command. I reduced your script to 13 lines to see if DOpus.NewCommand.UpdateToggle works for me and it works fine. My 3 lines of internal commands behave different if saved as user command or directly written as button code.
However, both are obsolete because a single line does the trick.