Skip to content

UXFileChooser

UXFileChooser is the model behind an open/save file panel: the current directory as a UXPath, a backend-supplied listing of its entries, an extension filter, and the prompt string. The backend provides the panel view and reads the directory; this class holds the testable state it drives.

The filter rule: directories always show; files show only when they match an allowed extension (an empty filter accepts all). Navigation is pure UXPath editing: entering a folder appends a component, and going up deletes one. The whole model can be tested with no filesystem.

#use <UXKit>

The chooser has no view of its own. It is the state behind whichever panel runs. Call UXOpenPanel.run() and you get the platform’s own dialog where one exists, or the toolkit-drawn UXFilePanel driving this model where none does. Two captures of that panel follow:

The toolkit file panel on GEM

The toolkit-drawn UXFilePanel (GEM has no OS file selector): mask + Find, the sortable Name/Size listing with folders first, Recent, and the Manage group. Every control is a neutral widget over this model.

UXFileChooser* fc = new UXFileChooser();
fc.setDirectory(UXPath.parse((u8*)"/home/user"));
fc.allowExtension((u8*)"png");
fc.allowExtension((u8*)"jpg");
fc.setEntries(listingFromBackend);
Array* show = fc.visibleEntries(); // dirs + matching files only

Navigation · directory · setDirectory · enter · goUp Listing · setEntries · visibleEntries · visibleCount · acceptsFile · allowExtension Open vs save · setSaveMode · setSaveName · setPrompt · resultPath

UXPath* directory(void)
void setDirectory(UXPath* p)

Where the chooser is browsing.

void enter(u8* dirname)

Appends the folder to the path and clears the entries. The backend then re-lists the new directory.

void goUp(void)

Deletes the last component and clears the entries.

void setEntries(Array* e)

The backend hands over the raw directory listing (UXFileEntry items).

Array<UXFileEntry>* visibleEntries(void)

The filtered listing: every directory, plus the files that pass the extension filter.

i32 visibleCount(void)

How many entries pass the filter.

bool acceptsFile(u8* name)

The filter itself: case-insensitive extension match, or every file when the filter is empty.

void allowExtension(u8* ext)

Adds an accepted extension (without the dot).

void setSaveMode(bool on)

Switches to save semantics. The default “Open” prompt becomes “Save” (a custom prompt is kept).

void setSaveName(u8* n)

The proposed file name a save panel returns.

void setPrompt(u8* p)

The customisable button/title string.

u8* resultPath(u8* chosenName)

The full path the panel returns: the directory plus the chosen name, or plus the save name in save mode.