From d028010c8c4ad9b76b8c3e115d3ab58e95193a3d Mon Sep 17 00:00:00 2001 From: luboslenco Date: Sun, 1 Mar 2026 15:30:24 +0100 Subject: [PATCH] base: improve handling of directories in browser (thanks to @blakelinkd) --- base/sources/ts/file.ts | 2 +- paint/sources/tab_browser.ts | 3 +++ paint/sources/ui_files.ts | 18 ++++++++++-------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/base/sources/ts/file.ts b/base/sources/ts/file.ts index d21522f6..8a6dc0d7 100644 --- a/base/sources/ts/file.ts +++ b/base/sources/ts/file.ts @@ -65,7 +65,7 @@ function file_read_directory(path: string): string[] { let num: i32 = files.length; for (let i: i32 = 0; i < num; ++i) { let f: string = files[i]; - if (string_index_of(f, ".") > -1) { + if (!iron_is_directory(path_join(path, f))) { array_splice(files, i, 1); array_push(files, f); i--; diff --git a/paint/sources/tab_browser.ts b/paint/sources/tab_browser.ts index 504cee06..94783e6c 100644 --- a/paint/sources/tab_browser.ts +++ b/paint/sources/tab_browser.ts @@ -245,6 +245,9 @@ function tab_browser_draw(htab: ui_handle_t) { tab_browser_known = false; } /// end + if (tab_browser_known && iron_is_directory(tab_browser_hpath.text)) { + tab_browser_known = false; + } if (show_full) { let bottom_y: i32 = ui._y; diff --git a/paint/sources/ui_files.ts b/paint/sources/ui_files.ts index d9321081..f8f1708c 100644 --- a/paint/sources/ui_files.ts +++ b/paint/sources/ui_files.ts @@ -119,8 +119,10 @@ function ui_files_file_browser(handle: ui_handle_t, drag_files: bool = false, se if (f == "" || char_at(f, 0) == ".") { continue; // Skip hidden } - if (string_index_of(f, ".") > 0 && !path_is_known(f)) { - continue; // Skip unknown extensions + if (!is_cloud && string_index_of(f, ".") > 0) { + if (!iron_is_directory(path_join(dir_path, f)) && !path_is_known(f)) { + continue; // Skip unknown extensions + } } if (is_cloud && string_index_of(f, "_icon.") >= 0) { continue; // Skip thumbnails @@ -163,12 +165,12 @@ function ui_files_file_browser(handle: ui_handle_t, drag_files: bool = false, se let f: string = ui_files_files[i]; let _x: f32 = ui._x; - - let rect: rect_t = string_index_of(f, ".") > 0 ? file : folder; + let is_folder: bool = iron_is_directory(path_join(handle.text, f)); + let rect: rect_t = is_folder ? folder : file; if (rect == file && is_cloud) { rect = downloading; } - let col: i32 = rect == file ? ui.ops.theme.LABEL_COL : ui.ops.theme.LABEL_COL - 0x00202020; + let col: i32 = rect == file ? ui.ops.theme.LABEL_COL : ui.ops.theme.LABEL_COL - 0x00202020; if (ui_files_selected == i) col = ui.ops.theme.HIGHLIGHT_COL; @@ -254,7 +256,7 @@ function ui_files_file_browser(handle: ui_handle_t, drag_files: bool = false, se } } - if (ends_with(f, ".arm") && !is_cloud) { + if (!is_folder && ends_with(f, ".arm") && !is_cloud) { if (ui_files_icon_map == null) { ui_files_icon_map = map_create(); } @@ -318,7 +320,7 @@ function ui_files_file_browser(handle: ui_handle_t, drag_files: bool = false, se } } - if (path_is_texture(f) && !is_cloud) { + if (!is_folder && path_is_texture(f) && !is_cloud) { let w: i32 = 50; if (ui_files_icon_map == null) { ui_files_icon_map = map_create(); @@ -392,7 +394,7 @@ function ui_files_file_browser(handle: ui_handle_t, drag_files: bool = false, se // Label ui._x = _x; ui._y += slotw * 0.75; - let label0: string = (ui_files_show_extensions || string_index_of(f, ".") <= 0) ? f : substring(f, 0, string_last_index_of(f, ".")); + let label0: string = (is_folder || ui_files_show_extensions || string_index_of(f, ".") <= 0) ? f : substring(f, 0, string_last_index_of(f, ".")); let label1: string = ""; while (label0.length > 0 && draw_string_width(ui.ops.font, ui.font_size, label0) > ui._w - 6) { // 2 line split label1 = char_at(label0, label0.length - 1) + label1;