Archive: SelectSection


SelectSection
Hi guys,

I'm looking for a way for one section to turn on a bunch of others when enabled.

Currently I'm looking at the SelectSection macro in Section.nsh, and doing something like this:

Section "First section"
!insertmacro SelectSection TEST
SectionEnd

Section "Second section" TEST
MessageBox MB_OK "Enabled!"
SectionEnd


When I turn on the first section and hit next I expect to see the second section run, because the first section should have enabled it. This doesn't seem to be the case though.

Any ideas where I'm going wrong, or alternative solutions for achieving the desired functionality?


The 'one-section.nsi' in the examples directory should give you some ideas.

Vytautas :)


TEST is parsed as 0 because NSIS expects a number for what the SelectSection macro uses. You should use ${TEST}. Another problem is that TEST will not be defined at that point so you'd need to define a function after the second section. That function should enable that section and should be called from the first section.


kichik: Firstly, thanks for actually offering some help, and not simply pointing me at an example file already referenced in the usage notes....

Second, perhaps you can help me understand how parameters are passed. If I look at the SelectSection macro code I see this:

!macro SelectSection SECTION

Push $0
SectionGetFlags "${SECTION}" $0
IntOp $0 $0 | ${SF_SELECTED}
SectionSetFlags "${SECTION}" $0
Pop $0


Which lead me to believe that SECTION should be the section name, not enclodes in ${}, since this is already added in the macro code. Obviously this isn't the case :)

It seems that one section can't enable another? I can make SelectSection work when I call it from a callback like .onSelChange, but I think there is an ordering problem.

You say I can't use TEST until it has been defined, so I can't try to enable the TEST section until after its already been processed, which means even if I enable it, it won't run...

Its kind of annoying that there is no callback that occurs right when the user leaves the components page but before sections are actually processed to enable you to manage this kind of thing. It makes my problem a lot harder...


Section "First section"
Call SelectSecond
SectionEnd

Section "Second section" TEST
MessageBox MB_OK "Enabled!"
SectionEnd

Function SelectSecond
!insertmacro SelectSection ${TEST}
FunctionEnd

Macro parameters are passed defines. For example:

!macro echo msg
DetailPrint "${msg}"
!macroend
!insertmacro echo "a message"
will translate into
DetailPrint "a message"
You can think of the !insertmacro lines as:
!define msg "a message"
DetailPrint "${msg}"
As for one section enabling another, you can use the function trick I talked about and Joost demonstrated.