Files
UnrealEngineUWP/Engine/Source/Developer/OutputLog/Private/OutputLogModule.cpp

182 lines
5.8 KiB
C++
Raw Normal View History

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#include "OutputLogPrivatePCH.h"
#include "SDebugConsole.h"
#include "SOutputLog.h"
#include "SDeviceOutputLog.h"
#include "Editor/WorkspaceMenuStructure/Public/WorkspaceMenuStructureModule.h"
#include "SDockTab.h"
IMPLEMENT_MODULE( FOutputLogModule, OutputLog );
namespace OutputLogModule
{
static const FName OutputLogTabName = FName(TEXT("OutputLog"));
static const FName DeviceOutputLogTabName = FName(TEXT("DeviceOutputLog"));
}
/** This class is to capture all log output even if the log window is closed */
class FOutputLogHistory : public FOutputDevice
{
public:
FOutputLogHistory()
{
GLog->AddOutputDevice(this);
GLog->SerializeBacklog(this);
}
~FOutputLogHistory()
{
// 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
SOutputLog::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<FOutputLogHistory> OutputLogHistory;
TSharedRef<SDockTab> SpawnOutputLog( const FSpawnTabArgs& Args )
{
return SNew(SDockTab)
.Icon(FEditorStyle::GetBrush("Log.TabIcon"))
.TabRole( ETabRole::NomadTab )
.Label( NSLOCTEXT("OutputLog", "TabTitle", "Output Log") )
[
SNew(SOutputLog).Messages( OutputLogHistory->GetMessages() )
];
}
TSharedRef<SDockTab> SpawnDeviceOutputLog( const FSpawnTabArgs& Args )
{
return SNew(SDockTab)
.Icon(FEditorStyle::GetBrush("Log.TabIcon"))
.TabRole( ETabRole::NomadTab )
.Label( NSLOCTEXT("OutputLog", "DeviceTabTitle", "Device Output Log") )
[
SNew(SDeviceOutputLog)
];
}
void FOutputLogModule::StartupModule()
{
FGlobalTabmanager::Get()->RegisterNomadTabSpawner(OutputLogModule::OutputLogTabName, FOnSpawnTab::CreateStatic( &SpawnOutputLog ) )
.SetDisplayName(NSLOCTEXT("UnrealEditor", "OutputLogTab", "Output Log"))
.SetTooltipText(NSLOCTEXT("UnrealEditor", "OutputLogTooltipText", "Open the Output Log tab."))
Window menu refactor & polish - Window menu is now sectioned and labeled based on the current editor. There's now a local workspace root member in FTabManager and a workspace category in FAssetEditorToolkit (both are FWorkspaceItem objects). Individual editors attach their local category to the tab manager's local root. Workflow app modes have their own category members that are swapped out when the mode changes. - Finally, the AssetEditorCategory of FWorkspaceMenuStructure has been removed entirely. - Replaced the AddMenuSeparator() call in FTabManager::PopulateSpawnerMenu_Helper() with a section of the same title as the workspace category. - Tab spawner menu entries for the local editor now properly show the icon of the associated tab. To accomplish this it was necessary to change FWorkflowTabFactory::TabIcon to be an FSlateIcon instead of an FSlateBrush*. All factory instances have been updated accordingly. - Added & updated lots of icons! (those missing will be TTP'd) - The nomad tab spawner section (named "General" in the menu) has been largely compressed into the Developer Tools submenu, which has also been organized into sections for readability. - Unreal frontend options were also moved into a context menu within the General section - Moved all experimental tools to their own section of the Window menu. When they're no longer experimental they should register as nomads in the appropriate category - Undo history now under Edit menu [CL 2324285 by Dan Hertzka in Main branch]
2014-10-09 12:34:55 -04:00
.SetGroup( WorkspaceMenu::GetMenuStructure().GetDeveloperToolsLogCategory() )
.SetIcon( FSlateIcon(FEditorStyle::GetStyleSetName(), "Log.TabIcon") );
FGlobalTabmanager::Get()->RegisterNomadTabSpawner(OutputLogModule::DeviceOutputLogTabName, FOnSpawnTab::CreateStatic( &SpawnDeviceOutputLog ) )
.SetDisplayName(NSLOCTEXT("UnrealEditor", "DeviceOutputLogTab", "Device Output Log"))
.SetTooltipText(NSLOCTEXT("UnrealEditor", "DeviceOutputLogTooltipText", "Open the Device Output Log tab."))
.SetGroup( WorkspaceMenu::GetMenuStructure().GetDeveloperToolsLogCategory() )
.SetIcon( FSlateIcon(FEditorStyle::GetStyleSetName(), "Log.TabIcon") )
.SetAutoGenerateMenuEntry(false); // remove once not Experimental
OutputLogHistory = MakeShareable(new FOutputLogHistory);
}
void FOutputLogModule::ShutdownModule()
{
if (FSlateApplication::IsInitialized())
{
FGlobalTabmanager::Get()->UnregisterNomadTabSpawner(OutputLogModule::OutputLogTabName);
FGlobalTabmanager::Get()->UnregisterNomadTabSpawner(OutputLogModule::DeviceOutputLogTabName);
}
}
TSharedRef< SWidget > FOutputLogModule::MakeConsoleInputBox( TSharedPtr< SEditableTextBox >& OutExposedEditableTextBox ) const
{
TSharedRef< SConsoleInputBox > NewConsoleInputBox = SNew( SConsoleInputBox );
OutExposedEditableTextBox = NewConsoleInputBox->GetEditableTextBox();
return NewConsoleInputBox;
}
void FOutputLogModule::ToggleDebugConsoleForWindow( const TSharedRef< SWindow >& Window, const EDebugConsoleStyle::Type InStyle, const FDebugConsoleDelegates& DebugConsoleDelegates )
{
bool bShouldOpen = true;
// Close an existing console box, if there is one
TSharedPtr< SWidget > PinnedDebugConsole( DebugConsole.Pin() );
if( PinnedDebugConsole.IsValid() )
{
// If the console is already open close it unless it is in a different window. In that case reopen it on that window
bShouldOpen = false;
TSharedPtr< SWindow > WindowForExistingConsole = FSlateApplication::Get().FindWidgetWindow(PinnedDebugConsole.ToSharedRef());
if (WindowForExistingConsole.IsValid())
{
WindowForExistingConsole->RemoveOverlaySlot(PinnedDebugConsole.ToSharedRef());
DebugConsole.Reset();
}
if( WindowForExistingConsole != Window )
{
// Console is being opened on another window
bShouldOpen = true;
}
}
TSharedPtr<SDockTab> ActiveTab = FGlobalTabmanager::Get()->GetActiveTab();
if (ActiveTab.IsValid() && ActiveTab->GetLayoutIdentifier() == FTabId(OutputLogModule::OutputLogTabName))
{
FGlobalTabmanager::Get()->DrawAttention(ActiveTab.ToSharedRef());
bShouldOpen = false;
}
if( bShouldOpen )
{
const EDebugConsoleStyle::Type DebugConsoleStyle = InStyle;
TSharedRef< SDebugConsole > DebugConsoleRef = SNew( SDebugConsole, DebugConsoleStyle, this, &DebugConsoleDelegates );
DebugConsole = DebugConsoleRef;
const int32 MaximumZOrder = MAX_int32;
Window->AddOverlaySlot( MaximumZOrder )
.VAlign(VAlign_Bottom)
.HAlign(HAlign_Center)
.Padding( 10.0f )
[
DebugConsoleRef
];
// Force keyboard focus
DebugConsoleRef->SetFocusToEditableText();
}
}
void FOutputLogModule::CloseDebugConsole()
{
TSharedPtr< SWidget > PinnedDebugConsole( DebugConsole.Pin() );
if( PinnedDebugConsole.IsValid() )
{
TSharedPtr< SWindow > WindowForExistingConsole = FSlateApplication::Get().FindWidgetWindow(PinnedDebugConsole.ToSharedRef());
if (WindowForExistingConsole.IsValid())
{
WindowForExistingConsole->RemoveOverlaySlot( PinnedDebugConsole.ToSharedRef() );
DebugConsole.Reset();
}
}
}