Skip to content

Commit 3d5b9b2

Browse files
committed
Refreshing asset editor when text asset modified externally.
1 parent d793af2 commit 3d5b9b2

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

Source/TextAssetEditor/Private/AssetTools/TextAssetActions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void FTextAssetActions::GetActions(const TArray<UObject*>& InObjects, FMenuBuild
4141
if (TextAsset.IsValid() && !TextAsset->Text.IsEmpty())
4242
{
4343
TextAsset->Text = FText::FromString(TextAsset->Text.ToString().Reverse());
44-
TextAsset->MarkPackageDirty();
44+
TextAsset->PostEditChange();
4545
}
4646
}
4747
}),

Source/TextAssetEditor/Private/Factories/TextAssetFactory.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ UObject* UTextAssetFactory::FactoryCreateBinary(UClass* Class, UObject* InParent
2525
UTextAsset* TextAsset = nullptr;
2626
FString TextString;
2727

28-
FEditorDelegates::OnAssetPreImport.Broadcast(this, Class, InParent, Name, Type);
29-
3028
if (FFileHelper::LoadFileToString(TextString, *CurrentFilename))
3129
{
3230
TextAsset = NewObject<UTextAsset>(InParent, Class, Name, Flags);

Source/TextAssetEditor/Private/Widgets/STextAssetEditor.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
/* STextAssetEditor interface
1111
*****************************************************************************/
1212

13+
STextAssetEditor::~STextAssetEditor()
14+
{
15+
FCoreUObjectDelegates::OnObjectPropertyChanged.RemoveAll(this);
16+
}
17+
18+
1319
void STextAssetEditor::Construct(const FArguments& InArgs, UTextAsset* InTextAsset, const TSharedRef<ISlateStyle>& InStyle)
1420
{
1521
TextAsset = InTextAsset;
@@ -27,6 +33,8 @@ void STextAssetEditor::Construct(const FArguments& InArgs, UTextAsset* InTextAss
2733
.Text(TextAsset->Text)
2834
]
2935
];
36+
37+
FCoreUObjectDelegates::OnObjectPropertyChanged.AddSP(this, &STextAssetEditor::HandleTextAssetPropertyChanged);
3038
}
3139

3240

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

4755

56+
void STextAssetEditor::HandleTextAssetPropertyChanged(UObject* Object, FPropertyChangedEvent& PropertyChangedEvent)
57+
{
58+
if (Object == TextAsset)
59+
{
60+
EditableTextBox->SetText(TextAsset->Text);
61+
}
62+
}
63+
64+
4865
#undef LOCTEXT_NAMESPACE

Source/TextAssetEditor/Private/Widgets/STextAssetEditor.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class STextAssetEditor
1616

1717
public:
1818

19+
/** Virtual destructor. */
20+
virtual ~STextAssetEditor();
21+
1922
/**
2023
* Construct this widget
2124
*
@@ -33,6 +36,9 @@ class STextAssetEditor
3336
/** Callback for committed text in the editable text box. */
3437
void HandleEditableTextBoxTextCommitted(const FText& Comment, ETextCommit::Type CommitType);
3538

39+
/** Callback for property changes in the text asset. */
40+
void HandleTextAssetPropertyChanged(UObject* Object, FPropertyChangedEvent& PropertyChangedEvent);
41+
3642
private:
3743

3844
/** Holds the editable text box widget. */

0 commit comments

Comments
 (0)