Archive: How to pop up a page if a section in component page is selected?


How to pop up a page if a section in component page is selected?
Hi all,

I am new to NSIS.
Can anybody tell me how to pop up a page if a section in component page is selected? This page should not show up in the main script, otherwise it always pops up no mater the related section is selected or not.
Thanks in advance.

Jue


You can see the example "makensis.nsi"


outfile test.exe
ShowInstDetails show
InstallDir "$PROGRAMFILES\My Application"

!include logiclib.nsh

page components
page directory pre_func
page instfiles

Section "Main Application" sec1
detailprint "installing Main pplication"
SectionEnd

Section /o "!When checked enables the directory page" sec2
detailprint "Installing..."
Sectionend

Function pre_func
SectionGetFlags ${sec2} $R0
Intop $R1 $R0 | 1
${Unless} $R0 = $R1
Abort
${EndUnless}
FunctionEnd

Thank both you experts. It works.


Hi, can I have another question?

I have a custom page on which there are 2 Radiobuttons, after the selection of the 2 Radiobuttons, a component page shows up, some of the sections will be disabled or enabled based on the Radiobutton selection. How can I set the sections?
From my understanding, there is one way, such as "SectionIn RO", but it is only for compile time but runtime.
And there is another way to do it for runtime, "SetSectionFlag ${SEC_NAM} ${SF_RO}", but I tried to set it either in RadioButton page function (PageLeave) or in the relative section.
Can you experts help?
Thanks in advance.


2 examples, first is to keep sections in tact when back button is pressed and second simply disables back button.

!define CUST_INI "$PLUGINSDIR\custom.ini"
!include Logiclib.nsh
!include Sections.nsh

!define SEC1_TEXT "Section One"
!define SEC2_TEXT "Section Two"
!define SEC3_TEXT "Section Three"

outfile "test.exe"
showinstdetails show
Installdir "$PROGRAMFILES\My App"

page custom CreateCustom
page components func_pre
page directory
page instfiles

section "${SEC1_TEXT}" sec1
detailprint "section 1 selected"
sectionend

section "${SEC2_TEXT}" sec2
detailprint "section 2 selected"
sectionend

section "${SEC3_TEXT}" sec3
detailprint "section 3 selected"
sectionend

Function .onInit
InitPluginsDir

WriteINIStr "${CUST_INI}" "Settings" "NumFields" "3"

WriteINIStr "${CUST_INI}" "field 1" "type" "radiobutton"
WriteINIStr "${CUST_INI}" "field 1" "left" "30"
WriteINIStr "${CUST_INI}" "field 1" "right" "-30"
WriteINIStr "${CUST_INI}" "field 1" "top" "40"
WriteINIStr "${CUST_INI}" "field 1" "bottom" "52"
WriteINIStr "${CUST_INI}" "field 1" "Text" "Unselect and hide section 1"
WriteINIStr "${CUST_INI}" "field 1" "state" "1"
WriteINIStr "${CUST_INI}" "field 1" "flags" "GROUP"

WriteINIStr "${CUST_INI}" "field 2" "type" "radiobutton"
WriteINIStr "${CUST_INI}" "field 2" "left" "30"
WriteINIStr "${CUST_INI}" "field 2" "right" "-30"
WriteINIStr "${CUST_INI}" "field 2" "top" "60"
WriteINIStr "${CUST_INI}" "field 2" "bottom" "72"
WriteINIStr "${CUST_INI}" "field 2" "Text" "Unselect and hide section 2"
WriteINIStr "${CUST_INI}" "field 2" "state" "0"

WriteINIStr "${CUST_INI}" "field 3" "type" "radiobutton"
WriteINIStr "${CUST_INI}" "field 3" "left" "30"
WriteINIStr "${CUST_INI}" "field 3" "right" "-30"
WriteINIStr "${CUST_INI}" "field 3" "top" "80"
WriteINIStr "${CUST_INI}" "field 3" "bottom" "92"
WriteINIStr "${CUST_INI}" "field 3" "Text" "Unselect and hide section 3"
WriteINIStr "${CUST_INI}" "field 3" "state" "0"
FunctionEnd

Function CreateCustom
InstallOptions::Dialog "${CUST_INI}"
pop $0
FunctionEnd

Function func_pre
ReadINIStr $0 "${CUST_INI}" "field 1" "state"
${If} $0 = 1
!insertmacro UnselectSection ${sec1}
SectionSetText ${sec1} ""
!insertmacro SelectSection ${sec2}
SectionSetText ${sec2} "${SEC2_TEXT}"
!insertmacro SelectSection ${sec3}
SectionSetText ${sec3} "${SEC3_TEXT}"
${ElseIf} $0 = 0
ReadINIStr $1 "${CUST_INI}" "field 2" "state"
${AndIf} $1 = 1
!insertmacro UnselectSection ${sec2}
SectionSetText ${sec2} ""
!insertmacro SelectSection ${sec1}
SectionSetText ${sec1} "${SEC1_TEXT}"
!insertmacro SelectSection ${sec3}
SectionSetText ${sec3} "${SEC3_TEXT}"
${Else}
!insertmacro UnselectSection ${sec3}
SectionSetText ${sec3} ""
!insertmacro SelectSection ${sec2}
SectionSetText ${sec2} "${SEC2_TEXT}"
!insertmacro SelectSection ${sec1}
SectionSetText ${sec1} "${SEC1_TEXT}"
${EndIf}
FunctionEnd

/*
Function func_pre
GetDlgItem $R0 $HWNDPARENT 3
EnableWindow $R0 0

ReadINIStr $0 "${CUST_INI}" "field 1" "state"
${If} $0 = 1
!insertmacro UnselectSection ${sec1}
SectionSetText ${sec1} ""
${ElseIf} $0 = 0
ReadINIStr $1 "${CUST_INI}" "field 2" "state"
${AndIf} $1 = 1
!insertmacro UnselectSection ${sec2}
SectionSetText ${sec2} ""
${Else}
!insertmacro UnselectSection ${sec3}
SectionSetText ${sec3} ""
${EndIf}
FunctionEnd

Thank you very much, Red Wine. It works.

Cheers!