From 5cbfcf68d6ab01e7000f00a1a2205bb8c5784a22 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Wed, 6 Nov 2019 22:52:26 +0100 Subject: [PATCH] Add 'Preferences - Native File Browser' option --- Sources/arm/ui/BoxPreferences.hx | 2 ++ Sources/arm/ui/UIFiles.hx | 34 +++++++++++++++++++++++++++++++- Sources/arm/ui/UITrait.hx | 1 + 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Sources/arm/ui/BoxPreferences.hx b/Sources/arm/ui/BoxPreferences.hx index 4724a5d0..0971ce46 100644 --- a/Sources/arm/ui/BoxPreferences.hx +++ b/Sources/arm/ui/BoxPreferences.hx @@ -52,6 +52,8 @@ class BoxPreferences { UITrait.inst.hwnd2.redraws = 2; } + UITrait.inst.nativeBrowser = ui.check(Id.handle({selected: UITrait.inst.nativeBrowser}), "Native File Browser"); + UITrait.inst.cacheDraws = ui.check(Id.handle({selected: UITrait.inst.cacheDraws}), "Cache Draws"); if (ui.isHovered) ui.tooltip("Enabling may reduce GPU usage"); diff --git a/Sources/arm/ui/UIFiles.hx b/Sources/arm/ui/UIFiles.hx index 59fe97bc..555cfcc2 100644 --- a/Sources/arm/ui/UIFiles.hx +++ b/Sources/arm/ui/UIFiles.hx @@ -3,6 +3,7 @@ package arm.ui; import zui.Zui; import zui.Id; import iron.system.Input; +import arm.util.Path; using StringTools; class UIFiles { @@ -14,9 +15,14 @@ class UIFiles { public static var filters = ""; public static var path = '/'; - @:access(zui.Zui) public static function render(g:kha.graphics2.Graphics) { show = false; + + if (!UITrait.inst.nativeBrowser) { + renderCustom(g); + return; + } + path = isSave ? Krom.saveDialog(filters, "") : Krom.openDialog(filters, ""); if (path != null) { #if krom_windows @@ -36,6 +42,32 @@ class UIFiles { releaseKeys(); } + @:access(zui.Zui) + static function renderCustom(g:kha.graphics2.Graphics) { + UIBox.showCustom(function(ui:Zui) { + if (ui.tab(Id.handle(), "File Browser")) { + var pathHandle = Id.handle(); + var fileHandle = Id.handle(); + ui.row([6/10, 2/10, 2/10]); + filename = ui.textInput(fileHandle, "File"); + ui.text('*.' + filters, Center); + var known = Path.checkTextureFormat(path) || Path.checkMeshFormat(path) || Path.checkProjectFormat(path); + if (ui.button(isSave ? "Save" : "Open") || known) { + UIBox.show = false; + #if krom_windows + var sep = "\\"; + #else + var sep = "/"; + #end + filesDone((known || isSave) ? path : path + sep + filename); + if (known) pathHandle.text = pathHandle.text.substr(0, pathHandle.text.lastIndexOf(sep)); + } + path = zui.Ext.fileBrowser(ui, pathHandle, false); + if (pathHandle.changed) ui.currentWindow.redraws = 3; + } + }, 600, 500); + } + static function releaseKeys() { // File dialog may prevent firing key up events var kb = Input.getKeyboard(); diff --git a/Sources/arm/ui/UITrait.hx b/Sources/arm/ui/UITrait.hx index a839514d..95a1a693 100644 --- a/Sources/arm/ui/UITrait.hx +++ b/Sources/arm/ui/UITrait.hx @@ -132,6 +132,7 @@ class UITrait { public var viewportMode = 0; public var hscaleWasChanged = false; public var exportMeshFormat = 0; + public var nativeBrowser = true; public var cacheDraws = false; public var textToolImage:Image = null;