From 64d1011acda797323ec17b32687e70b899cfe881 Mon Sep 17 00:00:00 2001 From: chatlanin Date: Fri, 13 Mar 2026 17:46:04 +0300 Subject: [PATCH] fix nfd --- src/monitor/libs/gtkfd.OLD/gtkfd.cpp | 500 --------------------------- src/monitor/libs/gtkfd.OLD/gtkfd.hpp | 244 ------------- 2 files changed, 744 deletions(-) delete mode 100644 src/monitor/libs/gtkfd.OLD/gtkfd.cpp delete mode 100644 src/monitor/libs/gtkfd.OLD/gtkfd.hpp diff --git a/src/monitor/libs/gtkfd.OLD/gtkfd.cpp b/src/monitor/libs/gtkfd.OLD/gtkfd.cpp deleted file mode 100644 index b478af7..0000000 --- a/src/monitor/libs/gtkfd.OLD/gtkfd.cpp +++ /dev/null @@ -1,500 +0,0 @@ -#include -#include -#include -#include -#include "gtkfd.hpp" - - template - struct Free_Guard - { - T* data; - Free_Guard(T* freeable) noexcept : data(freeable) {} - ~Free_Guard() { NFDi_Free(data); } - }; - - template - struct FreeCheck_Guard - { - T* data; - FreeCheck_Guard(T* freeable = nullptr) noexcept : data(freeable) {} - ~FreeCheck_Guard() { if (data) NFDi_Free(data); } - }; - - /* current error */ - const char* g_errorstr = nullptr; - - void NFDi_SetError(const char* msg) - { - g_errorstr = msg; - } - - template - T* NFDi_Malloc(size_t bytes) - { - void* ptr = malloc(bytes); - if (!ptr) NFDi_SetError("NFDi_Malloc failed."); - return static_cast(ptr); - } - - template - void NFDi_Free(T *ptr) - { - assert(ptr); - free(static_cast(ptr)); - } - - template - T* copy(const T* begin, const T* end, T* out) - { - for (; begin != end; ++begin) *out++ = *begin; - return out; - } - - // Does not own the filter and extension. - struct Pair_GtkFileFilter_FileExtension - { - GtkFileFilter* filter; - const char* extensionBegin; - const char* extensionEnd; - }; - - struct ButtonClickedArgs - { - Pair_GtkFileFilter_FileExtension* map; - GtkFileChooser* chooser; - }; - - void AddFiltersToDialog(GtkFileChooser* chooser, const item* filterList, uint_t filterCount) - { - if (filterCount) - { - assert(filterList); - // we have filters to add ... format and add them - - for (uint_t index = 0; index != filterCount; ++index) - { - GtkFileFilter* filter = gtk_file_filter_new(); - - // count number of file extensions - size_t sep = 1; - for (const char* p_spec = filterList[index].m_spec; *p_spec; ++p_spec) if (*p_spec == L',') ++sep; - - // calculate space needed (including the trailing '\0') - size_t nameSize = sep + strlen(filterList[index].m_spec) + 3 + strlen(filterList[index].m_name); - - // malloc the required memory - char* nameBuf = NFDi_Malloc(sizeof(char) * nameSize); - - char* p_nameBuf = nameBuf; - for (const char* p_filterName = filterList[index].m_name; *p_filterName; ++p_filterName) *p_nameBuf++ = *p_filterName; - *p_nameBuf++ = ' '; - *p_nameBuf++ = '('; - const char* p_extensionStart = filterList[index].m_spec; - for (const char *p_spec = filterList[index].m_spec; true; ++p_spec) - { - if (*p_spec == ',' || !*p_spec) - { - if (*p_spec == ',') - { - *p_nameBuf++ = ','; - *p_nameBuf++ = ' '; - } - - // +1 for the trailing '\0' - char* extnBuf = NFDi_Malloc(sizeof(char) * (p_spec - p_extensionStart + 3)); - char* p_extnBufEnd = extnBuf; - *p_extnBufEnd++ = '*'; - *p_extnBufEnd++ = '.'; - p_extnBufEnd = copy(p_extensionStart, p_spec, p_extnBufEnd); - *p_extnBufEnd++ = '\0'; - assert((unsigned int)(p_extnBufEnd - extnBuf) == sizeof(char) * (p_spec - p_extensionStart + 3)); - gtk_file_filter_add_pattern(filter, extnBuf); - NFDi_Free(extnBuf); - if (*p_spec) p_extensionStart = p_spec + 1; - else break; - } - else *p_nameBuf++ = *p_spec; - } - *p_nameBuf++ = ')'; - *p_nameBuf++ = '\0'; - assert((unsigned int)(p_nameBuf - nameBuf) == sizeof(char) * nameSize); - - // add to the filter - gtk_file_filter_set_name(filter, nameBuf); - - // free the memory - NFDi_Free(nameBuf); - - // add filter to chooser - gtk_file_chooser_add_filter(chooser, filter); - } - } - - /* always append a wildcard option to the end*/ - - GtkFileFilter* filter = gtk_file_filter_new(); - gtk_file_filter_set_name(filter, "All files"); - gtk_file_filter_add_pattern(filter, "*"); - gtk_file_chooser_add_filter(chooser, filter); - } - - // returns null-terminated map (trailing .filter is null) - Pair_GtkFileFilter_FileExtension* AddFiltersToDialogWithMap(GtkFileChooser* chooser, const item* filterList, uint_t filterCount) - { - Pair_GtkFileFilter_FileExtension* map = NFDi_Malloc(sizeof(Pair_GtkFileFilter_FileExtension) * (filterCount + 1)); - - if (filterCount) - { - assert(filterList); - for (uint_t index = 0; index != filterCount; ++index) - { - GtkFileFilter* filter = gtk_file_filter_new(); - - // store filter in map - map[index].filter = filter; - map[index].extensionBegin = filterList[index].m_spec; - map[index].extensionEnd = nullptr; - - // count number of file extensions - std::size_t sep = 1; - for (const char *p_spec = filterList[index].m_spec; *p_spec; ++p_spec) - if (*p_spec == L',') ++sep; - - // calculate space needed (including the trailing '\0') - std::size_t nameSize = sep + strlen(filterList[index].m_spec) + 3 + strlen(filterList[index].m_name); - - // malloc the required memory - char* nameBuf = NFDi_Malloc(sizeof(char) * nameSize); - char* p_nameBuf = nameBuf; - - for (const char *p_filterName = filterList[index].m_name; *p_filterName; ++p_filterName) *p_nameBuf++ = *p_filterName; - *p_nameBuf++ = ' '; - *p_nameBuf++ = '('; - const char* p_extensionStart = filterList[index].m_spec; - - for (const char* p_spec = filterList[index].m_spec; true; ++p_spec) - { - if (*p_spec == ',' || !*p_spec) - { - if (*p_spec == ',') - { - *p_nameBuf++ = ','; - *p_nameBuf++ = ' '; - } - - // +1 for the trailing '\0' - char *extnBuf = NFDi_Malloc(sizeof(char) * (p_spec - p_extensionStart + 3)); - char *p_extnBufEnd = extnBuf; - *p_extnBufEnd++ = '*'; - *p_extnBufEnd++ = '.'; - p_extnBufEnd = copy(p_extensionStart, p_spec, p_extnBufEnd); - *p_extnBufEnd++ = '\0'; - assert((unsigned int)(p_extnBufEnd - extnBuf) == sizeof(char) * (p_spec - p_extensionStart + 3)); - gtk_file_filter_add_pattern(filter, extnBuf); - NFDi_Free(extnBuf); - - // store current pointer in map (if it's the first one) - if (map[index].extensionEnd == nullptr) map[index].extensionEnd = p_spec; - if (*p_spec) p_extensionStart = p_spec + 1; - else break; - } - else *p_nameBuf++ = *p_spec; - } - *p_nameBuf++ = ')'; - *p_nameBuf++ = '\0'; - assert((unsigned int)(p_nameBuf - nameBuf) == sizeof(char) * nameSize); - - // add to the filter - gtk_file_filter_set_name(filter, nameBuf); - - // free the memory - NFDi_Free(nameBuf); - - // add filter to chooser - gtk_file_chooser_add_filter(chooser, filter); - } - } - - // set trailing map index to null - map[filterCount].filter = nullptr; - - /* always append a wildcard option to the end*/ - GtkFileFilter* filter = gtk_file_filter_new(); - gtk_file_filter_set_name(filter, "All files"); - gtk_file_filter_add_pattern(filter, "*"); - gtk_file_chooser_add_filter(chooser, filter); - - return map; - } - - void SetDefaultPath(GtkFileChooser* chooser, const char *defaultPath) - { - if (!defaultPath || !*defaultPath) return; - - /* GTK+ manual recommends not specifically setting the default path. - We do it anyway in order to be consistent across platforms. - If consistency with the native OS is preferred, this is the line - to comment out. -ml */ - gtk_file_chooser_set_current_folder(chooser, defaultPath); - } - - void SetDefaultName(GtkFileChooser* chooser, const char *defaultName) - { - if (!defaultName || !*defaultName) return; - gtk_file_chooser_set_current_name(chooser, defaultName); - } - - void WaitForCleanup() - { - while (gtk_events_pending()) gtk_main_iteration(); - } - - struct Widget_Guard - { - GtkWidget* data; - Widget_Guard(GtkWidget* widget) : data(widget) {} - ~Widget_Guard() - { - WaitForCleanup(); - gtk_widget_destroy(data); - WaitForCleanup(); - } - }; - - static void FileActivatedSignalHandler(GtkButton* saveButton, void* userdata) - { - ButtonClickedArgs* args = static_cast(userdata); - GtkFileChooser* chooser = args->chooser; - char* currentFileName = gtk_file_chooser_get_current_name(chooser); - - if (*currentFileName) - { - // string is not empty - // find a '.' in the file name - const char* p_period = currentFileName; - for (;*p_period; ++p_period) if (*p_period == '.') break; - - if (!*p_period) - { // there is no '.', so append the default extension - Pair_GtkFileFilter_FileExtension* filterMap = static_cast(args->map); - GtkFileFilter* currentFilter = gtk_file_chooser_get_filter(chooser); - if (currentFilter) - for (;filterMap->filter; ++filterMap) - if (filterMap->filter == currentFilter) break; - - if (filterMap->filter) - { - // memory for appended string (including '.' and trailing '\0') - char* appendedFileName = NFDi_Malloc(sizeof(char) * ((p_period - currentFileName) + (filterMap->extensionEnd - filterMap->extensionBegin) + 2)); - char* p_fileName = copy(currentFileName, p_period, appendedFileName); - *p_fileName++ = '.'; - p_fileName = copy(filterMap->extensionBegin, filterMap->extensionEnd, p_fileName); - *p_fileName++ = '\0'; - - assert(p_fileName - appendedFileName == (p_period - currentFileName) + (filterMap->extensionEnd - filterMap->extensionBegin) + 2); - - // set the appended file name - gtk_file_chooser_set_current_name(chooser, appendedFileName); - - // free the memory - NFDi_Free(appendedFileName); - } - } - } - - // free the memory - g_free(currentFileName); - } - -const char* NFD_GetError(void) -{ - return g_errorstr; -} - -void NFD_ClearError(void) -{ - NFDi_SetError(nullptr); -} - -/* public */ -nfdresult_t Init() -{ - // Init GTK - if (!gtk_init_check(NULL, NULL)) - { - NFDi_SetError("gtk_init_check failed to initilaize GTK+"); - return nfdresult_t::ERROR; - } - return nfdresult_t::OKAY; -} - -void NFD_Quit(void) -{ - // do nothing, GTK cannot be de-initialized -} - -void NFD_FreePathN(char* filePath) -{ - assert(filePath); - g_free(filePath); -} - -nfdresult_t NFD_OpenDialogN(char** outPath, const item* filterList, uint_t filterCount, const char* defaultPath) -{ - GtkWidget* widget = gtk_file_chooser_dialog_new("Open File", nullptr, GTK_FILE_CHOOSER_ACTION_OPEN, "_Cancel", GTK_RESPONSE_CANCEL, "_Open", GTK_RESPONSE_ACCEPT, nullptr); - - // guard to destroy the widget when returning from this function - Widget_Guard widgetGuard(widget); - - /* Build the filter list */ - AddFiltersToDialog(GTK_FILE_CHOOSER(widget), filterList, filterCount); - - /* Set the default path */ - SetDefaultPath(GTK_FILE_CHOOSER(widget), defaultPath); - - if (gtk_dialog_run(GTK_DIALOG(widget)) == GTK_RESPONSE_ACCEPT) - { - // write out the file name - *outPath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget)); - return nfdresult_t::OKAY; - } - else return nfdresult_t::CANCEL; -} - -nfdresult_t NFD_OpenDialogMultipleN(const nfdpathset_t** outPaths, const item* filterList, uint_t filterCount, const char* defaultPath ) -{ - GtkWidget* widget = gtk_file_chooser_dialog_new("Open Files", nullptr, GTK_FILE_CHOOSER_ACTION_OPEN, "_Cancel", GTK_RESPONSE_CANCEL, "_Open", GTK_RESPONSE_ACCEPT, nullptr); - - // guard to destroy the widget when returning from this function - Widget_Guard widgetGuard(widget); - - // set select multiple - gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(widget), TRUE); - - /* Build the filter list */ - AddFiltersToDialog(GTK_FILE_CHOOSER(widget), filterList, filterCount); - - /* Set the default path */ - SetDefaultPath(GTK_FILE_CHOOSER(widget), defaultPath); - - if (gtk_dialog_run(GTK_DIALOG(widget)) == GTK_RESPONSE_ACCEPT) - { - // write out the file name - GSList *fileList = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(widget)); - *outPaths = fileList; - return nfdresult_t::OKAY; - } - else return nfdresult_t::CANCEL; -} - -nfdresult_t NFD_SaveDialogN(char** outPath, const item* filterList, uint_t filterCount, const char* defaultPath, const char* defaultName) -{ - GtkWidget* widget = gtk_file_chooser_dialog_new("Save File", nullptr, GTK_FILE_CHOOSER_ACTION_SAVE, "_Cancel", GTK_RESPONSE_CANCEL, nullptr); - - // guard to destroy the widget when returning from this function - Widget_Guard widgetGuard(widget); - GtkWidget* saveButton = gtk_dialog_add_button(GTK_DIALOG(widget), "_Save", GTK_RESPONSE_ACCEPT); - - // Prompt on overwrite - gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(widget), TRUE); - - /* Build the filter list */ - ButtonClickedArgs buttonClickedArgs; - buttonClickedArgs.chooser = GTK_FILE_CHOOSER(widget); - buttonClickedArgs.map = AddFiltersToDialogWithMap(GTK_FILE_CHOOSER(widget), filterList, filterCount); - - /* Set the default path */ - SetDefaultPath(GTK_FILE_CHOOSER(widget), defaultPath); - - /* Set the default file name */ - SetDefaultName(GTK_FILE_CHOOSER(widget), defaultName); - - /* set the handler to add file extension */ - gulong handlerID = g_signal_connect(G_OBJECT(saveButton), "pressed", G_CALLBACK(FileActivatedSignalHandler), static_cast(&buttonClickedArgs)); - - /* invoke the dialog (blocks until dialog is closed) */ - gint result = gtk_dialog_run(GTK_DIALOG(widget)); - - /* unset the handler */ - g_signal_handler_disconnect(G_OBJECT(saveButton), handlerID); - - /* free the filter map */ - NFDi_Free(buttonClickedArgs.map); - - if (result == GTK_RESPONSE_ACCEPT) - { - // write out the file name - *outPath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget)); - return nfdresult_t::OKAY; - } - else return nfdresult_t::CANCEL; -} - -nfdresult_t NFD_PickFolderN(char** outPath, const char* defaultPath) -{ - GtkWidget* widget = gtk_file_chooser_dialog_new("Select folder", nullptr, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, "_Cancel", GTK_RESPONSE_CANCEL, "_Select", GTK_RESPONSE_ACCEPT, nullptr); - - // guard to destroy the widget when returning from this function - Widget_Guard widgetGuard(widget); - - /* Set the default path */ - SetDefaultPath(GTK_FILE_CHOOSER(widget), defaultPath); - - if (gtk_dialog_run(GTK_DIALOG(widget)) == GTK_RESPONSE_ACCEPT) - { - // write out the file name - *outPath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget)); - return nfdresult_t::OKAY; - } - else return nfdresult_t::CANCEL; -} - -nfdresult_t NFD_PathSet_GetCount(const nfdpathset_t* pathSet, uint_t* count) -{ - assert(pathSet); - - // const_cast because methods on GSList aren't const, but it should act like const to the caller - GSList*fileList = const_cast(static_cast(pathSet)); - - *count = g_slist_length(fileList); - return nfdresult_t::OKAY; -} - -nfdresult_t NFD_PathSet_GetPathN(const nfdpathset_t* pathSet, uint_t index, char** outPath) -{ - assert(pathSet); - - // const_cast because methods on GSList aren't const, but it should act like const to the caller - GSList* fileList = const_cast(static_cast(pathSet)); - - // Note: this takes linear time... but should be good enough - *outPath = static_cast(g_slist_nth_data(fileList, index)); - return nfdresult_t::OKAY; -} - -void NFD_PathSet_FreePathN(const char* filePath) -{ - assert(filePath); - // no-op, because NFD_PathSet_Free does the freeing for us -} - -void NFD_PathSet_Free(const nfdpathset_t *pathSet) -{ - assert(pathSet); - - // const_cast because methods on GSList aren't const, but it should act like const to the caller - GSList* fileList = const_cast(static_cast(pathSet)); - - // free all the nodes - for (GSList* node = fileList; node; node = node->next) - { - assert(node->data); - g_free(node->data); - } - - // free the path set memory - g_slist_free(fileList); -} - - - diff --git a/src/monitor/libs/gtkfd.OLD/gtkfd.hpp b/src/monitor/libs/gtkfd.OLD/gtkfd.hpp deleted file mode 100644 index bda3f88..0000000 --- a/src/monitor/libs/gtkfd.OLD/gtkfd.hpp +++ /dev/null @@ -1,244 +0,0 @@ -#pragma once - -#include // for std::unique_ptr -#include -#include -#include "monitor/utils/using.hpp" - -namespace monitor::libs -{ - class gtkfd - { - struct item - { - const char* m_name; - const char* m_spec; - }; - - }; -} - -using nfdpathset_t = GSList; - -struct item -{ - const char* m_name; - const char* m_spec; -}; - -enum class nfdresult_t -{ - OKAY, /* user pressed okay, or successful return */ - ERROR, /* programmatic error */ - CANCEL /* user pressed cancel */ -}; - -/* call this to de-initialize NFD, if NFD_Init returned NFD_OKAY */ -void NFD_Quit(void); - -/* free a file path that was returned by the dialogs */ -/* Note: use NFD_PathSet_FreePath to free path from pathset instead of this function */ -void NFD_FreePathN(char* filePath); - -/* single file open dialog */ -/* It is the caller's responsibility to free `outPath` via NFD_FreePathN() if this function returns NFD_OKAY */ -/* If filterCount is zero, filterList is ignored (you can use NULL) */ -/* If defaultPath is NULL, the operating system will decide */ -nfdresult_t NFD_OpenDialogN(char** outPath, const item* filterList, uint_t filterCount, const char* defaultPath); - -/* multiple file open dialog */ -/* It is the caller's responsibility to free `outPaths` via NFD_PathSet_Free() if this function returns NFD_OKAY */ -/* If filterCount is zero, filterList is ignored (you can use NULL) */ -/* If defaultPath is NULL, the operating system will decide */ -nfdresult_t NFD_OpenDialogMultipleN(const nfdpathset_t** outPaths, const item* filterList, uint_t filterCount, const char* defaultPath); - -/* save dialog */ -/* It is the caller's responsibility to free `outPath` via NFD_FreePathN() if this function returns NFD_OKAY */ -/* If filterCount is zero, filterList is ignored (you can use NULL) */ -/* If defaultPath is NULL, the operating system will decide */ -nfdresult_t NFD_SaveDialogN(char** outPath, const item* filterList, uint_t filterCount, const char* defaultPath, const char* defaultName); - -/* select folder dialog */ -/* It is the caller's responsibility to free `outPath` via NFD_FreePathN() if this function returns NFD_OKAY */ -/* If defaultPath is NULL, the operating system will decide */ -nfdresult_t NFD_PickFolderN(char** outPath, const char* defaultPath); - -/* Get last error -- set when nfdresult_t returns NFD_ERROR */ -/* Returns the last error that was set, or NULL if there is no error. */ -/* The memory is owned by NFD and should not be freed by user code. */ -/* This is *always* ASCII printable characters, so it can be interpreted as UTF-8 without any conversion. */ -const char* NFD_GetError(void); - -nfdresult_t Init(); - -/* clear the error */ -void NFD_ClearError(void); - -/* get the number of entries stored in pathSet */ -/* note that some paths might be invalid (NFD_ERROR will be returned by NFD_PathSet_GetPath), so we might not actually have this number of usable paths */ -nfdresult_t NFD_PathSet_GetCount(const nfdpathset_t* pathSet, uint_t* count); - -/* Get the UTF-8 path at offset index */ -/* It is the caller's responsibility to free `outPath` via NFD_PathSet_FreePathN() if this function returns NFD_OKAY */ -nfdresult_t NFD_PathSet_GetPathN(const nfdpathset_t* pathSet, uint_t index, char** outPath); - -/* Free the path gotten by NFD_PathSet_GetPathN */ -void NFD_PathSet_FreePathN(const char* filePath); - -/* Free the pathSet */ -void NFD_PathSet_Free(const nfdpathset_t* pathSet); - -namespace gtkfd -{ - inline nfdresult_t init() noexcept - { - return ::Init(); - } - - inline void Quit() noexcept - { - ::NFD_Quit(); - } - - inline void FreePath(char *outPath) noexcept - { - ::NFD_FreePathN(outPath); - } - - inline nfdresult_t OpenDialog(char*& outPath, const item* filterList = nullptr, uint_t filterCount = 0, const char* defaultPath = nullptr) noexcept - { - return ::NFD_OpenDialogN(&outPath, filterList, filterCount, defaultPath); - } - - inline nfdresult_t OpenDialogMultiple(const nfdpathset_t*& outPaths, const item* filterList = nullptr, uint_t filterCount = 0, const char* defaultPath = nullptr) noexcept - { - return ::NFD_OpenDialogMultipleN(&outPaths, filterList, filterCount, defaultPath); - } - - inline nfdresult_t SaveDialog(char*& outPath, const item* filterList = nullptr, uint_t filterCount = 0, const char* defaultPath = nullptr, const char* defaultName = nullptr) noexcept - { - return ::NFD_SaveDialogN(&outPath, filterList, filterCount, defaultPath, defaultName); - } - - inline nfdresult_t PickFolder(char*& outPath, const char* defaultPath = nullptr) noexcept - { - return ::NFD_PickFolderN(&outPath, defaultPath); - } - - inline const char* GetError() noexcept - { - return ::NFD_GetError(); - } - - inline void ClearError() noexcept - { - ::NFD_ClearError(); - } - - namespace PathSet - { - inline nfdresult_t Count(const nfdpathset_t* pathSet, uint_t& count) noexcept - { - return ::NFD_PathSet_GetCount(pathSet, &count); - } - - inline nfdresult_t GetPath(const nfdpathset_t* pathSet, uint_t index, char*& outPath) noexcept - { - return ::NFD_PathSet_GetPathN(pathSet, index, &outPath); - } - - inline void FreePath(char* filePath) noexcept - { - ::NFD_PathSet_FreePathN(filePath); - } - - inline void Free(const nfdpathset_t* pathSet) noexcept - { - ::NFD_PathSet_Free(pathSet); - } - } - - class guard - { - public: - inline guard() noexcept { init(); } - inline ~guard() noexcept { Quit(); } - - // Not allowed to copy or move this class - guard(const guard&) = delete; - guard& operator=(const guard&) = delete; - }; - - template - struct PathDeleter - { - inline void operator()(T* ptr) const noexcept { FreePath(ptr); } - }; - - typedef std::unique_ptr> UniquePath; - typedef std::unique_ptr> UniquePathN; - typedef std::unique_ptr> UniquePathU8; - - struct PathSetDeleter - { - inline void operator()(const nfdpathset_t* ptr) const noexcept { PathSet::Free(ptr); } - }; - - typedef std::unique_ptr UniquePathSet; - - template - struct PathSetPathDeleter - { - inline void operator()(T* ptr) const noexcept { PathSet::FreePath(ptr); } - }; - - typedef std::unique_ptr> UniquePathSetPath; - typedef std::unique_ptr> UniquePathSetPathN; - typedef std::unique_ptr> UniquePathSetPathU8; - - inline nfdresult_t OpenDialog(UniquePathN& outPath, const item* filterList = nullptr, uint_t filterCount = 0, const char* defaultPath = nullptr) noexcept - { - char* out; - nfdresult_t res = OpenDialog(out, filterList, filterCount, defaultPath); - if (res == nfdresult_t::OKAY) outPath.reset(out); - return res; - } - - inline nfdresult_t OpenDialogMultiple(UniquePathSet& outPaths, const item* filterList = nullptr, uint_t filterCount = 0, const char* defaultPath = nullptr) noexcept - { - const nfdpathset_t* out; - nfdresult_t res = OpenDialogMultiple(out, filterList, filterCount, defaultPath); - if (res == nfdresult_t::OKAY) outPaths.reset(out); - return res; - } - - inline nfdresult_t SaveDialog(UniquePathN& outPath, const item* filterList = nullptr, uint_t filterCount = 0, const char* defaultPath = nullptr, const char* defaultName = nullptr) noexcept - { - char* out; - nfdresult_t res = SaveDialog(out, filterList, filterCount, defaultPath, defaultName); - if (res == nfdresult_t::OKAY) outPath.reset(out); - return res; - } - - inline nfdresult_t PickFolder(UniquePathN& outPath, const char* defaultPath = nullptr) noexcept - { - char* out; - nfdresult_t res = PickFolder(out, defaultPath); - if (res == nfdresult_t::OKAY) outPath.reset(out); - return res; - } - - namespace PathSet - { - inline nfdresult_t Count(const UniquePathSet& uniquePathSet, uint_t& count) noexcept { return Count(uniquePathSet.get(), count); } - inline nfdresult_t GetPath(const UniquePathSet& uniquePathSet, uint_t index, UniquePathSetPathN& outPath) noexcept - { - char* out; - nfdresult_t res = GetPath(uniquePathSet.get(), index, out); - if (res == nfdresult_t::OKAY) outPath.reset(out); - return res; - } - } -} - -