FReply SPathInput::OnBrowseToFileClicked()

in GameLiftPlugin/Source/GameLiftPlugin/Private/SWidgets/SPathInput.cpp [113:181]


FReply SPathInput::OnBrowseToFileClicked()
{
	FString Path;
	IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();

	if (DesktopPlatform != nullptr)
	{
		void* ParentWindowWindowHandle = nullptr;
		IMainFrameModule& MainFrameModule = FModuleManager::LoadModuleChecked<IMainFrameModule>(TEXT("MainFrame"));
		const TSharedPtr<SWindow>& MainFrameParentWindow = MainFrameModule.GetParentWindow();

		if (MainFrameParentWindow.IsValid() && MainFrameParentWindow->GetNativeWindow().IsValid())
		{
			ParentWindowWindowHandle = MainFrameParentWindow->GetNativeWindow()->GetOSWindowHandle();
		}

		ensure(ParentWindowWindowHandle != nullptr);

		if (IsFileSelection)
		{
			auto DefaultPath = FPaths::GetPath(SelectedPath.ToString());
			TArray<FString> OpenedFilenames;
			bool IsOpened = DesktopPlatform->OpenFileDialog(
				ParentWindowWindowHandle,
				Title.ToString(),
				DefaultPath,
				SelectedPath.ToString(),
				*FileTypes,
				EFileDialogFlags::None,
				OpenedFilenames
			);

			if (IsOpened && OpenedFilenames.Num() > 0)
			{
				Path = OpenedFilenames[0];
			}
		}
		else
		{
			FString OpenedDirPath;

			bool IsOpened = DesktopPlatform->OpenDirectoryDialog(
				ParentWindowWindowHandle,
				Title.ToString(),
				SelectedPath.ToString(),
				OpenedDirPath
			);

			if (IsOpened)
			{
				Path = OpenedDirPath;
			}
		}
	}

	if (!Path.IsEmpty())
	{
		if (FPaths::IsRelative(Path))
		{
			Path = FPaths::ConvertRelativePathToFull(Path);
		}

		SelectedPath = FText::FromString(Path);
		EditableTextBox->SetText(SelectedPath);
		OnPathUpdated.ExecuteIfBound(SelectedPath.ToString());
	}

	return FReply::Handled();
}