2014-12-07 19:09:38 -05:00
|
|
|
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
|
2014-09-02 19:28:15 -04:00
|
|
|
|
|
|
|
|
#include "DetailCustomizationsPrivatePCH.h"
|
|
|
|
|
#include "DateTimeStructCustomization.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define LOCTEXT_NAMESPACE "DateTimeStructCustomization"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* IDetailCustomization interface
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void FDateTimeStructCustomization::CustomizeChildren( TSharedRef<IPropertyHandle> StructPropertyHandle, class IDetailChildrenBuilder& StructBuilder, IPropertyTypeCustomizationUtils& StructCustomizationUtils )
|
|
|
|
|
{
|
|
|
|
|
/* do nothing */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FDateTimeStructCustomization::CustomizeHeader( TSharedRef<IPropertyHandle> StructPropertyHandle, class FDetailWidgetRow& HeaderRow, IPropertyTypeCustomizationUtils& StructCustomizationUtils )
|
|
|
|
|
{
|
|
|
|
|
PropertyHandle = StructPropertyHandle;
|
|
|
|
|
|
|
|
|
|
HeaderRow
|
|
|
|
|
.NameContent()
|
|
|
|
|
[
|
|
|
|
|
StructPropertyHandle->CreatePropertyNameWidget()
|
|
|
|
|
]
|
|
|
|
|
.ValueContent()
|
|
|
|
|
.MaxDesiredWidth(0.0f)
|
|
|
|
|
.MinDesiredWidth(125.0f)
|
|
|
|
|
[
|
|
|
|
|
SNew(SEditableTextBox)
|
|
|
|
|
.ClearKeyboardFocusOnCommit(false)
|
|
|
|
|
.IsEnabled(!PropertyHandle->IsEditConst())
|
|
|
|
|
.ForegroundColor(this, &FDateTimeStructCustomization::HandleTextBoxForegroundColor)
|
|
|
|
|
.OnTextChanged(this, &FDateTimeStructCustomization::HandleTextBoxTextChanged)
|
|
|
|
|
.OnTextCommitted(this, &FDateTimeStructCustomization::HandleTextBoxTextCommited)
|
|
|
|
|
.SelectAllTextOnCommit(true)
|
|
|
|
|
.Text(this, &FDateTimeStructCustomization::HandleTextBoxText)
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* FDateTimeStructCustomization callbacks
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
FSlateColor FDateTimeStructCustomization::HandleTextBoxForegroundColor( ) const
|
|
|
|
|
{
|
|
|
|
|
if (InputValid)
|
|
|
|
|
{
|
2014-11-18 09:57:20 -05:00
|
|
|
static const FName InvertedForegroundName("InvertedForeground");
|
|
|
|
|
return FEditorStyle::GetSlateColor(InvertedForegroundName);
|
2014-09-02 19:28:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FLinearColor::Red;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FText FDateTimeStructCustomization::HandleTextBoxText( ) const
|
|
|
|
|
{
|
|
|
|
|
TArray<void*> RawData;
|
|
|
|
|
PropertyHandle->AccessRawData(RawData);
|
|
|
|
|
|
|
|
|
|
if (RawData.Num() != 1)
|
|
|
|
|
{
|
|
|
|
|
return LOCTEXT("MultipleValues", "Multiple Values");
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-11 18:17:51 -04:00
|
|
|
auto DateTimePtr = static_cast<FDateTime*>(RawData[0]);
|
|
|
|
|
if (!DateTimePtr)
|
|
|
|
|
{
|
|
|
|
|
return FText::GetEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FText::FromString(DateTimePtr->ToString());
|
2014-09-02 19:28:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FDateTimeStructCustomization::HandleTextBoxTextChanged( const FText& NewText )
|
|
|
|
|
{
|
|
|
|
|
FDateTime DateTime;
|
|
|
|
|
InputValid = FDateTime::Parse(NewText.ToString(), DateTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FDateTimeStructCustomization::HandleTextBoxTextCommited( const FText& NewText, ETextCommit::Type CommitInfo )
|
|
|
|
|
{
|
|
|
|
|
FDateTime ParsedDateTime;
|
2014-12-03 06:31:35 -05:00
|
|
|
|
|
|
|
|
InputValid = FDateTime::Parse(NewText.ToString(), ParsedDateTime);
|
|
|
|
|
if (InputValid && PropertyHandle.IsValid())
|
2014-09-02 19:28:15 -04:00
|
|
|
{
|
|
|
|
|
TArray<void*> RawData;
|
|
|
|
|
PropertyHandle->AccessRawData(RawData);
|
|
|
|
|
|
2014-12-03 06:31:35 -05:00
|
|
|
PropertyHandle->NotifyPreChange();
|
2014-09-02 19:28:15 -04:00
|
|
|
for (auto RawDataInstance : RawData)
|
|
|
|
|
{
|
|
|
|
|
*(FDateTime*)RawDataInstance = ParsedDateTime;
|
|
|
|
|
}
|
2014-12-03 06:31:35 -05:00
|
|
|
PropertyHandle->NotifyPostChange();
|
2014-09-02 19:28:15 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#undef LOCTEXT_NAMESPACE
|