Archive: A newbie with a slightly complex problem


A newbie with a slightly complex problem
Hello all :)
I've been having a problem that I'm hoping someone could help me with.
I have 3 checkboxes in my menu. Lets call them 'abc', 'mno' and 'xyz'

'abc' is selected when the installer starts. 'mno' and 'xyz' BOTH start unselected.
'mno' and 'xyz' should de-select each other when one is selected but can both be unselected at the same time.
If 'abc' is unselected, 'xyz' needs to unselect AND disable itself.
If 'abc' is reselected again, 'xyz' should re-enable itself for selection.

I've had a good go at this but I've been beaten. Here is my current code on the
Function .onSelChange section. I have no idea how 'right' or 'wrong' this code is.

===============================================================

Function .onSelChange

${If} ${SectionIsSelected} ${xyz}
!insertmacro UnselectSection ${mno}
${EndIf}

${If} ${SectionIsSelected} ${mno}
!insertmacro UnselectSection ${xyz}
${EndIf}

; Works wierd. nmo will uncheck xyz but not the other way round :(


${If} ${SectionIsSelected} ${abc}

SectionSetFlags ${xyz} ${SECTION_ON}

${Else}
!insertmacro UnselectSection ${xyz}
SectionSetFlags ${xyz} ${SF_RO}

${EndIf}

===============================================================

If anyone can help me with this, I'd appreciate it very much :) I've tried to make this as easy as possible to understand
Thank you!


That is because the second if statement is influenced by the first (which deselects mno).

You will have to create global variables to store the current section selection, and check in .onSelChange which checkbox has changed.


OK, here is a working example:

Name "Test"
OutFile "Test.exe"
!include LogicLib.nsh
Page components
Page instfiles
Var Last_abc
Var Last_mno
Var Last_xyz
Section "abc" abc
SectionEnd
Section /o "mno" mno
SectionEnd
Section /o "xyz" xyz
SectionEnd
Function .oninit
StrCpy $Last_abc ${SF_SELECTED}
StrCpy $Last_mno 0
StrCpy $Last_xyz 0
FunctionEnd
Function .onSelChange
# remove all but SF_SELECTED flag
IntOp $Last_abc $Last_abc & ${SF_SELECTED}
IntOp $Last_mno $Last_mno & ${SF_SELECTED}
IntOp $Last_xyz $Last_xyz & ${SF_SELECTED}
${If} ${SectionIsSelected} ${xyz}
${AndIf} $Last_xyz != ${SF_SELECTED}
!insertmacro UnselectSection ${mno}
${EndIf}
${If} ${SectionIsSelected} ${mno}
${AndIf} $Last_mno != ${SF_SELECTED}
!insertmacro UnselectSection ${xyz}
${EndIf}
${If} ${SectionIsSelected} ${abc}
${If} $Last_abc != ${SF_SELECTED}
SectionSetFlags ${xyz} ${SF_SELECTED}
${EndIf}
${Else}
${If} $Last_abc == ${SF_SELECTED}
!insertmacro UnselectSection ${xyz}
SectionSetFlags ${xyz} ${SF_RO}
${EndIf}
${EndIf}
SectionGetFlags ${abc} $Last_abc
SectionGetFlags ${mno} $Last_mno
SectionGetFlags ${xyz} $Last_xyz
FunctionEnd

Thank you so much jpderuiter :) this code worked a treat.

I found something I forgot to state in my Original Post though but was able to fix it.

${If} ${SectionIsSelected} ${abc}

${If} $Last_abc != ${SF_SELECTED}

SectionSetFlags ${xyz} ${SF_SELECTED}

${EndIf}

${Else}

I found that this code was making the checkbox selected on re-enabling it. The user is then able to select mno without xyz getting unchecked.

I just added this line to it under the SectionSetFlags

        !insertmacro UnselectSection ${xyz}

And now whenever the checkbox is re-enabled, it deselects itself and can no longer be installed along with xyz

Thank you very much for your time :)

Back again with a very small problem this time.

I have the exact same kind of code as before but this time, how would I go about having XYZ unchecked and disabled immediately on arriving to the Components page? ABC is still selected and checked at the start.

Thank you!


Add

SectionSetFlags ${xyz} ${SF_RO}
in the .oninit function.

That did the trick thank you again :)