[nostalgia/studio] Cleanup

This commit is contained in:
Gary Talent 2022-12-30 18:19:39 -06:00
parent 887d3b3d13
commit 5cae7cbd24
2 changed files with 12 additions and 13 deletions

View File

@ -14,17 +14,10 @@ struct FDFilterItem {
#else #else
using String = ox::Vector<char>; using String = ox::Vector<char>;
#endif #endif
String name; String name{};
String spec; String spec{};
constexpr FDFilterItem() noexcept = default; constexpr FDFilterItem() noexcept = default;
inline FDFilterItem(ox::CRStringView pName, ox::CRStringView pSpec) noexcept { FDFilterItem(ox::CRStringView pName, ox::CRStringView pSpec) noexcept;
name.resize(pName.len() + 1);
memcpy(name.data(), pName.data(), pName.len());
name.back().value = 0;
spec.resize(pSpec.len() + 1);
memcpy(spec.data(), pSpec.data(), pSpec.len());
spec.back().value = 0;
}
}; };
ox::Result<ox::String> saveFile(const ox::Vector<FDFilterItem> &exts) noexcept; ox::Result<ox::String> saveFile(const ox::Vector<FDFilterItem> &exts) noexcept;

View File

@ -6,12 +6,18 @@
#include <ox/std/error.hpp> #include <ox/std/error.hpp>
#include <ox/std/string.hpp> #include <ox/std/string.hpp>
#include <ox/std/trace.hpp>
#include "filedialog.hpp" #include "filedialog.hpp"
namespace nostalgia::studio { namespace nostalgia::studio {
FDFilterItem::FDFilterItem(ox::CRStringView pName, ox::CRStringView pSpec) noexcept {
name.resize(pName.len() + 1);
ox_strncpy(name.data(), pName.data(), pName.len());
spec.resize(pSpec.len() + 1);
ox_strncpy(spec.data(), pSpec.data(), pSpec.len());
}
static ox::Result<ox::String> toResult(nfdresult_t r, const NFD::UniquePathN &path) noexcept { static ox::Result<ox::String> toResult(nfdresult_t r, const NFD::UniquePathN &path) noexcept {
switch (r) { switch (r) {
case NFD_OKAY: { case NFD_OKAY: {
@ -30,7 +36,7 @@ static ox::Result<ox::String> toResult(nfdresult_t r, const NFD::UniquePathN &pa
} }
ox::Result<ox::String> saveFile(const ox::Vector<FDFilterItem> &filters) noexcept { ox::Result<ox::String> saveFile(const ox::Vector<FDFilterItem> &filters) noexcept {
NFD::Guard guard; const NFD::Guard guard;
NFD::UniquePathN path; NFD::UniquePathN path;
ox::Vector<nfdnfilteritem_t, 5> filterItems(filters.size()); ox::Vector<nfdnfilteritem_t, 5> filterItems(filters.size());
for (auto i = 0u; const auto &f : filters) { for (auto i = 0u; const auto &f : filters) {
@ -42,7 +48,7 @@ ox::Result<ox::String> saveFile(const ox::Vector<FDFilterItem> &filters) noexcep
} }
ox::Result<ox::String> chooseDirectory() noexcept { ox::Result<ox::String> chooseDirectory() noexcept {
NFD::Guard guard; const NFD::Guard guard;
NFD::UniquePathN path; NFD::UniquePathN path;
return toResult(NFD::PickFolder(path), path); return toResult(NFD::PickFolder(path), path);
} }