Files
armorpaint/Sources/arm/ui/UIFiles.hx
T
luboslenco 5b4cdf94dd Cleanup
2019-07-11 16:09:47 +02:00

50 lines
1.2 KiB
Haxe

package arm.ui;
import zui.Zui;
import zui.Id;
import iron.system.Input;
using StringTools;
class UIFiles {
public static var show = false;
public static var isSave = false;
public static var filename = "untitled";
public static var filesDone:String->Void;
public static var filters = "";
public static var path = '/';
@:access(zui.Zui)
public static function render(g:kha.graphics2.Graphics) {
// Krom with native file dialogs
#if kha_krom
show = false;
if (untyped Krom.openDialog != null) {
path = untyped isSave ? Krom.saveDialog(filters, "") : Krom.openDialog(filters, "");
if (path != null) {
if (!App.checkAscii(path)) return;
path = path.replace("\\\\", "\\");
path = path.replace("\r", "");
#if krom_windows
var sep = "\\";
#else
var sep = "/";
#end
filename = path.substr(path.lastIndexOf(sep) + 1);
if (isSave) path = path.substr(0, path.lastIndexOf(sep));
filesDone(path);
}
releaseKeys();
}
#end
}
static function releaseKeys() {
// File dialog may prevent firing key up events
var kb = Input.getKeyboard();
@:privateAccess kb.upListener(kha.input.KeyCode.Shift);
@:privateAccess kb.upListener(kha.input.KeyCode.Control);
}
}