Files
UnrealEngineUWP/Engine/Source/Editor/ContentBrowser/Private/SourcesViewWidgets.cpp
ryan durand 627baf970a Updating copyright for Engine Editor.
#rnx
#rb none


#ROBOMERGE-SOURCE: CL 10869241 via CL 10869527 via CL 10869904
#ROBOMERGE-BOT: (v613-10869866)

[CL 10870586 by ryan durand in Main branch]
2019-12-26 15:33:43 -05:00

554 lines
17 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "SourcesViewWidgets.h"
#include "Widgets/Images/SImage.h"
#include "EditorStyleSet.h"
#include "EditorFontGlyphs.h"
#include "PathViewTypes.h"
#include "DragAndDrop/DecoratedDragDropOp.h"
#include "DragAndDrop/AssetDragDropOp.h"
#include "DragAndDrop/CollectionDragDropOp.h"
#include "DragDropHandler.h"
#include "ContentBrowserUtils.h"
#include "CollectionViewUtils.h"
#define LOCTEXT_NAMESPACE "ContentBrowser"
//////////////////////////
// SAssetTreeItem
//////////////////////////
void SAssetTreeItem::Construct( const FArguments& InArgs )
{
TreeItem = InArgs._TreeItem;
OnNameChanged = InArgs._OnNameChanged;
OnVerifyNameChanged = InArgs._OnVerifyNameChanged;
OnAssetsOrPathsDragDropped = InArgs._OnAssetsOrPathsDragDropped;
OnFilesDragDropped = InArgs._OnFilesDragDropped;
IsItemExpanded = InArgs._IsItemExpanded;
bDraggedOver = false;
FolderOpenBrush = FEditorStyle::GetBrush("ContentBrowser.AssetTreeFolderOpen");
FolderClosedBrush = FEditorStyle::GetBrush("ContentBrowser.AssetTreeFolderClosed");
FolderOpenCodeBrush = FEditorStyle::GetBrush("ContentBrowser.AssetTreeFolderOpenCode");
FolderClosedCodeBrush = FEditorStyle::GetBrush("ContentBrowser.AssetTreeFolderClosedCode");
FolderDeveloperBrush = FEditorStyle::GetBrush("ContentBrowser.AssetTreeFolderDeveloper");
FolderType = EFolderType::Normal;
if( ContentBrowserUtils::IsDevelopersFolder(InArgs._TreeItem->FolderPath) )
{
FolderType = EFolderType::Developer;
}
else if( ContentBrowserUtils::IsClassPath/*IsClassRootDir*/(InArgs._TreeItem->FolderPath) )
{
FolderType = EFolderType::Code;
}
bool bIsRoot = !InArgs._TreeItem->Parent.IsValid();
ChildSlot
[
SNew(SBorder)
.BorderImage(this, &SAssetTreeItem::GetBorderImage)
.Padding( FMargin( 0, bIsRoot ? 3 : 0, 0, 0 ) ) // For root items in the tree, give them a little breathing room on the top
[
SNew(SHorizontalBox)
+SHorizontalBox::Slot()
.AutoWidth()
.Padding(0, 0, 2, 0)
.VAlign(VAlign_Center)
[
// Folder Icon
SNew(SImage)
.Image(this, &SAssetTreeItem::GetFolderIcon)
.ColorAndOpacity(this, &SAssetTreeItem::GetFolderColor)
]
+SHorizontalBox::Slot()
.AutoWidth()
.VAlign(VAlign_Center)
[
SAssignNew(InlineRenameWidget, SInlineEditableTextBlock)
.Text(this, &SAssetTreeItem::GetNameText)
.ToolTipText(this, &SAssetTreeItem::GetToolTipText)
.Font( InArgs._FontOverride.IsSet() ? InArgs._FontOverride : FEditorStyle::GetFontStyle(bIsRoot ? "ContentBrowser.SourceTreeRootItemFont" : "ContentBrowser.SourceTreeItemFont") )
.HighlightText( InArgs._HighlightText )
.OnTextCommitted(this, &SAssetTreeItem::HandleNameCommitted)
.OnVerifyTextChanged(this, &SAssetTreeItem::VerifyNameChanged)
.IsSelected( InArgs._IsSelected )
.IsReadOnly( this, &SAssetTreeItem::IsReadOnly )
]
]
];
if( InlineRenameWidget.IsValid() )
{
EnterEditingModeDelegateHandle = TreeItem.Pin()->OnRenamedRequestEvent.AddSP( InlineRenameWidget.Get(), &SInlineEditableTextBlock::EnterEditingMode );
}
}
SAssetTreeItem::~SAssetTreeItem()
{
if( InlineRenameWidget.IsValid() )
{
TreeItem.Pin()->OnRenamedRequestEvent.Remove( EnterEditingModeDelegateHandle );
}
}
bool SAssetTreeItem::ValidateDragDrop( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent, bool& OutIsKnownDragOperation ) const
{
OutIsKnownDragOperation = false;
TSharedPtr<FTreeItem> TreeItemPinned = TreeItem.Pin();
return TreeItemPinned.IsValid() && DragDropHandler::ValidateDragDropOnAssetFolder(MyGeometry, DragDropEvent, TreeItemPinned->FolderPath, OutIsKnownDragOperation);
}
void SAssetTreeItem::OnDragEnter( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent )
{
ValidateDragDrop(MyGeometry, DragDropEvent, bDraggedOver); // updates bDraggedOver
}
void SAssetTreeItem::OnDragLeave( const FDragDropEvent& DragDropEvent )
{
TSharedPtr<FDragDropOperation> Operation = DragDropEvent.GetOperation();
if (Operation.IsValid())
{
Operation->SetCursorOverride(TOptional<EMouseCursor::Type>());
if (Operation->IsOfType<FAssetDragDropOp>())
{
TSharedPtr<FAssetDragDropOp> DragDropOp = StaticCastSharedPtr<FAssetDragDropOp>(Operation);
DragDropOp->ResetToDefaultToolTip();
}
}
bDraggedOver = false;
}
FReply SAssetTreeItem::OnDragOver( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent )
{
ValidateDragDrop(MyGeometry, DragDropEvent, bDraggedOver); // updates bDraggedOver
return (bDraggedOver) ? FReply::Handled() : FReply::Unhandled();
}
FReply SAssetTreeItem::OnDrop( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent )
{
if (ValidateDragDrop(MyGeometry, DragDropEvent, bDraggedOver)) // updates bDraggedOver
{
bDraggedOver = false;
TSharedPtr<FDragDropOperation> Operation = DragDropEvent.GetOperation();
if (!Operation.IsValid())
{
return FReply::Unhandled();
}
if (Operation->IsOfType<FAssetDragDropOp>())
{
TSharedPtr<FAssetDragDropOp> DragDropOp = StaticCastSharedPtr<FAssetDragDropOp>( DragDropEvent.GetOperation() );
OnAssetsOrPathsDragDropped.ExecuteIfBound(DragDropOp->GetAssets(), DragDropOp->GetAssetPaths(), TreeItem.Pin());
return FReply::Handled();
}
if (Operation->IsOfType<FExternalDragOperation>())
{
TSharedPtr<FExternalDragOperation> DragDropOp = StaticCastSharedPtr<FExternalDragOperation>( DragDropEvent.GetOperation() );
OnFilesDragDropped.ExecuteIfBound(DragDropOp->GetFiles(), TreeItem.Pin());
return FReply::Handled();
}
}
if (bDraggedOver)
{
// We were able to handle this operation, but could not due to another error - still report this drop as handled so it doesn't fall through to other widgets
bDraggedOver = false;
return FReply::Handled();
}
return FReply::Unhandled();
}
void SAssetTreeItem::Tick( const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime )
{
LastGeometry = AllottedGeometry;
}
bool SAssetTreeItem::VerifyNameChanged(const FText& InName, FText& OutError) const
{
if ( TreeItem.IsValid() )
{
TSharedPtr<FTreeItem> TreeItemPtr = TreeItem.Pin();
if(OnVerifyNameChanged.IsBound())
{
return OnVerifyNameChanged.Execute(InName.ToString(), OutError, TreeItemPtr->FolderPath);
}
}
return true;
}
void SAssetTreeItem::HandleNameCommitted( const FText& NewText, ETextCommit::Type CommitInfo )
{
if ( TreeItem.IsValid() )
{
TSharedPtr<FTreeItem> TreeItemPtr = TreeItem.Pin();
if ( TreeItemPtr->bNamingFolder )
{
TreeItemPtr->bNamingFolder = false;
const FString OldPath = TreeItemPtr->FolderPath;
FString Path;
TreeItemPtr->FolderPath.Split(TEXT("/"), &Path, NULL, ESearchCase::CaseSensitive, ESearchDir::FromEnd);
TreeItemPtr->DisplayName = NewText;
TreeItemPtr->FolderName = NewText.ToString();
TreeItemPtr->FolderPath = Path + TEXT("/") + NewText.ToString();
FVector2D MessageLoc;
MessageLoc.X = LastGeometry.AbsolutePosition.X;
MessageLoc.Y = LastGeometry.AbsolutePosition.Y + LastGeometry.Size.Y * LastGeometry.Scale;
OnNameChanged.ExecuteIfBound(TreeItemPtr, OldPath, MessageLoc, CommitInfo);
}
}
}
bool SAssetTreeItem::IsReadOnly() const
{
if ( TreeItem.IsValid() )
{
return !TreeItem.Pin()->bNamingFolder;
}
else
{
return true;
}
}
bool SAssetTreeItem::IsValidAssetPath() const
{
if ( TreeItem.IsValid() )
{
// The classes folder is not a real path
return !ContentBrowserUtils::IsClassPath(TreeItem.Pin()->FolderPath);
}
else
{
return false;
}
}
const FSlateBrush* SAssetTreeItem::GetFolderIcon() const
{
switch( FolderType )
{
case EFolderType::Code:
return ( IsItemExpanded.Get() ) ? FolderOpenCodeBrush : FolderClosedCodeBrush;
case EFolderType::Developer:
return FolderDeveloperBrush;
default:
return ( IsItemExpanded.Get() ) ? FolderOpenBrush : FolderClosedBrush;
}
}
FSlateColor SAssetTreeItem::GetFolderColor() const
{
if ( TreeItem.IsValid() )
{
const TSharedPtr<FLinearColor> Color = ContentBrowserUtils::LoadColor( TreeItem.Pin()->FolderPath );
if ( Color.IsValid() )
{
return *Color.Get();
}
}
return ContentBrowserUtils::GetDefaultColor();
}
FText SAssetTreeItem::GetNameText() const
{
TSharedPtr<FTreeItem> TreeItemPin = TreeItem.Pin();
if ( TreeItemPin.IsValid() )
{
return TreeItemPin->DisplayName;
}
else
{
return FText();
}
}
FText SAssetTreeItem::GetToolTipText() const
{
TSharedPtr<FTreeItem> TreeItemPin = TreeItem.Pin();
if ( TreeItemPin.IsValid() )
{
return FText::FromString(TreeItemPin->FolderPath);
}
else
{
return FText();
}
}
const FSlateBrush* SAssetTreeItem::GetBorderImage() const
{
static const FName NAME_DraggedBorderImage = TEXT("Menu.Background");
static const FName NAME_NoBorderImage = TEXT("NoBorder");
return bDraggedOver ? FEditorStyle::GetBrush(NAME_DraggedBorderImage) : FEditorStyle::GetBrush(NAME_NoBorderImage);
}
//////////////////////////
// SCollectionTreeItem
//////////////////////////
void SCollectionTreeItem::Construct( const FArguments& InArgs )
{
ParentWidget = InArgs._ParentWidget;
CollectionItem = InArgs._CollectionItem;
OnBeginNameChange = InArgs._OnBeginNameChange;
OnNameChangeCommit = InArgs._OnNameChangeCommit;
OnVerifyRenameCommit = InArgs._OnVerifyRenameCommit;
OnValidateDragDrop = InArgs._OnValidateDragDrop;
OnHandleDragDrop = InArgs._OnHandleDragDrop;
bDraggedOver = false;
TSharedPtr<SAssetTagItem> AssetTagItem;
ChildSlot
[
SAssignNew(AssetTagItem, SAssetTagItem)
.ViewMode(InArgs._ViewMode)
.BaseColor(this, &SCollectionTreeItem::GetCollectionColor)
.DisplayName(this, &SCollectionTreeItem::GetNameText)
.CountText(this, &SCollectionTreeItem::GetCollectionObjectCountText)
.WarningText(this, &SCollectionTreeItem::GetCollectionWarningText)
.HighlightText(InArgs._HighlightText)
.OnBeginNameEdit(this, &SCollectionTreeItem::HandleBeginNameChange)
.OnNameCommitted(this, &SCollectionTreeItem::HandleNameCommitted)
.OnVerifyName(this, &SCollectionTreeItem::HandleVerifyNameChanged)
.IsSelected(InArgs._IsSelected)
.IsNameReadOnly(InArgs._IsReadOnly)
.IsCheckBoxEnabled(InArgs._IsCheckBoxEnabled)
.IsChecked(InArgs._IsCollectionChecked)
.OnCheckStateChanged(InArgs._OnCollectionCheckStateChanged)
.OnBuildToolTipInfo(this, &SCollectionTreeItem::BuildToolTipInfo)
];
// This is broadcast when the context menu / input binding requests a rename
InArgs._CollectionItem->OnRenamedRequestEvent.AddSP(AssetTagItem.Get(), &SAssetTagItem::RequestRename);
}
void SCollectionTreeItem::Tick( const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime )
{
// Cache this widget's geometry so it can pop up warnings over itself
CachedGeometry = AllottedGeometry;
}
bool SCollectionTreeItem::ValidateDragDrop( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent, bool& OutIsKnownDragOperation ) const
{
OutIsKnownDragOperation = false;
TSharedPtr<FCollectionItem> CollectionItemPtr = CollectionItem.Pin();
if (OnValidateDragDrop.IsBound() && CollectionItemPtr.IsValid())
{
return OnValidateDragDrop.Execute( CollectionItemPtr.ToSharedRef(), MyGeometry, DragDropEvent, OutIsKnownDragOperation );
}
return false;
}
void SCollectionTreeItem::OnDragEnter( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent )
{
ValidateDragDrop(MyGeometry, DragDropEvent, bDraggedOver); // updates bDraggedOver
}
void SCollectionTreeItem::OnDragLeave( const FDragDropEvent& DragDropEvent )
{
TSharedPtr<FDragDropOperation> Operation = DragDropEvent.GetOperation();
if (Operation.IsValid())
{
Operation->SetCursorOverride(TOptional<EMouseCursor::Type>());
if (Operation->IsOfType<FCollectionDragDropOp>() || Operation->IsOfType<FAssetDragDropOp>())
{
TSharedPtr<FDecoratedDragDropOp> DragDropOp = StaticCastSharedPtr<FDecoratedDragDropOp>(Operation);
DragDropOp->ResetToDefaultToolTip();
}
}
bDraggedOver = false;
}
FReply SCollectionTreeItem::OnDragOver( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent )
{
ValidateDragDrop(MyGeometry, DragDropEvent, bDraggedOver); // updates bDraggedOver
return (bDraggedOver) ? FReply::Handled() : FReply::Unhandled();
}
FReply SCollectionTreeItem::OnDrop( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent )
{
if (ValidateDragDrop(MyGeometry, DragDropEvent, bDraggedOver) && OnHandleDragDrop.IsBound()) // updates bDraggedOver
{
bDraggedOver = false;
return OnHandleDragDrop.Execute( CollectionItem.Pin().ToSharedRef(), MyGeometry, DragDropEvent );
}
if (bDraggedOver)
{
// We were able to handle this operation, but could not due to another error - still report this drop as handled so it doesn't fall through to other widgets
bDraggedOver = false;
return FReply::Handled();
}
return FReply::Unhandled();
}
void SCollectionTreeItem::HandleBeginNameChange( const FText& OldText )
{
TSharedPtr<FCollectionItem> CollectionItemPtr = CollectionItem.Pin();
if ( CollectionItemPtr.IsValid() )
{
// If we get here via a context menu or input binding, bRenaming will already be set on the item.
// If we got here by double clicking the editable text field, we need to set it now.
CollectionItemPtr->bRenaming = true;
OnBeginNameChange.ExecuteIfBound( CollectionItemPtr );
}
}
void SCollectionTreeItem::HandleNameCommitted( const FText& NewText, ETextCommit::Type CommitInfo )
{
TSharedPtr<FCollectionItem> CollectionItemPtr = CollectionItem.Pin();
if ( CollectionItemPtr.IsValid() )
{
if ( CollectionItemPtr->bRenaming )
{
CollectionItemPtr->bRenaming = false;
if ( OnNameChangeCommit.IsBound() )
{
FText WarningMessage;
bool bIsCommitted = (CommitInfo != ETextCommit::OnCleared);
if ( !OnNameChangeCommit.Execute(CollectionItemPtr, NewText.ToString(), bIsCommitted, WarningMessage) && ParentWidget.IsValid() && bIsCommitted )
{
// Failed to rename/create a collection, display a warning.
ContentBrowserUtils::DisplayMessage(WarningMessage, CachedGeometry.GetLayoutBoundingRect(), ParentWidget.ToSharedRef());
}
}
}
}
}
bool SCollectionTreeItem::HandleVerifyNameChanged( const FText& NewText, FText& OutErrorMessage )
{
TSharedPtr<FCollectionItem> CollectionItemPtr = CollectionItem.Pin();
if (CollectionItemPtr.IsValid())
{
return !OnVerifyRenameCommit.IsBound() || OnVerifyRenameCommit.Execute(CollectionItemPtr, NewText.ToString(), CachedGeometry.GetLayoutBoundingRect(), OutErrorMessage);
}
return true;
}
FText SCollectionTreeItem::GetNameText() const
{
TSharedPtr<FCollectionItem> CollectionItemPtr = CollectionItem.Pin();
if ( CollectionItemPtr.IsValid() )
{
return FText::FromName(CollectionItemPtr->CollectionName);
}
else
{
return FText();
}
}
FLinearColor SCollectionTreeItem::GetCollectionColor() const
{
TSharedPtr<FCollectionItem> CollectionItemPtr = CollectionItem.Pin();
if ( CollectionItemPtr.IsValid() )
{
return CollectionItemPtr->CollectionColor;
}
return CollectionViewUtils::GetDefaultColor();
}
FText SCollectionTreeItem::GetCollectionObjectCountText() const
{
TSharedPtr<FCollectionItem> CollectionItemPtr = CollectionItem.Pin();
if (CollectionItemPtr)
{
if (CollectionItemPtr->StorageMode == ECollectionStorageMode::Static)
{
return CollectionItemPtr->NumObjects > 999
? NSLOCTEXT("ContentBrowser", "999+", "999+")
: FText::AsNumber(CollectionItemPtr->NumObjects);
}
return NSLOCTEXT("ContentBrowser", "InfinitySymbol", "\u221E");
}
return FText::GetEmpty();
}
FText SCollectionTreeItem::GetCollectionWarningText() const
{
TSharedPtr<FCollectionItem> CollectionItemPtr = CollectionItem.Pin();
if (CollectionItemPtr)
{
switch (CollectionItemPtr->CurrentStatus)
{
case ECollectionItemStatus::IsOutOfDate:
return NSLOCTEXT("ContentBrowser", "CollectionStatus_IsOutOfDate", "Collection is not at the latest revision");
case ECollectionItemStatus::IsCheckedOutByAnotherUser:
return NSLOCTEXT("ContentBrowser", "CollectionStatus_IsCheckedOutByAnotherUser", "Collection is checked out by another user");
case ECollectionItemStatus::IsConflicted:
return NSLOCTEXT("ContentBrowser", "CollectionStatus_IsConflicted", "Collection is conflicted - please use your external source control provider to resolve this conflict");
case ECollectionItemStatus::IsMissingSCCProvider:
return NSLOCTEXT("ContentBrowser", "CollectionStatus_IsMissingSCCProvider", "Collection is missing its source control provider - please check your source control settings");
case ECollectionItemStatus::HasLocalChanges:
return NSLOCTEXT("ContentBrowser", "CollectionStatus_HasLocalChanges", "Collection has local unsaved or uncomitted changes");
default:
break;
}
}
return FText::GetEmpty();
}
void SCollectionTreeItem::BuildToolTipInfo(const FOnBuildAssetTagItemToolTipInfoEntry& InCallback) const
{
TSharedPtr<FCollectionItem> CollectionItemPtr = CollectionItem.Pin();
if (CollectionItemPtr)
{
InCallback(LOCTEXT("CollectionShareTypeKey", "Share Type"), ECollectionShareType::ToText(CollectionItemPtr->CollectionType));
InCallback(LOCTEXT("CollectionStorageModeKey", "Storage Mode"), ECollectionStorageMode::ToText(CollectionItemPtr->StorageMode));
if (CollectionItemPtr->StorageMode == ECollectionStorageMode::Static)
{
InCallback(LOCTEXT("CollectionObjectCountKey", "Object Count"), FText::AsNumber(CollectionItemPtr->NumObjects));
}
}
}
#undef LOCTEXT_NAMESPACE