I need a way for users to select files. For that I am using IDesktopPlatform::OpenFileDialog
function.
Problem is that after I am done with the dialog, the focus won’t get returned back to application. The game loop is frozen and nothing except the function call gets done.
If you alt+tab or click somewhere in the window it starts working again, but I want to make it work without the need for the extra click.
The code is this:
IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
TSharedPtr<SWindow> parentWindow = FSlateApplication::Get().FindWidgetWindow(FSlateApplication::Get().GetGameViewport()->AsShared());
TSharedPtr<FGenericWindow> window = parentWindow->GetNativeWindow();
const void* parentWindowHandle = (parentWindow.IsValid() && parentWindow->GetNativeWindow().IsValid()) ? parentWindow->GetNativeWindow()->GetOSWindowHandle() : nullptr;
TArray<FString> paths;
if (DesktopPlatform->OpenFileDialog(window->GetOSWindowHandle(),
"Choose 2D Launch File",
"",
"",
"",
EFileDialogFlags::None,
paths))
{
for (const auto& path : paths)
{
UE_LOG(LogTemp, Warning, TEXT("%s"), *path);
}
}
I tried multiple approaches of getting the parent window and all of the are returning the right one, since I was able to manipulate it (min, max, move etc.) so I know it is the right one.
It even works as expect in terms of having the “window” activated. The window itself is in the foreground and active, however Slate itself does not respond until you alt+tab or click inside the window.
I really want to make this more user friendly so if anyone knows a way how to get back to normal state after modal dialog is closed I would be very grateful.