Files
UnrealEngineUWP/Engine/Source/Editor/SourceControlWindows/Private/SourceControlWindowsModule.cpp
louise rasmussen 825c64a6f5 Level Editor Menu Re-org, Part 1
#JIRA UETOOL-3039
#rb Lauren.Barnes
#lockdown Simon.Tourangeau
#preflight 606b8e0315d4190001b1698b

#ROBOMERGE-SOURCE: CL 15924633 in //UE5/Release-5.0-EarlyAccess/...
#ROBOMERGE-BOT: STARSHIP (Release-5.0-EarlyAccess -> Main) (v786-15839533)

[CL 15924652 by louise rasmussen in ue5-main branch]
2021-04-05 19:11:24 -04:00

131 lines
3.7 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "CoreMinimal.h"
#include "Modules/ModuleManager.h"
#include "ISourceControlWindowsModule.h"
#include "ISourceControlModule.h"
#include "Widgets/Docking/SDockTab.h"
#include "Textures/SlateIcon.h"
#include "Framework/Application/SlateApplication.h"
#include "EditorStyleSet.h"
#include "LevelEditor.h"
#include "WorkspaceMenuStructure.h"
#include "WorkspaceMenuStructureModule.h"
#include "SSourceControlChangelists.h"
#define LOCTEXT_NAMESPACE "SourceControlWindows"
/**
* SourceControlWindows module
*/
class FSourceControlWindowsModule : public ISourceControlWindowsModule
{
public:
/**
* Called right after the module DLL has been loaded and the module object has been created
*/
virtual void StartupModule() override;
/**
* Called before the module is unloaded, right before the module object is destroyed.
*/
virtual void ShutdownModule() override;
virtual void ShowChangelistsTab() override;
virtual bool CanShowChangelistsTab() const override;
private:
TSharedRef<SDockTab> CreateChangelistsTab(const FSpawnTabArgs& Args);
TSharedPtr<SWidget> CreateChangelistsUI();
private:
TWeakPtr<SDockTab> ChangelistsTab;
TWeakPtr<SSourceControlChangelistsWidget> ChangelistsWidget;
};
IMPLEMENT_MODULE(FSourceControlWindowsModule, SourceControlWindows);
static const FName SourceControlChangelistsTabName = FName(TEXT("SourceControlChangelists"));
void FSourceControlWindowsModule::StartupModule()
{
ISourceControlWindowsModule::StartupModule();
// We're going to call a static function in the editor style module, so we need to make sure the module has actually been loaded
FModuleManager::Get().LoadModuleChecked("EditorStyle");
// Create a Source Control group under the Tools category
const FSlateIcon SourceControlIcon(FEditorStyle::GetStyleSetName(), "SourceControl.ChangelistsTab");
// Register the changlist tab spawner
FGlobalTabmanager::Get()->RegisterNomadTabSpawner(SourceControlChangelistsTabName, FOnSpawnTab::CreateRaw(this, &FSourceControlWindowsModule::CreateChangelistsTab))
.SetDisplayName(LOCTEXT("ChangelistsTabTitle", "Changelists"))
.SetGroup(WorkspaceMenu::GetMenuStructure().GetToolsCategory())
.SetIcon(SourceControlIcon);
#if WITH_RELOAD
// This code attempts to relaunch the GameplayCueEditor tab when you reload this module
if (IsReloadActive() && FSlateApplication::IsInitialized())
{
ShowChangelistsTab();
}
#endif // WITH_RELOAD
}
void FSourceControlWindowsModule::ShutdownModule()
{
if (FSlateApplication::IsInitialized())
{
FGlobalTabmanager::Get()->UnregisterNomadTabSpawner(SourceControlChangelistsTabName);
if (ChangelistsTab.IsValid())
{
ChangelistsTab.Pin()->RequestCloseTab();
}
}
}
TSharedRef<SDockTab> FSourceControlWindowsModule::CreateChangelistsTab(const FSpawnTabArgs & Args)
{
return SAssignNew(ChangelistsTab, SDockTab)
.Icon(FEditorStyle::Get().GetBrush("SourceControl.ChangelistsTab"))
.TabRole(ETabRole::NomadTab)
[
CreateChangelistsUI().ToSharedRef()
];
}
TSharedPtr<SWidget> FSourceControlWindowsModule::CreateChangelistsUI()
{
TSharedPtr<SWidget> ReturnWidget;
if (IsInGameThread())
{
TSharedPtr<SSourceControlChangelistsWidget> SharedPtr = SNew(SSourceControlChangelistsWidget);
ReturnWidget = SharedPtr;
ChangelistsWidget = SharedPtr;
}
return ReturnWidget;
}
void FSourceControlWindowsModule::ShowChangelistsTab()
{
FGlobalTabmanager::Get()->TryInvokeTab(FTabId(SourceControlChangelistsTabName));
}
bool FSourceControlWindowsModule::CanShowChangelistsTab() const
{
ISourceControlModule& SourceControlModule = ISourceControlModule::Get();
if (ISourceControlModule::Get().IsEnabled() &&
ISourceControlModule::Get().GetProvider().IsAvailable())
{
return true;
}
return false;
}
#undef LOCTEXT_NAMESPACE