Expose internal file selector failure state.

This commit is contained in:
Bartosz Taudul 2022-10-30 00:36:07 +02:00
parent fbfd7e5186
commit 11cafbff1d
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 30 additions and 5 deletions

View File

@ -11,6 +11,8 @@
namespace tracy::Fileselector
{
static bool s_hasFailed = false;
void Init()
{
#if !defined TRACY_NO_FILESELECTOR && !defined __EMSCRIPTEN__
@ -25,6 +27,19 @@ void Shutdown()
#endif
}
bool HasFailed()
{
if( s_hasFailed )
{
s_hasFailed = false;
return true;
}
else
{
return false;
}
}
#ifdef __EMSCRIPTEN__
static std::function<void(const char*)> s_openFileCallback;
@ -35,7 +50,7 @@ extern "C" int nativeOpenFile()
}
#endif
bool OpenFile( const char* ext, const char* desc, std::function<void(const char*)> callback )
static bool OpenFileImpl( const char* ext, const char* desc, std::function<void(const char*)> callback )
{
#ifndef TRACY_NO_FILESELECTOR
# ifdef __EMSCRIPTEN__
@ -73,7 +88,7 @@ bool OpenFile( const char* ext, const char* desc, std::function<void(const char*
return false;
}
bool SaveFile( const char* ext, const char* desc, std::function<void(const char*)> callback )
static bool SaveFileImpl( const char* ext, const char* desc, std::function<void(const char*)> callback )
{
#if !defined TRACY_NO_FILESELECTOR && !defined __EMSCRIPTEN__
nfdu8filteritem_t filter = { desc, ext };
@ -88,4 +103,14 @@ bool SaveFile( const char* ext, const char* desc, std::function<void(const char*
return false;
}
void OpenFile( const char* ext, const char* desc, std::function<void(const char*)> callback )
{
if( !OpenFileImpl( ext, desc, callback ) ) s_hasFailed = true;
}
void SaveFile( const char* ext, const char* desc, std::function<void(const char*)> callback )
{
if( !SaveFileImpl( ext, desc, callback ) ) s_hasFailed = true;
}
}

View File

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