/* * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. */ #include #include #include #include #include "filedialog.hpp" namespace nostalgia::studio { static ox::Result toResult(nfdresult_t r, const NFD::UniquePathN &path) noexcept { switch (r) { case NFD_OKAY: { ox::String out; for (auto i = 0u; path.get()[i]; ++i) { const auto c = static_cast(path.get()[i]); oxIgnoreError(out.append(&c, 1)); } return out; } case NFD_CANCEL: return OxError(1, "Operation cancelled"); default: return OxError(2, NFD::GetError()); } } ox::Result saveFile(const ox::Vector &filters) noexcept { NFD::Guard guard; NFD::UniquePathN path; ox::Vector filterItems(filters.size()); for (auto i = 0u; const auto &f : filters) { filterItems[i].name = f.name.data(); filterItems[i].spec = f.spec.data(); ++i; } return toResult(NFD::SaveDialog(path, filterItems.data(), filterItems.size()), path); } ox::Result chooseDirectory() noexcept { NFD::Guard guard; NFD::UniquePathN path; return toResult(NFD::PickFolder(path), path); } }