Skip to content

Commit 60e3076

Browse files
MAJigsaw77AbnormalPoof
authored andcommitted
Fixes for FileDialog.
1 parent 8f82625 commit 60e3076

File tree

1 file changed

+13
-29
lines changed

1 file changed

+13
-29
lines changed

flixel/addons/plugin/screengrab/FlxScreenGrab.hx

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package flixel.addons.plugin.screengrab;
22

33
#if !js
4+
import openfl.Lib;
45
import openfl.display.Bitmap;
56
import openfl.display.BitmapData;
67
import openfl.geom.Matrix;
@@ -11,7 +12,7 @@ import flixel.FlxG;
1112
import flixel.input.keyboard.FlxKey;
1213
#if sys
1314
import lime.ui.FileDialog;
14-
import lime.ui.FileDialogType;
15+
import lime.ui.FileDialogFilter;
1516
import openfl.display.PNGEncoderOptions;
1617
#else
1718
import openfl.net.FileReference;
@@ -175,41 +176,24 @@ class FlxScreenGrab extends FlxBasic
175176
file.save(png, Filename);
176177
#elseif (!lime_legacy || lime < "2.9.0")
177178
var documentsDirectory = "";
179+
178180
#if lime_legacy
179181
documentsDirectory = openfl.filesystem.File.documentsDirectory.nativePath;
180182
#else
181183
documentsDirectory = lime.system.System.documentsDirectory;
182184
#end
183185

184-
var fd:FileDialog = new FileDialog();
185-
186-
var path = "";
187-
188-
fd.onSelect.add(function(str:String)
189-
{
190-
path = fixFilename(str);
191-
var f = sys.io.File.write(path, true);
192-
f.writeString(png.readUTFBytes(png.length));
193-
f.close();
194-
path = null;
195-
});
196-
197-
try
198-
{
199-
fd.browse(FileDialogType.SAVE, "*.png", documentsDirectory);
200-
}
201-
catch (msg:String)
202-
{
203-
path = Filename; // if there was an error write out to default directory (game install directory)
204-
}
205-
206-
if (path != "" && path != null) // if path is empty, the user cancelled the save operation and we can safely do nothing
186+
FileDialog.saveFile(FlxG.stage.window, function(filepath:String, filter):Void
207187
{
208-
path = fixFilename(path);
209-
var f = sys.io.File.write(path, true);
210-
f.writeString(png.readUTFBytes(png.length));
211-
f.close();
212-
}
188+
if (filepath != null)
189+
{
190+
var path = fixFilename(filepath);
191+
var f = sys.io.File.write(path, true);
192+
f.writeString(png.readUTFBytes(png.length));
193+
f.close();
194+
path = null;
195+
}
196+
}, [new FileDialogFilter("PNG images", "png")], documentsDirectory);
213197
#end
214198
}
215199

0 commit comments

Comments
 (0)