Merge branch 'documentation' of github.com:pfoof/lime into documentation
This commit is contained in:
@@ -20,8 +20,7 @@ import js.html.Blob;
|
|||||||
#end
|
#end
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Simple file dialog used for asking user where to save a file, or select
|
Simple file dialog used for asking user where to save a file, or select files to open.
|
||||||
files to open.
|
|
||||||
|
|
||||||
Example usage:
|
Example usage:
|
||||||
```haxe
|
```haxe
|
||||||
@@ -31,13 +30,16 @@ import js.html.Blob;
|
|||||||
|
|
||||||
fileDialog.onSave.add( path -> trace("File saved in " + path) );
|
fileDialog.onSave.add( path -> trace("File saved in " + path) );
|
||||||
|
|
||||||
fileDialog.onOpen.add( res -> trace("Size of the file = " + cast(res, haxe.io.Bytes).length) );
|
fileDialog.onOpen.add( res -> trace("Size of the file = " + (res:haxe.io.Bytes).length) );
|
||||||
|
|
||||||
if ( fileDialog.open("jpg", null, "Load file") )
|
if ( fileDialog.open("jpg", null, "Load file") )
|
||||||
trace("Triggered opening file");
|
trace("File dialog opened, waiting for selection...");
|
||||||
else
|
else
|
||||||
trace("This dialog is unsupported.");
|
trace("This dialog is unsupported.");
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Availability note: most file dialog operations are only available on desktop targets, though
|
||||||
|
`save()` is also available in HTML5.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#if !lime_debug
|
#if !lime_debug
|
||||||
@@ -50,29 +52,31 @@ class FileDialog
|
|||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Handles clicking the "Cancel" button by the user. It is also triggered on unsupported platforms (like HTML5 for `open()`).
|
Triggers when the user clicks "Cancel" during any operation, or when a function is unsupported
|
||||||
|
(such as `open()` on HTML5).
|
||||||
**/
|
**/
|
||||||
public var onCancel = new Event<Void->Void>();
|
public var onCancel = new Event<Void->Void>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Triggers when file was successfuly opened. `lime.utils.Resource` is the argument passed
|
Triggers when `open()` is successful. The `lime.utils.Resource` contains the file's data, and can
|
||||||
which in essence is `haxe.io.Bytes` of the selected file's contents. Triggers only when used with `open()`.
|
be implicitly cast to `haxe.io.Bytes`.
|
||||||
**/
|
**/
|
||||||
public var onOpen = new Event<Resource->Void>();
|
public var onOpen = new Event<Resource->Void>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Triggers when file was successfuly saved by the user. Argument is `String` - the path under which the file was saved.
|
Triggers when `save()` is successful. The `String` is the path to the saved file.
|
||||||
Triggers only when used with `save()`.
|
|
||||||
**/
|
**/
|
||||||
public var onSave = new Event<String->Void>();
|
public var onSave = new Event<String->Void>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Selected single file from `browse()`. Passes `String` path to the file.
|
Triggers when `browse()` is successful and `type` is anything other than
|
||||||
|
`FileDialogType.OPEN_MULTIPLE`. The `String` is the path to the selected file.
|
||||||
**/
|
**/
|
||||||
public var onSelect = new Event<String->Void>();
|
public var onSelect = new Event<String->Void>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Is called with array of selected file paths from `browse()` with `FileDialogType.OPEN_MULTIPLE`.
|
Triggers when `browse()` is successful and `type` is `FileDialogType.OPEN_MULTIPLE`. The
|
||||||
|
`Array<String>` contains all selected file paths.
|
||||||
**/
|
**/
|
||||||
public var onSelectMultiple = new Event<Array<String>->Void>();
|
public var onSelectMultiple = new Event<Array<String>->Void>();
|
||||||
|
|
||||||
@@ -80,12 +84,17 @@ class FileDialog
|
|||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Opens a file dialog that will trigger either `onSelect` or `onSelectMultiple` returting path(s) to file(s).
|
Opens a file selection dialog. If successful, either `onSelect` or `onSelectMultiple` will trigger
|
||||||
@param type type of the file dialog: `OPEN`, `SAVE`, `OPEN_DIRECTORY` or `OPEN_MULTIPLE`.
|
with the result(s).
|
||||||
@param filter filter to be used when browsing for the file. For example for `"*.jpg"` it will be `"jpg"`.
|
|
||||||
@param defaultPath directory in which to start browsing. Default is current working directory of the application.
|
This function only works on desktop targets, and will return `false` otherwise.
|
||||||
@param title title to give the dialog window.
|
@param type Type of the file dialog: `OPEN`, `SAVE`, `OPEN_DIRECTORY` or `OPEN_MULTIPLE`.
|
||||||
@return `false` if the dialog is unsupported.
|
@param filter A filter to use when browsing. Asterisks are treated as wildcards. For example,
|
||||||
|
`"*.jpg"` will match any file ending in `.jpg`.
|
||||||
|
@param defaultPath The directory in which to start browsing and/or the default filename to
|
||||||
|
suggest. Defaults to `Sys.getCwd()`, with no default filename.
|
||||||
|
@param title The title to give the dialog window.
|
||||||
|
@return Whether `browse()` is supported on this target.
|
||||||
**/
|
**/
|
||||||
public function browse(type:FileDialogType = null, filter:String = null, defaultPath:String = null, title:String = null):Bool
|
public function browse(type:FileDialogType = null, filter:String = null, defaultPath:String = null, title:String = null):Bool
|
||||||
{
|
{
|
||||||
@@ -213,11 +222,15 @@ class FileDialog
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Shows an open file dialog and immediately returns the contents of the file in `onOpen` listeners.
|
Shows an open file dialog. If successful, `onOpen` will trigger with the file contents.
|
||||||
@param filter filter to be used when browsing for the file. For example for `"*.jpg"` it will be `"jpg"`.
|
|
||||||
@param defaultPath directory in which to start browsing. Default is current working directory of the application.
|
This function only works on desktop targets, and will return `false` otherwise.
|
||||||
@param title title to give the dialog window.
|
@param filter A filter to use when browsing. Asterisks are treated as wildcards. For example,
|
||||||
@return `false` if the dialog is unsupported.
|
`"*.jpg"` will match any file ending in `.jpg`.
|
||||||
|
@param defaultPath The directory in which to start browsing and/or the default filename to
|
||||||
|
suggest. Defaults to `Sys.getCwd()`, with no default filename.
|
||||||
|
@param title The title to give the dialog window.
|
||||||
|
@return Whether `open()` is supported on this target.
|
||||||
**/
|
**/
|
||||||
public function open(filter:String = null, defaultPath:String = null, title:String = null):Bool
|
public function open(filter:String = null, defaultPath:String = null, title:String = null):Bool
|
||||||
{
|
{
|
||||||
@@ -267,12 +280,19 @@ class FileDialog
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Asks the user where to save the `data`. Will return path of the saved file in `onSave`.
|
Shows an open file dialog. If successful, `onSave` will trigger with the selected path.
|
||||||
@param filter filter to be used when browsing for the file. For example for `"*.jpg"` it will be `"jpg"`.
|
|
||||||
@param defaultPath directory in which to start browsing. Default is current working directory of the application.
|
This function only works on desktop and HMTL5 targets, and will return `false` otherwise.
|
||||||
@param title title to give the dialog window.
|
@param data The file contents, in `haxe.io.Bytes` format. (Implicit casting possible.)
|
||||||
@param type MIME type of the file. Used only on HTML5 targets.
|
@param filter A filter to use when browsing. Asterisks are treated as wildcards. For example,
|
||||||
@return `false` if the dialog is unsupported.
|
`"*.jpg"` will match any file ending in `.jpg`. Used only if targeting deskop.
|
||||||
|
@param 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.
|
||||||
|
@param title The title to give the dialog window.
|
||||||
|
@param 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.
|
||||||
|
@return Whether `save()` is supported on this target.
|
||||||
**/
|
**/
|
||||||
public function save(data:Resource, filter:String = null, defaultPath:String = null, title:String = null, type:String = "application/octet-stream"):Bool
|
public function save(data:Resource, filter:String = null, defaultPath:String = null, title:String = null, type:String = "application/octet-stream"):Bool
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user