Archive: onSelChange


onSelChange
I have a modern NSIS installer with 3 sections called, lets say:

Section "1"
Section "2"
Section "3"

- Section 2 is needed for section 3 to work.

If user only choose section 3 in the component page, then I want the installer to choose section 2 also automatic. How can I do that? Can somebody maybe give an example of the onSelChange function with these requests?


Examples\one-section.nsi is the example you're looking for. In your specific case you need to preform these steps in .onSelChange:
1) Get the flags of Section 3
2) If the flags do not contain SF_SELECTED skip steps 3
3) Add ${SF_SELECTED} to the flags of Section 2


I was a little to fast there, thx alot!


Damn, can't get it to work. Do somebody have a simple example of this onSelChange with the content like above?


SectionGetFlags ${sec3} $0
IntOp $0 $0 & ${SF_SELECTED}
StrCmp $0 ${SF_SELECTED} 0 skip
SectionGetFlags ${sec2} $1
IntOp $1 $1 | ${SF_SELECTED}
SectionSetFlags ${sec2} $1
skip:

thx, but still can't get it to work. I have copy/paste my code here, so you can see what Im doing wrong. - and by the way, you really know your stuff kichik, so its great that you can help. Thanks alot!

[edit by kichik]please attach large scripts. attached below :down:[/edit]


You don't need that other code in .onSelChange, only the code that I gave you in the post above. Also, your defines are wrong. You should use Sections.nsh instead of defining your own values. Add !include "Sections.nsh" and remove !define SF_SELECTED, SECTION_ON and SECTION_OFF.

by the way, you really know your stuff kichik, so its great that you can help. Thanks alot!
Glad I could help :D

Attached is the original code.

Great, thanks. But it comes with an error for me, but think the problem is my NSIS installation, since I looked other places in this forum where same line is included. It is this one:

Error: Could not find Sections.nsh.

- Is it my NSIS installation which is wrong or? Like Im missing the file. Look for the file in whole NSIS folder without result.


Seems like you're using an old version. Upgrade to b3 and then use NSIS Update to get the latest CVS version.


:D thx


I have all components optional. This way when I choose some component for the first time .onSelChange doesn`t fire. How to hack it?


bad post, see next one :)


None of these codes don`t work:


!define component_index 0

Function .onSelChange

!insertmacro StartRadioButtons $1

${If} ${SectionIsSelected} 1

!undef component_index

!define component_index 1

${EndIf}


In this one component_index is still == 0.


Function .onSelChange

!insertmacro StartRadioButtons $1

${If} ${SectionIsSelected} 1

StrCpy $component_index 1

${EndIf}


And in this one compiler cry :

!insertmacro: end of StartRadioButtons
!insertmacro: _If
!insertmacro: end of _If
Usage: StrCpy $(user_var: output) str [maxlen] [startoffset]
Error in script "C:\Documents and Settings\1\?aai?ee noie\winamp.nsi" on line 146 -- aborting creation process


Can you please fix it.

Function .onSelChange
Var /global component_index
!insertmacro StartRadioButtons $1

${If} ${SectionIsSelected} 1

StrCpy $component_index 1

${EndIf}
FunctionEnd

When I paste


MessageBox MB_ICONEXCLAMATION|MB_OK ${component_index}


at the end of .onSelChange


${EndIf}
MessageBox MB_ICONEXCLAMATION|MB_OK ${component_index}
FunctionEnd


compiler says :

unknown variable/constant "{component_index}" detected, ignoring (C:\Documents and Settings\1\?aai?ee noie\winamp.nsi:181)


So how to get the value of just set variable and see if it`s ok in alert window?

Use $component_index, do not use ${component_index}. The first gets a variable's value, the latter gets a defined constant (and the compiler error message is telling you that there is no defined constant with that name).


thanks, i`ve tried it earlier and it didn`t work. but now it`s ok. maybe context have changed.


I have a question that is still unanswered:

I have all components optional. This way when I choose some component for the first time .onSelChange doesn`t fire. How to hack it?
Am I the only one experiencing this problem or nobody really doesn`t know the answer?

Or it`s not bug but feature :)? Maybe you can tell me how to make one section optional but still checked by default on components page.

tell me how to make one section optional but still checked by default
Don't add anything to the section statement. Just use Section "Some Text".
Here's the way it works:
Section "Main Code" Section1
# this section starts checked but can be changed.
SectionEnd

Section /o "Add-Ons" Section2
# this section starts unchecked but can be changed.
SectionEnd

Section "Support Files" Section3
Sectionin RO
# this section will always be executed. the user cannot uncheck it.
SectionEnd

Section /o "Dead Code" Section4
Sectionin RO
# this section will only be executed if your script changes the section flags.
SectionEnd
There's much more you can do with these, look in section 4.6.1.2 of the manual.

Don

i`ve tried this variant as well. and it didn`t work as well.
i wonder what have i changed.

is there any difference in sections scripting when i use


Page components


or


!insertmacro MUI_PAGE_COMPONENTS


?

I just took a look at the MUI macro code, and I don't see how using 'Page components' instead of '!insertmacro MUI_PAGE_COMPONENTS' will affect the sections.

Don