Report if file selector can be displayed.

This commit is contained in:
Bartosz Taudul 2022-10-30 00:31:15 +02:00
parent 343e7b6866
commit fbfd7e5186
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 10 additions and 4 deletions

View File

@ -35,7 +35,7 @@ extern "C" int nativeOpenFile()
} }
#endif #endif
void OpenFile( const char* ext, const char* desc, std::function<void(const char*)> callback ) bool OpenFile( const char* ext, const char* desc, std::function<void(const char*)> callback )
{ {
#ifndef TRACY_NO_FILESELECTOR #ifndef TRACY_NO_FILESELECTOR
# ifdef __EMSCRIPTEN__ # ifdef __EMSCRIPTEN__
@ -58,6 +58,7 @@ void OpenFile( const char* ext, const char* desc, std::function<void(const char*
}; };
input.click(); input.click();
}, ext ); }, ext );
return true;
# else # else
nfdu8filteritem_t filter = { desc, ext }; nfdu8filteritem_t filter = { desc, ext };
nfdu8char_t* fn; nfdu8char_t* fn;
@ -65,12 +66,14 @@ void OpenFile( const char* ext, const char* desc, std::function<void(const char*
{ {
callback( (const char*)fn ); callback( (const char*)fn );
NFD_FreePathU8( fn ); NFD_FreePathU8( fn );
return true;
} }
# endif # endif
#endif #endif
return false;
} }
void SaveFile( const char* ext, const char* desc, std::function<void(const char*)> callback ) bool SaveFile( const char* ext, const char* desc, std::function<void(const char*)> callback )
{ {
#if !defined TRACY_NO_FILESELECTOR && !defined __EMSCRIPTEN__ #if !defined TRACY_NO_FILESELECTOR && !defined __EMSCRIPTEN__
nfdu8filteritem_t filter = { desc, ext }; nfdu8filteritem_t filter = { desc, ext };
@ -79,8 +82,10 @@ void SaveFile( const char* ext, const char* desc, std::function<void(const char*
{ {
callback( (const char*)fn ); callback( (const char*)fn );
NFD_FreePathU8( fn ); NFD_FreePathU8( fn );
return true;
} }
#endif #endif
return false;
} }
} }

View File

@ -9,8 +9,9 @@ namespace tracy::Fileselector
void Init(); void Init();
void Shutdown(); void Shutdown();
void OpenFile( const char* ext, const char* desc, std::function<void(const char*)> callback ); // Will return false if file selector cannot be presented to the user.
void SaveFile( const char* ext, const char* desc, std::function<void(const char*)> callback ); bool OpenFile( const char* ext, const char* desc, std::function<void(const char*)> callback );
bool SaveFile( const char* ext, const char* desc, std::function<void(const char*)> callback );
} }