Skip to content

Commit da5a74b

Browse files
gajopclaude
andcommitted
Keep texture pickers file-only; list dirs only in the Open dialog
Listing sub-directories as grid cells was added so the Open dialog could show projects (`.sdd` folders the engine's file-only ListDir never returns). It leaked into every asset grid: the water/detail texture pickers browse engine VFS dirs like `bitmaps/`, whose dozens of unrelated sub-folders sorted ahead of the textures and buried them — the picker's first cell became a folder, and water-panel could no longer pick a normal texture. Gate the directory cells behind `list_entries_with_dirs`, used only by the file dialog. Texture pickers go back to files-only, restoring the verified behaviour. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 7d3cbad commit da5a74b

2 files changed

Lines changed: 51 additions & 25 deletions

File tree

native/src/sbc/panels/controls/grid.rs

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -392,36 +392,62 @@ pub(crate) fn list_assets(
392392
interface: &NativeInterfaceRef,
393393
dir: &str,
394394
extensions: &[&str],
395+
) -> Vec<GridItem> {
396+
list_entries(interface, dir, extensions, false)
397+
}
398+
399+
/// Like [`list_assets`], but also lists sub-directories as browsable folder
400+
/// cells. Only the Open/Load dialog wants that: a project is an `.sdd` folder,
401+
/// invisible to the engine's file-only `ListDir`. Texture pickers stay
402+
/// file-only, or engine dirs (`bitmaps/`) would bury the textures under dozens
403+
/// of unrelated sub-folders.
404+
pub(crate) fn list_entries_with_dirs(
405+
interface: &NativeInterfaceRef,
406+
dir: &str,
407+
extensions: &[&str],
408+
) -> Vec<GridItem> {
409+
list_entries(interface, dir, extensions, true)
410+
}
411+
412+
fn list_entries(
413+
interface: &NativeInterfaceRef,
414+
dir: &str,
415+
extensions: &[&str],
416+
include_dirs: bool,
395417
) -> Vec<GridItem> {
396418
let extensions = normalize_extensions(extensions);
397419
// Directories must come from SubDirs, not the entry listing: the engine's
398420
// ListDir only ever returns files (it never fills its directory list), so a
399421
// project -- an `.sdd` folder in the write dir -- is invisible to a plain
400422
// entry listing and Load comes back empty. SubDirs defaults to VFS.RAW_FIRST,
401423
// which sees the write dir, exactly as Lua's `Path.SubDirs` does.
402-
let mut dirs: Vec<GridItem> = vfs_sub_dirs(interface, dir.trim_end_matches('/'))
403-
.into_iter()
404-
.map(|name| {
405-
let path = join_entry(dir, &name);
406-
// A project folder carries a map thumbnail saved on its last save;
407-
// show it so projects are recognisable in the Open dialog. Other
408-
// directories simply have no such file.
409-
let thumb = format!("{path}/sb_project_files/screenshot.jpg");
410-
let image = interface
411-
.vfs()
412-
.file_exists(&thumb)
413-
.unwrap_or(false)
414-
.then_some(thumb);
415-
GridItem {
416-
id: path,
417-
caption: name,
418-
image,
419-
is_directory: true,
420-
tooltip: None,
421-
tooltip_markup: None,
422-
}
423-
})
424-
.collect();
424+
let mut dirs: Vec<GridItem> = if include_dirs {
425+
vfs_sub_dirs(interface, dir.trim_end_matches('/'))
426+
.into_iter()
427+
.map(|name| {
428+
let path = join_entry(dir, &name);
429+
// A project folder carries a map thumbnail saved on its last
430+
// save; show it so projects are recognisable in the Open dialog.
431+
// Other directories simply have no such file.
432+
let thumb = format!("{path}/sb_project_files/screenshot.jpg");
433+
let image = interface
434+
.vfs()
435+
.file_exists(&thumb)
436+
.unwrap_or(false)
437+
.then_some(thumb);
438+
GridItem {
439+
id: path,
440+
caption: name,
441+
image,
442+
is_directory: true,
443+
tooltip: None,
444+
tooltip_markup: None,
445+
}
446+
})
447+
.collect()
448+
} else {
449+
Vec::new()
450+
};
425451

426452
let mut files = Vec::new();
427453
if let Ok(entries) = interface.vfs().list_entries(dir, "*", "", false) {

native/src/sbc/panels/dialogs/file_dialog.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use spring_native::prelude::{Error, NativeInterfaceRef};
1414

1515
use crate::sbc::actions::{FileAcceptFn, FileDialogConfig, FileDialogResult};
1616
use crate::sbc::panels::controls::asset_picker::PickerEvent;
17-
use crate::sbc::panels::controls::grid::{list_assets, parent_dir, GridView};
17+
use crate::sbc::panels::controls::grid::{list_entries_with_dirs, parent_dir, GridView};
1818
use crate::sbc::panels::dialogs::form::{DialogForm, FormItem};
1919
use crate::sbc::panels::editor::Editor;
2020
use crate::sbc::panels::field::{
@@ -264,7 +264,7 @@ impl FileDialog {
264264
.map(|c| c.extensions.iter().map(String::as_str).collect())
265265
.unwrap_or_default();
266266
self.grid
267-
.set_items(list_assets(interface, &self.dir, &extensions));
267+
.set_items(list_entries_with_dirs(interface, &self.dir, &extensions));
268268
self.grid.render(interface, document)?;
269269
if let Some(e) = element_by_id(interface, document, "fd-path") {
270270
interface

0 commit comments

Comments
 (0)