-
Notifications
You must be signed in to change notification settings - Fork 765
Expand file tree
/
Copy pathPythonConsoleModule.cpp
More file actions
97 lines (79 loc) · 2.82 KB
/
PythonConsoleModule.cpp
File metadata and controls
97 lines (79 loc) · 2.82 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
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#include "PythonConsoleModule.h"
#include "PythonConsolePrivatePCH.h"
#include "SPythonConsole.h"
#include "SPythonLog.h"
#include "Editor/WorkspaceMenuStructure/Public/WorkspaceMenuStructureModule.h"
#include "SDockTab.h"
#include "Editor/WorkspaceMenuStructure/Public/WorkspaceMenuStructure.h"
IMPLEMENT_MODULE( FPythonConsoleModule, PythonConsole );
namespace PythonConsoleModule
{
static const FName PythonLogTabName = FName(TEXT("PythonLog"));
}
/** This class is to capture all log output even if the log window is closed */
class FPythonLogHistory : public FOutputDevice
{
public:
FPythonLogHistory()
{
GLog->AddOutputDevice(this);
GLog->SerializeBacklog(this);
}
~FPythonLogHistory()
{
// At shutdown, GLog may already be null
if( GLog != NULL )
{
GLog->RemoveOutputDevice(this);
}
}
/** Gets all captured messages */
const TArray< TSharedPtr<FLogMessage> >& GetMessages() const
{
return Messages;
}
protected:
virtual void Serialize( const TCHAR* V, ELogVerbosity::Type Verbosity, const class FName& Category ) override
{
// Capture all incoming messages and store them in history
SPythonLog::CreateLogMessages(V, Verbosity, Category, Messages);
}
private:
/** All log messsges since this module has been started */
TArray< TSharedPtr<FLogMessage> > Messages;
};
/** Our global output log app spawner */
static TSharedPtr<FPythonLogHistory> PythonLogHistory;
TSharedRef<SDockTab> SpawnPythonLog( const FSpawnTabArgs& Args )
{
return SNew(SDockTab)
.Icon(FEditorStyle::GetBrush("Log.TabIcon"))
.TabRole( ETabRole::NomadTab )
.Label( NSLOCTEXT("PythonConsole", "TabTitle", "Python Console") )
[
SNew(SPythonLog).Messages( PythonLogHistory->GetMessages() )
];
}
void FPythonConsoleModule::StartupModule()
{
FGlobalTabmanager::Get()->RegisterNomadTabSpawner(PythonConsoleModule::PythonLogTabName, FOnSpawnTab::CreateStatic( &SpawnPythonLog ) )
.SetDisplayName(NSLOCTEXT("UnrealEditor", "PythonLogTab", "Python Console"))
.SetTooltipText(NSLOCTEXT("UnrealEditor", "PythonLogTooltipText", "Open the Python Console tab."))
.SetGroup( WorkspaceMenu::GetMenuStructure().GetDeveloperToolsLogCategory() )
.SetIcon( FSlateIcon(FEditorStyle::GetStyleSetName(), "Log.TabIcon") );
PythonLogHistory = MakeShareable(new FPythonLogHistory);
}
void FPythonConsoleModule::ShutdownModule()
{
if (FSlateApplication::IsInitialized())
{
FGlobalTabmanager::Get()->UnregisterNomadTabSpawner(PythonConsoleModule::PythonLogTabName);
}
}
TSharedRef< SWidget > FPythonConsoleModule::MakeConsoleInputBox( TSharedPtr< SEditableTextBox >& OutExposedEditableTextBox ) const
{
TSharedRef< SPythonConsoleInputBox > NewConsoleInputBox = SNew( SPythonConsoleInputBox );
OutExposedEditableTextBox = NewConsoleInputBox->GetEditableTextBox();
return NewConsoleInputBox;
}