Archive: group exclusion


group exclusion
A recent post by Red Wine (here) gave me some much-needed clues about the quirks of using RadioButtons for selecting sections, but I'm really struggling with setting up some exclusion logic.

Basically, I have several sets of optional sections that are mutually exclusive. The exclusion itself isn't the problem, per se. The problem is that the first call to UnSelectSection seems to also inadvertently deselect the first section, even though that section is required (RO) and never referenced by any of the RadioButton logic.

Why does it do this and how can I work around it?

I can sort of get around the problem with an ugly hack to repeatedly SelectSection ${Required}, but this doesn't work well if there's a choice to be made in the required sectiongroup, so it's really not a solution.

My actual code is quite long, so for the sake of brevity and clarity I have replicated the issue using a modified version of Red Wine's script. To test it, check whatever options you want in the first two sectiongroups, then pick something in the last sectiongroup (grp3), then scroll back up to the top and you'll see that the Required section has somehow become deselected. I've commented out the aforementioned ugly hack.

Any help would be greatly appreciated.



; group-exlude.nsi
;
; This example demonstrates the problem with exclusive control
; of section selection.

;--------------------------------

; Section define/macro header file
; See this header file for more info

!include "Sections.nsh"
!include "logiclib.nsh"

;--------------------------------

Name "Group Exclusion Problem"
OutFile "group-exlude.exe"

;--------------------------------

; Pages

Page components

;--------------------------------

; Sections

Section !Required Required
SectionIn RO
SectionEnd

SectionGroup /e "Group 1" grp1
Section "Group 1 - Option 1" g1o1
SectionEnd

Section /o "Group 1 - Option 2" g1o2
SectionEnd

Section /o "Group 1 - Option 3" g1o3
SectionEnd
SectionGroupEnd

SectionGroup /e "Group 2" grp2
Section "Group 2 - Option 1" g2o1
SectionEnd

Section /o "Group 2 - Option 2" g2o2
SectionEnd

Section /o "Group 2 - Option 3" g2o3
SectionEnd
SectionGroupEnd

SectionGroup /e "Group 3 - excludes Group 2" grp3
Section /o "Group 3 - Option 1" g3o1
SectionEnd

Section /o "Group 3 - Option 2" g3o2
SectionEnd

Section /o "Group 3 - Option 3" g3o3
SectionEnd

Section /o "Do Not Use Group 3" g3NONE
SectionEnd

SectionGroupEnd

;--------------------------------

; Functions

; $1 stores the status of group 1
; $2 stores the status of group 2

Function .onInit

StrCpy $1 ${g1o1} ; Group 1 - Option 1 is selected by default
StrCpy $2 ${g2o1} ; Group 2 - Option 1 is selected by default

FunctionEnd

Function .onSelChange

SectionGetFlags ${grp1} $R0
IntOp $R0 $R0 & ${SF_SELECTED}

${If} $R0 == ${SF_SELECTED}
!insertmacro SelectSection ${g1o1}
!insertmacro UnSelectSection ${g1o2}
!insertmacro UnSelectSection ${g1o3}
${EndIf}

!insertmacro StartRadioButtons $1
!insertmacro RadioButton ${g1o1}
!insertmacro RadioButton ${g1o2}
!insertmacro RadioButton ${g1o3}
!insertmacro EndRadioButtons

SectionGetFlags ${grp2} $R0
IntOp $R0 $R0 & ${SF_SELECTED}

${If} $R0 == ${SF_SELECTED}
!insertmacro SelectSection ${g2o1}
!insertmacro UnSelectSection ${g2o2}
!insertmacro UnSelectSection ${g2o3}
${EndIf}

!insertmacro StartRadioButtons $2
!insertmacro RadioButton ${g2o1}
!insertmacro RadioButton ${g2o2}
!insertmacro RadioButton ${g2o3}
!insertmacro EndRadioButtons

SectionGetFlags ${grp3} $R0
IntOp $R0 $R0 & ${SF_SELECTED}

${If} $R0 == ${SF_SELECTED}
!insertmacro SelectSection ${g3o1}
!insertmacro UnSelectSection ${g3o2}
!insertmacro UnSelectSection ${g3o3}
!insertmacro UnSelectSection ${g3NONE}
!insertmacro UnSelectSection ${grp2}
#!insertmacro SelectSection ${Required}
${EndIf}

${If} ${SectionIsSelected} ${g3o1}
!insertmacro UnSelectSection ${grp2}
!insertmacro StartRadioButtons $3
!insertmacro RadioButton ${g3o1}
!insertmacro RadioButton ${g3o2}
!insertmacro RadioButton ${g3o3}
!insertmacro RadioButton ${g3NONE}
!insertmacro EndRadioButtons
#!insertmacro SelectSection ${Required}

${ElseIf} ${SectionIsSelected} ${g3o2}
!insertmacro UnSelectSection ${grp2}
!insertmacro StartRadioButtons $3
!insertmacro RadioButton ${g3o1}
!insertmacro RadioButton ${g3o2}
!insertmacro RadioButton ${g3o3}
!insertmacro RadioButton ${g3NONE}
!insertmacro EndRadioButtons
#!insertmacro SelectSection ${Required}

${ElseIf} ${SectionIsSelected} ${g3o3}
!insertmacro UnSelectSection ${grp2}
!insertmacro StartRadioButtons $3
!insertmacro RadioButton ${g3o1}
!insertmacro RadioButton ${g3o2}
!insertmacro RadioButton ${g3o3}
!insertmacro RadioButton ${g3NONE}
!insertmacro EndRadioButtons
#!insertmacro SelectSection ${Required}

${ElseIf} ${SectionIsSelected} ${g3NONE}
!insertmacro UnSelectSection ${g3NONE}
!insertmacro UnSelectSection ${grp3}
#!insertmacro SelectSection ${Required}
${EndIf}

FunctionEnd

Nice code dev_akm :)
Add the following line to function .onInit to resolve the referred issue,

  StrCpy $3 ${g3o1} ; Group 3 - Option 1 is selected by default

Originally posted by Red Wine
Nice code dev_akm :)
Add the following line to function .onInit to resolve the referred issue,
  StrCpy $3 ${g3o1} ; Group 3 - Option 1 is selected by default
Thanks for the reply. Seems obvious, now that you mention it. :-)

However, I'm doing this already in my actual code and it's not helping.

I will experiment further and post a followup if I can replicate the issue in your example code.

Thanks again!