Files
UnrealEngineUWP/Engine/Source/Editor/Blutility/Private/EditorUtilityWidgetBlueprint.cpp
vincent gauthier b5083323f8 Remove Callbacks to rebuild UMG Detail View as they are already handled at the Editor Utility Widget Blueprint level.
#jira UE-133916
#rb lauren.barnes, patrick.boutot

#ROBOMERGE-AUTHOR: vincent.gauthier
#ROBOMERGE-SOURCE: CL 18296375 in //UE5/Release-5.0/... via CL 18296382
#ROBOMERGE-BOT: STARSHIP (Release-Engine-Staging -> Release-Engine-Test) (v895-18170469)

[CL 18296391 by vincent gauthier in ue5-release-engine-test branch]
2021-11-25 14:33:29 -05:00

153 lines
4.5 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "EditorUtilityWidgetBlueprint.h"
#include "WidgetBlueprint.h"
#include "Editor.h"
#include "EditorUtilityWidget.h"
#include "IBlutilityModule.h"
#include "Modules/ModuleManager.h"
#include "LevelEditor.h"
/////////////////////////////////////////////////////
// UEditorUtilityWidgetBlueprint
UEditorUtilityWidgetBlueprint::UEditorUtilityWidgetBlueprint(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
}
void UEditorUtilityWidgetBlueprint::BeginDestroy()
{
// Only cleanup script if it has been registered and we're not shutdowning editor
if (!IsEngineExitRequested() && RegistrationName != NAME_None)
{
IBlutilityModule* BlutilityModule = FModuleManager::GetModulePtr<IBlutilityModule>("Blutility");
if (BlutilityModule)
{
BlutilityModule->RemoveLoadedScriptUI(this);
}
FLevelEditorModule* LevelEditorModule = FModuleManager::GetModulePtr<FLevelEditorModule>(TEXT("LevelEditor"));
if (LevelEditorModule)
{
TSharedPtr<FTabManager> LevelEditorTabManager = LevelEditorModule->GetLevelEditorTabManager();
if (LevelEditorTabManager.IsValid())
{
LevelEditorTabManager->UnregisterTabSpawner(RegistrationName);
}
}
}
Super::BeginDestroy();
}
TSharedRef<SDockTab> UEditorUtilityWidgetBlueprint::SpawnEditorUITab(const FSpawnTabArgs& SpawnTabArgs)
{
TSharedRef<SDockTab> SpawnedTab = SNew(SDockTab);
TSharedRef<SWidget> TabWidget = CreateUtilityWidget();
SpawnedTab->SetContent(TabWidget);
SpawnedTab->SetOnTabClosed(SDockTab::FOnTabClosedCallback::CreateUObject(this, &UEditorUtilityWidgetBlueprint::UpdateRespawnListIfNeeded));
CreatedTab = SpawnedTab;
OnCompiled().AddUObject(this, &UEditorUtilityWidgetBlueprint::RegenerateCreatedTab);
FLevelEditorModule& LevelEditor = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
LevelEditor.OnMapChanged().AddUObject(this, &UEditorUtilityWidgetBlueprint::ChangeTabWorld);
return SpawnedTab;
}
TSharedRef<SWidget> UEditorUtilityWidgetBlueprint::CreateUtilityWidget()
{
TSharedRef<SWidget> TabWidget = SNullWidget::NullWidget;
UClass* BlueprintClass = GeneratedClass;
TSubclassOf<UEditorUtilityWidget> WidgetClass = BlueprintClass;
UWorld* World = GEditor->GetEditorWorldContext().World();
if (World)
{
if (CreatedUMGWidget)
{
CreatedUMGWidget->Rename(nullptr, GetTransientPackage(), REN_DoNotDirty);
}
CreatedUMGWidget = CreateWidget<UEditorUtilityWidget>(World, WidgetClass);
if (CreatedUMGWidget)
{
// Editor Utility is flagged as transient to prevent from dirty the World it's created in when a property added to the Utility Widget is changed
CreatedUMGWidget->SetFlags(RF_Transient);
}
}
if (CreatedUMGWidget)
{
TabWidget = SNew(SVerticalBox)
+ SVerticalBox::Slot()
.HAlign(HAlign_Fill)
[
CreatedUMGWidget->TakeWidget()
];
}
return TabWidget;
}
void UEditorUtilityWidgetBlueprint::RegenerateCreatedTab(UBlueprint* RecompiledBlueprint)
{
if (CreatedTab.IsValid())
{
TSharedRef<SWidget> TabWidget = CreateUtilityWidget();
CreatedTab.Pin()->SetContent(TabWidget);
}
}
void UEditorUtilityWidgetBlueprint::ChangeTabWorld(UWorld* World, EMapChangeType MapChangeType)
{
if (MapChangeType == EMapChangeType::TearDownWorld)
{
// We need to Delete the UMG widget if we are tearing down the World it was built with.
if (CreatedUMGWidget && World == CreatedUMGWidget->GetWorld())
{
if (CreatedTab.IsValid())
{
CreatedTab.Pin()->SetContent(SNullWidget::NullWidget);
}
CreatedUMGWidget->Rename(nullptr, GetTransientPackage());
CreatedUMGWidget = nullptr;
}
}
else if (MapChangeType != EMapChangeType::SaveMap)
{
// Recreate the widget if we are loading a map or opening a new map
RegenerateCreatedTab(nullptr);
}
}
void UEditorUtilityWidgetBlueprint::UpdateRespawnListIfNeeded(TSharedRef<SDockTab> TabBeingClosed)
{
if (GeneratedClass)
{
const UEditorUtilityWidget* EditorUtilityWidget = GeneratedClass->GetDefaultObject<UEditorUtilityWidget>();
if (EditorUtilityWidget && EditorUtilityWidget->ShouldAlwaysReregisterWithWindowsMenu() == false)
{
IBlutilityModule* BlutilityModule = FModuleManager::GetModulePtr<IBlutilityModule>("Blutility");
BlutilityModule->RemoveLoadedScriptUI(this);
}
}
CreatedUMGWidget = nullptr;
}
void UEditorUtilityWidgetBlueprint::GetReparentingRules(TSet< const UClass* >& AllowedChildrenOfClasses, TSet< const UClass* >& DisallowedChildrenOfClasses) const
{
AllowedChildrenOfClasses.Empty();
AllowedChildrenOfClasses.Add(UEditorUtilityWidget::StaticClass());
}