ryanpager
21st July 2009 15:32 UTC
Only allowing 1 component per install?
Is there a way to disable the ability to chose more than 1 component everytime someone wants to do the install.
Reason being, as this is acting as a 4 in 1 installer, and they should only be able to install 1 at a time.
Thanks,
Ryan
jpderuiter
21st July 2009 17:19 UTC
You can use .onSelChange (Manual chapter 4.7.2.1.8).
This function is called when the user changes the selection.
Then find out which component is selected with SectionGetFlags (Manual chapter 4.9.13.2).
(You have to remember what component was selected previously).
Then use SectionSetFlags to select this component only.
Afrow UK
21st July 2009 17:54 UTC
Check out Examples\one-section.nsi
Stu
ryanpager
21st July 2009 20:11 UTC
This is what I have so far, its working for the most part. The only problem I am having, is that I need the default to be all "off/unselected" rather than all selected from the start.
Ideas? Here is my code
Function .onInit
!insertmacro MUI_LANGDLL_DISPLAY
StrCpy $1 ${SEC01} ; Group 1 - Option 1 is selected by default
StrCpy $2 ${SEC02}
StrCpy $3 ${SEC03}
StrCpy $4 ${SEC04}
FunctionEnd
Function .onSelChange
!insertmacro StartRadioButtons $1
!insertmacro RadioButton ${SEC01}
!insertmacro RadioButton ${SEC02}
!insertmacro RadioButton ${SEC03}
!insertmacro RadioButton ${SEC04}
!insertmacro EndRadioButtons
FunctionEnd
jpderuiter
21st July 2009 20:28 UTC
OK, I didn't know about these macro's.
Makes it easier ;-)
Well, obviously you have to make all sections unselected by default, by adding the /o flag for each section:
; Sections
Section /o "Option 1" SEC01
SectionEnd
Section /o "Option 2" SEC02
SectionEnd
Section /o "Option 3" SEC03
SectionEnd
Section /o "Option 4" SEC04
SectionEnd
;--------------------------------
; Functions
Function .onInit
!insertmacro MUI_LANGDLL_DISPLAY
StrCpy $1 ${SEC01} ; Group 1 - Option 1 is selected by default
FunctionEnd
Function .onSelChange
!insertmacro StartRadioButtons $1
!insertmacro RadioButton ${SEC01}
!insertmacro RadioButton ${SEC02}
!insertmacro RadioButton ${SEC03}
!insertmacro RadioButton ${SEC04}
!insertmacro EndRadioButtons
FunctionEnd
BTW, you only need to have ${SEC01} copied to $1 in onInit.
This is where the previous selected section is stored.
ryanpager
21st July 2009 20:53 UTC
Got it, all I needed to do was add the /o!
Thanks!
Afrow UK
21st July 2009 23:45 UTC
One problem there is once the user has clicked one of the components he's forced to install one of them. You may want to add an additional empty section in the group that the user can select.
Stu