mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-22 14:44:34 +00:00
Change file selector to work with callbacks.
This commit is contained in:
parent
a4e39f3d5f
commit
ec0757c03a
@ -575,12 +575,10 @@ static void DrawContents()
|
||||
#ifndef TRACY_NO_FILESELECTOR
|
||||
if( ImGui::Button( ICON_FA_FOLDER_OPEN " Open saved trace" ) && !loadThread.joinable() )
|
||||
{
|
||||
auto fn = tracy::Fileselector::OpenFile( "tracy", "Tracy Profiler trace file" );
|
||||
if( !fn.empty() )
|
||||
{
|
||||
tracy::Fileselector::OpenFile( "tracy", "Tracy Profiler trace file", []( const char* fn ) {
|
||||
try
|
||||
{
|
||||
auto f = std::shared_ptr<tracy::FileRead>( tracy::FileRead::Open( fn.c_str() ) );
|
||||
auto f = std::shared_ptr<tracy::FileRead>( tracy::FileRead::Open( fn ) );
|
||||
if( f )
|
||||
{
|
||||
loadThread = std::thread( [f] {
|
||||
@ -609,7 +607,7 @@ static void DrawContents()
|
||||
{
|
||||
badVer.state = tracy::BadVersionState::ReadError;
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
if( badVer.state != tracy::BadVersionState::Ok )
|
||||
|
@ -21,34 +21,30 @@ void Shutdown()
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string OpenFile( const char* ext, const char* desc )
|
||||
void OpenFile( const char* ext, const char* desc, std::function<void(const char*)> callback )
|
||||
{
|
||||
std::string ret;
|
||||
#ifndef TRACY_NO_FILESELECTOR
|
||||
nfdu8filteritem_t filter = { desc, ext };
|
||||
nfdu8char_t* fn;
|
||||
if( NFD_OpenDialogU8( &fn, &filter, 1, nullptr ) == NFD_OKAY )
|
||||
{
|
||||
ret.assign( fn );
|
||||
callback( (const char*)fn );
|
||||
NFD_FreePathU8( fn );
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string SaveFile( const char* ext, const char* desc )
|
||||
void SaveFile( const char* ext, const char* desc, std::function<void(const char*)> callback )
|
||||
{
|
||||
std::string ret;
|
||||
#ifndef TRACY_NO_FILESELECTOR
|
||||
nfdu8filteritem_t filter = { desc, ext };
|
||||
nfdu8char_t* fn;
|
||||
if( NFD_SaveDialogU8( &fn, &filter, 1, nullptr, nullptr ) == NFD_OKAY )
|
||||
{
|
||||
ret.assign( fn );
|
||||
callback( (const char*)fn );
|
||||
NFD_FreePathU8( fn );
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef __TRACYFILESELECTOR_HPP__
|
||||
#define __TRACYFILESELECTOR_HPP__
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
namespace tracy::Fileselector
|
||||
{
|
||||
@ -9,8 +9,8 @@ namespace tracy::Fileselector
|
||||
void Init();
|
||||
void Shutdown();
|
||||
|
||||
std::string OpenFile( const char* ext, const char* desc );
|
||||
std::string SaveFile( const char* ext, const char* desc );
|
||||
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 );
|
||||
|
||||
}
|
||||
|
||||
|
@ -5356,23 +5356,20 @@ void SourceView::Save( const Worker& worker, size_t start, size_t stop )
|
||||
assert( start < m_asm.size() );
|
||||
assert( start < stop );
|
||||
|
||||
auto fn = Fileselector::SaveFile( "asm", "Assembly file" );
|
||||
if( !fn.empty() )
|
||||
{
|
||||
Fileselector::SaveFile( "asm", "Assembly file", [this, &worker, start, stop]( const char* fn ) {
|
||||
FILE* f = nullptr;
|
||||
const auto sz = fn.size();
|
||||
if( sz < 5 || memcmp( fn.c_str() + sz - 4, ".asm", 4 ) != 0 )
|
||||
const auto sz = strlen( fn );
|
||||
if( sz < 5 || memcmp( fn + sz - 4, ".asm", 4 ) != 0 )
|
||||
{
|
||||
char tmp[1024];
|
||||
sprintf( tmp, "%s.asm", fn.c_str() );
|
||||
sprintf( tmp, "%s.asm", fn );
|
||||
f = fopen( tmp, "wb" );
|
||||
}
|
||||
else
|
||||
{
|
||||
f = fopen( fn.c_str(), "wb" );
|
||||
f = fopen( fn, "wb" );
|
||||
}
|
||||
if( f )
|
||||
{
|
||||
if( !f ) return;
|
||||
char tmp[16];
|
||||
auto sym = worker.GetSymbolData( m_symAddr );
|
||||
assert( sym );
|
||||
@ -5429,8 +5426,7 @@ void SourceView::Save( const Worker& worker, size_t start, size_t stop )
|
||||
}
|
||||
}
|
||||
fclose( f );
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -149,12 +149,10 @@ void View::DrawCompare()
|
||||
ImGui::TextWrapped( "Please load a second trace to compare results." );
|
||||
if( ImGui::Button( ICON_FA_FOLDER_OPEN " Open second trace" ) && !m_compare.loadThread.joinable() )
|
||||
{
|
||||
auto fn = Fileselector::OpenFile( "tracy", "Tracy Profiler trace file" );
|
||||
if( !fn.empty() )
|
||||
{
|
||||
Fileselector::OpenFile( "tracy", "Tracy Profiler trace file", [this]( const char* fn ) {
|
||||
try
|
||||
{
|
||||
auto f = std::shared_ptr<tracy::FileRead>( tracy::FileRead::Open( fn.c_str() ) );
|
||||
auto f = std::shared_ptr<tracy::FileRead>( tracy::FileRead::Open( fn ) );
|
||||
if( f )
|
||||
{
|
||||
m_compare.loadThread = std::thread( [this, f] {
|
||||
@ -179,7 +177,7 @@ void View::DrawCompare()
|
||||
{
|
||||
m_compare.badVer.state = BadVersionState::ReadError;
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
tracy::BadVersion( m_compare.badVer, m_bigFont );
|
||||
ImGui::End();
|
||||
|
@ -121,25 +121,25 @@ bool View::DrawConnection()
|
||||
ImGui::Separator();
|
||||
if( ImGui::Button( ICON_FA_FLOPPY_DISK " Save trace" ) && m_saveThreadState.load( std::memory_order_relaxed ) == SaveThreadState::Inert )
|
||||
{
|
||||
#ifndef TRACY_NO_FILESELECTOR
|
||||
auto fn = Fileselector::SaveFile( "tracy", "Tracy Profiler trace file" );
|
||||
if( !fn.empty() )
|
||||
#else
|
||||
std::string fn = "trace.tracy";
|
||||
#endif
|
||||
{
|
||||
const auto sz = fn.size();
|
||||
if( sz < 7 || memcmp( fn.c_str() + sz - 6, ".tracy", 6 ) != 0 )
|
||||
auto cb = [this]( const char* fn ) {
|
||||
const auto sz = strlen( fn );
|
||||
if( sz < 7 || memcmp( fn + sz - 6, ".tracy", 6 ) != 0 )
|
||||
{
|
||||
char tmp[1024];
|
||||
sprintf( tmp, "%s.tracy", fn.c_str() );
|
||||
sprintf( tmp, "%s.tracy", fn );
|
||||
m_filenameStaging = tmp;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_filenameStaging = std::move( fn );
|
||||
}
|
||||
m_filenameStaging = fn;
|
||||
}
|
||||
};
|
||||
|
||||
#ifndef TRACY_NO_FILESELECTOR
|
||||
Fileselector::SaveFile( "tracy", "Tracy Profiler trace file", cb );
|
||||
#else
|
||||
cb( "trace.tracy" );
|
||||
#endif
|
||||
}
|
||||
|
||||
ImGui::SameLine( 0, 2 * ty );
|
||||
|
Loading…
Reference in New Issue
Block a user