Set owner of file dialogs on windows.

This commit is contained in:
Bartosz Taudul 2020-06-10 01:52:17 +02:00
parent 483bc3f549
commit d1ef8ea90b
9 changed files with 57 additions and 29 deletions

View File

@ -38,7 +38,8 @@ typedef enum {
/* single file open dialog */
nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList,
const nfdchar_t *defaultPath,
nfdchar_t **outPath );
nfdchar_t **outPath,
void* owner );
/* multiple file open dialog */
nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList,
@ -48,7 +49,8 @@ nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList,
/* save dialog */
nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList,
const nfdchar_t *defaultPath,
nfdchar_t **outPath );
nfdchar_t **outPath,
void* owner );
/* select folder dialog */

View File

@ -119,7 +119,8 @@ static nfdresult_t AllocPathSet( NSArray *urls, nfdpathset_t *pathset )
nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList,
const nfdchar_t *defaultPath,
nfdchar_t **outPath )
nfdchar_t **outPath,
void* owner )
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@ -205,7 +206,8 @@ nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList,
nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList,
const nfdchar_t *defaultPath,
nfdchar_t **outPath )
nfdchar_t **outPath,
void* owner )
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow];

View File

@ -167,7 +167,8 @@ static void WaitForCleanup(void)
nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList,
const nfdchar_t *defaultPath,
nfdchar_t **outPath )
nfdchar_t **outPath,
void* owner )
{
GtkWidget *dialog;
nfdresult_t result;
@ -271,7 +272,8 @@ nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList,
nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList,
const nfdchar_t *defaultPath,
nfdchar_t **outPath )
nfdchar_t **outPath,
void* owner )
{
GtkWidget *dialog;
nfdresult_t result;

View File

@ -364,7 +364,8 @@ static nfdresult_t SetDefaultPath( IFileDialog *dialog, const char *defaultPath
nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList,
const nfdchar_t *defaultPath,
nfdchar_t **outPath )
nfdchar_t **outPath,
void* owner )
{
HRESULT result;
nfdresult_t nfdResult = NFD_ERROR;
@ -407,7 +408,7 @@ nfdresult_t NFD_OpenDialog( const nfdchar_t *filterList,
}
// Show the dialog.
result = fileOpenDialog->Show(NULL);
result = fileOpenDialog->Show((HWND)owner);
if ( SUCCEEDED(result) )
{
// Get the file name
@ -559,7 +560,8 @@ end:
nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList,
const nfdchar_t *defaultPath,
nfdchar_t **outPath )
nfdchar_t **outPath,
void* owner )
{
nfdresult_t nfdResult = NFD_ERROR;
@ -600,7 +602,7 @@ nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList,
}
// Show the dialog.
result = fileSaveDialog->Show(NULL);
result = fileSaveDialog->Show((HWND)owner);
if ( SUCCEEDED(result) )
{
// Get the file name

View File

@ -22,6 +22,8 @@
#ifdef _WIN32
# include <windows.h>
# include <shellapi.h>
# define GLFW_EXPOSE_NATIVE_WIN32
# include <GLFW/glfw3native.h>
#endif
#define STB_IMAGE_IMPLEMENTATION
@ -83,6 +85,15 @@ static void WindowRefreshCallback( GLFWwindow* window )
DrawContents();
}
void* GetMainWindowNative()
{
#ifdef _WIN32
return (void*)glfwGetWin32Window( s_glfwWindow );
#else
return nullptr;
#endif
}
std::vector<std::unordered_map<std::string, uint64_t>::const_iterator> RebuildConnectionHistory( const std::unordered_map<std::string, uint64_t>& connHistMap )
{
std::vector<std::unordered_map<std::string, uint64_t>::const_iterator> ret;
@ -291,7 +302,7 @@ int main( int argc, char** argv )
auto f = std::unique_ptr<tracy::FileRead>( tracy::FileRead::Open( argv[1] ) );
if( f )
{
view = std::make_unique<tracy::View>( *f, fixedWidth, smallFont, bigFont, SetWindowTitleCallback );
view = std::make_unique<tracy::View>( *f, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative );
}
}
else
@ -317,7 +328,7 @@ int main( int argc, char** argv )
}
if( connectTo )
{
view = std::make_unique<tracy::View>( connectTo, port, fixedWidth, smallFont, bigFont, SetWindowTitleCallback );
view = std::make_unique<tracy::View>( connectTo, port, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative );
}
glfwShowWindow( window );
@ -613,18 +624,18 @@ static void DrawContents()
{
std::string addrPart = std::string( addr, ptr );
uint32_t portPart = atoi( ptr+1 );
view = std::make_unique<tracy::View>( addrPart.c_str(), portPart, fixedWidth, smallFont, bigFont, SetWindowTitleCallback );
view = std::make_unique<tracy::View>( addrPart.c_str(), portPart, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative );
}
else
{
view = std::make_unique<tracy::View>( addr, port, fixedWidth, smallFont, bigFont, SetWindowTitleCallback );
view = std::make_unique<tracy::View>( addr, port, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative );
}
}
ImGui::SameLine( 0, ImGui::GetFontSize() * 2 );
if( ImGui::Button( ICON_FA_FOLDER_OPEN " Open saved trace" ) && !loadThread.joinable() )
{
nfdchar_t* fn;
auto res = NFD_OpenDialog( "tracy", nullptr, &fn );
auto res = NFD_OpenDialog( "tracy", nullptr, &fn, GetMainWindowNative() );
if( res == NFD_OKAY )
{
try
@ -635,7 +646,7 @@ static void DrawContents()
loadThread = std::thread( [f] {
try
{
view = std::make_unique<tracy::View>( *f, fixedWidth, smallFont, bigFont, SetWindowTitleCallback );
view = std::make_unique<tracy::View>( *f, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative );
}
catch( const tracy::UnsupportedVersion& e )
{
@ -757,7 +768,7 @@ static void DrawContents()
}
if( selected && !loadThread.joinable() )
{
view = std::make_unique<tracy::View>( v.second.address.c_str(), v.second.port, fixedWidth, smallFont, bigFont, SetWindowTitleCallback );
view = std::make_unique<tracy::View>( v.second.address.c_str(), v.second.port, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative );
}
ImGui::NextColumn();
const auto acttime = ( v.second.activeTime + ( time - v.second.time ) / 1000 ) * 1000000000ll;
@ -897,7 +908,7 @@ static void DrawContents()
viewShutdown.store( ViewShutdown::False, std::memory_order_relaxed );
if( reconnect )
{
view = std::make_unique<tracy::View>( reconnectAddr.c_str(), reconnectPort, fixedWidth, smallFont, bigFont, SetWindowTitleCallback );
view = std::make_unique<tracy::View>( reconnectAddr.c_str(), reconnectPort, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative );
}
break;
default:

View File

@ -68,7 +68,7 @@ static SourceView::RegsX86 s_regMapX86[X86_REG_ENDING];
enum { JumpSeparation = 6 };
enum { JumpArrowBase = 9 };
SourceView::SourceView( ImFont* font )
SourceView::SourceView( ImFont* font, GetWindowCallback gwcb )
: m_font( font )
, m_file( nullptr )
, m_fileStringIdx( 0 )
@ -93,6 +93,7 @@ SourceView::SourceView( ImFont* font )
, m_showJumps( true )
, m_cpuArch( CpuArchUnknown )
, m_showLatency( false )
, m_gwcb( gwcb )
{
m_microArchOpMap.reserve( OpsNum );
for( int i=0; i<OpsNum; i++ )
@ -3537,7 +3538,7 @@ void SourceView::Save( const Worker& worker, size_t start, size_t stop )
assert( start < stop );
nfdchar_t* fn;
auto res = NFD_SaveDialog( "asm", nullptr, &fn );
auto res = NFD_SaveDialog( "asm", nullptr, &fn, m_gwcb ? m_gwcb() : nullptr );
if( res == NFD_OKAY )
{
FILE* f = nullptr;

View File

@ -127,7 +127,9 @@ private:
};
public:
SourceView( ImFont* font );
using GetWindowCallback = void*(*)();
SourceView( ImFont* font, GetWindowCallback gwcb );
~SourceView();
void SetCpuId( uint32_t cpuid );
@ -242,6 +244,8 @@ private:
float m_srcWidth;
float m_asmWidth;
GetWindowCallback m_gwcb;
};
}

View File

@ -128,7 +128,7 @@ enum { MinFrameSize = 5 };
static View* s_instance = nullptr;
View::View( const char* addr, int port, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb )
View::View( const char* addr, int port, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, GetWindowCallback gwcb )
: m_worker( addr, port )
, m_staticView( false )
, m_pause( false )
@ -139,6 +139,7 @@ View::View( const char* addr, int port, ImFont* fixedWidth, ImFont* smallFont, I
, m_smallFont( smallFont )
, m_bigFont( bigFont )
, m_stcb( stcb )
, m_gwcb( gwcb )
, m_userData()
{
assert( s_instance == nullptr );
@ -147,7 +148,7 @@ View::View( const char* addr, int port, ImFont* fixedWidth, ImFont* smallFont, I
InitTextEditor( fixedWidth );
}
View::View( FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb )
View::View( FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, GetWindowCallback gwcb )
: m_worker( f )
, m_filename( f.GetFilename() )
, m_staticView( true )
@ -157,6 +158,7 @@ View::View( FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont,
, m_smallFont( smallFont )
, m_bigFont( bigFont )
, m_stcb( stcb )
, m_gwcb( gwcb )
, m_userData( m_worker.GetCaptureProgram().c_str(), m_worker.GetCaptureTime() )
{
assert( s_instance == nullptr );
@ -196,7 +198,7 @@ View::~View()
void View::InitTextEditor( ImFont* font )
{
m_sourceView = std::make_unique<SourceView>( font );
m_sourceView = std::make_unique<SourceView>( font, m_gwcb );
m_sourceViewFile = nullptr;
}
@ -1120,7 +1122,7 @@ bool View::DrawConnection()
{
#ifndef TRACY_NO_FILESELECTOR
nfdchar_t* fn;
auto res = NFD_SaveDialog( "tracy", nullptr, &fn );
auto res = NFD_SaveDialog( "tracy", nullptr, &fn, m_gwcb ? m_gwcb() : nullptr );
if( res == NFD_OKAY )
#else
const char* fn = "trace.tracy";
@ -10312,7 +10314,7 @@ void View::DrawCompare()
if( ImGui::Button( ICON_FA_FOLDER_OPEN " Open second trace" ) && !m_compare.loadThread.joinable() )
{
nfdchar_t* fn;
auto res = NFD_OpenDialog( "tracy", nullptr, &fn );
auto res = NFD_OpenDialog( "tracy", nullptr, &fn, m_gwcb ? m_gwcb() : nullptr );
if( res == NFD_OKAY )
{
try

View File

@ -73,10 +73,11 @@ public:
};
using SetTitleCallback = void(*)( const char* );
using GetWindowCallback = void*(*)();
View( ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr ) : View( "127.0.0.1", 8086, fixedWidth, smallFont, bigFont, stcb ) {}
View( const char* addr, int port, ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr );
View( FileRead& f, ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr );
View( ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr, GetWindowCallback gwcb = nullptr ) : View( "127.0.0.1", 8086, fixedWidth, smallFont, bigFont, stcb, gwcb ) {}
View( const char* addr, int port, ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr, GetWindowCallback gwcb = nullptr );
View( FileRead& f, ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr, GetWindowCallback gwcb = nullptr );
~View();
static bool Draw();
@ -402,6 +403,7 @@ private:
float m_rootWidth, m_rootHeight;
SetTitleCallback m_stcb;
bool m_titleSet = false;
GetWindowCallback m_gwcb;
float m_notificationTime = 0;
std::string m_notificationText;