Retain data on custom pages when back button is pressed
Asked Answered
G

4

7

Incase of custom pages in NSIS script is there any way to retain the data entered by user when back button is pressed (when the installer is running)?

Godlike answered 15/1, 2010 at 6:27 Comment(0)
B
5

There are a couple of ways to do this. Either way you need to store your data in globals.

1) Use a "Leave" function.

Page custom EnterCustom LeaveCustom

; Create two variables for each value/widget pair
Var Text
Var TextWidget
Var Check
Var CheckWidget

Function EnterCustom
  nsDialogs::Create 1018
  Pop $0

  ${NSD_CreateText} 0 0 80u 12u $Text
  Pop $TextWidget

  ${NSD_CreateCheckBox} 0 26u 80u 12u "Check this box"
  Pop $CheckWidget
  ${NSD_SetState} $CheckWidget $Check

  nsDialogs::Show
FunctionEnd

Function LeaveCustom
  ${NSD_GetText} $TextWidget $Text
  ${NSD_GetState} $CheckWidget $Check
FunctionEnd

The only problem with this method is that LeaveCustom only gets called if you hit the next button. So if you edit the fields then click the Back button your changes are lost. The changes are however saved if you go forward then come back.

2) Use the OnChange callback.

This is a little more complicated but solves the problem with the previous method.

Page custom EnterCustom

Var Initialized
; Create two variables for each value/widget pair
Var Text
Var TextWidget
Var Check
Var CheckWidget

Function EnterCustom
  nsDialogs::Create 1018
  Pop $0

  ${If} $Initialized != "True"
    ; Set defaults for all your values here
    StrCpy $Text "Initial Value"
    StrCpy $Check ${BST_UNCHECKED}
    StrCpy $Initialized "True"
  ${EndIf}

  ; Create and configure all of your widgets
  ${NSD_CreateText} 0 0 80u 12u $Text
  Pop $TextWidget
  ${NSD_OnChange} $TextWidget OnTextChange

  ${NSD_CreateCheckBox} 0 26u 80u 12u "Check this box"
  Pop $CheckWidget
  ${NSD_SetState} $CheckWidget $Check
  ${NSD_OnClick} $CheckWidget OnCheckClick

  nsDialogs::Show
FunctionEnd

; Create a callback function for each Widget
Function OnTextChange
  Pop $0 ; Widget handle is on stack
  ${NSD_GetText} $TextWidget $Text
FunctionEnd

Function OnCheckClick
  Pop $0 ; Widget handle is on stack
  ${NSD_GetState} $CheckWidget $Check
FunctionEnd

Some widgets, e.g. RadioButtons and CheckBoxes, use the OnClick function instead. Also the ComboBox does not work well with this method. However, a DropList, which does not seem to be documented, can usually replace it and works fine.

Radio buttons are also a little tricky because only the click callback for the selected button is called. I solved this by updating all of the radio button values in each radio button click callback.

Messy/tedious but it works.

Bellflower answered 28/12, 2010 at 3:57 Comment(0)
I
5

I know it's an old question, but I've landed here from my googling.

You can use NSD_OnBack (or call nsDialogs::OnBack directly) to set OnBack callback.

Here is the code snipet:

Function portsSelectionPage
    nsDialogs::Create 1018
    Pop $0
    ${NSD_CreateNumber} 70u 0 40u 12u $TomcatPort
    Pop $TomcatPortHWND
    ${NSD_CreateNumber} 70u 14u 40u 12u $PostgresPort
    Pop $PostgresPortHWND

    nsDialogs::Show

    ${NSD_OnBack} "portsSelectionPageLeave"
FunctionEnd

Function portsSelectionPageLeave
    ${NSD_GetText} $TomcatPortHWND $TomcatPort
    ${NSD_GetText} $PostgresPortHWND $PostgresPort
FunctionEnd
Isadora answered 26/4, 2013 at 19:53 Comment(0)
M
1

You can store data in a global variable, or in a .ini in $pluginsdir

Mckenna answered 15/1, 2010 at 8:10 Comment(2)
Can you elaborate more? When I run the setup file created by NSIS and enter some data in textboxes of a custom page, click next and then click back button, the data I just entered is not retained. So even if I have to change only few of the values on my previous page, I have to write all of them all over again as the page gets reset.Godlike
There is no automatic storing of data, you have to do it all on your ownMckenna
S
0
!include nsDialogs.nsh
!include LogicLib.nsh

Name nsDialogs
OutFile nsDialogs.exe

XPStyle on

Var Dialog
Var Label
Var Text
Var Text_State
Var Checkbox
Var Checkbox_State

Page custom nsDialogsPage nsDialogsPageLeave
Page license
Page instfiles

Function .onInit

    StrCpy $Text_State "Type something here..."

FunctionEnd

Function nsDialogsPage

    nsDialogs::Create 1018
    Pop $Dialog

    ${If} $Dialog == error
        Abort
    ${EndIf}

    ${NSD_CreateLabel} 0 0 100% 12u "Hello, welcome to nsDialogs!"
    Pop $Label

    ${NSD_CreateText} 0 13u 100% 12u $Text_State
    Pop $Text

    ${NSD_CreateCheckbox} 0 30u 100% 10u "&Something"
    Pop $Checkbox

    ${If} $Checkbox_State == ${BST_CHECKED}
        ${NSD_Check} $Checkbox
    ${EndIf}

    # alternative for the above ${If}:
    #${NSD_SetState} $Checkbox_State

    nsDialogs::Show

FunctionEnd

Function nsDialogsPageLeave

    ${NSD_GetText} $Text $Text_State
    ${NSD_GetState} $Checkbox $Checkbox_State

FunctionEnd

Section

    DetailPrint "hello world"

SectionEnd

more information http://nsis.sourceforge.net/Docs/nsDialogs/Readme.html#step-memory

Schmit answered 3/11, 2017 at 5:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.