Skip to content

Commit d028010

Browse files
committed
base: improve handling of directories in browser (thanks to @blakelinkd)
1 parent ffd6cda commit d028010

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

base/sources/ts/file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function file_read_directory(path: string): string[] {
6565
let num: i32 = files.length;
6666
for (let i: i32 = 0; i < num; ++i) {
6767
let f: string = files[i];
68-
if (string_index_of(f, ".") > -1) {
68+
if (!iron_is_directory(path_join(path, f))) {
6969
array_splice(files, i, 1);
7070
array_push(files, f);
7171
i--;

paint/sources/tab_browser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ function tab_browser_draw(htab: ui_handle_t) {
245245
tab_browser_known = false;
246246
}
247247
/// end
248+
if (tab_browser_known && iron_is_directory(tab_browser_hpath.text)) {
249+
tab_browser_known = false;
250+
}
248251

249252
if (show_full) {
250253
let bottom_y: i32 = ui._y;

paint/sources/ui_files.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,10 @@ function ui_files_file_browser(handle: ui_handle_t, drag_files: bool = false, se
119119
if (f == "" || char_at(f, 0) == ".") {
120120
continue; // Skip hidden
121121
}
122-
if (string_index_of(f, ".") > 0 && !path_is_known(f)) {
123-
continue; // Skip unknown extensions
122+
if (!is_cloud && string_index_of(f, ".") > 0) {
123+
if (!iron_is_directory(path_join(dir_path, f)) && !path_is_known(f)) {
124+
continue; // Skip unknown extensions
125+
}
124126
}
125127
if (is_cloud && string_index_of(f, "_icon.") >= 0) {
126128
continue; // Skip thumbnails
@@ -163,12 +165,12 @@ function ui_files_file_browser(handle: ui_handle_t, drag_files: bool = false, se
163165

164166
let f: string = ui_files_files[i];
165167
let _x: f32 = ui._x;
166-
167-
let rect: rect_t = string_index_of(f, ".") > 0 ? file : folder;
168+
let is_folder: bool = iron_is_directory(path_join(handle.text, f));
169+
let rect: rect_t = is_folder ? folder : file;
168170
if (rect == file && is_cloud) {
169171
rect = downloading;
170172
}
171-
let col: i32 = rect == file ? ui.ops.theme.LABEL_COL : ui.ops.theme.LABEL_COL - 0x00202020;
173+
let col: i32 = rect == file ? ui.ops.theme.LABEL_COL : ui.ops.theme.LABEL_COL - 0x00202020;
172174
if (ui_files_selected == i)
173175
col = ui.ops.theme.HIGHLIGHT_COL;
174176

@@ -254,7 +256,7 @@ function ui_files_file_browser(handle: ui_handle_t, drag_files: bool = false, se
254256
}
255257
}
256258

257-
if (ends_with(f, ".arm") && !is_cloud) {
259+
if (!is_folder && ends_with(f, ".arm") && !is_cloud) {
258260
if (ui_files_icon_map == null) {
259261
ui_files_icon_map = map_create();
260262
}
@@ -318,7 +320,7 @@ function ui_files_file_browser(handle: ui_handle_t, drag_files: bool = false, se
318320
}
319321
}
320322

321-
if (path_is_texture(f) && !is_cloud) {
323+
if (!is_folder && path_is_texture(f) && !is_cloud) {
322324
let w: i32 = 50;
323325
if (ui_files_icon_map == null) {
324326
ui_files_icon_map = map_create();
@@ -392,7 +394,7 @@ function ui_files_file_browser(handle: ui_handle_t, drag_files: bool = false, se
392394
// Label
393395
ui._x = _x;
394396
ui._y += slotw * 0.75;
395-
let label0: string = (ui_files_show_extensions || string_index_of(f, ".") <= 0) ? f : substring(f, 0, string_last_index_of(f, "."));
397+
let label0: string = (is_folder || ui_files_show_extensions || string_index_of(f, ".") <= 0) ? f : substring(f, 0, string_last_index_of(f, "."));
396398
let label1: string = "";
397399
while (label0.length > 0 && draw_string_width(ui.ops.font, ui.font_size, label0) > ui._w - 6) { // 2 line split
398400
label1 = char_at(label0, label0.length - 1) + label1;

0 commit comments

Comments
 (0)