OnAfterFolderChange and the evaluation of @hideif

function OnAfterFolderChange(data) {
    if (!data.result)
        return;
    
	DOpus.Output(data.tab.path);
	isInGit= DOpus.FSUtil().exists(data.tab.path+"/.git");
	if(isInGit)
		data.tab.vars.Set("isInGit", true);
	else
		data.tab.vars.Delete("isInGit");

	DOpus.Output(isInGit);
}

I use this script to set the variable isInGit. Then I add command modifier @hideif:!$tab:isInGit in my button.

My customization works but there is a delay in reading the variable. If I navigate into a git folder, the button doesn't show. If I refresh the view, the button then appears.

I believe there is an ordering issue in OnAfterFolderChange and the evaluation of button states. How do I fix it?

Should I listen to event OnBeforeFolderChange? Can @hideif monitor/observe variables? Can my JS script force refresh a button?

I'm using DO 12.33.

Add this to the script, after setting the variable:

	DOpus.Create.Command.UpdateToggle();

That should make the toolbars update for the variable change.

Details at the bottom of the Command object docs. (Opus 13 docs linked, but this works the same in 12 as well.)

1 Like

Thank you Leo, you are always so helpful!

In case you are looking for a reason to upgrade: Opus 13 can handle this with a single line.

@showif:=Exists(source + ".git")
1 Like

Cool, that's a reason for me to upgrade.

I love to see more programmability and interoperability.