redxii
24th February 2010 21:13 UTC
nsDialogs radiobuttons default state
I am trying to follow this example for radiobuttons:
http://nsis.sourceforge.net/NsDialog...ton_selections
I have been all through the Googlenets. I am not too familiar with nsDialogs and am running into trouble:
1) I want the first radio button to be selected by default. I can do this with SendMessage or NSD_SetState or NSD_Check but they all have the same problem: if the user simply clicks Next, it will not work, $MPLAYER_VERSION is supposed to return 'mplayer-svn-30369' for the first choice but it will be simply blank. I have to click on the first choice even if it is already checked for it to work.
2) Remember what the user selected if they leave the page and come back. I read the readme and am unsure how to apply it to the code. Maybe a bump in the right direction...
redxii
24th February 2010 21:14 UTC
Script. Doesn't require any other files.
Afrow UK
24th February 2010 21:55 UTC
Instead of deciding on what radio button has been selected when they click on them, just check which radio button is selected in the page leave function.
No need for Get/SetUserdata either.
Edit: And you can store which radio button was selected (maybe a numeric value) in another variable then use that value to set the check state again on page creation.
Stu
redxii
24th February 2010 23:24 UTC
I got it to work. If the user presses Next without clicking the default choice it will register properly and to remember the choice when going back to the page.
; The name of the installer
Name "MPlayer"
; The file to write
OutFile "mp-inst.exe"
; Request application privileges for Windows Vista
RequestExecutionLevel user
InstallDir "$DESKTOP"
ShowInstDetails show
!include MUI2.nsh
!include LogicLib.nsh
!include nsDialogs.nsh
Var MPLAYER_486GENERIC
Var MPLAYER_AMDMULTI
Var MPLAYER_INTELMULTI
Var MPLAYER_SELECTION_STATE
Var MPLAYER_VERSION
;--------------------------------
; Pages
!insertmacro MUI_PAGE_DIRECTORY
Page custom PageMPlayerBuild PageMPlayerBuildLeave
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
;--------------------------------
!insertmacro MUI_LANGUAGE "English"
Function PageMPlayerBuild
nsDialogs::Create /NOUNLOAD 1018
Pop $0
!insertmacro MUI_HEADER_TEXT "Choose MPlayer Build" "Choose which MPlayer build you would like to install."
${NSD_CreateLabel} 0 0 100% 10u "Select the MPlayer build you would like to install and click Install to continue."
${NSD_CreateRadioButton} 10 35 100% 10u "Generic i486 or better (CPU Runtime Detection)"
Pop $MPLAYER_486GENERIC
${NSD_AddStyle} $MPLAYER_486GENERIC ${WS_GROUP}
${NSD_CreateLabel} 26 55 100% 20u "Generic build for all x86/x86-64 CPUs using runtime cpudetection.$\nIf you are unsure, select this build."
${NSD_CreateRadioButton} 10 95 100% 10u "AMD Multicore (X2/X3/X4/Phenom)"
Pop $MPLAYER_AMDMULTI
${NSD_CreateLabel} 26 115 100% 20u "Optimized for multicore AMD processors using experimental multithreaded$\nFFmpeg-mt branch."
${NSD_CreateRadioButton} 10 155 100% 10u "Intel Multicore (P4EE/P4D/Xeon/Core2/i7/etc)"
Pop $MPLAYER_INTELMULTI
${NSD_CreateLabel} 26 175 100% 20u "Optimized for multicore Intel processors using experimental multithreaded$\nFFmpeg-mt branch."
${If} $MPLAYER_SELECTION_STATE = 1
SendMessage $MPLAYER_486GENERIC ${BM_SETCHECK} 1 0
${ElseIf} $MPLAYER_SELECTION_STATE = 2
SendMessage $MPLAYER_AMDMULTI ${BM_SETCHECK} 1 0
${ElseIf} $MPLAYER_SELECTION_STATE = 3
SendMessage $MPLAYER_INTELMULTI ${BM_SETCHECK} 1 0
${Else}
SendMessage $MPLAYER_486GENERIC ${BM_SETCHECK} 1 0
${EndIf}
nsDialogs::Show
FunctionEnd
Function PageMPlayerBuildLeave
${NSD_GetState} $MPLAYER_486GENERIC $R0
${NSD_GetState} $MPLAYER_AMDMULTI $R1
${NSD_GetState} $MPLAYER_INTELMULTI $R2
${If} $R0 = 1
StrCpy $MPLAYER_VERSION "mplayer-svn-30369"
StrCpy $MPLAYER_SELECTION_STATE 1
${ElseIf} $R1 = 1
StrCpy $MPLAYER_VERSION "mplayer-amd-30687-mt"
StrCpy $MPLAYER_SELECTION_STATE 2
${ElseIf} $R2 = 1
StrCpy $MPLAYER_VERSION "mplayer-intel-30687-mt"
StrCpy $MPLAYER_SELECTION_STATE 3
${EndIf}
FunctionEnd
; The stuff to install
Section "MPlayer" ;No components page, name is not important
; Set output path to the installation directory.
DetailPrint "$R0 $R1 $R2"
DetailPrint "MPLAYER_VERSION: $MPLAYER_VERSION"
DetailPrint "MPLAYER_SELECTION_STATE: $MPLAYER_SELECTION_STATE"
SectionEnd ; end the section
Afrow UK
24th February 2010 23:28 UTC
Spot on!
Stu