-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathJavascriptUICommands.cpp
More file actions
145 lines (122 loc) · 3.26 KB
/
JavascriptUICommands.cpp
File metadata and controls
145 lines (122 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "JavascriptUICommands.h"
#include "JavascriptMenuLibrary.h"
#include "Framework/Commands/Commands.h"
#include "Runtime/Launch/Resources/Version.h"
//PRAGMA_DISABLE_OPTIMIZATION
UJavascriptUICommands::UJavascriptUICommands(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer), bRegistered(false)
{
}
void UJavascriptUICommands::BeginDestroy()
{
Super::BeginDestroy();
Discard();
}
void UJavascriptUICommands::Commit()
{
Discard();
// IJavascriptEditorModule::Get().AddExtension(this);
bRegistered = true;
}
void UJavascriptUICommands::Discard()
{
if (bRegistered)
{
// IJavascriptEditorModule::Get().RemoveExtension(this);
}
bRegistered = false;
}
void UJavascriptUICommands::Initialize()
{
for (auto info : Commands)
{
if (info.CommandInfo.Handle.IsValid())
{
CommandInfos.Add(info.CommandInfo);
}
else
{
FJavascriptUICommandInfo CommandInfo = UJavascriptMenuLibrary::UI_COMMAND_Function(BindingContext, info, TextSubNamespace);
CommandInfos.Add(CommandInfo);
}
}
BroadcastCommandsChanged(ContextName);
}
void UJavascriptUICommands::Uninitialize()
{
CommandInfos.Empty();
BroadcastCommandsChanged(ContextName);
}
void UJavascriptUICommands::BroadcastCommandsChanged(const FString& InContextName)
{
#if (ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 14) || ENGINE_MAJOR_VERSION > 4
TSharedPtr<FBindingContext> ExistingBindingContext = FInputBindingManager::Get().GetContextByName(*InContextName);
if (ExistingBindingContext.IsValid())
{
FBindingContext::CommandsChanged.Broadcast(*ExistingBindingContext);
}
#else
FBindingContext::CommandsChanged.Broadcast();
#endif
}
void UJavascriptUICommands::Refresh()
{
}
void UJavascriptUICommands::Bind(FJavascriptUICommandList CommandList)
{
Bind(CommandList.Handle.Get());
}
void UJavascriptUICommands::Unbind(FJavascriptUICommandList CommandList)
{
Unbind(CommandList.Handle.Get());
}
void UJavascriptUICommands::Bind(FUICommandList* CommandList)
{
for (int32 Index = 0; Index < Commands.Num(); ++Index)
{
CommandList->MapAction(
CommandInfos[Index].Handle,
FExecuteAction::CreateLambda([this, Index](){
if (OnExecuteAction.IsBound())
{
OnExecuteAction.Execute(Commands[Index].Id);
}
}),
FCanExecuteAction::CreateLambda([this, Index](){
return !OnCanExecuteAction.IsBound() || OnCanExecuteAction.Execute(Commands[Index].Id);
}),
FCanExecuteAction::CreateLambda([this, Index](){
return !OnIsActionChecked.IsBound() || OnIsActionChecked.Execute(Commands[Index].Id);
}),
FCanExecuteAction::CreateLambda([this, Index](){
return !OnIsActionButtonVisible.IsBound() || OnIsActionButtonVisible.Execute(Commands[Index].Id);
})
);
}
}
void UJavascriptUICommands::Unbind(FUICommandList* CommandList)
{
// unbind is not supported, just rebind again!
for (auto CommandInfo : CommandInfos)
{
if (CommandList->IsActionMapped(CommandInfo.Handle))
{
CommandList->UnmapAction(CommandInfo.Handle);
}
}
}
FJavascriptUICommandInfo UJavascriptUICommands::GetAction(FString Id)
{
if (Commands.Num() == CommandInfos.Num())
{
for (int32 Index = 0; Index < Commands.Num(); ++Index)
{
if (Commands[Index].Id == Id)
{
return CommandInfos[Index];
}
}
}
return FJavascriptUICommandInfo();
}
//PRAGMA_ENABLE_OPTIMIZATION