Button Fails to Remember Toggled State

I use this button to toggle a toolbar:

@toggle:if $glob:SidebarShown
@icon:C:\Users\Chuck\Documents\DOpus\Themes\CCleanerish\Icons\left.png,$glob!:SidebarShown

@ifset:$glob!:SidebarShown
@set glob:SidebarShown
Toolbar "CCleanerish - Sidebar (Left)" CLOSE

@ifset:else
@set glob:SidebarShown=1
Toolbar "CCleanerish - Sidebar (Left)" STATE=left LINE=0

The button fails to remember its state (both highlight and icon) when I close and open the lister.

Any suggestions?

Some of the ! were in slightly the wrong place:

@toggle:if $glob:SidebarShown
@icon:C:\Users\Chuck\Documents\DOpus\Themes\CCleanerish\Icons\left.png,!$glob:SidebarShown

@if:$glob:SidebarShown
@set $glob:SidebarShown
Toolbar "CCleanerish - Sidebar (Left)" CLOSE

@if:else
@set $glob:SidebarShown=1
Toolbar "CCleanerish - Sidebar (Left)" STATE=left LINE=0

(I also used @if instead of @ifset, although it doesn't really matter in this case. @if is newer and lets you do more in some situations.)


If you don't care about making the icon change states, this is all you need to toggle the toolbar and have the button change states:

Toolbar "CCleanerish - Sidebar (Left)" STATE=left LINE=0 TOGGLE

Leo,

thanks for the reply. Your adjustment did not resolve the issue. Here's the expected result:

When I close the toolbar, it looks like this:

When I then close and reopen the lister, I get this (toolbar opens based on toolbar sets configuration):

How do I correct this so the button remains in the same state as the toolbar?

You probably need another script which uses one or multiple of the events DO fires whenever a lister opens or a general change happens to the UI. In that script, the particular variable SidebarShown would be set to the status of the toolbar in question, so the button "knows" what status the toolbar is in, even if the button itself was not used to show/hide the bar.

@tbone - Thanks for weighing in. I suspected I might have to go that route to resolve this. With next to no scripting skill, I wouldn't even know where to start.

How are you closing the toolbar? With the button, it should work, and does work here.

If you close the toolbar some other way, it won't work because the button is using variables that it, and only it, will toggle.

I close the toolbar with the button. The issue occurs when I close and reopen the lister. The lister's toolbar set has the toolbar in question open by default. As you indicate, the toolbar button is the only thing that toggles the variable. How can I get DOpus to toggle the variable when it opens based on the toolbar's status itself as open based on the toolbar set configuration?

You could use a script that runs whenever a new lister opens, checks the toolbar state and sets the variable.

You probably also want to use a lister variable instead of a global variable, since the toolbar state is per lister not global, and you might open more than one window. (lst: as the preview instead of glob:)

All of this is a lot of complication just to make the button's icon change though. If you don't 100% need that then the simple one-line command in my earlier post does everything else without any need for variables or scripting.

Actually, if you want the icon, there is an easier way:

Have two buttons:

@hideif:Toolbar "CCleanerish - Sidebar (Left)" STATE=left LINE=0 TOGGLE
Toolbar "CCleanerish - Sidebar (Left)" STATE=left LINE=0 TOGGLE
@hideif:!Toolbar "CCleanerish - Sidebar (Left)" STATE=left LINE=0 TOGGLE
Toolbar "CCleanerish - Sidebar (Left)" STATE=left LINE=0 TOGGLE

The only difference is the ! after @hideif:.

Set one button to one icon, and the other to the other icon. You will only see one button or the other one, as one is hidden when the toolbar is visible and the other is hidden when the toolbar is visible.

Solved... Thanks Leo!