Old 5th January 2009, 11:28   #1
hanschen
Junior Member
 
Join Date: Jan 2009
Posts: 6
If section is checked, show fields

I haven't been able to find what I'm looking for. It could be that I'm searching wrong as my English isn't the best.

Anyways, here is my problem:

I've created an installer and now there have to be some extra options. I have 4 sections and 4 fields which have to write in 2 files. A .txt file and a .cmd file.

The first 2 fields aren't a problem as they need to be filled in always. But the last to 2 fields should be hidden or grayed-out when sec04 is unchecked.

So SEC04 brings the .cmd file and then the last 2 fields are needed to fill in.

PHP Code:
!insertmacro MUI_INSTALLOPTIONS_WRITE "ihm.ini" "Field 6" "State" $HOST   
!insertmacro MUI_INSTALLOPTIONS_WRITE "ihm.ini" "Field 2" "State" $SERVER  
!insertmacro MUI_INSTALLOPTIONS_WRITE "ihm.ini" "Field 8" "State" $DLC   
!insertmacro MUI_INSTALLOPTIONS_WRITE "ihm.ini" "Field 10" "State" $DBMTC 
PHP Code:
Section "MM" SEC04 
So what I was thinking was something like if SEC04 is Checked then show the last 2 fields: Field 8 en Field 10.

Attached is a picture of the four fields I'm reffering to.
I hope you can help me with my sucky english :-)

If you have any questions left, let me know!
Attached Images
File Type: jpg fg.jpg (14.2 KB, 142 views)
hanschen is offline   Reply With Quote
Old 5th January 2009, 13:10   #2
Animaether
Major Dude
 
Join Date: Jun 2001
Posts: 1,173
should be simple enough... use SectionGetFlags or the Sections header to check if section ${SEC04} is selected or not.
If it is not selected, then use EnableWindow <control hwnd> 0 or ShowWindow <control hwnd> 0 to disable/hide the two controls.

Depending on what you use to build the custom page, getting the control hwnd is either as simple as accessing the variable (NSDialogs), or as 'complex' as using ReadIniStr for InstallOptions(2/Ex), to completely fudging it yourself using GetDlgItem <parent dialog> <control id>.

Edit: Quick example (NSDialogs)
code:

!include MUI.nsh
!include nsDialogs.nsh

OutFile "c:\testsetup.exe"

Page Components
Page Custom fnCreate

!insertmacro MUI_LANGUAGE "English"

Var CHECKBOX

Section "Hello" Hello
SectionEnd

Function fnCreate
nsDialogs::Create /NOUNLOAD 1018
Pop $0

${NSD_CreateCheckbox} 0 -50 100% 8u "Test"
Pop $CHECKBOX

SectionGetFlags ${Hello} $0
IntOp $0 $0 & 1 ; 1 == selected

IntCmp $0 1 _check _uncheck
_check:
${NSD_SetState} $CHECKBOX 1
goto _done
_uncheck:
${NSD_SetState} $CHECKBOX 0
_done:
nsDialogs::Show
FunctionEnd


Last edited by Animaether; 5th January 2009 at 14:01.
Animaether is offline   Reply With Quote
Old 5th January 2009, 13:30   #3
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Instead of using labels, just use LogicLib:

code:
${If} ${SectionIsSelected} ${SectionId}
...
${Else}
...
${EndIf}



Also make sure you put this code after you define the section in your script - Animaether's code references a section with an id of ${Hello} before the actual section is defined in the script. This will not work.

