bool UZenoCommonBlueprintLibrary::OpenSettingsModal(UObject* InObject, const FText& InTitle /** = LOCTEXT("ModalTitle", "") */)
{
	ensure(IsValid(InObject));

	FPropertyEditorModule& PropertyEditorModule = FModuleManager::GetModuleChecked<FPropertyEditorModule>("PropertyEditor");
	const TSharedRef<IDetailsView> DetailsView = PropertyEditorModule.CreateDetailView({});
	DetailsView->SetObject(InObject);
	TSharedPtr<SWindow> ModalWindow;
	TSharedPtr<SVerticalBox> ContextBox;

	bool bFlag = false;

	const auto CloseThisWindow = [&ModalWindow] ()
	{
		if (ModalWindow.IsValid())
		{
			ModalWindow->RequestDestroyWindow();
		}
	};


	SAssignNew(ContextBox, SVerticalBox)
	+ SVerticalBox::Slot()
	.AutoHeight()
	[
		 DetailsView
	]
	+ SVerticalBox::Slot()
	.AutoHeight()
	[
		 SNew(SHorizontalBox)
		 + SHorizontalBox::Slot()
		 .AutoWidth()
		 [
			   SNew(SButton)
			   .Text(LOCTEXT("Apply", "Apply"))
			   .OnClicked_Lambda([&bFlag, CloseThisWindow] () mutable
			   {
					bFlag = true;
					CloseThisWindow();
					return FReply::Handled();
			   })
		]
		+ SHorizontalBox::Slot()
		.AutoWidth()
		[
			  SNew(SButton)
			  .Text(LOCTEXT("Cancel", "Cancel"))
			  .OnClicked_Lambda([CloseThisWindow] { CloseThisWindow(); return FReply::Handled(); })
		]
	];

	// Force update desired size in current tick
	ContextBox->SlatePrepass(ContextBox->GetTickSpaceGeometry().Scale);

	SAssignNew(ModalWindow, SWindow)
		.Title(InTitle)
		.Content()
		[
			ContextBox.ToSharedRef()
		]
		.ClientSize(FVector2D(1200, 600))
		.SupportsMaximize(true)
		.IsInitiallyMinimized(false)
		.AutoCenter(EAutoCenter::PreferredWorkArea)
		.SizingRule(ESizingRule::Autosized)
	;

	const IMainFrameModule& MainFrame = FModuleManager::LoadModuleChecked<IMainFrameModule>("MainFrame");
	const TSharedPtr<const SWidget> ParentWidget = MainFrame.GetParentWindow();

	FSlateApplication::Get().AddModalWindow(ModalWindow.ToSharedRef(), ParentWidget, false);
	return bFlag;
}