Skip to content

Commit 6546606

Browse files
committed
Added example for adding context menu actions.
1 parent 0075fb2 commit 6546606

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

Source/TextAssetEditor/Private/AssetTools/TextAssetActions.cpp

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,41 @@ bool FTextAssetActions::CanFilter()
2424
}
2525

2626

27+
void FTextAssetActions::GetActions(const TArray<UObject*>& InObjects, FMenuBuilder& MenuBuilder)
28+
{
29+
FAssetTypeActions_Base::GetActions(InObjects, MenuBuilder);
30+
31+
auto TextAssets = GetTypedWeakObjectPtrs<UTextAsset>(InObjects);
32+
33+
MenuBuilder.AddMenuEntry(
34+
LOCTEXT("TextAsset_ReverseText", "Reverse Text"),
35+
LOCTEXT("TextAsset_ReverseTextToolTip", "Reverse the text stored in the selected text asset(s)."),
36+
FSlateIcon(),
37+
FUIAction(
38+
FExecuteAction::CreateLambda([=]{
39+
for (auto& TextAsset : TextAssets)
40+
{
41+
if (TextAsset.IsValid() && !TextAsset->Text.IsEmpty())
42+
{
43+
TextAsset->Text = FText::FromString(TextAsset->Text.ToString().Reverse());
44+
}
45+
}
46+
}),
47+
FCanExecuteAction::CreateLambda([=] {
48+
for (auto& TextAsset : TextAssets)
49+
{
50+
if (TextAsset.IsValid() && !TextAsset->Text.IsEmpty())
51+
{
52+
return true;
53+
}
54+
}
55+
return false;
56+
})
57+
)
58+
);
59+
}
60+
61+
2762
uint32 FTextAssetActions::GetCategories()
2863
{
2964
return EAssetTypeCategories::Misc;
@@ -50,7 +85,7 @@ FColor FTextAssetActions::GetTypeColor() const
5085

5186
bool FTextAssetActions::HasActions(const TArray<UObject*>& InObjects) const
5287
{
53-
return false;
88+
return true;
5489
}
5590

5691

@@ -73,5 +108,4 @@ void FTextAssetActions::OpenAssetEditor(const TArray<UObject*>& InObjects, TShar
73108
}
74109

75110

76-
77111
#undef LOCTEXT_NAMESPACE

Source/TextAssetEditor/Private/AssetTools/TextAssetActions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class FTextAssetActions
2525
// FAssetTypeActions_Base overrides
2626

2727
virtual bool CanFilter() override;
28+
virtual void GetActions(const TArray<UObject*>& InObjects, FMenuBuilder& MenuBuilder) override;
2829
virtual uint32 GetCategories() override;
2930
virtual FText GetName() const override;
3031
virtual UClass* GetSupportedClass() const override;

0 commit comments

Comments
 (0)