You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#preflight 6272a74d2f6d177be3c6fdda #rb Matt.Kuhlenschmidt #ROBOMERGE-OWNER: Lauren.Barnes #ROBOMERGE-AUTHOR: lauren.barnes #ROBOMERGE-SOURCE: CL 20057269 via CL 20070159 via CL 20072035 via CL 20072203 #ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v943-19904690) #ROBOMERGE-CONFLICT from-shelf [CL 20105363 by Lauren Barnes in ue5-main branch]
120 lines
4.3 KiB
C++
120 lines
4.3 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "NewAssetOrClassContextMenu.h"
|
|
#include "Widgets/DeclarativeSyntaxSupport.h"
|
|
#include "Widgets/SCompoundWidget.h"
|
|
#include "Widgets/SBoxPanel.h"
|
|
#include "Widgets/SOverlay.h"
|
|
#include "Textures/SlateIcon.h"
|
|
#include "Widgets/Layout/SBorder.h"
|
|
#include "Widgets/Images/SImage.h"
|
|
#include "Widgets/Text/STextBlock.h"
|
|
#include "Widgets/Layout/SBox.h"
|
|
#include "Framework/MultiBox/MultiBoxBuilder.h"
|
|
#include "Styling/AppStyle.h"
|
|
#include "Settings/ContentBrowserSettings.h"
|
|
#include "ContentBrowserUtils.h"
|
|
#include "Widgets/SToolTip.h"
|
|
#include "ToolMenus.h"
|
|
#include "IContentBrowserDataModule.h"
|
|
#include "ContentBrowserDataSubsystem.h"
|
|
#include "ContentBrowserDataMenuContexts.h"
|
|
|
|
#define LOCTEXT_NAMESPACE "ContentBrowser"
|
|
|
|
void FNewAssetOrClassContextMenu::MakeContextMenu(
|
|
UToolMenu* Menu,
|
|
const TArray<FName>& InSelectedPaths,
|
|
const FOnNewFolderRequested& InOnNewFolderRequested,
|
|
const FOnGetContentRequested& InOnGetContentRequested
|
|
)
|
|
{
|
|
UContentBrowserDataSubsystem* ContentBrowserData = IContentBrowserDataModule::Get().GetSubsystem();
|
|
|
|
const FName FirstSelectedPath = (InSelectedPaths.Num() > 0) ? InSelectedPaths[0] : FName();
|
|
const bool bIsValidNewFolderPath = ContentBrowserData->CanCreateFolder(FirstSelectedPath, nullptr);
|
|
const bool bHasSinglePathSelected = InSelectedPaths.Num() == 1;
|
|
|
|
auto CanExecuteFolderActions = [bHasSinglePathSelected, bIsValidNewFolderPath]() -> bool
|
|
{
|
|
// We can execute folder actions when we only have a single path selected, and that path is a valid path for creating a folder
|
|
return bHasSinglePathSelected && bIsValidNewFolderPath;
|
|
};
|
|
|
|
const FCanExecuteAction CanExecuteFolderActionsDelegate = FCanExecuteAction::CreateLambda(CanExecuteFolderActions);
|
|
|
|
// Get Content
|
|
FToolMenuSection& GetContentSection = Menu->AddSection("ContentBrowserGetContent", LOCTEXT("GetContentMenuHeading", "Get Content"));
|
|
|
|
if ( InOnGetContentRequested.IsBound() )
|
|
{
|
|
UContentBrowserDataMenuContext_AddNewMenu* AddNewMenuContext = Menu->FindContext<UContentBrowserDataMenuContext_AddNewMenu>();
|
|
if (AddNewMenuContext && AddNewMenuContext->bCanBeModified && AddNewMenuContext->bContainsValidPackagePath)
|
|
{
|
|
GetContentSection.AddMenuEntry(
|
|
"GetContent",
|
|
LOCTEXT( "GetContentText", "Add Feature or Content Pack..." ),
|
|
LOCTEXT( "GetContentTooltip", "Add features and content packs to the project." ),
|
|
FSlateIcon( FAppStyle::GetAppStyleSetName(), "ContentBrowser.AddContent" ),
|
|
FUIAction( FExecuteAction::CreateStatic( &FNewAssetOrClassContextMenu::ExecuteGetContent, InOnGetContentRequested ) )
|
|
);
|
|
}
|
|
}
|
|
|
|
// If a single folder is selected and it is not valid for creating a new folder (The All Folder), don't create a context menu
|
|
if (bHasSinglePathSelected && !bIsValidNewFolderPath)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// New Folder
|
|
if(InOnNewFolderRequested.IsBound() && GetDefault<UContentBrowserSettings>()->DisplayFolders)
|
|
{
|
|
{
|
|
FToolMenuSection& Section = Menu->AddSection("ContentBrowserNewFolder", LOCTEXT("FolderMenuHeading", "Folder") );
|
|
FText NewFolderToolTip;
|
|
if(bHasSinglePathSelected)
|
|
{
|
|
if(bIsValidNewFolderPath)
|
|
{
|
|
NewFolderToolTip = FText::Format(LOCTEXT("NewFolderTooltip_CreateIn", "Create a new folder in {0}."), FText::FromName(FirstSelectedPath));
|
|
}
|
|
else
|
|
{
|
|
NewFolderToolTip = FText::Format(LOCTEXT("NewFolderTooltip_InvalidPath", "Cannot create new folders in {0}."), FText::FromName(FirstSelectedPath));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
NewFolderToolTip = LOCTEXT("NewFolderTooltip_InvalidNumberOfPaths", "Can only create folders when there is a single path selected.");
|
|
}
|
|
|
|
Section.AddMenuEntry(
|
|
"NewFolder",
|
|
LOCTEXT("NewFolderLabel", "New Folder"),
|
|
NewFolderToolTip,
|
|
FSlateIcon(FAppStyle::GetAppStyleSetName(), "ContentBrowser.NewFolderIcon"),
|
|
FUIAction(
|
|
FExecuteAction::CreateStatic(&FNewAssetOrClassContextMenu::ExecuteNewFolder, FirstSelectedPath, InOnNewFolderRequested),
|
|
CanExecuteFolderActionsDelegate
|
|
)
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
void FNewAssetOrClassContextMenu::ExecuteNewFolder(FName InPath, FOnNewFolderRequested InOnNewFolderRequested)
|
|
{
|
|
if (ensure(!InPath.IsNone()))
|
|
{
|
|
InOnNewFolderRequested.ExecuteIfBound(InPath.ToString());
|
|
}
|
|
}
|
|
|
|
void FNewAssetOrClassContextMenu::ExecuteGetContent( FOnGetContentRequested InOnGetContentRequested )
|
|
{
|
|
InOnGetContentRequested.ExecuteIfBound();
|
|
}
|
|
|
|
#undef LOCTEXT_NAMESPACE
|