-
-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathGenerativeAISupportEditor.cpp
More file actions
166 lines (138 loc) · 5.64 KB
/
GenerativeAISupportEditor.cpp
File metadata and controls
166 lines (138 loc) · 5.64 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Copyright (c) 2025 Prajwal Shetty. All rights reserved.
// Licensed under the MIT License. See LICENSE file in the root directory of this
// source tree or http://opensource.org/licenses/MIT.
#include "GenerativeAISupportEditor.h"
#include "ISettingsModule.h"
#include "Styling/AppStyle.h"
#include "GenerativeAISupportSettings.h"
#include "ISettingsSection.h"
#include "LevelEditor.h"
#include "WorkspaceMenuStructure.h"
#include "WorkspaceMenuStructureModule.h"
#include "Editor/GenEditorCommands.h"
#include "Editor/GenEditorWindow.h"
#define LOCTEXT_NAMESPACE "FGenerativeAISupportEditorModule"
// Define the tab ID for our editor window
static const FName GenEditorTabId("GenEditorWindow");
FGenerativeAISupportEditorModule::FGenerativeAISupportEditorModule()
: bSettingsRegistered(false)
{
// Constructor initialization ensures proper state
}
void FGenerativeAISupportEditorModule::StartupModule()
{
// Log to debug module loading
UE_LOG(LogTemp, Log, TEXT("FGenerativeAISupportEditorModule::StartupModule called"));
// Register project settings
RegisterSettings();
// Register menu extension
RegisterMenuExtension();
// Register tab spawner
FGlobalTabmanager::Get()->RegisterNomadTabSpawner(
GenEditorTabId,
FOnSpawnTab::CreateRaw(&FGenEditorWindowManager::Get(),
&FGenEditorWindowManager::SpawnEditorWindowTab))
.SetDisplayName(LOCTEXT("GenEditorWindowTitle", "Gen AI Support"))
.SetTooltipText(LOCTEXT("GenEditorWindowTooltip", "Open the Generative AI Support window"))
.SetIcon(FSlateIcon(FAppStyle::GetAppStyleSetName(), "LevelEditor.Tabs.Details"))
.SetGroup(WorkspaceMenu::GetMenuStructure().GetToolsCategory());
}
void FGenerativeAISupportEditorModule::ShutdownModule()
{
// Unregister settings
UnregisterSettings();
// Unregister menu extension
UnregisterMenuExtension();
// Unregister tab spawner
if (FSlateApplication::IsInitialized())
{
FGlobalTabmanager::Get()->UnregisterNomadTabSpawner(GenEditorTabId);
}
}
void FGenerativeAISupportEditorModule::RegisterSettings()
{
// Prevent duplicate registration
if (bSettingsRegistered)
{
UE_LOG(LogTemp, Warning, TEXT("GenerativeAISupport settings already registered, skipping."));
return;
}
if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
{
ISettingsSectionPtr SettingsSection = SettingsModule->RegisterSettings(
"Project", "Plugins", "GenerativeAISupport",
LOCTEXT("GenerativeAISupportSettingsName", "Generative AI Support"),
LOCTEXT("GenerativeAISupportDescription", "Configuration for the GenerativeAISupport plugin"),
GetMutableDefault<UGenerativeAISupportSettings>()
);
if (SettingsSection.IsValid())
{
SettingsSection->OnModified().BindRaw(this, &FGenerativeAISupportEditorModule::HandleSettingsSaved);
bSettingsRegistered = true;
UE_LOG(LogTemp, Log, TEXT("GenerativeAISupport settings registered successfully."));
}
else
{
UE_LOG(LogTemp, Error, TEXT("Failed to register GenerativeAISupport settings."));
}
}
else
{
UE_LOG(LogTemp, Error, TEXT("Settings module not found."));
}
}
void FGenerativeAISupportEditorModule::UnregisterSettings()
{
if (bSettingsRegistered)
{
if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
{
SettingsModule->UnregisterSettings("Project", "Plugins", "GenerativeAISupport");
bSettingsRegistered = false;
UE_LOG(LogTemp, Log, TEXT("GenerativeAISupport settings unregistered successfully."));
}
else
{
UE_LOG(LogTemp, Error, TEXT("Settings module not found during unregistration."));
}
}
}
bool FGenerativeAISupportEditorModule::HandleSettingsSaved()
{
UGenerativeAISupportSettings* Settings = GetMutableDefault<UGenerativeAISupportSettings>();
Settings->SaveConfig();
return true;
}
void FGenerativeAISupportEditorModule::RegisterMenuExtension()
{
// Register commands
FGenEditorCommands::Register();
PluginCommands = MakeShareable(new FUICommandList);
// Map commands to actions
PluginCommands->MapAction(
FGenEditorCommands::Get().OpenGenEditorWindow,
FExecuteAction::CreateRaw(this, &FGenerativeAISupportEditorModule::OnEditorWindowMenuClicked),
FCanExecuteAction());
// Register menu extension - add to the Window menu
FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
TSharedPtr<FExtender> MenuExtender = MakeShareable(new FExtender());
MenuExtender->AddMenuExtension(
"WindowLayout",
EExtensionHook::After,
PluginCommands,
FMenuExtensionDelegate::CreateLambda([](FMenuBuilder& Builder) {
Builder.AddMenuEntry(FGenEditorCommands::Get().OpenGenEditorWindow);
}));
LevelEditorModule.GetMenuExtensibilityManager()->AddExtender(MenuExtender);
}
void FGenerativeAISupportEditorModule::UnregisterMenuExtension()
{
// Unregister commands
FGenEditorCommands::Unregister();
}
void FGenerativeAISupportEditorModule::OnEditorWindowMenuClicked()
{
FGlobalTabmanager::Get()->TryInvokeTab(GenEditorTabId);
}
#undef LOCTEXT_NAMESPACE
IMPLEMENT_MODULE(FGenerativeAISupportEditorModule, GenerativeAISupportEditor)