// 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& InPropertyHandle, const TSharedPtr& 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 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 PropertyHandle; TSharedPtr PropertyUtilities; }; } void FTextCustomization::CustomizeHeader( TSharedRef InPropertyHandle, class FDetailWidgetRow& HeaderRow, IPropertyTypeCustomizationUtils& PropertyTypeCustomizationUtils ) { TSharedRef 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 InPropertyHandle, class IDetailChildrenBuilder& StructBuilder, IPropertyTypeCustomizationUtils& PropertyTypeCustomizationUtils ) { }