Simple file dialog used for asking user where to save a file, or select files to open.
Example usage:
var fileDialog = new FileDialog();
fileDialog.onCancel.add( () -> trace("Canceled.") );
fileDialog.onSave.add( path -> trace("File saved in " + path) );
fileDialog.onOpen.add( res -> trace("Size of the file = " + (res:haxe.io.Bytes).length) );
if ( fileDialog.open("jpg", null, "Load file") )
trace("File dialog opened, waiting for selection...");
else
trace("This dialog is unsupported.");
Availability note: most file dialog operations are only available on desktop targets, though
save()
is also available in HTML5.
Constructor
Variables
onCancel:_Event_Void_Void<() ‑> Void> = new Event<Void>()
Triggers when the user clicks "Cancel" during any operation, or when a function is unsupported
(such as open()
on HTML5).
onOpen:_Event_lime_utils_Resource_Void<Resource ‑> Void> = new Event<Resource>()
Triggers when open()
is successful. The lime.utils.Resource
contains the file's data, and can
be implicitly cast to haxe.io.Bytes
.
onSave:_Event_String_Void<String ‑> Void> = new Event<String>()
Triggers when save()
is successful. The String
is the path to the saved file.
onSelect:_Event_String_Void<String ‑> Void> = new Event<String>()
Triggers when browse()
is successful and type
is anything other than
FileDialogType.OPEN_MULTIPLE
. The String
is the path to the selected file.
onSelectMultiple:_Event_Array_String__Void<Array<String> ‑> Void> = new Event<Array<String>>()
Triggers when browse()
is successful and type
is FileDialogType.OPEN_MULTIPLE
. The
Array<String>
contains all selected file paths.
Methods
browse(?type:FileDialogType, ?filter:String, ?defaultPath:String, ?title:String):Bool
Opens a file selection dialog. If successful, either onSelect
or onSelectMultiple
will trigger
with the result(s).
This function only works on desktop targets, and will return false
otherwise.
Parameters:
type | Type of the file dialog: |
---|---|
filter | A filter to use when browsing. Asterisks are treated as wildcards. For example,
|
defaultPath | The directory in which to start browsing and/or the default filename to
suggest. Defaults to |
title | The title to give the dialog window. |
Returns:
Whether browse()
is supported on this target.
open(?filter:String, ?defaultPath:String, ?title:String):Bool
Shows an open file dialog. If successful, onOpen
will trigger with the file contents.
This function only works on desktop targets, and will return false
otherwise.
Parameters:
filter | A filter to use when browsing. Asterisks are treated as wildcards. For example,
|
---|---|
defaultPath | The directory in which to start browsing and/or the default filename to
suggest. Defaults to |
title | The title to give the dialog window. |
Returns:
Whether open()
is supported on this target.
save(data:Resource, ?filter:String, ?defaultPath:String, ?title:String, type:String = "application/octet-stream"):Bool
Shows an open file dialog. If successful, onSave
will trigger with the selected path.
This function only works on desktop and HMTL5 targets, and will return false
otherwise.
Parameters:
data | The file contents, in |
---|---|
filter | A filter to use when browsing. Asterisks are treated as wildcards. For example,
|
defaultPath | The directory in which to start browsing and/or the default filename to
suggest. When targeting destkop, this defaults to |
title | The title to give the dialog window. |
type | The default MIME type of the file, in case the type can't be determined from the file data. Used only if targeting HTML5. |
Returns:
Whether save()
is supported on this target.