diff --git a/Examples/one-section.nsi b/Examples/one-section.nsi index df5c1cc8..3e1a9c78 100644 --- a/Examples/one-section.nsi +++ b/Examples/one-section.nsi @@ -48,11 +48,11 @@ Function .onInit FunctionEnd Function .onSelChange - Push $0 - !ifdef USE_SUBSECTION ; Check if the user have selected all of the sections using the sub-section ; This piece of code is not needed when there are only two sections + Push $0 + SectionGetFlags ${subsec} $0 IntOp $0 $0 & ${SF_SELECTED} StrCmp $0 0 skip @@ -61,40 +61,14 @@ Function .onSelChange SectionSetFlags ${sec3} 0 SectionSetFlags ${sec4} 0 skip: + + Pop $0 !endif - ; Turn off old selected section - SectionGetFlags $1 $0 - IntOp $0 $0 & ${SECTION_OFF} - SectionSetFlags $1 $0 - # !insertmacro UnselectSection $1 - - ; Now remember the current selection - Push $2 - StrCpy $2 $1 - - SectionGetFlags ${sec1} $0 - IntOp $0 $0 & ${SF_SELECTED} - IntCmp $0 ${SF_SELECTED} 0 +2 +2 - StrCpy $1 ${sec1} - SectionGetFlags ${sec2} $0 - IntOp $0 $0 & ${SF_SELECTED} - IntCmp $0 ${SF_SELECTED} 0 +2 +2 - StrCpy $1 ${sec2} - SectionGetFlags ${sec3} $0 - IntOp $0 $0 & ${SF_SELECTED} - IntCmp $0 ${SF_SELECTED} 0 +2 +2 - StrCpy $1 ${sec3} - SectionGetFlags ${sec4} $0 - IntOp $0 $0 & ${SF_SELECTED} - IntCmp $0 ${SF_SELECTED} 0 +2 +2 - StrCpy $1 ${sec4} - - StrCmp $2 $1 0 +4 ; selection hasn't changed - SectionGetFlags $1 $0 - IntOp $0 $0 | ${SF_SELECTED} - SectionSetFlags $1 $0 - # !insertmacro SelectSection $1 - Pop $2 - Pop $0 + !insertmacro StartRadioButtons $1 + !insertmacro RadioButton ${sec1} + !insertmacro RadioButton ${sec2} + !insertmacro RadioButton ${sec3} + !insertmacro RadioButton ${sec4} + !insertmacro EndRadioButtons FunctionEnd \ No newline at end of file diff --git a/Include/Sections.nsh b/Include/Sections.nsh index 86b7f32c..b32a5191 100644 --- a/Include/Sections.nsh +++ b/Include/Sections.nsh @@ -45,49 +45,58 @@ # macros for mutually exclusive section selection # written by Tim Gallagher -#### usage example: +#### usage example (see one-section.nsi too): +# Var SomeVar +# # Function .onSelChange -# !insertmacro StartRadioButtons +# !insertmacro StartRadioButtons $SomeVar # !insertmacro RadioButton ${sec1} # !insertmacro RadioButton ${sec2} # !insertmacro RadioButton ${sec3} # !insertmacro EndRadioButtons # FunctionEnd - +# # Function .onInit -# !insertmacro UnselectSection ${sec1} +# StrCpy $SomeVar ${sec1} ; default section # !insertmacro UnselectSection ${sec2} # !insertmacro UnselectSection ${sec3} # FunctionEnd -# starts the Radio Button Block -!macro StartRadioButtons - Push $0 - SectionGetFlags $1 $0 - IntOp $0 $0 & ${SECTION_OFF} - SectionSetFlags $1 $0 +# Starts the Radio Button Block. +# You should pass a variable that keeps the selected section +# as the first parameter for this macro. This variable should +# be initialized to the default section's index. As this macro +# uses $R0 and $R1 you can't use those two as the varible +# which will keep the selected section. +!macro StartRadioButtons var +!define StartRadioButtons_Var "${var}" + Push $R0 + SectionGetFlags "${StartRadioButtons_Var}" $R0 + IntOp $R0 $R0 & ${SECTION_OFF} + SectionSetFlags "${StartRadioButtons_Var}" $R0 - Push $2 - StrCpy $2 $1 + Push $R1 + StrCpy $R1 "${StartRadioButtons_Var}" !macroend !macro RadioButton SECTION_NAME - SectionGetFlags ${SECTION_NAME} $0 - IntOp $0 $0 & ${SF_SELECTED} - IntCmp $0 ${SF_SELECTED} 0 +2 +2 - StrCpy $1 ${SECTION_NAME} + SectionGetFlags ${SECTION_NAME} $R0 + IntOp $R0 $R0 & ${SF_SELECTED} + IntCmp $R0 ${SF_SELECTED} 0 +2 +2 + StrCpy "${StartRadioButtons_Var}" ${SECTION_NAME} !macroend # ends the radio button block !macro EndRadioButtons - StrCmp $2 $1 0 +4 ; selection hasn't changed - SectionGetFlags $1 $0 - IntOp $0 $0 | ${SF_SELECTED} - SectionSetFlags $1 $0 + StrCmp $R1 "${StartRadioButtons_Var}" 0 +4 ; selection hasn't changed + SectionGetFlags "${StartRadioButtons_Var}" $R0 + IntOp $R0 $R0 | ${SF_SELECTED} + SectionSetFlags "${StartRadioButtons_Var}" $R0 - Pop $2 - Pop $0 + Pop $R1 + Pop $R0 +!undef StartRadioButtons_Var !macroend ; For details about SetSectionInInstType and ClearSectionInInstType, see