Files
UnrealEngineUWP/Engine/Source/Editor/LevelEditor/Private/LevelViewportTabContent.cpp
brooke hubert a3564a7967 Fix for level viewport layout not saving/loading from user settings post CL 14066626.
#rnx
#Jira none
#rb lauren.barnes

[CL 14078925 by brooke hubert in ue5-main branch]
2020-08-11 13:54:17 -04:00

85 lines
2.7 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "LevelViewportTabContent.h"
#include "Misc/ConfigCacheIni.h"
#include "Framework/Docking/LayoutService.h"
#include "Modules/ModuleManager.h"
#include "LevelEditor.h"
#include "Widgets/Docking/SDockTab.h"
#include "LevelViewportLayout.h"
#include "LevelEditorViewport.h"
// FLevelViewportTabContent ///////////////////////////
TSharedPtr< FEditorViewportLayout > FLevelViewportTabContent::FactoryViewportLayout(bool bIsSwitchingLayouts)
{
TSharedPtr<FLevelViewportLayout> ViewportLayout = MakeShareable(new FLevelViewportLayout);
ViewportLayout->SetIsReplacement(bIsSwitchingLayouts);
return ViewportLayout;
}
FName FLevelViewportTabContent::GetLayoutTypeNameFromLayoutString() const
{
const FString& IniSection = FLayoutSaveRestore::GetAdditionalLayoutConfigIni();
FString LayoutTypeString;
if (LayoutString.IsEmpty() ||
!GConfig->GetString(*IniSection, *(LayoutString + TEXT(".LayoutType")), LayoutTypeString, GEditorPerProjectIni))
{
return EditorViewportConfigurationNames::FourPanes2x2;
}
return *LayoutTypeString;
}
FLevelViewportTabContent::~FLevelViewportTabContent()
{
if (GEditor)
{
GEditor->OnLevelViewportClientListChanged().RemoveAll(this);
}
}
void FLevelViewportTabContent::Initialize(AssetEditorViewportFactoryFunction Func, TSharedPtr<SDockTab> InParentTab, const FString& InLayoutString)
{
check(InParentTab.IsValid());
InParentTab->SetOnPersistVisualState( SDockTab::FOnPersistVisualState::CreateSP(this, &FLevelViewportTabContent::SaveConfig) );
OnViewportTabContentLayoutStartChangeEvent.AddSP(this, &FLevelViewportTabContent::OnLayoutStartChange);
OnViewportTabContentLayoutChangedEvent.AddSP(this, &FLevelViewportTabContent::OnLayoutChanged);
FEditorViewportTabContent::Initialize(Func, InParentTab, InLayoutString);
}
void FLevelViewportTabContent::OnLayoutStartChange(bool bSwitchingLayouts)
{
GCurrentLevelEditingViewportClient = nullptr;
GLastKeyLevelEditingViewportClient = nullptr;
}
void FLevelViewportTabContent::OnLayoutChanged()
{
// Set the global level editor to the first, valid perspective viewport found
if (GEditor)
{
const TArray<FLevelEditorViewportClient*>& LevelViewportClients = GEditor->GetLevelViewportClients();
for (FLevelEditorViewportClient* LevelViewport : LevelViewportClients)
{
if (LevelViewport->IsPerspective())
{
LevelViewport->SetCurrentViewport();
break;
}
}
// Otherwise just make sure it's set to something
if (!GCurrentLevelEditingViewportClient && LevelViewportClients.Num())
{
GCurrentLevelEditingViewportClient = LevelViewportClients[0];
}
}
FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
LevelEditorModule.OnTabContentChanged().Broadcast();
}