File Browser controls display an editable text box and a file browser widget along with an optional label. They are associated to an underlying String parameter.
Clicking on the file browser widget launches a File Browser which can be used to identify a path and filename. When the user clicks OK on the File Browser, it updates the associated text box with the selected path and filename.
You create them using the PPGLayout.AddItem or PPGLayout::AddItem method with the siControlFilePath control type enum:
var oItem = oLayout.AddItem( "ScriptFile", "Script File", siControlFilePath );
Here are some tips and tricks for how to set up some of the special features for file browser widget:
The following item attributes are available:
Available on all Controls also as a property on the PPGItem object: |
Common to many Controls: |
Specific to the File Browser control: |
---|---|---|
To indicate files to Save vs. Open
By default, the file browser provides the name and location of an existing file (ie., an Open action). However, if you need a way to get the user to specify the file name and location for a file to write to (Save action), you can set the siUIOpenFile and the siUIFileMustExist attributes to false:
oItem.SetAttribute( siUIOpenFile, false ); oItem.SetAttribute( siUIFileMustExist, false );
To specify a default directory
You can specify the directory for the browser widget to initially display:
var path = XSIUtils.BuildPath( Application.InstallationPath(siFactoryPath), "Application", "Plugins" ); oItem.SetAttribute( siUIInitialDir, path );
If the path doesn't exist, Softimage will use a generic location (eg., the Desktop on Windows) instead of throwing an error.
To specify a file extension filter
You can filter the files by any file extension you want with the siUIFileFilter attribute:
var filterstring = "Script files (*.js *.vbs *.py)|*.js:*.vbs:*.py|"; filterstring += "Source files (*.cpp *.cs)|*.cpp:*.cs|"; filterstring += "Text files (*.txt *.text)|*.txt:*.text|"; filterstring += "All Files (*.*)|*.*||"; oItem.SetAttribute( siUIFileFilter, filterstring );
There are also two special attributes that encapsulate all image and audio types:
oItem.SetAttribute( siUIImageFile, true );
oItem.SetAttribute( siUIAudioFile, true );
If you try to set the siUIFileFilter attribute in addition to the siUIAudioFile and siUIImageFile attribute(s), only the image filter will be used if specified; otherwise only the audio filter will be used. Any custom filter string you specify will be ignored.