Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::view::FileChooser Class Reference

Builder-style file chooser. More...

#include <file_chooser.hpp>

Public Types

using ResultCallback = std::function<void(std::vector<std::string>)>
 Callback signature shared by every dialog kind.

Public Member Functions

 FileChooser ()=default
FileChooser & set_title (std::string title)
 Dialog window title.
const std::string & title () const
FileChooser & set_initial_directory (std::string path)
 Initial directory the dialog opens to. Empty == platform default.
const std::string & initial_directory () const
FileChooser & set_default_name (std::string name)
 Default filename suggested in save dialogs.
const std::string & default_name () const
FileChooser & add_filter (pulp::platform::FileFilter filter)
 Append a fully-formed FileFilter.
FileChooser & add_extension_filter (std::string description, std::string extensions)
 Convenience wrapper: append a description + semicolon-separated extension list.
FileChooser & clear_filters ()
 Clear all filters. Returns *this so the call chain still flows.
const std::vector< pulp::platform::FileFilter > & filters () const
 Read-only view of accumulated filters (preserves insertion order).
FileChooser & set_allow_multiple (bool allow)
 When true, open() invokes the platform multi-file dialog and the callback may receive more than one path.
bool allow_multiple () const
void open (ResultCallback callback) const
 Show an open dialog.
void save (ResultCallback callback) const
 Show a save dialog. Runs the callback exactly once.
void choose_folder (ResultCallback callback) const
 Show a folder-chooser dialog.

Detailed Description

Builder-style file chooser.

Usage:

FileChooser chooser;
chooser.set_title("Load preset")
.set_initial_directory("/Users/me/Presets")
.add_extension_filter("Pulp preset", "pulp")
.add_extension_filter("All audio", "wav;flac;aiff");
chooser.open([](const std::vector<std::string>& paths) {
if (!paths.empty()) load_preset(paths.front());
});
void open(ResultCallback callback) const
Show an open dialog.
FileChooser & set_title(std::string title)
Dialog window title.
FileChooser & set_initial_directory(std::string path)
Initial directory the dialog opens to. Empty == platform default.
FileChooser & add_extension_filter(std::string description, std::string extensions)
Convenience wrapper: append a description + semicolon-separated extension list.

open() calls the open-file dialog (single-selection unless set_allow_multiple(true)). save() calls the save dialog. The chooser can be reused across multiple calls; per-call results never mutate the builder state.

Member Typedef Documentation

◆ ResultCallback

using pulp::view::FileChooser::ResultCallback = std::function<void(std::vector<std::string>)>

Callback signature shared by every dialog kind.

  • open() yields 0 or 1 paths (or N when allow_multiple is true).
  • save() yields 0 or 1 paths.
  • choose_folder() yields 0 or 1 paths. An empty vector means the user cancelled or no backend was installed.

Constructor & Destructor Documentation

◆ FileChooser()

pulp::view::FileChooser::FileChooser ( )
default

Member Function Documentation

◆ add_extension_filter()

FileChooser & pulp::view::FileChooser::add_extension_filter ( std::string description,
std::string extensions )

Convenience wrapper: append a description + semicolon-separated extension list.

Equivalent to add_filter({desc, exts}).

◆ add_filter()

FileChooser & pulp::view::FileChooser::add_filter ( pulp::platform::FileFilter filter)

Append a fully-formed FileFilter.

See pulp::platform::FileFilter for the description + semicolon-extension contract.

◆ allow_multiple()

bool pulp::view::FileChooser::allow_multiple ( ) const
inline

◆ choose_folder()

void pulp::view::FileChooser::choose_folder ( ResultCallback callback) const

Show a folder-chooser dialog.

Filters are ignored. Runs the callback exactly once.

◆ clear_filters()

FileChooser & pulp::view::FileChooser::clear_filters ( )

Clear all filters. Returns *this so the call chain still flows.

◆ default_name()

const std::string & pulp::view::FileChooser::default_name ( ) const
inline

◆ filters()

const std::vector< pulp::platform::FileFilter > & pulp::view::FileChooser::filters ( ) const
inline

Read-only view of accumulated filters (preserves insertion order).

◆ initial_directory()

const std::string & pulp::view::FileChooser::initial_directory ( ) const
inline

◆ open()

void pulp::view::FileChooser::open ( ResultCallback callback) const

Show an open dialog.

Runs the callback exactly once with the selected paths (empty on cancel / no-backend). Callback may be null — the dialog still runs, but the result is discarded.

◆ save()

void pulp::view::FileChooser::save ( ResultCallback callback) const

Show a save dialog. Runs the callback exactly once.

◆ set_allow_multiple()

FileChooser & pulp::view::FileChooser::set_allow_multiple ( bool allow)

When true, open() invokes the platform multi-file dialog and the callback may receive more than one path.

Defaults to false.

◆ set_default_name()

FileChooser & pulp::view::FileChooser::set_default_name ( std::string name)

Default filename suggested in save dialogs.

Ignored by open() / choose_folder(). Empty == platform default.

◆ set_initial_directory()

FileChooser & pulp::view::FileChooser::set_initial_directory ( std::string path)

Initial directory the dialog opens to. Empty == platform default.

◆ set_title()

FileChooser & pulp::view::FileChooser::set_title ( std::string title)

Dialog window title.

Defaults differ per dialog kind (Open / Save / Choose Folder); set explicitly when you want a custom prompt.

◆ title()

const std::string & pulp::view::FileChooser::title ( ) const
inline

The documentation for this class was generated from the following file: