2019-12-26 15:33:43 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
#include "FilePathStructCustomization.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/DeclarativeSyntaxSupport.h"
|
|
|
|
|
#include "Engine/GameViewportClient.h"
|
|
|
|
|
#include "Misc/PackageName.h"
|
|
|
|
|
#include "PropertyHandle.h"
|
|
|
|
|
#include "Misc/MessageDialog.h"
|
|
|
|
|
#include "EditorDirectories.h"
|
|
|
|
|
#include "DetailWidgetRow.h"
|
|
|
|
|
#include "Widgets/Input/SFilePathPicker.h"
|
2014-09-02 15:22:15 -04:00
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
#define LOCTEXT_NAMESPACE "FilePathStructCustomization"
|
|
|
|
|
|
|
|
|
|
|
2014-09-02 15:22:15 -04:00
|
|
|
/* IDetailCustomization interface
|
|
|
|
|
*****************************************************************************/
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2014-06-04 11:16:24 -04:00
|
|
|
void FFilePathStructCustomization::CustomizeChildren( TSharedRef<IPropertyHandle> StructPropertyHandle, class IDetailChildrenBuilder& StructBuilder, IPropertyTypeCustomizationUtils& StructCustomizationUtils )
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-09-02 15:22:15 -04:00
|
|
|
/* do nothing */
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-09-02 15:22:15 -04:00
|
|
|
void FFilePathStructCustomization::CustomizeHeader( TSharedRef<IPropertyHandle> StructPropertyHandle, class FDetailWidgetRow& HeaderRow, IPropertyTypeCustomizationUtils& StructCustomizationUtils )
|
|
|
|
|
{
|
2014-09-05 17:49:31 -04:00
|
|
|
PathStringProperty = StructPropertyHandle->GetChildHandle("FilePath");
|
2014-09-02 15:22:15 -04:00
|
|
|
|
|
|
|
|
FString FileTypeFilter;
|
|
|
|
|
|
|
|
|
|
// construct file type filter
|
2014-09-05 17:49:31 -04:00
|
|
|
const FString& MetaData = StructPropertyHandle->GetMetaData(TEXT("FilePathFilter"));
|
2014-09-02 15:22:15 -04:00
|
|
|
|
2016-04-07 12:59:50 -04:00
|
|
|
|
|
|
|
|
bLongPackageName = StructPropertyHandle->HasMetaData(TEXT("LongPackageName"));
|
2019-02-08 11:35:12 -05:00
|
|
|
bRelativeToGameDir = StructPropertyHandle->HasMetaData(TEXT("RelativeToGameDir"));
|
2016-04-07 12:59:50 -04:00
|
|
|
|
2014-09-02 15:22:15 -04:00
|
|
|
if (MetaData.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
FileTypeFilter = TEXT("All files (*.*)|*.*");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-10-04 13:11:45 -04:00
|
|
|
if (MetaData.Contains(TEXT("|"))) // If MetaData follows the Description|ExtensionList format, use it as is
|
|
|
|
|
{
|
|
|
|
|
FileTypeFilter = MetaData;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
FileTypeFilter = FString::Printf(TEXT("%s files (*.%s)|*.%s"), *MetaData, *MetaData, *MetaData);
|
|
|
|
|
}
|
2014-09-02 15:22:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// create path picker widget
|
|
|
|
|
HeaderRow
|
|
|
|
|
.NameContent()
|
|
|
|
|
[
|
|
|
|
|
StructPropertyHandle->CreatePropertyNameWidget()
|
|
|
|
|
]
|
|
|
|
|
.ValueContent()
|
|
|
|
|
.MaxDesiredWidth(0.0f)
|
|
|
|
|
.MinDesiredWidth(125.0f)
|
|
|
|
|
[
|
|
|
|
|
SNew(SFilePathPicker)
|
2022-05-09 13:12:28 -04:00
|
|
|
.BrowseButtonImage(FAppStyle::GetBrush("PropertyWindow.Button_Ellipsis"))
|
|
|
|
|
.BrowseButtonStyle(FAppStyle::Get(), "HoverHintOnly")
|
2014-09-02 15:22:15 -04:00
|
|
|
.BrowseButtonToolTip(LOCTEXT("FileButtonToolTipText", "Choose a file from this computer"))
|
|
|
|
|
.BrowseDirectory(FEditorDirectories::Get().GetLastDirectory(ELastDirectory::GENERIC_OPEN))
|
|
|
|
|
.BrowseTitle(LOCTEXT("PropertyEditorTitle", "File picker..."))
|
|
|
|
|
.FilePath(this, &FFilePathStructCustomization::HandleFilePathPickerFilePath)
|
|
|
|
|
.FileTypeFilter(FileTypeFilter)
|
|
|
|
|
.OnPathPicked(this, &FFilePathStructCustomization::HandleFilePathPickerPathPicked)
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-09-02 19:28:15 -04:00
|
|
|
/* FFilePathStructCustomization callbacks
|
2014-09-02 15:22:15 -04:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
FString FFilePathStructCustomization::HandleFilePathPickerFilePath( ) const
|
|
|
|
|
{
|
|
|
|
|
FString FilePath;
|
2014-09-05 17:49:31 -04:00
|
|
|
PathStringProperty->GetValue(FilePath);
|
2014-09-02 15:22:15 -04:00
|
|
|
|
|
|
|
|
return FilePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FFilePathStructCustomization::HandleFilePathPickerPathPicked( const FString& PickedPath )
|
|
|
|
|
{
|
2016-04-07 12:59:50 -04:00
|
|
|
FString FinalPath = PickedPath;
|
|
|
|
|
if (bLongPackageName)
|
|
|
|
|
{
|
|
|
|
|
FString LongPackageName;
|
|
|
|
|
FString StringFailureReason;
|
|
|
|
|
if (FPackageName::TryConvertFilenameToLongPackageName(PickedPath, LongPackageName, &StringFailureReason) == false)
|
|
|
|
|
{
|
|
|
|
|
FMessageDialog::Open(EAppMsgType::Ok, FText::FromString(StringFailureReason));
|
|
|
|
|
}
|
|
|
|
|
FinalPath = LongPackageName;
|
|
|
|
|
}
|
2020-12-11 14:21:20 -04:00
|
|
|
else if (bRelativeToGameDir && !PickedPath.IsEmpty())
|
2019-02-08 11:35:12 -05:00
|
|
|
{
|
2020-12-11 14:21:20 -04:00
|
|
|
//A filepath under the project directory will be made relative to the project directory
|
|
|
|
|
//Otherwise, the absolute path will be returned unless it doesn't exist, the current path will
|
|
|
|
|
//be kept. This can happen if it's already relative to project dir (tabbing when selected)
|
|
|
|
|
|
|
|
|
|
const FString ProjectDir = FPaths::ProjectDir();
|
|
|
|
|
const FString AbsoluteProjectDir = FPaths::ConvertRelativePathToFull(ProjectDir);
|
|
|
|
|
const FString AbsolutePickedPath = FPaths::ConvertRelativePathToFull(PickedPath);
|
|
|
|
|
|
|
|
|
|
//Verify if absolute path to file exists. If it was already relative to content directory
|
|
|
|
|
//the absolute will be to binaries and will possibly be garbage
|
|
|
|
|
if (FPaths::FileExists(AbsolutePickedPath))
|
2019-02-08 11:35:12 -05:00
|
|
|
{
|
2020-12-11 14:21:20 -04:00
|
|
|
//If file is part of the project dir, chop the project dir part
|
|
|
|
|
//Otherwise, use the absolute path
|
|
|
|
|
if (AbsolutePickedPath.StartsWith(AbsoluteProjectDir))
|
2019-07-19 10:15:01 -04:00
|
|
|
{
|
|
|
|
|
FinalPath = AbsolutePickedPath.RightChop(AbsoluteProjectDir.Len());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
FinalPath = AbsolutePickedPath;
|
|
|
|
|
}
|
2019-02-08 11:35:12 -05:00
|
|
|
}
|
2020-12-11 14:21:20 -04:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//If absolute file doesn't exist, it might already be relative to project dir
|
|
|
|
|
//If not, then it might be a manual entry, so keep it untouched either way
|
|
|
|
|
FinalPath = PickedPath;
|
|
|
|
|
}
|
2019-02-08 11:35:12 -05:00
|
|
|
}
|
2016-04-07 12:59:50 -04:00
|
|
|
|
|
|
|
|
PathStringProperty->SetValue(FinalPath);
|
2014-09-02 15:22:15 -04:00
|
|
|
FEditorDirectories::Get().SetLastDirectory(ELastDirectory::GENERIC_OPEN, FPaths::GetPath(PickedPath));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#undef LOCTEXT_NAMESPACE
|