Add search to browser tab

This commit is contained in:
luboslenco
2021-02-17 16:41:44 +01:00
parent 48bae68eec
commit 3c73e262f6
2 changed files with 15 additions and 4 deletions
+10 -2
View File
@@ -9,7 +9,9 @@ import arm.Enums;
class TabBrowser {
static var hpath = new Handle();
static var hsearch = new Handle();
static var known = false;
static var lastPath = "";
@:access(zui.Zui)
public static function draw() {
@@ -28,18 +30,24 @@ class TabBrowser {
}
ui.beginSticky();
ui.row([bookmarksW / ui._w, 1 - bookmarksW / ui._w]);
ui.row([bookmarksW / ui._w, (1 - bookmarksW / ui._w) * 0.8, (1 - bookmarksW / ui._w) * 0.2]);
if (ui.button("+")) {
Config.raw.bookmarks.push(hpath.text);
Config.save();
}
hpath.text = ui.textInput(hpath, tr("Path"));
hsearch.text = ui.textInput(hsearch, tr("Search"));
ui.endSticky();
if (lastPath != hpath.text) {
hsearch.text = "";
}
lastPath = hpath.text;
var _y = ui._y;
ui._x = bookmarksW;
ui._w -= bookmarksW;
UIFiles.fileBrowser(ui, hpath, false, true);
UIFiles.fileBrowser(ui, hpath, false, true, hsearch.text);
if (known) {
var path = hpath.text;
+5 -2
View File
@@ -15,6 +15,7 @@ class UIFiles {
public static var filename: String;
public static var path = defaultPath;
static var lastPath = "";
static var lastSearch = "";
static var files: Array<String> = null;
static var iconMap: Map<String, kha.Image> = null;
static var selected = -1;
@@ -81,7 +82,7 @@ class UIFiles {
}
@:access(zui.Zui)
public static function fileBrowser(ui: Zui, handle: Handle, foldersOnly = false, dragFiles = false): String {
public static function fileBrowser(ui: Zui, handle: Handle, foldersOnly = false, dragFiles = false, search = ""): String {
var icons = Res.get("icons.k");
var folder = Res.tile50(icons, 2, 1);
@@ -89,7 +90,7 @@ class UIFiles {
var isCloud = handle.text.startsWith("cloud");
if (handle.text == "") handle.text = defaultPath;
if (handle.text != lastPath) {
if (handle.text != lastPath || search != lastSearch) {
files = [];
// Up directory
@@ -102,10 +103,12 @@ class UIFiles {
if (f == "" || f.charAt(0) == ".") continue; // Skip hidden
if (f.indexOf(".") > 0 && !Path.isKnown(f)) continue; // Skip unknown extensions
if (isCloud && f.indexOf("_icon.") >= 0) continue; // Skip thumbnails
if (f.toLowerCase().indexOf(search.toLowerCase()) < 0) continue; // Search filter
files.push(f);
}
}
lastPath = handle.text;
lastSearch = search;
handle.changed = false;
var slotw = Std.int(70 * ui.SCALE());