Archive: Programmatically return back to the previuos page


Programmatically return back to the previuos page
  Hi everybody.
I'd like to obtain the following behaviour with NSIS 2.0 beta 0:
When the user clicks "Next" on the directory choosing page, the path is verified (maybe in the next page creation function)
and if it is not valid, a warning is displayed and the directory choosing page is displayed again.
I'm not able to obtain it because in the creation callback function of a custom page it is not possible to return back to the previous page, but only to skip the current one with Abort.

I can not user .onVerifyInstDir because it's called while the user is typing, and I don't like this behaviour.. as I said I'd like to check the path when the "next" button is pressed.

Anyone can help please?

Thanks
Chocho


Look here and use the post_function to check wether the path is valid. If not, use 'abort'.


Post function is called just before the page is shown, not after. I am working right now on a function that will do that because a lot of people requested it and because it will solve the radio buttons/checkbox on the license page problem.


Gosh, never used it, so... :D

Then it will propably become:

Page license|directory|etc... [preshow_function] [postshow_function] [onleave_function]

(chocho_rock, before copying my line here, this won't work yet!)


Precreate, preshow, and preleave.


OK, I have finished this, but I want to test it a bit so I will release it only tomorrow.


PreLeave funtionality on a custom page
  Is the preleave funtionality going to be implemented for a custom page?


I am sorry, I forgot to let you know. It's already available in the latest CVS version.


Looking at code
  After looking at the latest code, I don't see how to implement the 'preleave' function for a custom page. It only seems to be dealt with for the non-custom pages.

I don't know if it's a typo or not, but lines 785-788 in script.cpp look like they may not do what was inteded. Both of these 'if' statements set p.showfunc. Should the second one set p.leavefunc?


Pre-leave function was not designed to work with custom pages, but now that I look at it again, it should. I'll add this in a couple of days.

Those lines indeed contain a typo. Thanks.


Hi,

I was just wondering if the Pre-leave function is now available for custom pages?

Thanks.
:)


Oops... Thanks for reminding me. It's now in the todo list where I won't miss it ;)


This means, now the installer can return to a previuos page automatically?
How? someone have a script example? :)


No it's *not* available yet. KiCHiK added it to the CVS file TODO.txt so that he knows it needs to be done and won't be forgotten.


Well, actually it's only not available for custom pages. For normal pages just use the leave callback function. If you call Abort from that function it won't leave the page.


Ready and waiting in CVS. Use NSIS Update to get it.


Is there any example code for the leave function in a custom page?


This will work.
Use like so...

Page Custom CustomPage


Function CustomPage
top:
InstallOptions::dialog "$PLUGINSDIR\IO1.ini"

ReadINIStr $R0 "$PLUGINSDIR\IO1.ini" "Field 2" "State"

IfFileExists $R0\*.* done
MessageBox MB_OK|MB_ICONEXCLAMATION "The entered installtion path is invalid."
Goto top

done:
FunctionEnd


-Stu

Your example doens't use the new leave callback function. Contrib\InstallOptions\test.nsi contains such an example.


I think I'm confused. What exactly is the leave callback function. Can you use it in a .nsi script? Or do you have to edit the C code?


Afrow UK, I was able to use the code you posted. It does exactly what I want, but I would still like to know what the leave callback is.


thanks for all the help!
mlm (aka, digitalda)


I'm having some problems. I tried to implement the above suggestion and I thought it was working, but now when I try to cancel before making a selection it forces me to make a selection before canceling.

Function SetIDE

MakeSelection:
!insertmacro MUI_HEADER_TEXT "Choose your IDE" ""
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "SetIDE.ini"
!insertmacro MUI_INSTALLOPTIONS_READ $R1 "SetIDE.ini" "Field 2" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $R2 "SetIDE.ini" "Field 3" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $R3 "SetIDE.ini" "Field 4" "State"

StrCmp $R1 "1" "Done" ""
StrCmp $R2 "1" "Done" ""
StrCmp $R3 "1" "Done" ""

MessageBox MB_OK|MB_iconexclamation "Please select your IDE."
Goto MakeSelection
Done:
>FunctionEnd
>

any suggestions?

A callback function is a function that is called when a particular event occures. The normal Page-instruction syntax is this:


Page (license|components|directory|instfiles) ***91;pre_function***93; ***91;show_function***93; ***91;leave_function***93; 

[pre_function] is replaced by the name of the function that is called before showing the page.
[show_function] is replaced by the name of the function that should be called after creating the page's components, but before showing it (allows some UI tweaking).
[leave_function] is replaced by the name of the function that is called just before the page is made invisible, but after the 'Next' button is clicked.

Something similar now exists for Custom pages:
Page custom***91;creator_function***93; ***91;leave_function***93; ***91;caption***93; 

[creator_function] is replaced by the name of the function which contains the custom page creating script (InstallOptions::dialog "$PLUGINSDIR\IO.ini").
[leave_function] is replaced by the name of the function that is called just before the page is made invisible, but after the 'Next' button of the custom page is clicked.

This allows something like this (not tested):

Page custom CustomPageCreate CustomPageLeave


>Function CustomPageCreate
GetTempFileName $R0
File/oname=$R0 customPage.ini
InstallOptions
::dialog $R0
FunctionEnd

>Function CustomPageLeave
MessageBox MB_YES"Do you want to leave the custom page?" IDYES yes
Abort
yes:
>FunctionEnd
>