I should also point out that (although if you use LogicLib, then this doesn't matter) Animaether has used the wrong operator with IntOp. It should be a single ampersand (&) and not two (&&). Two ampersands being a logical AND rather than a binary AND.

Stu
Afrow UK is offline   Reply With Quote
Old 5th January 2009, 13:50   #4
hanschen
Junior Member
 
Join Date: Jan 2009
Posts: 6
I've tried the following options:

PHP Code:
 ConfigOptionsEtape4:
  !
insertmacro MUI_INSTALLOPTIONS_WRITE "ihm.ini" "Field 6" "State" $HOST
  
!insertmacro MUI_INSTALLOPTIONS_WRITE "ihm.ini" "Field 2" "State" $SERVER
  
${If} ${SectionIsSelected} ${SEC04}
  !
insertmacro MUI_INSTALLOPTIONS_WRITE "ihm.ini" "Field 8" "State" $DLC
  
!insertmacro MUI_INSTALLOPTIONS_WRITE "ihm.ini" "Field 10" "State" $DBMTC
  
${Else}
  ${EndIf 
and

PHP Code:
  ConfigOptionsEtape4:
  !
insertmacro MUI_INSTALLOPTIONS_WRITE "ihm.ini" "Field 6" "State" $HOST
  
!insertmacro MUI_INSTALLOPTIONS_WRITE "ihm.ini" "Field 2" "State" $SERVER
  
${If} ${SectionIsSelected} ${SEC04}
  !
insertmacro MUI_INSTALLOPTIONS_WRITE "ihm.ini" "Field 8" "State" $DLC
  
!insertmacro MUI_INSTALLOPTIONS_WRITE "ihm.ini" "Field 10" "State" $DBMTC
  
${Else}
  
Abort
  
${EndIf} 
The first option didn't work. And the section option was all or nothing. When I selected the SEC04 it showed what it should, but when I didn't select SEC04 it didn't do anything at all.

Am I doing something wrong. I already had LogicLib included.
hanschen is offline   Reply With Quote
Old 5th January 2009, 13:56   #5
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Have you got this code after the section declaration in your script?
At what point are you running this code? Before the install options page is shown?

Stu
Afrow UK is offline   Reply With Quote
Old 5th January 2009, 14:00   #6
Animaether
Major Dude
 
Join Date: Jun 2001
Posts: 1,173
whoops - mea culpa on the single vs double ampersands; adjusting post.

Oddly enough the code does work despite the section being declared after the function, though o_O
Animaether is offline   Reply With Quote
Old 5th January 2009, 14:03   #7
hanschen
Junior Member
 
Join Date: Jan 2009
Posts: 6
Quote:
Originally posted by Afrow UK
Have you got this code after the section declaration in your script?
At what point are you running this code? Before the install options page is shown?

Stu
Can I PM you my script? That will probally explain a lot more I guess.
hanschen is offline   Reply With Quote
Old 5th January 2009, 14:04   #8
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Yes if you give SectionGetFlags/SectionGetText an invalid index (in this case the string "${Hello}") then it gets the flags/text of the first section in your script.

Stu
Afrow UK is offline   Reply With Quote
Old 5th January 2009, 14:11   #9
hanschen
Junior Member
 
Join Date: Jan 2009
Posts: 6
I've used your hint, however I can't PM at. It contains to many characters.

I've got the code behind the section declaration in the Function declaration.
hanschen is offline   Reply With Quote
Old 5th January 2009, 14:22   #10
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Mail to afrowuk tiscali co uk

Stu
Afrow UK is offline   Reply With Quote
Old 5th January 2009, 14:25   #11
hanschen
Junior Member
 
Join Date: Jan 2009
Posts: 6
Quote:
Originally posted by Afrow UK
Mail to afrowuk tiscali co uk

Stu
Its on its way!
hanschen is offline   Reply With Quote
Old 5th January 2009, 15:54   #12
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Code looks fine. Try putting a MessageBox in your If branch to see if it gets displayed depending on the section state.

Stu
Afrow UK is offline   Reply With Quote
Old 6th January 2009, 06:44   #13
hanschen
Junior Member
 
Join Date: Jan 2009
Posts: 6
I think I have found one of the problems. If you look at the code I send you, what I was talking about was line: 338 t/m 342

How ever, if I'd look a few row's down where my ini files get called, should I do something there?
hanschen is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump