// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved. #include "DetailCustomizationsPrivatePCH.h" #include "DirectoryPathStructCustomization.h" #include "DesktopPlatformModule.h" #include "ContentBrowserDelegates.h" #define LOCTEXT_NAMESPACE "DirectoryPathStructCustomization" TSharedRef FDirectoryPathStructCustomization::MakeInstance() { return MakeShareable(new FDirectoryPathStructCustomization()); } void FDirectoryPathStructCustomization::CustomizeStructHeader( TSharedRef StructPropertyHandle, class FDetailWidgetRow& HeaderRow, IStructCustomizationUtils& StructCustomizationUtils ) { TSharedPtr PathProperty = StructPropertyHandle->GetChildHandle("Path"); bool bUseRelativePath = StructPropertyHandle->GetProperty()->HasMetaData( TEXT("RelativePath") ); if(PathProperty.IsValid()) { HeaderRow.ValueContent() .MinDesiredWidth(125.0f) .MaxDesiredWidth(600.0f) [ SNew(SHorizontalBox) +SHorizontalBox::Slot() .FillWidth(1.0f) .VAlign(VAlign_Center) [ PathProperty->CreatePropertyValueWidget() ] +SHorizontalBox::Slot() .AutoWidth() .Padding(FMargin(4.0f, 0.0f, 0.0f, 0.0f)) .VAlign(VAlign_Center) [ SAssignNew(BrowseButton, SButton) .ButtonStyle( FEditorStyle::Get(), "HoverHintOnly" ) .ToolTipText( LOCTEXT( "FolderButtonToolTipText", "Choose a directory from this computer").ToString() ) .OnClicked( FOnClicked::CreateSP(this, &FDirectoryPathStructCustomization::OnPickDirectory, PathProperty.ToSharedRef(), bUseRelativePath) ) .ContentPadding( 2.0f ) .ForegroundColor( FSlateColor::UseForeground() ) .IsFocusable( false ) [ SNew( SImage ) .Image( FEditorStyle::GetBrush("PropertyWindow.Button_Ellipsis") ) .ColorAndOpacity( FSlateColor::UseForeground() ) ] ] ] .NameContent() [ StructPropertyHandle->CreatePropertyNameWidget() ]; } } void FDirectoryPathStructCustomization::CustomizeStructChildren( TSharedRef StructPropertyHandle, class IDetailChildrenBuilder& StructBuilder, IStructCustomizationUtils& StructCustomizationUtils ) { } FReply FDirectoryPathStructCustomization::OnPickDirectory(TSharedRef PropertyHandle, const bool bUseRelativePath) const { FString Directory; IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get(); if ( DesktopPlatform ) { TSharedPtr ParentWindow = FSlateApplication::Get().FindWidgetWindow(BrowseButton.ToSharedRef()); void* ParentWindowHandle = (ParentWindow.IsValid() && ParentWindow->GetNativeWindow().IsValid()) ? ParentWindow->GetNativeWindow()->GetOSWindowHandle() : nullptr; if(DesktopPlatform->OpenDirectoryDialog(ParentWindowHandle, LOCTEXT( "FolderDialogTitle", "Choose a directory").ToString(), FEditorDirectories::Get().GetLastDirectory(ELastDirectory::GENERIC_IMPORT), Directory)) { FEditorDirectories::Get().SetLastDirectory(ELastDirectory::GENERIC_IMPORT, Directory); if( bUseRelativePath ) { Directory = IFileManager::Get().ConvertToRelativePath(*Directory); } PropertyHandle->SetValue(Directory); } } return FReply::Handled(); } #undef LOCTEXT_NAMESPACE