Implement fileDialog.save for HTML5
This commit is contained in:
@@ -57,6 +57,7 @@
|
|||||||
<dependency name="extension-api" path="dependencies/extension-api" if="android" />
|
<dependency name="extension-api" path="dependencies/extension-api" if="android" />
|
||||||
<dependency path="dependencies/howler.min.js" if="html5 howlerjs" />
|
<dependency path="dependencies/howler.min.js" if="html5 howlerjs" />
|
||||||
<dependency path="dependencies/pako.min.js" if="html5" />
|
<dependency path="dependencies/pako.min.js" if="html5" />
|
||||||
|
<dependency path="dependencies/FileSaver.min.js" if="html5" />
|
||||||
<dependency path="dependencies/webgl-debug.js" if="html5 webgl-debug" />
|
<dependency path="dependencies/webgl-debug.js" if="html5 webgl-debug" />
|
||||||
<dependency path="dependencies/stats.min.js" if="html5 stats" />
|
<dependency path="dependencies/stats.min.js" if="html5 stats" />
|
||||||
<dependency path="dependencies/angle/d3dcompiler_47.dll" if="windows angle" unless="static_link" />
|
<dependency path="dependencies/angle/d3dcompiler_47.dll" if="windows angle" unless="static_link" />
|
||||||
|
|||||||
@@ -1,21 +1,30 @@
|
|||||||
package lime.ui;
|
package lime.ui;
|
||||||
|
|
||||||
|
|
||||||
|
import haxe.io.Bytes;
|
||||||
|
import haxe.io.Path;
|
||||||
import lime._backend.native.NativeCFFI;
|
import lime._backend.native.NativeCFFI;
|
||||||
import lime.app.Event;
|
import lime.app.Event;
|
||||||
|
import lime.graphics.Image;
|
||||||
import lime.system.BackgroundWorker;
|
import lime.system.BackgroundWorker;
|
||||||
|
import lime.utils.ArrayBuffer;
|
||||||
import lime.utils.Resource;
|
import lime.utils.Resource;
|
||||||
|
|
||||||
#if sys
|
#if sys
|
||||||
import sys.io.File;
|
import sys.io.File;
|
||||||
#end
|
#end
|
||||||
|
|
||||||
|
#if (js && html5)
|
||||||
|
import js.html.Blob;
|
||||||
|
#end
|
||||||
|
|
||||||
#if !lime_debug
|
#if !lime_debug
|
||||||
@:fileXml('tags="haxe,release"')
|
@:fileXml('tags="haxe,release"')
|
||||||
@:noDebug
|
@:noDebug
|
||||||
#end
|
#end
|
||||||
|
|
||||||
@:access(lime._backend.native.NativeCFFI)
|
@:access(lime._backend.native.NativeCFFI)
|
||||||
|
@:access(lime.graphics.Image)
|
||||||
|
|
||||||
|
|
||||||
class FileDialog {
|
class FileDialog {
|
||||||
@@ -190,6 +199,13 @@ class FileDialog {
|
|||||||
|
|
||||||
public function save (data:Resource, filter:String = null, defaultPath:String = null, title:String = null):Bool {
|
public function save (data:Resource, filter:String = null, defaultPath:String = null, title:String = null):Bool {
|
||||||
|
|
||||||
|
if (data == null) {
|
||||||
|
|
||||||
|
onCancel.dispatch ();
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#if desktop
|
#if desktop
|
||||||
|
|
||||||
var worker = new BackgroundWorker ();
|
var worker = new BackgroundWorker ();
|
||||||
@@ -226,6 +242,42 @@ class FileDialog {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
#elseif (js && html5)
|
||||||
|
|
||||||
|
// TODO: Cleaner API for mimeType detection
|
||||||
|
|
||||||
|
var type = "application/octet-stream";
|
||||||
|
var defaultExtension = "";
|
||||||
|
|
||||||
|
if (Image.__isPNG (data)) {
|
||||||
|
|
||||||
|
type = "image/png";
|
||||||
|
defaultExtension = ".png";
|
||||||
|
|
||||||
|
} else if (Image.__isJPG (data)) {
|
||||||
|
|
||||||
|
type = "image/jpeg";
|
||||||
|
defaultExtension = ".jpg";
|
||||||
|
|
||||||
|
} else if (Image.__isGIF (data)) {
|
||||||
|
|
||||||
|
type = "image/gif";
|
||||||
|
defaultExtension = ".gif";
|
||||||
|
|
||||||
|
} else if (Image.__isWebP (data)) {
|
||||||
|
|
||||||
|
type = "image/webp";
|
||||||
|
defaultExtension = ".webp";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var path = defaultPath != null ? Path.withoutDirectory (defaultPath) : "download" + defaultExtension;
|
||||||
|
var buffer = (data:Bytes).getData ();
|
||||||
|
|
||||||
|
untyped window.saveAs (new Blob ([ buffer ], { type: type }), path, true);
|
||||||
|
onSave.dispatch (path);
|
||||||
|
return true;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
onCancel.dispatch ();
|
onCancel.dispatch ();
|
||||||
|
|||||||
Reference in New Issue
Block a user