Search guides and the APICtrl K
  1. API reference
  2. Native GUI

gfx/file_browser.h

Choosing a file from inside the editor.

#include <sonore/gfx/file_browser.h>
On this page

Design notes

Why not just use the system dialog

file_dialog.h opens the OS chooser, and for "load an impulse response" that is right: it is the dialog the user knows, it has their places and their recent folders, and it costs nothing to maintain.

It is the wrong tool for a sampler. A browser that lives IN the editor stays open while you audition, keeps its position between plugins, can preview on selection, and does not steal focus from the host every time you look at another file. Every sampler worth using has one, and none of them use the OS dialog for it.

What this is made of

TreeView over listDirectory, and almost nothing else. The tree is already lazy and already virtual, so a hundred-thousand-file library costs one readdir per folder the user actually opens. What is here is the wiring, and the handful of decisions that wiring has to make.

The synthetic root

On Windows there is no single top: a library on D: cannot be reached from C: by going up. So when no start folder is given, the browser's root has one child per drive. On POSIX it has one child, "/". Either way the user can always get to everything, which is what a browser that traps you on one volume cannot say.

Types 1

class FileBrowser : public Widget

A file tree that lives inside the editor, for a sampler's library rather than a one-off "open" -- see the file comment for why it is not the system dialog, and what its root is when none is given.

Folders are read lazily, one directory listing when the user opens one, and on the calling thread: message thread only, and a folder on a slow network share blocks the UI while it is read. Nothing watches the disk; refresh() is how a change made elsewhere shows up. Paths are UTF-8, and every node's id is its full path.

↑↓ to move↵ to openEvery public name in the headers, and every guide