gfx/file_chooser.h
The pieces of a file chooser drawn inside the editor.
#include <sonore/gfx/file_chooser.h>- 7types
- Guides: The native editor
On this page
Design notes
Next to file_browser.h and file_dialog.h
file_dialog.h opens the operating system's chooser, and for "load an impulse response" that is still the right call: it has the user's places, it reaches network volumes, and on macOS it is the only door out of the sandbox. file_browser.h is the sampler's browser: a tree that lives in the editor and stays open while you audition.
This file is the rest of the reference's set, built on the same listDirectory:
FileListComponent- one folder as a list -- name, kind, size -- that is walked into and out of, with type-ahead
FileTreeComponent- FileBrowser rooted at a folder, with a preview hook
FilePreviewComponent- what a chooser calls when the selection moves
ImagePreviewComponent- a preview that shows PNG and SVG files
FilenameComponent- a path field with a browse button and the recently used files behind a drop-down -- the control a plugin's settings page uses for "sample folder"
FileSearchPathListComponent- an editable list of folders, for a plugin that looks for content in several places
FileChooserDialogBox- all of it in a dialog over the editor: open, save (asking before it overwrites) or choose a folder
The dialog is in the editor, like every dialog here
alert.h says why: a plugin's own top-level window can end up behind the host's, waiting on a click that cannot happen. The dialog is an Overlay, answers through a callback, and blocks nothing.
Nothing watches the disk
A folder is read when it is shown and when refresh() is called. A watch is a per-platform API with a thread behind it, and a plugin holding one on a network share keeps the share awake -- file_browser.h made the same call.
Types 7
class FilePreviewComponent : public Widget
Something a chooser shows beside its list, told whenever the selected file changes -- an empty path when nothing is selected.
class ImagePreviewComponent : public FilePreviewComponent
A preview of PNG and SVG files: the picture, scaled to fit without distortion, with its name and size under it.
class FileListComponent : public Widget
One folder's contents as a list.
A ListBox underneath, so the keyboard, the scroll bar and the reader's "row 12 of 40" are the list's own; this adds the folder, the rows' look, walking in and out, and type-ahead -- pressing a letter selects the next entry beginning with it, which is how anybody finds a file in a folder of four hundred without the mouse.
class FileTreeComponent : public FileBrowser
FileBrowser rooted at one folder, with a preview hook.
The tree itself is file_browser.h's -- lazy, one read per folder opened -- and this is the shape the reference gives it: a folder to show, a selected file, and a preview told as the selection moves.
class FileChooserDialogBox : public Overlay
Choosing a file or a folder, in a dialog over the editor.
Add it to the editor's root (or let a FilenameComponent do so), then show(). The answer arrives once, through the callback: the chosen path, or empty when the user cancelled.
class FilenameComponent : public Widget
A path in a field, a button to browse for it, and the last few chosen behind a drop-down.
Typing a path and pressing Return (or leaving the field) sets it; so does dropping a file on it. The recently used list is the caller's to persist -- recentlyUsedFilenames() out, setRecentlyUsedFilenames() back in.
class FileSearchPathListComponent : public Widget
A list of folders to look in, edited in place: add, remove, change, and move up or down -- the order is the search order.