Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use WiX browser dialog to set edit box value

Tags:

I'm trying to create a WiX installer dialog that provides a series of textboxes that users need to fill in with directory locations.

What I would like to do is put a Browse button next to each dialog and when they click it, the WiX Browse dialog will come up, they select a file location, click OK, and the text box next to the browse button will be filled in.

I know how to do it with a custom action, but I was wondering if there was a pure WiX way of doing this.

EDIT: I should be more clear. I meant directory locations, not file locations. Wix doesn't have file browsing support as one user indicated below.

like image 644
chrisdrobison Avatar asked Dec 13 '11 22:12

chrisdrobison


2 Answers

I did end up finding a way to do it completely in Wix. Wix comes with a browse dialog called BrowseDlg. Here's what I did:

  1. I created a dialog that includes a PathEdit control and PushButton control. Notice that the PathEdit control has the Indirect property set to yes. This means that whatever you set Property to is just a pointer to something else.

        <Dialog Id="BackupConfigDlg" Width="370" Height="270" Title="Backup Configuration">         <Control Type="Text" Id="lblInstructions" Width="348" Height="13" X="10" Y="10">             <Text>{\WixUI_Font_Title}Please select the directory you want to backup.</Text>         </Control>         <Control Type="Text" Id="lblBackupDirectory" Width="69" Height="9" X="10" Y="40" Text="Backup directory:">         </Control>         <Control Type="PathEdit" Id="Folder" Width="219" Height="15" X="82" Y="38" Property="_BrowseProperty" Indirect="yes" />         <Control Type="PushButton" Id="Browse" Width="56" Height="17" X="304" Y="37" Text="Browse..." />         <Control Type="Line" Id="line" Width="362" Height="2" X="4" Y="229" />         <Control Id="Cancel" Type="PushButton" X="239" Y="240" Width="56" Height="17" Cancel="yes" Text="Cancel">             <Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>         </Control>         <Control Type="PushButton" Id="Install" Width="56" Height="17" X="300" Y="240" Text="Install">             <Publish Event="EndDialog" Value="Return" />         </Control>     </Dialog> 
  2. The browse dialog (that we'll eventually get to) expects to set an object in the Directory table, so we need to create a Directory object that will only be used to hold the value we browse to. Since we won't put any components in it, nothing on the file system will change relating to the directory we choose. I call mine TARGETBACKUPDIRECTORY.

        <Directory Id="TARGETDIR" Name="SourceDir">         <Directory Id="TARGETBACKUPDIRECTORY">         </Directory>         ...     </Directory> 
  3. Now we need to create a property that points to the Directory object.

    <Property Id="BACKUPDIRECTORY" Value="TARGETBACKUPDIRECTORY" /> 
  4. We now need to make sure that the _BrowserProperty property is properly bound to BACKUPDIRECTORY (because it points to the Directory object we want set) before this dialog opens. If you don't, you will get an error during the install process when you attempt to open the dialog. In my example, PrevDlg is a dialog that appears before BackupConfigDlg. What's happening here is that when the Next button is pushed, I set the _BrowserProperty property to BACKUPDIRECTORY, I then open the dialog. It must take place in that order so I use the Order property to enforce it. I do the same thing when the browse button is pushed, not sure I need to do, but I do it just for safe measure.

        <Publish Dialog="PrevDlg" Control="Next" Property="_BrowseProperty" Value="[BACKUPDIRECTORY]" Order="1">1</Publish>     <Publish Dialog="PrevDlg" Control="Next" Event="NewDialog" Value="BackupConfigDlg" Order="2">1</Publish>     <Publish Dialog="BackupConfigDlg" Control="Browse" Property="_BrowseProperty" Value="[BACKUPDIRECTORY]" Order="1">     </Publish>     <Publish Dialog="BackupConfigDlg" Control="Browse" Event="SpawnDialog" Value="BrowseDlg" Order="2">     </Publish> 

That's what worked for me.

like image 187
chrisdrobison Avatar answered Oct 05 '22 16:10

chrisdrobison


The selected answer to this question is way too much work. You don't need to do all that.

Set your PathEdit control to the directory to configure as you normally would. Then, in the actions of the browse button, set _BrowseProperty to the NAME (not value of) of your property to configure and then SpawnDialog. That's it.

<Control Type="PathEdit" Id="TxtDir" Width="155" Height="15" X="105" Y="57" Property="OUTPUTDIRECTORY"/> <Control Id="btnDirBrowse" Type="PushButton" Width="56" Height="17" X="260" Y="57" Text="Browse..." >   <Publish Property="_BrowseProperty" Value="OUTPUTDIRECTORY" Order="1">1</Publish>   <Publish Event="SpawnDialog" Value="BrowseDlg" Order="2">1</Publish> </Control> 
like image 25
Nick Whaley Avatar answered Oct 05 '22 16:10

Nick Whaley