Archive: toggle bold on/off


toggle bold on/off
Does anyone here know how to make a function to toggle SF_BOLD on/off for a SectionGroup without any negative side-effects?

I've tried numerous variations of the suggested SectionGetFlags, IntOp, SectionSetFlags combinations without success.

For example, I have two required main files, one of which has no options and one of which has a lot of options. So, it works great if I do simple code like:


Function .onSelChange
${If} ${SectionIsSelected} ${MainFileNoOptions}
!insertmacro UnSelectSection ${OptionGroup}
${EndIf}
FunctionEnd


This prevents selection of anything in the OptionGroup if MainFileNoOptions is selected. Thus, if MainFileWithOptions is selected, then the test fails and I can pick things from the OptionGroup.

Great, but I'd also like to indicate whether the OptionGroup is active or not by making it bold if you can use it, non-bold if you can't use it. So, if I expand the logic to say something like:


Function .onSelChange
${If} ${SectionIsSelected} ${MainFileNoOptions}
!insertmacro UnSelectSection ${OptionGroup}
SectionGetFlags ${OptionGroup} $R0
IntOp $R0 $R0 - ${SF_BOLD}
SectionSetFlags ${OptionGroup} $R0
${ElseIf} ${SectionIsSelected} ${MainFileWithOptions}
SectionGetFlags ${OptionGroup} $R0
IntOp $R0 $R0 + ${SF_BOLD}
SectionSetFlags ${OptionGroup} $R0
${EndIf}
FunctionEnd


Then it adds/removes SF_BOLD correctly when I toggle between MainFileNoOptions and MainFileWithOptions, but now OptionGroup stops working correctly (clicking any of the sections inside it merely toggles the bold on/off and nothing can be selected because the SectionSetFlags command is blocking my change attempts).

Any suggestions would be greatly appreciated. Thanks!

FYI, I also tried this:


Function .onSelChange
${If} ${SectionIsSelected} ${MainFileNoOptions}
!insertmacro UnSelectSection ${OptionGroup}
!insertmacro ClearSectionFlag ${OptionGroup} ${SF_BOLD}
${ElseIf} ${SectionIsSelected} ${MainFileWithOptions}
!insertmacro SetSectionFlag ${OptionGroup} ${SF_BOLD}
${EndIf}
FunctionEnd


And it works a bit better, but still prevents me from selecting anything in the OptionGroup.

Don't use plus and minus. Use bitwise or and bitwise and. You have the SetSectionFlag and ClearSectionFlag macros to handle that for you.

Since setting the flags of a section group also sets the flags of its children and there's no way to prevent that, you'd have to remember the flags of those sections manually.

Function .onSelChange
SectionGetFlags ${a} $0
SectionGetFlags ${b} $1
${If} ${SectionIsSelected} ${MainFileNoOptions}
!insertmacro UnSelectSection ${OptionGroup}
!insertmacro ClearSectionFlag ${OptionGroup} ${SF_BOLD}
${ElseIf} ${SectionIsSelected} ${MainFileWithOptions}
!insertmacro SetSectionFlag ${OptionGroup} ${SF_BOLD}
${EndIf}
SectionSetFlags ${a} $0
SectionSetFlags ${b} $1
FunctionEnd

Thanks for the reply.

Sounds like it's more trouble than it's worth, especially since the SectionGroup loses any ability to track the state of the children once you force it to SF_BOLD.

It's really too bad NSIS doesn't use something more like an XHTML DOM

Although I suppose there's probably good reasons for the way the section and sectiongroup properties are handled, it's very cumbersome and frustrating to work with when you're trying to do anything out of the norm.