2019-10-17 22:00:59 +02:00
|
|
|
package arm.ui;
|
|
|
|
|
|
2022-04-23 18:23:55 +02:00
|
|
|
import kha.input.KeyCode;
|
2020-01-13 23:40:14 +01:00
|
|
|
import zui.Zui;
|
2019-10-17 22:00:59 +02:00
|
|
|
import zui.Id;
|
2020-01-13 23:40:14 +01:00
|
|
|
import arm.sys.Path;
|
|
|
|
|
import arm.io.ImportAsset;
|
2020-09-07 14:44:01 +02:00
|
|
|
import arm.Enums;
|
2019-10-17 22:00:59 +02:00
|
|
|
|
|
|
|
|
class TabBrowser {
|
|
|
|
|
|
2020-01-13 23:40:14 +01:00
|
|
|
static var hpath = new Handle();
|
2021-02-17 16:41:44 +01:00
|
|
|
static var hsearch = new Handle();
|
2020-01-13 23:40:14 +01:00
|
|
|
static var known = false;
|
2021-02-17 16:41:44 +01:00
|
|
|
static var lastPath = "";
|
2020-01-13 23:40:14 +01:00
|
|
|
|
2022-02-16 11:12:16 +01:00
|
|
|
public static function showDirectory(directory: String) {
|
2022-02-11 15:19:51 +01:00
|
|
|
hpath.text = directory;
|
|
|
|
|
hsearch.text = "";
|
|
|
|
|
UIStatus.inst.statustab.position = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 22:00:59 +02:00
|
|
|
@:access(zui.Zui)
|
|
|
|
|
public static function draw() {
|
2020-03-18 20:26:28 +01:00
|
|
|
var ui = UISidebar.inst.ui;
|
2020-09-07 14:44:01 +02:00
|
|
|
var statush = Config.raw.layout[LayoutStatusH];
|
|
|
|
|
if (ui.tab(UIStatus.inst.statustab, tr("Browser")) && statush > UIStatus.defaultStatusH * ui.SCALE()) {
|
2020-01-14 13:12:17 +01:00
|
|
|
|
|
|
|
|
if (Config.raw.bookmarks == null) {
|
|
|
|
|
Config.raw.bookmarks = [];
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-13 23:40:14 +01:00
|
|
|
var bookmarksW = Std.int(100 * ui.SCALE());
|
|
|
|
|
|
2020-01-14 13:12:17 +01:00
|
|
|
if (hpath.text == "" && Config.raw.bookmarks.length > 0) { // Init to first bookmark
|
|
|
|
|
hpath.text = Config.raw.bookmarks[0];
|
|
|
|
|
}
|
2020-07-08 23:51:42 +02:00
|
|
|
|
2021-02-15 11:36:29 +01:00
|
|
|
ui.beginSticky();
|
2022-02-03 11:58:57 +01:00
|
|
|
if (hsearch.text != "") {
|
|
|
|
|
ui.row([bookmarksW / ui._w, (1 - bookmarksW / ui._w) * 0.75, (1 - bookmarksW / ui._w) * 0.05, (1 - bookmarksW / ui._w) * 0.17, (1 - bookmarksW / ui._w) * 0.03]);
|
2021-12-28 14:00:00 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2022-02-03 11:58:57 +01:00
|
|
|
ui.row([bookmarksW / ui._w, (1 - bookmarksW / ui._w) * 0.75, (1 - bookmarksW / ui._w) * 0.05, (1 - bookmarksW / ui._w) * 0.2]);
|
2021-12-28 14:00:00 +01:00
|
|
|
}
|
|
|
|
|
|
2021-02-15 11:36:29 +01:00
|
|
|
if (ui.button("+")) {
|
|
|
|
|
Config.raw.bookmarks.push(hpath.text);
|
|
|
|
|
Config.save();
|
|
|
|
|
}
|
2020-03-17 19:16:19 +01:00
|
|
|
hpath.text = ui.textInput(hpath, tr("Path"));
|
2021-12-28 14:00:00 +01:00
|
|
|
var refresh = false;
|
|
|
|
|
var inFocus = ui.inputX > ui._windowX && ui.inputX < ui._windowX + ui._windowW &&
|
|
|
|
|
ui.inputY > ui._windowY && ui.inputY < ui._windowY + ui._windowH;
|
|
|
|
|
if (ui.button(tr("Refresh")) || (inFocus && ui.isKeyPressed && ui.key == kha.input.KeyCode.F5)) {
|
|
|
|
|
refresh = true;
|
|
|
|
|
}
|
2022-04-23 18:23:55 +02:00
|
|
|
hsearch.text = ui.textInput(hsearch, tr("Search"), Align.Left, true, true);
|
|
|
|
|
if (ui.isHovered) ui.tooltip(tr("Press ctrl+f to search and esc to cancel"));
|
|
|
|
|
if (ui.isCtrlDown && ui.isKeyPressed && ui.key == KeyCode.F) { // start searching via ctrl+f
|
|
|
|
|
ui.startTextEdit(hsearch);
|
|
|
|
|
}
|
|
|
|
|
if (hsearch.text != "" && (ui.button(tr("X")) || ui.isEscapeDown)) {
|
2021-12-28 14:00:00 +01:00
|
|
|
hsearch.text = "";
|
|
|
|
|
}
|
2021-02-15 11:36:29 +01:00
|
|
|
ui.endSticky();
|
2020-07-08 23:51:42 +02:00
|
|
|
|
2021-02-17 16:41:44 +01:00
|
|
|
if (lastPath != hpath.text) {
|
|
|
|
|
hsearch.text = "";
|
|
|
|
|
}
|
|
|
|
|
lastPath = hpath.text;
|
|
|
|
|
|
2021-02-17 10:21:19 +01:00
|
|
|
var _y = ui._y;
|
2021-02-15 11:36:29 +01:00
|
|
|
ui._x = bookmarksW;
|
|
|
|
|
ui._w -= bookmarksW;
|
2021-12-28 14:00:00 +01:00
|
|
|
UIFiles.fileBrowser(ui, hpath, false, true, hsearch.text, refresh);
|
2020-01-13 23:40:14 +01:00
|
|
|
|
|
|
|
|
if (known) {
|
2020-09-29 11:12:43 +02:00
|
|
|
var path = hpath.text;
|
|
|
|
|
iron.App.notifyOnInit(function() {
|
|
|
|
|
ImportAsset.run(path);
|
|
|
|
|
});
|
2020-01-13 23:40:14 +01:00
|
|
|
hpath.text = hpath.text.substr(0, hpath.text.lastIndexOf(Path.sep));
|
|
|
|
|
}
|
2021-02-10 12:10:29 +01:00
|
|
|
known = hpath.text.substr(hpath.text.lastIndexOf(Path.sep)).indexOf(".") > 0;
|
|
|
|
|
#if krom_android
|
|
|
|
|
if (hpath.text.endsWith(".armorpaint")) known = false;
|
|
|
|
|
#end
|
2020-01-13 23:40:14 +01:00
|
|
|
|
|
|
|
|
var bottomY = ui._y;
|
|
|
|
|
ui._x = 0;
|
|
|
|
|
ui._y = _y;
|
|
|
|
|
ui._w = bookmarksW;
|
|
|
|
|
|
2021-01-15 16:54:11 +01:00
|
|
|
if (ui.button(tr("Cloud"), Left)) {
|
|
|
|
|
hpath.text = "cloud";
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-15 16:54:37 +01:00
|
|
|
if (ui.button(tr("Disk"), Left)) {
|
|
|
|
|
hpath.text = UIFiles.defaultPath;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-13 23:40:14 +01:00
|
|
|
for (b in Config.raw.bookmarks) {
|
|
|
|
|
var folder = b.substr(b.lastIndexOf(Path.sep) + 1);
|
|
|
|
|
|
|
|
|
|
if (ui.button(folder, Left)) {
|
|
|
|
|
hpath.text = b;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ui.isHovered && ui.inputReleasedR) {
|
|
|
|
|
UIMenu.draw(function(ui: Zui) {
|
|
|
|
|
ui.text(folder, Right, ui.t.HIGHLIGHT_COL);
|
2020-03-17 19:16:19 +01:00
|
|
|
if (ui.button(tr("Delete"), Left)) {
|
2020-01-13 23:40:14 +01:00
|
|
|
Config.raw.bookmarks.remove(b);
|
|
|
|
|
Config.save();
|
|
|
|
|
}
|
2020-02-01 12:39:23 +01:00
|
|
|
}, 2);
|
2020-01-13 23:40:14 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-15 11:36:29 +01:00
|
|
|
if (ui._y < bottomY) ui._y = bottomY;
|
2019-10-17 22:00:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|