Skip to content

Commit

Permalink
Refreshing asset editor when text asset modified externally.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmpreussner committed Apr 4, 2016
1 parent d793af2 commit 3d5b9b2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void FTextAssetActions::GetActions(const TArray<UObject*>& InObjects, FMenuBuild
if (TextAsset.IsValid() && !TextAsset->Text.IsEmpty())
{
TextAsset->Text = FText::FromString(TextAsset->Text.ToString().Reverse());
TextAsset->MarkPackageDirty();
TextAsset->PostEditChange();
}
}
}),
Expand Down
2 changes: 0 additions & 2 deletions Source/TextAssetEditor/Private/Factories/TextAssetFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ UObject* UTextAssetFactory::FactoryCreateBinary(UClass* Class, UObject* InParent
UTextAsset* TextAsset = nullptr;
FString TextString;

FEditorDelegates::OnAssetPreImport.Broadcast(this, Class, InParent, Name, Type);

if (FFileHelper::LoadFileToString(TextString, *CurrentFilename))
{
TextAsset = NewObject<UTextAsset>(InParent, Class, Name, Flags);
Expand Down
17 changes: 17 additions & 0 deletions Source/TextAssetEditor/Private/Widgets/STextAssetEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
/* STextAssetEditor interface
*****************************************************************************/

STextAssetEditor::~STextAssetEditor()
{
FCoreUObjectDelegates::OnObjectPropertyChanged.RemoveAll(this);
}


void STextAssetEditor::Construct(const FArguments& InArgs, UTextAsset* InTextAsset, const TSharedRef<ISlateStyle>& InStyle)
{
TextAsset = InTextAsset;
Expand All @@ -27,6 +33,8 @@ void STextAssetEditor::Construct(const FArguments& InArgs, UTextAsset* InTextAss
.Text(TextAsset->Text)
]
];

FCoreUObjectDelegates::OnObjectPropertyChanged.AddSP(this, &STextAssetEditor::HandleTextAssetPropertyChanged);
}


Expand All @@ -45,4 +53,13 @@ void STextAssetEditor::HandleEditableTextBoxTextCommitted(const FText& Comment,
}


void STextAssetEditor::HandleTextAssetPropertyChanged(UObject* Object, FPropertyChangedEvent& PropertyChangedEvent)
{
if (Object == TextAsset)
{
EditableTextBox->SetText(TextAsset->Text);
}
}


#undef LOCTEXT_NAMESPACE
6 changes: 6 additions & 0 deletions Source/TextAssetEditor/Private/Widgets/STextAssetEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class STextAssetEditor

public:

/** Virtual destructor. */
virtual ~STextAssetEditor();

/**
* Construct this widget
*
Expand All @@ -33,6 +36,9 @@ class STextAssetEditor
/** Callback for committed text in the editable text box. */
void HandleEditableTextBoxTextCommitted(const FText& Comment, ETextCommit::Type CommitType);

/** Callback for property changes in the text asset. */
void HandleTextAssetPropertyChanged(UObject* Object, FPropertyChangedEvent& PropertyChangedEvent);

private:

/** Holds the editable text box widget. */
Expand Down

0 comments on commit 3d5b9b2

Please sign in to comment.