Files
UnrealEngineUWP/Engine/Source/Editor/DetailCustomizations/Private/TextCustomization.cpp
Lauren Barnes 6248f8d412 Replacing legacy EditorStyle calls with AppStyle
#preflight 6272a74d2f6d177be3c6fdda
#rb Matt.Kuhlenschmidt

#ROBOMERGE-OWNER: Lauren.Barnes
#ROBOMERGE-AUTHOR: lauren.barnes
#ROBOMERGE-SOURCE: CL 20057269 via CL 20070159 via CL 20072035 via CL 20072203
#ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v943-19904690)
#ROBOMERGE-CONFLICT from-shelf

[CL 20105363 by Lauren Barnes in ue5-main branch]
2022-05-09 13:12:28 -04:00

143 lines
4.3 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "TextCustomization.h"
#include "Widgets/DeclarativeSyntaxSupport.h"
#include "Engine/GameViewportClient.h"
#include "PropertyHandle.h"
#include "DetailWidgetRow.h"
#include "IPropertyUtilities.h"
#include "STextPropertyEditableTextBox.h"
namespace
{
/** Allows STextPropertyEditableTextBox to edit a property handle */
class FEditableTextPropertyHandle : public IEditableTextProperty
{
public:
FEditableTextPropertyHandle(const TSharedRef<IPropertyHandle>& InPropertyHandle, const TSharedPtr<IPropertyUtilities>& InPropertyUtilities)
: PropertyHandle(InPropertyHandle)
, PropertyUtilities(InPropertyUtilities)
{
}
virtual bool IsMultiLineText() const override
{
return PropertyHandle->IsValidHandle() && PropertyHandle->GetBoolMetaData("MultiLine");
}
virtual bool IsPassword() const override
{
return PropertyHandle->IsValidHandle() && PropertyHandle->GetBoolMetaData("PasswordField");
}
virtual bool IsReadOnly() const override
{
return !PropertyHandle->IsValidHandle() || PropertyHandle->IsEditConst();
}
virtual bool IsDefaultValue() const override
{
return PropertyHandle->IsValidHandle() && !PropertyHandle->DiffersFromDefault();
}
virtual FText GetToolTipText() const override
{
return (PropertyHandle->IsValidHandle())
? PropertyHandle->GetToolTipText()
: FText::GetEmpty();
}
virtual int32 GetNumTexts() const override
{
return (PropertyHandle->IsValidHandle())
? PropertyHandle->GetNumPerObjectValues()
: 0;
}
virtual FText GetText(const int32 InIndex) const override
{
if (PropertyHandle->IsValidHandle())
{
FString ObjectValue;
if (PropertyHandle->GetPerObjectValue(InIndex, ObjectValue) == FPropertyAccess::Success)
{
FText TextValue;
if (FTextStringHelper::ReadFromBuffer(*ObjectValue, TextValue))
{
return TextValue;
}
}
}
return FText::GetEmpty();
}
virtual void SetText(const int32 InIndex, const FText& InText) override
{
if (PropertyHandle->IsValidHandle())
{
FString ObjectValue;
FTextStringHelper::WriteToBuffer(ObjectValue, InText);
PropertyHandle->SetPerObjectValue(InIndex, ObjectValue);
}
}
virtual bool IsValidText(const FText& InText, FText& OutErrorMsg) const override
{
return true;
}
#if USE_STABLE_LOCALIZATION_KEYS
virtual void GetStableTextId(const int32 InIndex, const ETextPropertyEditAction InEditAction, const FString& InTextSource, const FString& InProposedNamespace, const FString& InProposedKey, FString& OutStableNamespace, FString& OutStableKey) const override
{
if (PropertyHandle->IsValidHandle())
{
TArray<UPackage*> PropertyPackages;
PropertyHandle->GetOuterPackages(PropertyPackages);
check(PropertyPackages.IsValidIndex(InIndex));
StaticStableTextId(PropertyPackages[InIndex], InEditAction, InTextSource, InProposedNamespace, InProposedKey, OutStableNamespace, OutStableKey);
}
}
#endif // USE_STABLE_LOCALIZATION_KEYS
virtual void RequestRefresh() override
{
if (PropertyUtilities.IsValid())
{
PropertyUtilities->RequestRefresh();
}
}
private:
TSharedRef<IPropertyHandle> PropertyHandle;
TSharedPtr<IPropertyUtilities> PropertyUtilities;
};
}
void FTextCustomization::CustomizeHeader( TSharedRef<class IPropertyHandle> InPropertyHandle, class FDetailWidgetRow& HeaderRow, IPropertyTypeCustomizationUtils& PropertyTypeCustomizationUtils )
{
TSharedRef<IEditableTextProperty> EditableTextProperty = MakeShareable(new FEditableTextPropertyHandle(InPropertyHandle, PropertyTypeCustomizationUtils.GetPropertyUtilities()));
const bool bIsMultiLine = EditableTextProperty->IsMultiLineText();
HeaderRow.FilterString(InPropertyHandle->GetPropertyDisplayName())
.NameContent()
[
InPropertyHandle->CreatePropertyNameWidget()
]
.ValueContent()
.MinDesiredWidth(bIsMultiLine ? 250.f : 125.f)
.MaxDesiredWidth(600.f)
[
SNew(STextPropertyEditableTextBox, EditableTextProperty)
.Font(FAppStyle::GetFontStyle("PropertyWindow.NormalFont"))
.AutoWrapText(true)
];
}
void FTextCustomization::CustomizeChildren( TSharedRef<class IPropertyHandle> InPropertyHandle, class IDetailChildrenBuilder& StructBuilder, IPropertyTypeCustomizationUtils& PropertyTypeCustomizationUtils )
{
}