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

new()

Variables

@:value(new Event<Void>())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).

@:value(new Event<Resource>())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.

@:value(new Event<String>())onSave:_Event_String_Void<String ‑> Void> = new Event<String>()

Triggers when save() is successful. The String is the path to the saved file.

@:value(new Event<String>())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.

@:value(new Event<Array<String>>())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

@:value({ title : null, defaultPath : null, filter : null, type : null })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: OPEN, SAVE, OPEN_DIRECTORY or OPEN_MULTIPLE.

filter

A filter to use when browsing. Asterisks are treated as wildcards. For example, "*.jpg" will match any file ending in .jpg.

defaultPath

The directory in which to start browsing and/or the default filename to suggest. Defaults to Sys.getCwd(), with no default filename.

title

The title to give the dialog window.

Returns:

Whether browse() is supported on this target.

@:value({ title : null, defaultPath : null, filter : null })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, "*.jpg" will match any file ending in .jpg.

defaultPath

The directory in which to start browsing and/or the default filename to suggest. Defaults to Sys.getCwd(), with no default filename.

title

The title to give the dialog window.

Returns:

Whether open() is supported on this target.

@:value({ type : "application/octet-stream", title : null, defaultPath : null, filter : null })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 haxe.io.Bytes format. (Implicit casting possible.)

filter

A filter to use when browsing. Asterisks are treated as wildcards. For example, "*.jpg" will match any file ending in .jpg. Used only if targeting deskop.

defaultPath

The directory in which to start browsing and/or the default filename to suggest. When targeting destkop, this defaults to Sys.getCwd() with no default filename. When targeting HTML5, this defaults to the browser's download directory, with a default filename based on the MIME type.

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.