MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ save_file() [2/2]

template<typename T >
T MayaFlux::Portal::System::Dialog::save_file ( std::function< T(std::filesystem::path)>  on_success,
std::function< void(Core::SystemDialogError)>  on_error,
std::string  suggested_name = {},
std::vector< ChooserFilter filters = {},
std::filesystem::path  start_dir = {} 
)

Present a native save-file dialog, returning T produced by on_success.

Blocks until the user completes or dismisses the dialog.

Template Parameters
TReturn type of on_success.
Parameters
on_successCalled with the chosen path on success. Must return T.
on_errorCalled with the error on cancellation or failure.
suggested_nameFilename pre-filled in the dialog name field.
filtersExtension filter groups shown in the dialog.
start_dirDirectory the dialog opens in. Platform default if empty.
Returns
The value returned by on_success, or a default T on error.
Todo:
Post-0.4: when C++23 is the minimum, add a non-blocking overload using std::expected::transform / and_then on a future-returning variant.

Definition at line 140 of file Chooser.hpp.

143 {},
144 std::vector<ChooserFilter> filters = {},
145 std::filesystem::path start_dir = {})
146{
147 std::promise<T> promise;
148 auto future = promise.get_future();
149
150 save_file(
151 [&promise, on_success = std::move(on_success), on_error = std::move(on_error)](ChooserResult result) {
152 if (result) {
153 promise.set_value(on_success(std::move(*result)));
154 } else {
155 on_error(result.error());
156 promise.set_value(T {});
157 }
158 },
159 std::move(suggested_name),
160 std::move(filters),
161 std::move(start_dir));
162
163 return future.get();
164}