You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
This change consists of multiple changes: Core: - Deprecation of ANY_PACKAGE macro. Added ANY_PACKAGE_DEPRECATED macro which can still be used for backwards compatibility purposes (only used in CoreUObject) - Deprecation of StaticFindObjectFast* functions that take bAnyPackage parameter - Added UStruct::GetStructPathName function that returns FTopLevelAssetPath representing the path name (package + object FName, super quick compared to UObject::GetPathName) + wrapper UClass::GetClassPathName to make it look better when used with UClasses - Added (Static)FindFirstObject* functions that find a first object given its Name (no Outer). These functions are used in places I consider valid to do global UObject (UClass) lookups like parsing command line parameters / checking for unique object names - Added static UClass::TryFindType function which serves a similar purpose as FindFirstObject however it's going to throw a warning (with a callstack / maybe ensure in the future?) if short class name is provided. This function is used in places that used to use short class names but now should have been converted to use path names to catch any potential regressions and or edge cases I missed. - Added static UClass::TryConvertShortNameToPathName utility function - Added static UClass::TryFixShortClassNameExportPath utility function - Object text export paths will now also include class path (Texture2D'/Game/Textures/Grass.Grass' -> /Script/Engine.Texture2D'/Game/Textures/Grass.Grass') - All places that manually generated object export paths for objects will now use FObjectPropertyBase::GetExportPath - Added a new startup test that checks for short type names in UClass/FProperty MetaData values AssetRegistry: - Deprecated any member variables (FAssetData / FARFilter) or functions that use FNames to represent class names and replaced them with FTopLevelAssetPath - Added new member variables and new function overloads that use FTopLevelAssetPath to represent class names - This also applies to a few other modules' APIs to match AssetRegistry changes Everything else: - Updated code that used ANY_PACKAGE (depending on the use case) to use FindObject(nullptr, PathToObject), UClass::TryFindType (used when path name is expected, warns if it's a short name) or FindFirstObject (usually for finding types based on user input but there's been a few legitimate use cases not related to user input) - Updated code that used AssetRegistry API to use FTopLevelAssetPaths and USomeClass::StaticClass()->GetClassPathName() instead of GetFName() - Updated meta data and hardcoded FindObject(ANY_PACKAGE, "EEnumNameOrClassName") calls to use path names #jira UE-99463 #rb many.people [FYI] Marcus.Wassmer #preflight 629248ec2256738f75de9b32 #codereviewnumbers 20320742, 20320791, 20320799, 20320756, 20320809, 20320830, 20320840, 20320846, 20320851, 20320863, 20320780, 20320765, 20320876, 20320786 #ROBOMERGE-OWNER: robert.manuszewski #ROBOMERGE-AUTHOR: robert.manuszewski #ROBOMERGE-SOURCE: CL 20430220 via CL 20433854 via CL 20435474 via CL 20435484 #ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v949-20362246) [CL 20448496 by robert manuszewski in ue5-main branch]
381 lines
12 KiB
C++
381 lines
12 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "EditorClassUtils.h"
|
|
#include "HAL/FileManager.h"
|
|
#include "Widgets/Layout/SSpacer.h"
|
|
#include "Styling/AppStyle.h"
|
|
#include "Engine/Blueprint.h"
|
|
#include "Editor.h"
|
|
#include "AssetRegistry/AssetRegistryModule.h"
|
|
|
|
#include "IDocumentationPage.h"
|
|
#include "IDocumentation.h"
|
|
#include "SourceCodeNavigation.h"
|
|
#include "Widgets/Input/SHyperlink.h"
|
|
#include "BlueprintEditorSettings.h"
|
|
|
|
FString FEditorClassUtils::GetDocumentationPage(const UClass* Class)
|
|
{
|
|
return (Class ? FString::Printf( TEXT("Shared/Types/%s%s"), Class->GetPrefixCPP(), *Class->GetName() ) : FString());
|
|
}
|
|
|
|
FString FEditorClassUtils::GetDocumentationExcerpt(const UClass* Class)
|
|
{
|
|
return (Class ? FString::Printf( TEXT("%s%s"), Class->GetPrefixCPP(), *Class->GetName() ) : FString());
|
|
}
|
|
|
|
TSharedRef<SToolTip> FEditorClassUtils::GetTooltip(const UClass* Class)
|
|
{
|
|
return (Class ? GetTooltip(Class, Class->GetToolTipText(GetDefault<UBlueprintEditorSettings>()->bShowShortTooltips)) : SNew(SToolTip));
|
|
}
|
|
|
|
TSharedRef<SToolTip> FEditorClassUtils::GetTooltip(const UClass* Class, const TAttribute<FText>& OverrideText)
|
|
{
|
|
return (Class ? IDocumentation::Get()->CreateToolTip(OverrideText, nullptr, GetDocumentationPage(Class), GetDocumentationExcerpt(Class)) : SNew(SToolTip));
|
|
}
|
|
|
|
FString FEditorClassUtils::GetDocumentationLinkFromExcerpt(const FString& DocLink, const FString DocExcerpt)
|
|
{
|
|
FString DocumentationLink;
|
|
TSharedRef<IDocumentation> Documentation = IDocumentation::Get();
|
|
if (Documentation->PageExists(DocLink))
|
|
{
|
|
TSharedRef<IDocumentationPage> ClassDocs = Documentation->GetPage(DocLink, NULL);
|
|
|
|
FExcerpt Excerpt;
|
|
if (ClassDocs->GetExcerpt(DocExcerpt, Excerpt))
|
|
{
|
|
FString* FullDocumentationLink = Excerpt.Variables.Find(TEXT("ToolTipFullLink"));
|
|
if (FullDocumentationLink)
|
|
{
|
|
DocumentationLink = *FullDocumentationLink;
|
|
}
|
|
}
|
|
}
|
|
|
|
return DocumentationLink;
|
|
}
|
|
|
|
|
|
FString FEditorClassUtils::GetDocumentationLink(const UClass* Class, const FString& OverrideExcerpt)
|
|
{
|
|
const FString ClassDocsPage = GetDocumentationPage(Class);
|
|
const FString ExcerptSection = (OverrideExcerpt.IsEmpty() ? GetDocumentationExcerpt(Class) : OverrideExcerpt);
|
|
|
|
return GetDocumentationLinkFromExcerpt(ClassDocsPage, ExcerptSection);
|
|
}
|
|
|
|
|
|
TSharedRef<SWidget> FEditorClassUtils::GetDocumentationLinkWidget(const UClass* Class)
|
|
{
|
|
TSharedRef<SWidget> DocLinkWidget = SNullWidget::NullWidget;
|
|
const FString DocumentationLink = GetDocumentationLink(Class);
|
|
|
|
if (!DocumentationLink.IsEmpty())
|
|
{
|
|
DocLinkWidget = IDocumentation::Get()->CreateAnchor(DocumentationLink);
|
|
}
|
|
|
|
return DocLinkWidget;
|
|
}
|
|
|
|
TSharedRef<SWidget> FEditorClassUtils::GetDynamicDocumentationLinkWidget(const TAttribute<const UClass*>& ClassAttribute)
|
|
{
|
|
auto GetLink = [ClassAttribute]()
|
|
{
|
|
return GetDocumentationLink(ClassAttribute.Get(nullptr));
|
|
};
|
|
return IDocumentation::Get()->CreateAnchor(TAttribute<FString>::CreateLambda(GetLink));
|
|
}
|
|
|
|
TSharedRef<SWidget> FEditorClassUtils::GetSourceLink(const UClass* Class, const FSourceLinkParams& Params)
|
|
{
|
|
TSharedRef<SWidget> Link = SNew(SSpacer);
|
|
|
|
UBlueprint* Blueprint = (Class ? Cast<UBlueprint>(Class->ClassGeneratedBy) : nullptr);
|
|
if (Blueprint)
|
|
{
|
|
struct Local
|
|
{
|
|
static void OnEditBlueprintClicked(TWeakObjectPtr<UBlueprint> InBlueprint, TWeakObjectPtr<UObject> InAsset)
|
|
{
|
|
if (UBlueprint* BlueprintToEdit = InBlueprint.Get())
|
|
{
|
|
// Set the object being debugged if given an actor reference (if we don't do this before we edit the object the editor wont know we are debugging something)
|
|
if (UObject* Asset = InAsset.Get())
|
|
{
|
|
check(Asset->GetClass()->ClassGeneratedBy == BlueprintToEdit);
|
|
BlueprintToEdit->SetObjectBeingDebugged(Asset);
|
|
}
|
|
// Open the blueprint
|
|
GEditor->EditObject(BlueprintToEdit);
|
|
}
|
|
}
|
|
};
|
|
|
|
TWeakObjectPtr<UBlueprint> BlueprintPtr = Blueprint;
|
|
|
|
FText Text = FText::FromName(Blueprint->GetFName());
|
|
if (Params.BlueprintFormat)
|
|
{
|
|
Text = FText::Format(*Params.BlueprintFormat, Text);
|
|
}
|
|
else if (Params.bUseDefaultFormat)
|
|
{
|
|
const FText DefaultBlueprintFormat = NSLOCTEXT("SourceHyperlink", "EditBlueprint", "Edit {0}");
|
|
Text = FText::Format(DefaultBlueprintFormat, Text);
|
|
}
|
|
|
|
Link = SNew(SHyperlink)
|
|
.Style(FAppStyle::Get(), "Common.GotoBlueprintHyperlink")
|
|
.OnNavigate_Static(&Local::OnEditBlueprintClicked, BlueprintPtr, Params.Object)
|
|
.Text(Text)
|
|
.ToolTipText(NSLOCTEXT("SourceHyperlink", "EditBlueprint_ToolTip", "Click to edit the blueprint"));
|
|
}
|
|
else if (Class)
|
|
{
|
|
TWeakObjectPtr<const UClass> WeakClassPtr(Class);
|
|
|
|
auto OnNavigateToClassCode = [WeakClassPtr]()
|
|
{
|
|
if (const UClass* Class = WeakClassPtr.Get())
|
|
{
|
|
FSourceCodeNavigation::NavigateToClass(Class);
|
|
}
|
|
};
|
|
|
|
auto CanNavigateToClassCode = [WeakClassPtr]()
|
|
{
|
|
if (const UClass* Class = WeakClassPtr.Get())
|
|
{
|
|
return FSourceCodeNavigation::CanNavigateToClass(Class);
|
|
}
|
|
return false;
|
|
};
|
|
|
|
FText ClassNameText = FText::FromName(Class->GetFName());
|
|
|
|
FText FormattedText;
|
|
if (Params.CodeFormat)
|
|
{
|
|
FormattedText = FText::Format(*Params.CodeFormat, ClassNameText);
|
|
}
|
|
else if (Params.bUseDefaultFormat)
|
|
{
|
|
const FText DefaultCodeFormat = NSLOCTEXT("SourceHyperlink", "GoToCode", "Open {0}");
|
|
FormattedText = FText::Format(DefaultCodeFormat, ClassNameText);
|
|
}
|
|
else
|
|
{
|
|
FormattedText = ClassNameText;
|
|
}
|
|
|
|
TSharedRef<SWidget> NoLinkWidget = SNullWidget::NullWidget;
|
|
if (Params.bEmptyIfNoLink)
|
|
{
|
|
NoLinkWidget = SNew(SSpacer)
|
|
.Visibility_Lambda([CanNavigateToClassCode]() { return CanNavigateToClassCode() ? EVisibility::Collapsed : EVisibility::Visible; });
|
|
}
|
|
else
|
|
{
|
|
NoLinkWidget = SNew(STextBlock)
|
|
.Text(Params.bUseFormatIfNoLink ? FormattedText : ClassNameText)
|
|
.ColorAndOpacity(FSlateColor::UseSubduedForeground())
|
|
.Visibility_Lambda([CanNavigateToClassCode]() { return CanNavigateToClassCode() ? EVisibility::Collapsed : EVisibility::Visible; });
|
|
}
|
|
|
|
Link = SNew(SHorizontalBox)
|
|
+ SHorizontalBox::Slot()
|
|
.AutoWidth()
|
|
.VAlign(VAlign_Center)
|
|
[
|
|
SNew(SHyperlink)
|
|
.Style(FAppStyle::Get(), "Common.GotoNativeCodeHyperlink")
|
|
.OnNavigate_Lambda(OnNavigateToClassCode)
|
|
.Text(FormattedText)
|
|
.ToolTipText(FText::Format(NSLOCTEXT("SourceHyperlink", "GoToCode_ToolTip", "Click to open this source file in {0}"), FSourceCodeNavigation::GetSelectedSourceCodeIDE()))
|
|
.Visibility_Lambda([CanNavigateToClassCode]() { return CanNavigateToClassCode() ? EVisibility::Visible : EVisibility::Collapsed; })
|
|
]
|
|
+ SHorizontalBox::Slot()
|
|
.AutoWidth()
|
|
.VAlign(VAlign_Center)
|
|
[
|
|
NoLinkWidget
|
|
];
|
|
}
|
|
|
|
return Link;
|
|
}
|
|
|
|
TSharedRef<SWidget> FEditorClassUtils::GetSourceLink(const UClass* Class, const TWeakObjectPtr<UObject> ObjectWeakPtr)
|
|
{
|
|
FSourceLinkParams Params;
|
|
Params.Object = ObjectWeakPtr;
|
|
Params.bUseDefaultFormat = true;
|
|
Params.bEmptyIfNoLink = true;
|
|
|
|
return GetSourceLink(Class, Params);
|
|
}
|
|
|
|
TSharedRef<SWidget> FEditorClassUtils::GetSourceLinkFormatted(const UClass* Class, const TWeakObjectPtr<UObject> ObjectWeakPtr, const FText& BlueprintFormat, const FText& CodeFormat)
|
|
{
|
|
FSourceLinkParams Params;
|
|
Params.Object = ObjectWeakPtr;
|
|
Params.BlueprintFormat = &BlueprintFormat;
|
|
Params.CodeFormat = &CodeFormat;
|
|
Params.bEmptyIfNoLink = true;
|
|
|
|
return GetSourceLink(Class, Params);
|
|
}
|
|
|
|
UClass* FEditorClassUtils::GetClassFromString(const FString& ClassName)
|
|
{
|
|
if(ClassName.IsEmpty() || ClassName == TEXT("None"))
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
UClass* Class = nullptr;
|
|
if (!FPackageName::IsShortPackageName(ClassName))
|
|
{
|
|
Class = FindObject<UClass>(nullptr, *ClassName);
|
|
}
|
|
else
|
|
{
|
|
Class = FindFirstObject<UClass>(*ClassName, EFindFirstObjectOptions::None, ELogVerbosity::Warning, TEXT("FEditorClassUtils::GetClassFromString"));
|
|
}
|
|
if(!Class)
|
|
{
|
|
Class = LoadObject<UClass>(nullptr, *ClassName);
|
|
}
|
|
return Class;
|
|
}
|
|
|
|
bool FEditorClassUtils::IsBlueprintAsset(const FAssetData& InAssetData, bool* bOutIsBPGC /*= nullptr*/)
|
|
{
|
|
bool bIsBP = (InAssetData.AssetClassPath == UBlueprint::StaticClass()->GetClassPathName());
|
|
bool bIsBPGC = (InAssetData.AssetClassPath == UBlueprintGeneratedClass::StaticClass()->GetClassPathName());
|
|
|
|
if (!bIsBP && !bIsBPGC)
|
|
{
|
|
IAssetRegistry& AssetRegistry = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(AssetRegistryConstants::ModuleName).Get();
|
|
TArray<FTopLevelAssetPath> AncestorClassNames;
|
|
AssetRegistry.GetAncestorClassNames(InAssetData.AssetClassPath, AncestorClassNames);
|
|
|
|
if (AncestorClassNames.Contains(UBlueprint::StaticClass()->GetClassPathName()))
|
|
{
|
|
bIsBP = true;
|
|
}
|
|
else if (AncestorClassNames.Contains(UBlueprintGeneratedClass::StaticClass()->GetClassPathName()))
|
|
{
|
|
bIsBPGC = true;
|
|
}
|
|
}
|
|
|
|
if (bOutIsBPGC)
|
|
{
|
|
*bOutIsBPGC = bIsBPGC;
|
|
}
|
|
|
|
return bIsBP || bIsBPGC;
|
|
}
|
|
|
|
FName FEditorClassUtils::GetClassPathFromAssetTag(const FAssetData& InAssetData)
|
|
{
|
|
const FString GeneratedClassPath = InAssetData.GetTagValueRef<FString>(FBlueprintTags::GeneratedClassPath);
|
|
return FName(FPackageName::ExportTextPathToObjectPath(FStringView(GeneratedClassPath)));
|
|
}
|
|
|
|
FTopLevelAssetPath FEditorClassUtils::GetClassPathNameFromAssetTag(const FAssetData& InAssetData)
|
|
{
|
|
const FString GeneratedClassPath = InAssetData.GetTagValueRef<FString>(FBlueprintTags::GeneratedClassPath);
|
|
return FTopLevelAssetPath(FPackageName::ExportTextPathToObjectPath(FStringView(GeneratedClassPath)));
|
|
}
|
|
|
|
FName FEditorClassUtils::GetClassPathFromAsset(const FAssetData& InAssetData, bool bGenerateClassPathIfMissing /*= false*/)
|
|
{
|
|
bool bIsBPGC = false;
|
|
const bool bIsBP = IsBlueprintAsset(InAssetData, &bIsBPGC);
|
|
|
|
if (bIsBPGC)
|
|
{
|
|
return InAssetData.ObjectPath;
|
|
}
|
|
else if (bIsBP)
|
|
{
|
|
PRAGMA_DISABLE_DEPRECATION_WARNINGS
|
|
FName ClassPath = GetClassPathFromAssetTag(InAssetData);
|
|
PRAGMA_ENABLE_DEPRECATION_WARNINGS
|
|
if (bGenerateClassPathIfMissing && ClassPath.IsNone())
|
|
{
|
|
FNameBuilder ClassPathBuilder(InAssetData.ObjectPath);
|
|
ClassPathBuilder << "_C";
|
|
ClassPath = FName(ClassPathBuilder.ToString());
|
|
}
|
|
return ClassPath;
|
|
}
|
|
return NAME_None;
|
|
}
|
|
|
|
FTopLevelAssetPath FEditorClassUtils::GetClassPathNameFromAsset(const FAssetData& InAssetData, bool bGenerateClassPathIfMissing /*= false*/)
|
|
{
|
|
bool bIsBPGC = false;
|
|
const bool bIsBP = IsBlueprintAsset(InAssetData, &bIsBPGC);
|
|
|
|
if (bIsBPGC)
|
|
{
|
|
return FTopLevelAssetPath(InAssetData.ObjectPath.ToString());
|
|
}
|
|
else if (bIsBP)
|
|
{
|
|
FTopLevelAssetPath ClassPath = GetClassPathNameFromAssetTag(InAssetData);
|
|
if (bGenerateClassPathIfMissing && ClassPath.IsNull())
|
|
{
|
|
FString ClassPathString = InAssetData.ObjectPath.ToString();
|
|
ClassPathString += TEXT("_C");
|
|
ClassPath = FTopLevelAssetPath(ClassPathString);
|
|
}
|
|
return ClassPath;
|
|
}
|
|
return FTopLevelAssetPath();
|
|
}
|
|
|
|
void FEditorClassUtils::GetImplementedInterfaceClassPathsFromAsset(const struct FAssetData& InAssetData, TArray<FString>& OutClassPaths)
|
|
{
|
|
if (!InAssetData.IsValid())
|
|
{
|
|
return;
|
|
}
|
|
|
|
const FString ImplementedInterfaces = InAssetData.GetTagValueRef<FString>(FBlueprintTags::ImplementedInterfaces);
|
|
if (!ImplementedInterfaces.IsEmpty())
|
|
{
|
|
// Parse string like "((Interface=Class'"/Script/VPBookmark.VPBookmarkProvider"'),(Interface=Class'"/Script/VPUtilities.VPContextMenuProvider"'))"
|
|
// We don't want to actually resolve the hard ref so do some manual parsing
|
|
|
|
FString FullInterface;
|
|
FString CurrentString = *ImplementedInterfaces;
|
|
while (CurrentString.Split(TEXT("Interface="), nullptr, &FullInterface))
|
|
{
|
|
// Cutoff at next )
|
|
int32 RightParen = INDEX_NONE;
|
|
if (FullInterface.FindChar(TCHAR(')'), RightParen))
|
|
{
|
|
// Keep parsing
|
|
CurrentString = FullInterface.Mid(RightParen);
|
|
|
|
// Strip class name
|
|
FullInterface = *FPackageName::ExportTextPathToObjectPath(FullInterface.Left(RightParen));
|
|
|
|
// Handle quotes
|
|
FString InterfacePath;
|
|
const TCHAR* NewBuffer = FPropertyHelpers::ReadToken(*FullInterface, InterfacePath, true);
|
|
|
|
if (NewBuffer)
|
|
{
|
|
OutClassPaths.Add(InterfacePath);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |