fishsauce
3rd April 2007 08:47 UTC
Weird section validation
I'm having problems with trying to activate/deactivate components/sections depending on what the user selects.
I have 4 sections:
- Section 0 (Read only, always selected)
- Section 1
- Section 2
- Section 3 (This section is independent of the others)
The thing is section 1 is a dependency of section 2, so when section 2 is selected I want section 1 to be selected automatically, and when section 1 is deselected I want section 2 to be deselected automatically as well. However, section 1 should also be free of section 2 in that when section 2 is not selected, section 1 can still be selected anyways.
So far I've only been able to get the two to be selected/deselected at the same time based on what I've found in this board and in the docs, but I haven't been able to let section 1 be selected when section 2 is not selected. Also this only allows one of the sections to be checked/unchecked; the other is always locked in the checked state, which is undesirable. I should probably note that the NSIS logic syntax feels awkward to me so I might be missing something that is really simple.
Here's my code (all section flags are initially set to the checked state):
Function .onSelChange
Push $0
SectionGetFlags ${Section2} $0
IntOp $0 $0 & ${SF_SELECTED}
SectionsetFlags ${Section1} $0
Pop $0
FunctionEnd
Thanks in advance for your help!
kichik
3rd April 2007 09:21 UTC
You have two mistakes here. The first being always setting section1's flags to the same value of section2's. The second is that you set only the SF_SELECTED flag and remove all the rest.
What you should do is get section2's flags, check if SF_SELECTED is on. If it is, get section1's flags, add SF_SELECTED to it and set the flags to the new value.
You can do all that very simply with Sections.nsh.
!include LogicLib.nsh
!include Sections.nsh
Function .onSelChange
${If} ${SectionIsSelected} ${Section2}
!insertmacro SelectSection ${Section1}
${EndIf}
FunctionEnd
fishsauce
4th April 2007 06:08 UTC
Thanks! I got it partially working with this code (the macros didn't seem to want to work so I wrote it out by hand)
Function .onSelChange
Push $0
${If} ${SectionIsSelected} ${Section2}
SectionGetFlags ${Section1} $0
IntOp $0 $0 | ${SF_SELECTED}
SectionSetFlags ${Section1} $0
${EndIf}
Pop $0
FunctionEnd
However, this locks the Section1 checkbox whenever Section2 is enabled. Is it possible to uncheck Section2 when the Section1 checkbox is cleared? It seems kind of hard because NSIS doesn't seem to know which checkbox is clicked, so the two conditions conflict.
Thanks!
kichik
8th April 2007 16:45 UTC
You can probably do that if you remember the state of Section1 in .onSelChange. If it's changed from unselected to selected, select Section2. If it hasn't changed, do nothing.