-
Notifications
You must be signed in to change notification settings - Fork 765
Expand file tree
/
Copy pathPythonEditor.cpp
More file actions
94 lines (76 loc) · 3.18 KB
/
PythonEditor.cpp
File metadata and controls
94 lines (76 loc) · 3.18 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
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#include "Runtime/Core/Public/Modules/ModuleManager.h"
#include "AssetToolsModule.h"
#include "Editor/UnrealEd/Public/Toolkits/AssetEditorToolkit.h"
#include "LevelEditor.h"
#include "PythonEditorStyle.h"
#include "PythonProjectEditor.h"
#include "PythonProject.h"
#include "Subsystems/AssetEditorSubsystem.h"
#include "Runtime/Slate/Public/Framework/MultiBox/MultiBoxBuilder.h"
static const FName PythonEditorTabName( TEXT( "PythonEditor" ) );
#define LOCTEXT_NAMESPACE "PythonEditor"
class FPythonEditor : public IModuleInterface
{
public:
/** IModuleInterface implementation */
virtual void StartupModule() override
{
FPythonEditorStyle::Initialize();
struct Local
{
static TSharedRef<SDockTab> SpawnPythonEditorTab(const FSpawnTabArgs& TabArgs)
{
TSharedRef<FPythonProjectEditor> NewPythonProjectEditor(new FPythonProjectEditor());
NewPythonProjectEditor->InitPythonEditor(EToolkitMode::Standalone, TSharedPtr<class IToolkitHost>(), GetMutableDefault<UPythonProject>());
return FGlobalTabmanager::Get()->GetMajorTabForTabManager(NewPythonProjectEditor->GetTabManager().ToSharedRef()).ToSharedRef();
}
static void OpenPythonEditor()
{
SpawnPythonEditorTab(FSpawnTabArgs(TSharedPtr<SWindow>(), FTabId()));
}
static void ExtendMenu(class FMenuBuilder& MenuBuilder)
{
MenuBuilder.AddMenuEntry
(
LOCTEXT( "PythonEditorTabTitle", "Python Editor" ),
LOCTEXT( "PythonEditorTooltipText", "Open the Python Editor tab." ),
FSlateIcon(FPythonEditorStyle::Get().GetStyleSetName(), "PythonEditor.TabIcon"),
FUIAction
(
FExecuteAction::CreateStatic(&Local::OpenPythonEditor)
)
);
}
};
Extender = MakeShareable(new FExtender());
// Add Python editor extension to main menu
Extender->AddMenuExtension(
"WindowLayout",
EExtensionHook::After,
TSharedPtr<FUICommandList>(),
FMenuExtensionDelegate::CreateStatic( &Local::ExtendMenu ) );
FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
LevelEditorModule.GetMenuExtensibilityManager()->AddExtender( Extender );
// Register a tab spawner so that our tab can be automatically restored from layout files
FGlobalTabmanager::Get()->RegisterTabSpawner( PythonEditorTabName, FOnSpawnTab::CreateStatic( &Local::SpawnPythonEditorTab ) )
.SetDisplayName( LOCTEXT( "PythonEditorTabTitle", "Python Editor" ) )
.SetTooltipText( LOCTEXT( "PythonEditorTooltipText", "Open the Python Editor tab." ) )
.SetIcon(FSlateIcon(FPythonEditorStyle::Get().GetStyleSetName(), "PythonEditor.TabIcon"));
}
virtual void ShutdownModule() override
{
// Unregister the tab spawner
FGlobalTabmanager::Get()->UnregisterTabSpawner( PythonEditorTabName );
if(FModuleManager::Get().IsModuleLoaded("LevelEditor"))
{
FLevelEditorModule& LevelEditorModule = FModuleManager::GetModuleChecked<FLevelEditorModule>("LevelEditor");
LevelEditorModule.GetMenuExtensibilityManager()->RemoveExtender( Extender );
}
FPythonEditorStyle::Shutdown();
}
private:
TSharedPtr<FExtender> Extender;
};
IMPLEMENT_MODULE( FPythonEditor, PythonEditor )
#undef LOCTEXT_NAMESPACE