Skip to content

Commit

Permalink
Merge branch 'development' of github.com:HaxeFoundation/haxe into dev…
Browse files Browse the repository at this point in the history
…elopment
  • Loading branch information
RealyUniqueName committed Jan 24, 2018
2 parents a78e553 + caf85fe commit 6fb4220
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions std/hl/UI.hx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ enum DialogFlags {
var Quit = 2;
}

typedef FileOptions = {
@:optional var window : Window;
@:optional var filters : Array<{ name : String, exts : Array<String> }>;
@:optional var filterIndex : Int;
@:optional var fileName : String;
@:optional var title : String;
}

/**
These are the bindings for the HL `ui.hdll` library, which contains some low level system access.
**/
Expand Down Expand Up @@ -170,4 +178,56 @@ class UI {
public static function closeConsole() : Void {
}

public static function loadFile( opts : FileOptions ) {
return chooseFile(false, opts);
}

public static function saveFile( opts : FileOptions ) {
return chooseFile(true, opts);
}

static function chooseFile( save : Bool, opts : FileOptions ) @:privateAccess {
var out : Dynamic = {
};
if( opts.fileName != null ) {
var file = sys.FileSystem.absolutePath(opts.fileName);
if( Sys.systemName() == "Windows" )
file = file.split("/").join("\\");
var dir = null;
if( sys.FileSystem.isDirectory(file) ) {
dir = file;
file = null;
} else {
var path = new haxe.io.Path(file);
dir = path.dir;
file = path.file + (path.ext == null ? "" : "." + path.ext);
}
if( file != null )
out.fileName = file.bytes;
if( dir != null )
out.directory = dir.bytes;
}
if( opts.title != null )
out.title = opts.title.bytes;
if( opts.filters != null ) {
var filters = new hl.NativeArray<hl.Bytes>(opts.filters.length * 2);
var i = 0;
for( f in opts.filters ) {
filters[i++] = f.name.bytes;
filters[i++] = [for( e in f.exts ) "*."+e].join(";").bytes;
}
out.filters = filters;
out.filterIndex = opts.filterIndex;
}
if( opts.window != null )
out.window = opts.window.h;
var str = _chooseFile(save, out);
return str == null ? null : String.fromUCS2(str);
}

@:hlNative("ui","ui_choose_file")
static function _chooseFile( forSave : Bool, obj : Dynamic ) : hl.Bytes {
return null;
}

}

0 comments on commit 6fb4220

Please sign in to comment.