Built-in preset manager for Pulp plugins. More...
#include <preset_manager.hpp>
Public Member Functions | |
| PresetManager (StateStore &store, const std::string &manufacturer, const std::string &plugin_name) | |
| Construct with a StateStore and plugin identity for path resolution. | |
| bool | save (const std::string &name, const std::string &folder="") |
| Save current state as a named preset in the user presets folder. | |
| bool | load (const PresetInfo &preset) |
| Load a preset from a PresetInfo (sets all parameter values). | |
| bool | load (const std::filesystem::path &path) |
| Load a preset by file path. | |
| std::optional< std::vector< ParamSetting > > | read_values (const std::filesystem::path &path) const |
| Read the parameter values a preset file holds without applying them. | |
| bool | delete_preset (const PresetInfo &preset) |
| Delete a user preset file. Factory presets cannot be deleted. | |
| bool | rename (const PresetInfo &preset, const std::string &new_name) |
| Rename a user preset. | |
| std::optional< PresetInfo > | import_file (const std::filesystem::path &source) |
| Import a preset file from an external location into user presets. | |
| std::vector< PresetInfo > | all_presets () const |
| Get all presets (factory + user), sorted alphabetically. | |
| std::vector< PresetInfo > | factory_presets () const |
| Get factory presets only. | |
| std::vector< PresetInfo > | user_presets () const |
| Get user presets only. | |
| std::vector< PresetInfo > | content_presets () const |
| Get installed content-pack presets matching this plugin's content capabilities. | |
| void | set_content_preset_source (ContentPresetSource source) |
| Install the reader that lists installed content-pack presets. | |
| void | set_content_plugin_id (std::string plugin_id) |
| Opt into installed content-pack discovery for this plugin id. | |
| void | set_content_capabilities (std::vector< std::string > capabilities) |
| Limit installed content packs to matching capabilities such as content.presets.v1. | |
| void | set_content_data_root (std::filesystem::path data_root) |
| Override the content data root. | |
| void | set_content_manifest (const ContentCapabilityManifest &manifest) |
| Opt into content discovery from a parsed pulp.plugin-runtime.v1 manifest embedded in the plugin/app bundle. | |
| void | refresh () |
| Rescan preset directories (call after external changes). | |
| const std::string & | current_preset_name () const |
| The currently loaded preset (empty if unsaved/modified). | |
| void | set_current_preset_name (const std::string &name) |
| bool | has_unsaved_changes () const |
| True if parameters have changed since the last load/save. | |
| void | mark_as_changed () |
| void | mark_as_saved () |
| bool | load_next () |
| Load the next preset in the list. Wraps around. | |
| bool | load_previous () |
| Load the previous preset in the list. Wraps around. | |
| std::filesystem::path | user_presets_dir () const |
| The user presets directory. | |
| std::filesystem::path | factory_presets_dir () const |
| The factory presets directory (inside the plugin bundle). | |
| void | set_factory_presets_dir (std::filesystem::path dir) |
| Point factory-preset discovery at a directory. | |
Public Attributes | |
| std::function< void(const PresetInfo &)> | on_preset_loaded |
| Called after a preset is loaded. | |
| std::function< void()> | on_list_changed |
| Called after the preset list changes (save/delete/rename/import). | |
Built-in preset manager for Pulp plugins.
Handles the full preset lifecycle: save, load, delete, rename, import, factory vs user separation, folder scanning, and current-preset tracking.
Preset files are JSON with the plugin's serialized state plus metadata.
Storage locations (platform-standard):
Factory presets live in the plugin bundle's Resources/Presets/ directory.
| pulp::state::PresetManager::PresetManager | ( | StateStore & | store, |
| const std::string & | manufacturer, | ||
| const std::string & | plugin_name ) |
Construct with a StateStore and plugin identity for path resolution.
| std::vector< PresetInfo > pulp::state::PresetManager::all_presets | ( | ) | const |
Get all presets (factory + user), sorted alphabetically.
| std::vector< PresetInfo > pulp::state::PresetManager::content_presets | ( | ) | const |
Get installed content-pack presets matching this plugin's content capabilities.
These are read-only expansion/factory presets. Empty until both a content plugin id and a content-preset source are set.
|
inline |
The currently loaded preset (empty if unsaved/modified).
| bool pulp::state::PresetManager::delete_preset | ( | const PresetInfo & | preset | ) |
Delete a user preset file. Factory presets cannot be deleted.
| std::vector< PresetInfo > pulp::state::PresetManager::factory_presets | ( | ) | const |
Get factory presets only.
|
inline |
The factory presets directory (inside the plugin bundle).
|
inline |
True if parameters have changed since the last load/save.
| std::optional< PresetInfo > pulp::state::PresetManager::import_file | ( | const std::filesystem::path & | source | ) |
Import a preset file from an external location into user presets.
| bool pulp::state::PresetManager::load | ( | const PresetInfo & | preset | ) |
Load a preset from a PresetInfo (sets all parameter values).
| bool pulp::state::PresetManager::load | ( | const std::filesystem::path & | path | ) |
Load a preset by file path.
| bool pulp::state::PresetManager::load_next | ( | ) |
Load the next preset in the list. Wraps around.
| bool pulp::state::PresetManager::load_previous | ( | ) |
Load the previous preset in the list. Wraps around.
|
inline |
|
inline |
| std::optional< std::vector< ParamSetting > > pulp::state::PresetManager::read_values | ( | const std::filesystem::path & | path | ) | const |
Read the parameter values a preset file holds without applying them.
Only parameters the store defines and the file names are returned, in store order. Returns nullopt when the file cannot be read or has no parameters section. Lets a caller cache a preset once and apply it later from a thread that must not touch the file system.
| void pulp::state::PresetManager::refresh | ( | ) |
Rescan preset directories (call after external changes).
| bool pulp::state::PresetManager::rename | ( | const PresetInfo & | preset, |
| const std::string & | new_name ) |
Rename a user preset.
Factory presets cannot be renamed, and the new name must be a single path component (see save()).
| bool pulp::state::PresetManager::save | ( | const std::string & | name, |
| const std::string & | folder = "" ) |
Save current state as a named preset in the user presets folder.
| name | Preset name (used as filename, .json appended) |
| folder | Optional subfolder within user presets directory |
| void pulp::state::PresetManager::set_content_capabilities | ( | std::vector< std::string > | capabilities | ) |
Limit installed content packs to matching capabilities such as content.presets.v1.
| void pulp::state::PresetManager::set_content_data_root | ( | std::filesystem::path | data_root | ) |
Override the content data root.
Intended for tests and explicit sandboxing; normal plugins use the platform user-data root.
| void pulp::state::PresetManager::set_content_manifest | ( | const ContentCapabilityManifest & | manifest | ) |
Opt into content discovery from a parsed pulp.plugin-runtime.v1 manifest embedded in the plugin/app bundle.
| void pulp::state::PresetManager::set_content_plugin_id | ( | std::string | plugin_id | ) |
Opt into installed content-pack discovery for this plugin id.
| void pulp::state::PresetManager::set_content_preset_source | ( | ContentPresetSource | source | ) |
Install the reader that lists installed content-pack presets.
This state layer carries no content-pack reader of its own; the content-pack layer provides one (content_registry_preset_source()). Code that opts this manager into content discovery installs it together with set_content_plugin_id() or set_content_manifest(); the format adapters do neither, so their managers list no content-pack presets and carry no content-pack link.
|
inline |
|
inline |
Point factory-preset discovery at a directory.
The constructor cannot resolve this on its own: the folder that holds a plug-in's bundled presets is format- and platform-specific (a macOS bundle keeps them under Contents/Resources/Presets, a flat iOS app-extension bundle directly under Presets), and a headless host has no bundle at all. Until a caller sets it, factory_presets() scans an empty path and returns nothing — so a plug-in that ships factory presets must call this, normally from its format adapter.
| std::vector< PresetInfo > pulp::state::PresetManager::user_presets | ( | ) | const |
Get user presets only.
|
inline |
The user presets directory.
| std::function<void()> pulp::state::PresetManager::on_list_changed |
Called after the preset list changes (save/delete/rename/import).
| std::function<void(const PresetInfo&)> pulp::state::PresetManager::on_preset_loaded |
Called after a preset is loaded.