howzer
6th October 2011 11:51 UTC
How to check if cancel button pressed in nsDialogs
Hello,
I've created a cutom page using nsDialogs. How would I check if the user has pressed the cancel button. At the moment I have a condition to make sure a text box has been filled and not left blank. If it is left blank and the user decides to cancel then and there, the same check condition gets executed and there is no way of aborting the installer. Many Thanks.
Function ConnectionDialogShowAndLeave
Push $R0
${Do}
!insertmacro MUI_HEADER_TEXT "Registry Connection Details" "Please provide information regarding your connection string and database settings."
nsDialogs::Create 1018
Pop $0
${If} $0 == error
Abort
${EndIf}
# LHApp Connection String
${NSD_CreateLabel} 0 12 25% 12u "Database Connection:"
${NSD_CreateText} 25% 10 75% 12u "$ConnectionString"
Pop $Text
GetFunctionAddress $0 GetText
nsDialogs::OnChange $Text $0
# DBMS Radio buttons
${NSD_CreateGroupBox} 0 40 100% 45u "Database Type"
${NSD_CreateRadioButton} 10 60 50% 12u "Oracle"
Pop $Button1
GetFunctionAddress $0 GetButtonState
nsDialogs::OnClick $Button1 $0
${NSD_CreateRadioButton} 10 80 50% 12u "SQL-Server"
Pop $Button2
nsDialogs::OnClick $Button2 $0
# Check the current value of DBMS and check the associated radio button
${If} $DBMS == "0"
${NSD_Check} $Button1
${ElseIf} $DBMS == "1"
${NSD_Check} $Button2
${EndIf}
nsDialogs::Show
# Set the correlating DBMS value
${If} $Button1State == ${BST_CHECKED}
StrCpy $DBMS "0"
${ElseIf} $Button2State == ${BST_CHECKED}
StrCpy $DBMS "1"
${EndIf}
# Ensure connection string has been provided
${If} $ConnectionString == ""
MessageBox MB_ICONEXCLAMATION "Please provide the database connection."
${Continue}
${EndIf}
# Ensure DBMS has been selected
${If} $DBMS != "0"
${AndIf} $DBMS != "1"
MessageBox MB_ICONEXCLAMATION "Please choose a database type."
${Continue}
${EndIf}
# If we get here, then all details have been provided, so exit the loop
${ExitDo}
${Loop}
Pop $R0
FunctionEnd
Afrow UK
6th October 2011 12:06 UTC
You are validating your fields incorrectly. You should be doing it in the page leave function where you can simply call Abort to return back to the page. The leave function is not called if they click Back or Cancel.
Stu
howzer
6th October 2011 12:20 UTC
If I wanted to return back to the page from another function, wouldn't I get a stack error? Wouldn't calling abort just leave the installer?
howzer
6th October 2011 12:31 UTC
Ok I tried what you suggested and it worked! Thanks Stu. All this time I thought calling abort would just close the installer but in nsDialogs, it will just refresh the page?
Function ConnectionDialogShow
!insertmacro MUI_HEADER_TEXT "Registry Connection Details" "Please provide information regarding your connection string and database settings."
nsDialogs::Create 1018
Pop $0
${If} $0 == error
Abort
${EndIf}
# LHApp Connection String
${NSD_CreateLabel} 0 12 25% 12u "Database Connection:"
${NSD_CreateText} 25% 10 75% 12u "$ConnectionString"
Pop $Text
GetFunctionAddress $0 GetText
nsDialogs::OnChange $Text $0
# DBMS Radio buttons
${NSD_CreateGroupBox} 0 40 100% 45u "Database Type"
${NSD_CreateRadioButton} 10 60 50% 12u "Oracle"
Pop $Button1
GetFunctionAddress $0 GetButtonState
nsDialogs::OnClick $Button1 $0
${NSD_CreateRadioButton} 10 80 50% 12u "SQL-Server"
Pop $Button2
nsDialogs::OnClick $Button2 $0
# Check the current value of DBMS and check the associated radio button
${If} $DBMS == "0"
${NSD_Check} $Button1
${ElseIf} $DBMS == "1"
${NSD_Check} $Button2
${EndIf}
nsDialogs::Show
FunctionEnd
Function ConnectionDialogLeave
${NSD_GetText} $Text $ConnectionString
${NSD_GetState} $Button1 $Button1State
${NSD_GetState} $Button2 $Button2State
# Set the correlating DBMS value
${If} $Button1State == ${BST_CHECKED}
StrCpy $DBMS "0"
${ElseIf} $Button2State == ${BST_CHECKED}
StrCpy $DBMS "1"
${EndIf}
# Ensure connection string has been provided
${If} $ConnectionString == ""
MessageBox MB_ICONEXCLAMATION "Please provide the database connection."
Abort
${EndIf}
# Ensure DBMS has been selected
${If} $DBMS != "0"
${AndIf} $DBMS != "1"
MessageBox MB_ICONEXCLAMATION "Please choose a database type."
Abort
${EndIf}
FunctionEnd
Afrow UK
6th October 2011 14:58 UTC
Read section 4.5.3 Callbacks in the manual.
Stu