Files

354 lines
10 KiB
C++
Raw Permalink Normal View History

// Copyright Epic Games, Inc. All Rights Reserved.
#include "SPackageReportDialog.h"
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
#include "Modules/ModuleManager.h"
#include "Widgets/SWindow.h"
#include "Layout/WidgetPath.h"
#include "SlateOptMacros.h"
#include "Framework/Application/SlateApplication.h"
#include "Widgets/Images/SImage.h"
#include "Widgets/Layout/SUniformGridPanel.h"
#include "Widgets/Input/SCheckBox.h"
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
#include "Widgets/Input/SButton.h"
#include "Styling/AppStyle.h"
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
#include "Interfaces/IMainFrameModule.h"
#define LOCTEXT_NAMESPACE "PackageReportDialog"
struct FCompareFPackageReportNodeByName
{
FORCEINLINE bool operator()( TSharedPtr<FPackageReportNode> A, TSharedPtr<FPackageReportNode> B ) const
{
return A->NodeName < B->NodeName;
}
};
FPackageReportNode::FPackageReportNode()
: CheckedState(ECheckBoxState::Undetermined)
, bShouldMigratePackage(nullptr)
, bIsFolder(false)
, Parent(nullptr)
{}
FPackageReportNode::FPackageReportNode(const FString& InNodeName, bool InIsFolder)
: NodeName(InNodeName)
, CheckedState(ECheckBoxState::Undetermined)
, bShouldMigratePackage(nullptr)
, bIsFolder(InIsFolder)
, Parent(nullptr)
{}
void FPackageReportNode::AddPackage(const FString& PackageName, bool* bInShouldMigratePackage)
{
TArray<FString> PathElements;
PackageName.ParseIntoArray(PathElements, TEXT("/"), /*InCullEmpty=*/true);
(void)AddPackage_Recursive(PathElements, bInShouldMigratePackage);
}
void FPackageReportNode::ExpandChildrenRecursively(const TSharedRef<PackageReportTree>& Treeview)
{
for ( auto ChildIt = Children.CreateConstIterator(); ChildIt; ++ChildIt )
{
Treeview->SetItemExpansion(*ChildIt, (*ChildIt)->CheckedState != ECheckBoxState::Unchecked);
(*ChildIt)->ExpandChildrenRecursively(Treeview);
}
}
FPackageReportNode::FChildrenState FPackageReportNode::AddPackage_Recursive(TArray<FString>& PathElements, bool* bInShouldMigratePackage)
{
FChildrenState ChildrenState;
ChildrenState.bAnyChildIsChecked = false;
ChildrenState.bAllChildrenAreChecked = true;
if ( PathElements.Num() > 0 )
{
// Pop the bottom element
FString ChildNodeName = PathElements[0];
PathElements.RemoveAt(0);
// Try to find a child which uses this folder name
TSharedPtr<FPackageReportNode> Child;
for ( auto ChildIt = Children.CreateConstIterator(); ChildIt; ++ChildIt )
{
if ( (*ChildIt)->NodeName == ChildNodeName )
{
Child = (*ChildIt);
break;
}
}
// If one was not found, create it
if ( !Child.IsValid() )
{
const bool bIsAFolder = (PathElements.Num() > 0);
int32 ChildIdx = Children.Add( MakeShareable(new FPackageReportNode(ChildNodeName, bIsAFolder)) );
Child = Children[ChildIdx];
Child.Get()->Parent = this;
Children.Sort( FCompareFPackageReportNodeByName() );
}
if ( ensure(Child.IsValid()) )
{
FChildrenState ChildChildrenState = Child->AddPackage_Recursive(PathElements, bInShouldMigratePackage);
ChildrenState.bAnyChildIsChecked |= ChildChildrenState.bAnyChildIsChecked;
ChildrenState.bAllChildrenAreChecked &= ChildChildrenState.bAllChildrenAreChecked;
}
CheckedState = ChildrenState.bAllChildrenAreChecked ? ECheckBoxState::Checked : (ChildrenState.bAnyChildIsChecked ? ECheckBoxState::Undetermined : ECheckBoxState::Unchecked);
}
else
{
CheckedState = *bInShouldMigratePackage ? ECheckBoxState::Checked : ECheckBoxState::Unchecked;
ChildrenState.bAnyChildIsChecked = ChildrenState.bAllChildrenAreChecked = CheckedState == ECheckBoxState::Checked;
bShouldMigratePackage = bInShouldMigratePackage;
}
return ChildrenState;
}
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
void SPackageReportDialog::Construct( const FArguments& InArgs, const FText& InReportMessage, TArray<ReportPackageData>& InPackageNames, const FOnReportConfirmed& InOnReportConfirmed )
{
OnReportConfirmed = InOnReportConfirmed;
FolderOpenBrush = FAppStyle::GetBrush("ContentBrowser.AssetTreeFolderOpen");
FolderClosedBrush = FAppStyle::GetBrush("ContentBrowser.AssetTreeFolderClosed");
PackageBrush = FAppStyle::GetBrush("ContentBrowser.ColumnViewAssetIcon");
ConstructNodeTree(InPackageNames);
ChildSlot
[
SNew(SBorder)
.BorderImage( FAppStyle::GetBrush("Docking.Tab.ContentAreaBrush") )
.Padding(FMargin(4, 8, 4, 4))
[
SNew(SVerticalBox)
// Report Message
+SVerticalBox::Slot()
.AutoHeight()
.Padding(0, 4)
[
SNew(STextBlock)
.Text(InReportMessage)
.TextStyle( FAppStyle::Get(), "PackageMigration.DialogTitle" )
]
// Tree of packages in the report
+SVerticalBox::Slot()
.FillHeight(1.f)
[
SNew(SBorder)
.BorderImage( FAppStyle::GetBrush("ToolPanel.GroupBorder") )
[
SAssignNew( ReportTreeView, PackageReportTree )
.TreeItemsSource(&PackageReportRootNode.Children)
.SelectionMode(ESelectionMode::Single)
.OnGenerateRow( this, &SPackageReportDialog::GenerateTreeRow )
.OnGetChildren( this, &SPackageReportDialog::GetChildrenForTree )
]
]
// Ok/Cancel buttons
+SVerticalBox::Slot()
.AutoHeight()
.HAlign(HAlign_Right)
.Padding(0,4,0,0)
[
SNew(SUniformGridPanel)
.SlotPadding(FAppStyle::GetMargin("StandardDialog.SlotPadding"))
.MinDesiredSlotWidth(FAppStyle::GetFloat("StandardDialog.MinDesiredSlotWidth"))
.MinDesiredSlotHeight(FAppStyle::GetFloat("StandardDialog.MinDesiredSlotHeight"))
+SUniformGridPanel::Slot(0,0)
[
SNew(SButton)
.HAlign(HAlign_Center)
.ContentPadding( FAppStyle::GetMargin("StandardDialog.ContentPadding") )
.OnClicked(this, &SPackageReportDialog::OkClicked)
.Text(LOCTEXT("OkButton", "OK"))
]
+SUniformGridPanel::Slot(1,0)
[
SNew(SButton)
.HAlign(HAlign_Center)
.ContentPadding( FAppStyle::GetMargin("StandardDialog.ContentPadding") )
.OnClicked(this, &SPackageReportDialog::CancelClicked)
.Text(LOCTEXT("CancelButton", "Cancel"))
]
]
]
];
if ( ensure(ReportTreeView.IsValid()) )
{
PackageReportRootNode.ExpandChildrenRecursively(ReportTreeView.ToSharedRef());
}
}
END_SLATE_FUNCTION_BUILD_OPTIMIZATION
void SPackageReportDialog::OpenPackageReportDialog(const FText& ReportMessage, TArray<ReportPackageData>& PackageNames, const FOnReportConfirmed& InOnReportConfirmed)
{
TSharedRef<SWindow> ReportWindow = SNew(SWindow)
.Title(LOCTEXT("ReportWindowTitle", "Asset Report"))
.ClientSize( FVector2D(600, 500) )
.SupportsMaximize(false)
.SupportsMinimize(false)
[
SNew(SPackageReportDialog, ReportMessage, PackageNames, InOnReportConfirmed)
];
IMainFrameModule& MainFrameModule = FModuleManager::LoadModuleChecked<IMainFrameModule>(TEXT("MainFrame"));
if ( MainFrameModule.GetParentWindow().IsValid() )
{
FSlateApplication::Get().AddWindowAsNativeChild(ReportWindow, MainFrameModule.GetParentWindow().ToSharedRef());
}
else
{
FSlateApplication::Get().AddWindow(ReportWindow);
}
}
void SPackageReportDialog::CloseDialog()
{
TSharedPtr<SWindow> Window = FSlateApplication::Get().FindWidgetWindow(AsShared());
if ( Window.IsValid() )
{
Window->RequestDestroyWindow();
}
}
TSharedRef<ITableRow> SPackageReportDialog::GenerateTreeRow( TSharedPtr<FPackageReportNode> TreeItem, const TSharedRef<STableViewBase>& OwnerTable)
{
check(TreeItem.IsValid());
const FSlateBrush* IconBrush = GetNodeIcon(TreeItem);
return SNew( STableRow< TSharedPtr<FPackageReportNode> >, OwnerTable )
[
// Icon
SNew(SHorizontalBox)
+SHorizontalBox::Slot()
.AutoWidth()
[
SNew(SCheckBox)
.OnCheckStateChanged(this, &SPackageReportDialog::CheckBoxStateChanged, TreeItem, OwnerTable)
.IsChecked(this, &SPackageReportDialog::GetEnabledCheckState, TreeItem)
]
+SHorizontalBox::Slot()
.AutoWidth()
[
SNew(SImage).Image(IconBrush)
]
// Name
+SHorizontalBox::Slot()
.FillWidth(1.f)
[
SNew(STextBlock).Text(FText::FromString(TreeItem->NodeName))
.ColorAndOpacity(FSlateColor::UseForeground())
]
];
}
ECheckBoxState SPackageReportDialog::GetEnabledCheckState(TSharedPtr<FPackageReportNode> TreeItem) const
{
return TreeItem.Get()->CheckedState;
}
void SPackageReportDialog::SetStateRecursive(TSharedPtr<FPackageReportNode> TreeItem, bool bIsChecked)
{
if (TreeItem.Get() == nullptr)
{
return;
}
TreeItem.Get()->CheckedState = bIsChecked ? ECheckBoxState::Checked : ECheckBoxState::Unchecked;
if (TreeItem.Get()->bShouldMigratePackage)
{
*(TreeItem.Get()->bShouldMigratePackage) = bIsChecked;
}
TArray< TSharedPtr<FPackageReportNode> > Children;
GetChildrenForTree(TreeItem, Children);
for (int i = 0; i < Children.Num(); i++)
{
if (Children[i].Get() == nullptr)
{
continue;
}
SetStateRecursive(Children[i], bIsChecked);
}
}
void SPackageReportDialog::CheckBoxStateChanged(ECheckBoxState InCheckBoxState, TSharedPtr<FPackageReportNode> TreeItem, TSharedRef<STableViewBase> OwnerTable)
{
SetStateRecursive(TreeItem, InCheckBoxState == ECheckBoxState::Checked);
FPackageReportNode* CurrentParent = TreeItem->Parent;
while (CurrentParent != nullptr)
{
bool bAnyChildIsChecked = false;
bool bAllChildrenAreChecked = true;
for (int i = 0; i < CurrentParent->Children.Num(); i++)
{
bAnyChildIsChecked |= CurrentParent->Children[i]->CheckedState != ECheckBoxState::Unchecked;
bAllChildrenAreChecked &= CurrentParent->Children[i]->CheckedState != ECheckBoxState::Unchecked;
}
CurrentParent->CheckedState = bAllChildrenAreChecked ? ECheckBoxState::Checked : (bAnyChildIsChecked ? ECheckBoxState::Undetermined : ECheckBoxState::Unchecked);
CurrentParent = CurrentParent->Parent;
}
OwnerTable.Get().RebuildList();
}
void SPackageReportDialog::GetChildrenForTree( TSharedPtr<FPackageReportNode> TreeItem, TArray< TSharedPtr<FPackageReportNode> >& OutChildren )
{
OutChildren = TreeItem->Children;
}
void SPackageReportDialog::ConstructNodeTree(TArray<ReportPackageData>& PackageNames)
{
for (ReportPackageData& Package : PackageNames)
{
PackageReportRootNode.AddPackage(Package.Name, &Package.bShouldMigratePackage);
}
}
const FSlateBrush* SPackageReportDialog::GetNodeIcon(const TSharedPtr<FPackageReportNode>& ReportNode) const
{
if ( !ReportNode->bIsFolder )
{
return PackageBrush;
}
else if ( ReportTreeView->IsItemExpanded(ReportNode) )
{
return FolderOpenBrush;
}
else
{
return FolderClosedBrush;
}
}
FReply SPackageReportDialog::OkClicked()
{
CloseDialog();
OnReportConfirmed.ExecuteIfBound();
return FReply::Handled();
}
FReply SPackageReportDialog::CancelClicked()
{
CloseDialog();
return FReply::Handled();
}
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
#undef LOCTEXT_NAMESPACE