Files
UnrealEngineUWP/Engine/Source/Editor/UnrealEd/Public/EditorClassUtils.h
robert manuszewski d1443992e1 Deprecating ANY_PACKAGE.
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]
2022-06-01 03:46:59 -04:00

196 lines
8.2 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Widgets/SWidget.h"
#include "Widgets/SToolTip.h"
template< typename ObjectType > class TAttribute;
struct FAssetData;
namespace FEditorClassUtils
{
/**
* Gets the page that documentation for this class is contained on
*
* @param InClass Class we want to find the documentation page of
* @return Path to the documentation page
*/
UNREALED_API FString GetDocumentationPage(const UClass* Class);
/**
* Gets the excerpt to use for this class
* Excerpt will be contained on the page returned by GetDocumentationPage
*
* @param InClass Class we want to find the documentation excerpt of
* @return Name of the to the documentation excerpt
*/
UNREALED_API FString GetDocumentationExcerpt(const UClass* Class);
/**
* Gets the tooltip to display for a given class
*
* @param InClass Class we want to build a tooltip for
* @return Shared reference to the constructed tooltip
*/
UNREALED_API TSharedRef<SToolTip> GetTooltip(const UClass* Class);
/**
* Gets the tooltip to display for a given class with specified text for the tooltip
*
* @param InClass Class we want to build a tooltip for
* @param OverrideText The text to display on the standard tooltip
* @return Shared reference to the constructed tooltip
*/
UNREALED_API TSharedRef<SToolTip> GetTooltip(const UClass* Class, const TAttribute<FText>& OverrideText);
/**
* Returns the link path to the documentation for a given class
*
* @param Class Class we want to build a link for
* @return The path to the documentation for the class
*/
UNREALED_API FString GetDocumentationLink(const UClass* Class, const FString& OverrideExcerpt = FString());
/**
* Return link path from a specified excerpt
*/
UNREALED_API FString GetDocumentationLinkFromExcerpt(const FString& DocLink, const FString DocExcerpt);
/**
* Creates a link widget to the documentation for a given class
*
* @param Class Class we want to build a link for
* @return Shared pointer to the constructed tooltip
*/
UNREALED_API TSharedRef<SWidget> GetDocumentationLinkWidget(const UClass* Class);
/**
* Create a link widget to the documentation for a potentially dynamic link widget.
* @param Class The attribute of the class to show documentation for.
*/
UNREALED_API TSharedRef<SWidget> GetDynamicDocumentationLinkWidget(const TAttribute<const UClass*>& ClassAttribute);
/** Optional GetSourceLink parameters */
struct FSourceLinkParams
{
/* Object to set blueprint debugging to in the case we have a blueprint generated class */
TWeakObjectPtr<UObject> Object;
/* Text format for blueprint links */
const FText* BlueprintFormat = nullptr;
/* Text format for C++ code file links */
const FText* CodeFormat = nullptr;
/**
* If true, use default values for BlueprintFormat (Edit ...) and CodeFormat (Open ...) when unspecified
* If false, use only the class name when BlueprintFormat and CodeFormat are unspecified
*/
bool bUseDefaultFormat = false;
/** If true, use specified text format if the link is unavailable for some reason, otherwise use only the class name */
bool bUseFormatIfNoLink = false;
/** Whether a spacer widget is used if the link is unavailable for some reason */
bool bEmptyIfNoLink = false;
};
/**
* Creates an hyperlink to the source code or blueprint for a given class
* (or a text block/spacer if the link is unavailable for some reason)
*
* @param Class Class we want to build a link for
* @param Params See FSourceLinkOptionalParams
* @return Shared pointer to the constructed widget
*/
UNREALED_API TSharedRef<SWidget> GetSourceLink(const UClass* Class, const FSourceLinkParams& Params = FSourceLinkParams());
/**
* Creates an hyperlink to the source code or blueprint for a given class
* (or a spacer if the link is unavailable for some reason)
*
* @param Class Class we want to build a link for
* @param ObjectWeakPtr Optional object to set blueprint debugging to in the case we are choosing a blueprint
* @return Shared pointer to the constructed widget
*/
UNREALED_API TSharedRef<SWidget> GetSourceLink(const UClass* Class, const TWeakObjectPtr<UObject> ObjectWeakPtr);
/**
* Creates an hyperlink to the source code or blueprint for a given class formatted however you need. Example "Edit {0}"
* (or a spacer if the link is unavailable for some reason)
*
* @param Class Class we want to build a link for
* @param ObjectWeakPtr Optional object to set blueprint debugging to in the case we are choosing a blueprint
* @param BlueprintFormat The text format for blueprint links
* @param CodeFormat The text format for C++ code file links
* @return Shared pointer to the constructed widget
*/
UNREALED_API TSharedRef<SWidget> GetSourceLinkFormatted(const UClass* Class, const TWeakObjectPtr<UObject> ObjectWeakPtr, const FText& BlueprintFormat, const FText& CodeFormat);
/**
* Fetches a UClass from the string name of the class
*
* @param ClassName Name of the class we want the UClass for
* @return UClass pointer if it exists
*/
UNREALED_API UClass* GetClassFromString(const FString& ClassName);
/**
* Returns whether the specified asset is a UBlueprint or UBlueprintGeneratedClass (or any of their derived classes)
*
* @param InAssetData Reference to an asset data entry
* @param bOutIsBPGC Outputs whether the asset is a BlueprintGeneratedClass (or any of its derived classes)
* @return Whether the specified asset is a UBlueprint or UBlueprintGeneratedClass (or any of their derived classes)
*/
UNREALED_API bool IsBlueprintAsset(const FAssetData& InAssetData, bool* bOutIsBPGC = nullptr);
/**
* Gets the class path from the asset tag (i.e. GeneratedClassPath tag on blueprints)
*
* @param InAssetData Reference to an asset data entry.
* @return Class path or None if the asset cannot or doesn't have a class associated with it
*/
UE_DEPRECATED(5.1, "Class names are now represented by path names. Please use GetClassPathNameFromAssetTag.")
UNREALED_API FName GetClassPathFromAssetTag(const FAssetData& InAssetData);
/**
* Gets the class path from the asset tag (i.e. GeneratedClassPath tag on blueprints)
*
* @param InAssetData Reference to an asset data entry.
* @return Class path or None if the asset cannot or doesn't have a class associated with it
*/
UNREALED_API FTopLevelAssetPath GetClassPathNameFromAssetTag(const FAssetData& InAssetData);
/**
* Gets the object path of the class associated with the specified asset
* (i.e. the BlueprintGeneratedClass of a Blueprint asset or the BlueprintGeneratedClass asset itself)
*
* @param InAssetData Reference to an asset data entry
* @param bGenerateClassPathIfMissing Whether to generate a class path if the class is missing (and the asset can have a class associated with it)
* @return Class path or None if the asset cannot or doesn't have a class associated with it
*/
UE_DEPRECATED(5.1, "Class names are now represented by path names. Please use GetClassPathNameFromAsset.")
UNREALED_API FName GetClassPathFromAsset(const FAssetData& InAssetData, bool bGenerateClassPathIfMissing = false);
/**
* Gets the object path of the class associated with the specified asset
* (i.e. the BlueprintGeneratedClass of a Blueprint asset or the BlueprintGeneratedClass asset itself)
*
* @param InAssetData Reference to an asset data entry
* @param bGenerateClassPathIfMissing Whether to generate a class path if the class is missing (and the asset can have a class associated with it)
* @return Class path or None if the asset cannot or doesn't have a class associated with it
*/
UNREALED_API FTopLevelAssetPath GetClassPathNameFromAsset(const FAssetData& InAssetData, bool bGenerateClassPathIfMissing = false);
/**
* Fetches the set of interface class object paths from an asset data entry containing the appropriate asset tag(s).
*
* @param InAssetData Reference to an asset data entry.
* @param OutClassPaths One or more interface class object paths, or empty if the corresponding asset tag(s) were not found.
*/
UNREALED_API void GetImplementedInterfaceClassPathsFromAsset(const FAssetData& InAssetData, TArray<FString>& OutClassPaths);
};