ExtSourcesViewWidgets.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  1. // Copyright 2017-2021 marynate. All Rights Reserved.
  2. #include "ExtSourcesViewWidgets.h"
  3. #include "ExtContentBrowserUtils.h"
  4. #include "ExtContentBrowserStyle.h"
  5. #include "Widgets/Images/SImage.h"
  6. #include "Widgets/Images/SThrobber.h"
  7. #include "Widgets/Images/SSpinningImage.h"
  8. #include "EditorStyleSet.h"
  9. #include "EditorFontGlyphs.h"
  10. #include "ExtPathViewTypes.h"
  11. #include "DragAndDrop/DecoratedDragDropOp.h"
  12. #include "DragAndDrop/AssetDragDropOp.h"
  13. #include "DragAndDrop/CollectionDragDropOp.h"
  14. #include "DragDropHandler.h"
  15. #include "CollectionViewUtils.h"
  16. #include "Widgets/Text/SInlineEditableTextBlock.h"
  17. #define LOCTEXT_NAMESPACE "ExtContentBrowser"
  18. //////////////////////////
  19. // SExtAssetTreeItem
  20. //////////////////////////
  21. void SExtAssetTreeItem::Construct( const FArguments& InArgs )
  22. {
  23. TreeItem = InArgs._TreeItem;
  24. OnNameChanged = InArgs._OnNameChanged;
  25. OnVerifyNameChanged = InArgs._OnVerifyNameChanged;
  26. OnAssetsOrPathsDragDropped = InArgs._OnAssetsOrPathsDragDropped;
  27. OnFilesDragDropped = InArgs._OnFilesDragDropped;
  28. IsItemExpanded = InArgs._IsItemExpanded;
  29. bDraggedOver = false;
  30. FolderClosedBrush = FExtContentBrowserStyle::Get().GetBrush("UAssetBrowser.AssetTreeFolderClosed");
  31. FolderOpenBrush = FExtContentBrowserStyle::Get().GetBrush("UAssetBrowser.AssetTreeFolderOpen");
  32. FolderClosedCodeBrush = FExtContentBrowserStyle::Get().GetBrush("UAssetBrowser.AssetTreeFolderClosedCode");
  33. FolderOpenCodeBrush = FExtContentBrowserStyle::Get().GetBrush("UAssetBrowser.AssetTreeFolderOpenCode");
  34. FolderDeveloperBrush = FExtContentBrowserStyle::Get().GetBrush("UAssetBrowser.AssetTreeFolderDeveloper");
  35. FolderClosedPluginBrush = FExtContentBrowserStyle::Get().GetBrush("UAssetBrowser.AssetTreeFolderClosedPlugin");
  36. FolderOpenPluginBrush = FExtContentBrowserStyle::Get().GetBrush("UAssetBrowser.AssetTreeFolderOpenPlugin");
  37. FolderClosedProjectBrush = FExtContentBrowserStyle::Get().GetBrush("UAssetBrowser.AssetTreeFolderClosedProject");
  38. FolderOpenProjectBrush = FExtContentBrowserStyle::Get().GetBrush("UAssetBrowser.AssetTreeFolderOpenProject");
  39. FolderClosedVaultCacheBrush = FExtContentBrowserStyle::Get().GetBrush("UAssetBrowser.AssetTreeFolderClosedVaultCache");
  40. FolderOpenVaultCacheBrush = FExtContentBrowserStyle::Get().GetBrush("UAssetBrowser.AssetTreeFolderOpenVaultCache");
  41. FolderType = EFolderType::Normal;
  42. #if ECB_DISABLE
  43. if( ExtContentBrowserUtils::IsDevelopersFolder(InArgs._TreeItem->FolderPath) )
  44. {
  45. FolderType = EFolderType::Developer;
  46. }
  47. else if( ExtContentBrowserUtils::IsClassPath/*IsClassRootDir*/(InArgs._TreeItem->FolderPath) )
  48. {
  49. FolderType = EFolderType::Code;
  50. }
  51. #endif
  52. bool bIsRoot = !InArgs._TreeItem->Parent.IsValid();
  53. bool bIsLoading = !InArgs._TreeItem->bLoading;
  54. #if ECB_WIP_FOLDER_ICONS
  55. if (bIsRoot)
  56. {
  57. if (ExtContentBrowserUtils::ECBFolderCategory::ProjectContent == ExtContentBrowserUtils::GetRootFolderCategory(InArgs._TreeItem->FolderPath))
  58. {
  59. FolderType = EFolderType::Project;
  60. }
  61. else if (ExtContentBrowserUtils::ECBFolderCategory::VaultCacheContent == ExtContentBrowserUtils::GetRootFolderCategory(InArgs._TreeItem->FolderPath))
  62. {
  63. FolderType = EFolderType::VaultCache;
  64. }
  65. else if (ExtContentBrowserUtils::ECBFolderCategory::PluginContent == ExtContentBrowserUtils::GetRootFolderCategory(InArgs._TreeItem->FolderPath))
  66. {
  67. FolderType = EFolderType::Plugin;
  68. }
  69. }
  70. #endif
  71. ChildSlot
  72. [
  73. SNew(SBorder)
  74. .BorderImage(this, &SExtAssetTreeItem::GetBorderImage)
  75. .Padding( FMargin( 0, bIsRoot ? 3 : 0, 0, 0 ) ) // For root items in the tree, give them a little breathing room on the top
  76. [
  77. SNew(SHorizontalBox)
  78. #if ECB_LEGACY
  79. +SHorizontalBox::Slot()
  80. .AutoWidth()
  81. .Padding(0, 0, 2, 0)
  82. .VAlign(VAlign_Center)
  83. [
  84. // Folder Icon
  85. SNew(SImage)
  86. .Image(this, &SExtAssetTreeItem::GetFolderIcon)
  87. .ColorAndOpacity(this, &SExtAssetTreeItem::GetFolderColor)
  88. ]
  89. #endif
  90. + SHorizontalBox::Slot()
  91. .AutoWidth()
  92. .Padding(0, 0, 2, 0)
  93. .VAlign(VAlign_Center)
  94. [
  95. SNew(SHorizontalBox)
  96. // Loading Indicator
  97. + SHorizontalBox::Slot().Padding(0)
  98. [
  99. SNew(SSpinningImage)
  100. .Image(FExtContentBrowserStyle::Get().GetBrush("UAssetBrowser.Rotation16px"))
  101. .Visibility(this, &SExtAssetTreeItem::GetLoadingIndicatorVisibility)
  102. ]
  103. // Folder Icon
  104. + SHorizontalBox::Slot().Padding(0)
  105. [
  106. SNew(SImage)
  107. .Image(this, &SExtAssetTreeItem::GetFolderIcon)
  108. .Visibility(this, &SExtAssetTreeItem::GetFolderIconVisibility)
  109. .ColorAndOpacity(this, &SExtAssetTreeItem::GetFolderColor)
  110. ]
  111. ]
  112. +SHorizontalBox::Slot()
  113. .AutoWidth()
  114. .VAlign(VAlign_Center)
  115. [
  116. SAssignNew(InlineRenameWidget, SInlineEditableTextBlock)
  117. .Text(this, &SExtAssetTreeItem::GetNameText)
  118. .ToolTipText(this, &SExtAssetTreeItem::GetToolTipText)
  119. .Font( InArgs._FontOverride.IsSet() ? InArgs._FontOverride : FExtContentBrowserStyle::GetFontStyle(bIsRoot ? "UAssetBrowser.SourceTreeRootItemFont" : "UAssetBrowser.SourceTreeItemFont") )
  120. .HighlightText( InArgs._HighlightText )
  121. .OnTextCommitted(this, &SExtAssetTreeItem::HandleNameCommitted)
  122. .OnVerifyTextChanged(this, &SExtAssetTreeItem::VerifyNameChanged)
  123. .IsSelected( InArgs._IsSelected )
  124. .IsReadOnly( this, &SExtAssetTreeItem::IsReadOnly )
  125. .ColorAndOpacity(this, &SExtAssetTreeItem::GetTreeItemColor)
  126. ]
  127. + SHorizontalBox::Slot()
  128. .AutoWidth()
  129. .VAlign(VAlign_Center)
  130. .Padding(5, 0, 0, 0)
  131. [
  132. SNew(STextBlock)
  133. .TextStyle(FExtContentBrowserStyle::Get(), "UAssetBrowser.SourceTreeRootItem.Loading")
  134. .Text(this, &SExtAssetTreeItem::GetStatusText)
  135. .ColorAndOpacity(this, &SExtAssetTreeItem::GetTreeItemColor)
  136. .Visibility(this, &SExtAssetTreeItem::GetStatusTextVisibility)
  137. ]
  138. #if ECB_LEGACY
  139. // Loading indicator
  140. + SHorizontalBox::Slot()
  141. .AutoWidth()
  142. .VAlign(VAlign_Center)
  143. [
  144. SNew(SBox)
  145. .Padding(FMargin(2.f, 0.0f, 0.0f, 0.0f))
  146. [
  147. SNew(SSpinningImage)
  148. .Image(FExtContentBrowserStyle::Get().GetBrush("UAssetBrowser.Rotation16px"))
  149. .Visibility(this, &SExtAssetTreeItem::GetLoadIndicatorVisibility)
  150. ]
  151. ]
  152. + SHorizontalBox::Slot()
  153. .AutoWidth()
  154. .VAlign(VAlign_Center)
  155. [
  156. SNew(SBox)
  157. .Padding(FMargin(2.f, 5.0f, 0.0f, 0.0f))
  158. [
  159. SNew(SThrobber)
  160. .Animate(SThrobber::Opacity)
  161. ]
  162. ]
  163. #endif
  164. ]
  165. ];
  166. if( InlineRenameWidget.IsValid() )
  167. {
  168. EnterEditingModeDelegateHandle = TreeItem.Pin()->OnRenamedRequestEvent.AddSP( InlineRenameWidget.Get(), &SInlineEditableTextBlock::EnterEditingMode );
  169. }
  170. }
  171. SExtAssetTreeItem::~SExtAssetTreeItem()
  172. {
  173. if( InlineRenameWidget.IsValid() )
  174. {
  175. TreeItem.Pin()->OnRenamedRequestEvent.Remove( EnterEditingModeDelegateHandle );
  176. }
  177. }
  178. bool SExtAssetTreeItem::ValidateDragDrop( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent, bool& OutIsKnownDragOperation ) const
  179. {
  180. OutIsKnownDragOperation = false;
  181. TSharedPtr<FTreeItem> TreeItemPinned = TreeItem.Pin();
  182. return TreeItemPinned.IsValid() && DragDropHandler::ValidateDragDropOnAssetFolder(MyGeometry, DragDropEvent, TreeItemPinned->FolderPath, OutIsKnownDragOperation);
  183. }
  184. void SExtAssetTreeItem::OnDragEnter( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent )
  185. {
  186. ValidateDragDrop(MyGeometry, DragDropEvent, bDraggedOver); // updates bDraggedOver
  187. }
  188. void SExtAssetTreeItem::OnDragLeave( const FDragDropEvent& DragDropEvent )
  189. {
  190. TSharedPtr<FDragDropOperation> Operation = DragDropEvent.GetOperation();
  191. if (Operation.IsValid())
  192. {
  193. Operation->SetCursorOverride(TOptional<EMouseCursor::Type>());
  194. if (Operation->IsOfType<FAssetDragDropOp>())
  195. {
  196. TSharedPtr<FAssetDragDropOp> DragDropOp = StaticCastSharedPtr<FAssetDragDropOp>(Operation);
  197. DragDropOp->ResetToDefaultToolTip();
  198. }
  199. }
  200. bDraggedOver = false;
  201. }
  202. FReply SExtAssetTreeItem::OnDragOver( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent )
  203. {
  204. ValidateDragDrop(MyGeometry, DragDropEvent, bDraggedOver); // updates bDraggedOver
  205. return (bDraggedOver) ? FReply::Handled() : FReply::Unhandled();
  206. }
  207. FReply SExtAssetTreeItem::OnDrop( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent )
  208. {
  209. if (ValidateDragDrop(MyGeometry, DragDropEvent, bDraggedOver)) // updates bDraggedOver
  210. {
  211. bDraggedOver = false;
  212. TSharedPtr<FDragDropOperation> Operation = DragDropEvent.GetOperation();
  213. if (!Operation.IsValid())
  214. {
  215. return FReply::Unhandled();
  216. }
  217. if (Operation->IsOfType<FAssetDragDropOp>())
  218. {
  219. TSharedPtr<FAssetDragDropOp> DragDropOp = StaticCastSharedPtr<FAssetDragDropOp>( DragDropEvent.GetOperation() );
  220. OnAssetsOrPathsDragDropped.ExecuteIfBound(DragDropOp->GetAssets(), DragDropOp->GetAssetPaths(), TreeItem.Pin());
  221. return FReply::Handled();
  222. }
  223. if (Operation->IsOfType<FExternalDragOperation>())
  224. {
  225. TSharedPtr<FExternalDragOperation> DragDropOp = StaticCastSharedPtr<FExternalDragOperation>( DragDropEvent.GetOperation() );
  226. OnFilesDragDropped.ExecuteIfBound(DragDropOp->GetFiles(), TreeItem.Pin());
  227. return FReply::Handled();
  228. }
  229. }
  230. if (bDraggedOver)
  231. {
  232. // 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
  233. bDraggedOver = false;
  234. return FReply::Handled();
  235. }
  236. return FReply::Unhandled();
  237. }
  238. void SExtAssetTreeItem::Tick( const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime )
  239. {
  240. LastGeometry = AllottedGeometry;
  241. }
  242. bool SExtAssetTreeItem::VerifyNameChanged(const FText& InName, FText& OutError) const
  243. {
  244. if ( TreeItem.IsValid() )
  245. {
  246. TSharedPtr<FTreeItem> TreeItemPtr = TreeItem.Pin();
  247. if(OnVerifyNameChanged.IsBound())
  248. {
  249. return OnVerifyNameChanged.Execute(InName.ToString(), OutError, TreeItemPtr->FolderPath);
  250. }
  251. }
  252. return true;
  253. }
  254. void SExtAssetTreeItem::HandleNameCommitted( const FText& NewText, ETextCommit::Type CommitInfo )
  255. {
  256. if ( TreeItem.IsValid() )
  257. {
  258. TSharedPtr<FTreeItem> TreeItemPtr = TreeItem.Pin();
  259. if ( TreeItemPtr->bNamingFolder )
  260. {
  261. TreeItemPtr->bNamingFolder = false;
  262. const FString OldPath = TreeItemPtr->FolderPath;
  263. FString Path;
  264. TreeItemPtr->FolderPath.Split(TEXT("/"), &Path, NULL, ESearchCase::CaseSensitive, ESearchDir::FromEnd);
  265. TreeItemPtr->DisplayName = NewText;
  266. TreeItemPtr->FolderName = NewText.ToString();
  267. TreeItemPtr->FolderPath = Path + TEXT("/") + NewText.ToString();
  268. FVector2D MessageLoc;
  269. MessageLoc.X = LastGeometry.AbsolutePosition.X;
  270. MessageLoc.Y = LastGeometry.AbsolutePosition.Y + LastGeometry.Size.Y * LastGeometry.Scale;
  271. OnNameChanged.ExecuteIfBound(TreeItemPtr, OldPath, MessageLoc, CommitInfo);
  272. }
  273. }
  274. }
  275. bool SExtAssetTreeItem::IsReadOnly() const
  276. {
  277. if ( TreeItem.IsValid() )
  278. {
  279. return !TreeItem.Pin()->bNamingFolder;
  280. }
  281. else
  282. {
  283. return true;
  284. }
  285. }
  286. bool SExtAssetTreeItem::IsValidAssetPath() const
  287. {
  288. if ( TreeItem.IsValid() )
  289. {
  290. // The classes folder is not a real path
  291. return !ExtContentBrowserUtils::IsClassPath(TreeItem.Pin()->FolderPath);
  292. }
  293. else
  294. {
  295. return false;
  296. }
  297. }
  298. const FSlateBrush* SExtAssetTreeItem::GetFolderIcon() const
  299. {
  300. switch( FolderType )
  301. {
  302. case EFolderType::Code:
  303. return ( IsItemExpanded.Get() ) ? FolderOpenCodeBrush : FolderClosedCodeBrush;
  304. case EFolderType::Developer:
  305. return FolderDeveloperBrush;
  306. case EFolderType::Plugin:
  307. return (IsItemExpanded.Get()) ? FolderOpenPluginBrush : FolderClosedPluginBrush;
  308. case EFolderType::Project:
  309. return (IsItemExpanded.Get()) ? FolderOpenProjectBrush : FolderClosedProjectBrush;
  310. case EFolderType::VaultCache:
  311. return (IsItemExpanded.Get()) ? FolderOpenVaultCacheBrush : FolderClosedVaultCacheBrush;
  312. default:
  313. return ( IsItemExpanded.Get() ) ? FolderOpenBrush : FolderClosedBrush;
  314. }
  315. }
  316. FSlateColor SExtAssetTreeItem::GetFolderColor() const
  317. {
  318. if ( TreeItem.IsValid() )
  319. {
  320. #if ECB_LEGACY
  321. const TSharedPtr<FLinearColor> Color = ExtContentBrowserUtils::LoadColor( TreeItem.Pin()->FolderPath );
  322. if ( Color.IsValid() )
  323. {
  324. return *Color.Get();
  325. }
  326. #endif
  327. FLinearColor FolderColor;
  328. if (ExtContentBrowserUtils::LoadFolderColor(TreeItem.Pin()->FolderPath, FolderColor))
  329. {
  330. return FolderColor;
  331. }
  332. }
  333. return ExtContentBrowserUtils::GetDefaultColor();
  334. }
  335. FText SExtAssetTreeItem::GetNameText() const
  336. {
  337. TSharedPtr<FTreeItem> TreeItemPin = TreeItem.Pin();
  338. if ( TreeItemPin.IsValid() )
  339. {
  340. return TreeItemPin->DisplayName;
  341. }
  342. else
  343. {
  344. return FText();
  345. }
  346. }
  347. FText SExtAssetTreeItem::GetStatusText() const
  348. {
  349. TSharedPtr<FTreeItem> TreeItemPin = TreeItem.Pin();
  350. if (TreeItemPin.IsValid() && TreeItemPin->bLoading && !TreeItemPin->LoadingStatus.IsEmpty())
  351. {
  352. return FText::FromString(FString::Printf(TEXT("%s"), *TreeItemPin->LoadingStatus));
  353. }
  354. else
  355. {
  356. return FText();
  357. }
  358. }
  359. EVisibility SExtAssetTreeItem::GetStatusTextVisibility() const
  360. {
  361. TSharedPtr<FTreeItem> TreeItemPin = TreeItem.Pin();
  362. if (TreeItemPin.IsValid() && TreeItemPin->bLoading && !TreeItemPin->LoadingStatus.IsEmpty())
  363. {
  364. return EVisibility::Visible;
  365. }
  366. else
  367. {
  368. return EVisibility::Collapsed;
  369. }
  370. }
  371. FText SExtAssetTreeItem::GetToolTipText() const
  372. {
  373. TSharedPtr<FTreeItem> TreeItemPin = TreeItem.Pin();
  374. if ( TreeItemPin.IsValid() )
  375. {
  376. return FText::FromString(TreeItemPin->FolderPath);
  377. }
  378. else
  379. {
  380. return FText();
  381. }
  382. }
  383. const FSlateBrush* SExtAssetTreeItem::GetBorderImage() const
  384. {
  385. return bDraggedOver ? FAppStyle::GetBrush("Menu.Background") : FAppStyle::GetBrush("NoBorder");
  386. }
  387. EVisibility SExtAssetTreeItem::GetLoadingIndicatorVisibility() const
  388. {
  389. TSharedPtr<FTreeItem> TreeItemPin = TreeItem.Pin();
  390. if (TreeItemPin->bLoading)
  391. {
  392. return EVisibility::Visible;
  393. }
  394. return EVisibility::Collapsed;
  395. }
  396. EVisibility SExtAssetTreeItem::GetFolderIconVisibility() const
  397. {
  398. TSharedPtr<FTreeItem> TreeItemPin = TreeItem.Pin();
  399. if (TreeItemPin->bLoading)
  400. {
  401. return EVisibility::Collapsed;
  402. }
  403. return EVisibility::Visible;
  404. }
  405. FSlateColor SExtAssetTreeItem::GetTreeItemColor() const
  406. {
  407. bool bIsRootLoading = false;
  408. TSharedPtr<FTreeItem> TreeItemPin = TreeItem.Pin();
  409. if (TreeItemPin.IsValid() && !TreeItemPin->Parent.IsValid() && TreeItemPin->bLoading)
  410. {
  411. //return FLinearColor::Gray;
  412. return FSlateColor::UseSubduedForeground();
  413. }
  414. return FSlateColor::UseForeground();
  415. }
  416. #if ECB_WIP_COLLECTION
  417. //////////////////////////
  418. // SCollectionTreeItem
  419. //////////////////////////
  420. void SCollectionTreeItem::Construct( const FArguments& InArgs )
  421. {
  422. ParentWidget = InArgs._ParentWidget;
  423. CollectionItem = InArgs._CollectionItem;
  424. OnBeginNameChange = InArgs._OnBeginNameChange;
  425. OnNameChangeCommit = InArgs._OnNameChangeCommit;
  426. OnVerifyRenameCommit = InArgs._OnVerifyRenameCommit;
  427. OnValidateDragDrop = InArgs._OnValidateDragDrop;
  428. OnHandleDragDrop = InArgs._OnHandleDragDrop;
  429. bDraggedOver = false;
  430. ChildSlot
  431. [
  432. SNew(SBorder)
  433. .BorderImage(this, &SCollectionTreeItem::GetBorderImage)
  434. .Padding(0)
  435. [
  436. SNew(SHorizontalBox)
  437. +SHorizontalBox::Slot()
  438. .AutoWidth()
  439. .VAlign(VAlign_Center)
  440. .Padding(0, 0, 2, 0)
  441. [
  442. SNew(SCheckBox)
  443. .Visibility( InArgs._IsCollectionChecked.IsSet() ? EVisibility::Visible : EVisibility::Collapsed )
  444. .IsEnabled( InArgs._IsCheckBoxEnabled )
  445. .IsChecked( InArgs._IsCollectionChecked )
  446. .OnCheckStateChanged( InArgs._OnCollectionCheckStateChanged )
  447. ]
  448. +SHorizontalBox::Slot()
  449. .AutoWidth()
  450. .VAlign(VAlign_Center)
  451. .Padding(0, 0, 2, 0)
  452. [
  453. // Share Type Icon
  454. SNew(SImage)
  455. .Image( FAppStyle::GetBrush( ECollectionShareType::GetIconStyleName(InArgs._CollectionItem->CollectionType) ) )
  456. .ColorAndOpacity( this, &SCollectionTreeItem::GetCollectionColor )
  457. .ToolTipText(ECollectionShareType::GetDescription(InArgs._CollectionItem->CollectionType))
  458. ]
  459. +SHorizontalBox::Slot()
  460. [
  461. SAssignNew(InlineRenameWidget, SInlineEditableTextBlock)
  462. .Text( this, &SCollectionTreeItem::GetNameText )
  463. .HighlightText( InArgs._HighlightText )
  464. .Font( FAppStyle::GetFontStyle("ContentBrowser.SourceListItemFont") )
  465. .OnBeginTextEdit(this, &SCollectionTreeItem::HandleBeginNameChange)
  466. .OnTextCommitted(this, &SCollectionTreeItem::HandleNameCommitted)
  467. .OnVerifyTextChanged(this, &SCollectionTreeItem::HandleVerifyNameChanged)
  468. .IsSelected( InArgs._IsSelected )
  469. .IsReadOnly( InArgs._IsReadOnly )
  470. ]
  471. +SHorizontalBox::Slot()
  472. .AutoWidth()
  473. .Padding(2, 0, 3, 0)
  474. [
  475. // Storage Mode Icon
  476. SNew(SBox)
  477. .WidthOverride(16)
  478. .HeightOverride(16)
  479. .VAlign(VAlign_Center)
  480. .HAlign(HAlign_Center)
  481. [
  482. SNew(STextBlock)
  483. .Font(FAppStyle::Get().GetFontStyle("FontAwesome.10"))
  484. .Text(this, &SCollectionTreeItem::GetCollectionStorageModeIconText)
  485. .ColorAndOpacity(FLinearColor::Gray)
  486. .ToolTipText(this, &SCollectionTreeItem::GetCollectionStorageModeToolTipText)
  487. ]
  488. ]
  489. +SHorizontalBox::Slot()
  490. .AutoWidth()
  491. .VAlign(VAlign_Center)
  492. .Padding(2, 0, 2, 0)
  493. [
  494. SNew(SImage)
  495. .Image(FAppStyle::GetBrush("ContentBrowser.CollectionStatus"))
  496. .ColorAndOpacity(this, &SCollectionTreeItem::GetCollectionStatusColor)
  497. .ToolTipText(this, &SCollectionTreeItem::GetCollectionStatusToolTipText)
  498. ]
  499. ]
  500. ];
  501. if(InlineRenameWidget.IsValid())
  502. {
  503. // This is broadcast when the context menu / input binding requests a rename
  504. EnterEditingModeDelegateHandle = CollectionItem.Pin()->OnRenamedRequestEvent.AddSP(InlineRenameWidget.Get(), &SInlineEditableTextBlock::EnterEditingMode);
  505. }
  506. }
  507. SCollectionTreeItem::~SCollectionTreeItem()
  508. {
  509. if(InlineRenameWidget.IsValid())
  510. {
  511. CollectionItem.Pin()->OnRenamedRequestEvent.Remove( EnterEditingModeDelegateHandle );
  512. }
  513. }
  514. void SCollectionTreeItem::Tick( const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime )
  515. {
  516. // Cache this widget's geometry so it can pop up warnings over itself
  517. CachedGeometry = AllottedGeometry;
  518. }
  519. bool SCollectionTreeItem::ValidateDragDrop( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent, bool& OutIsKnownDragOperation ) const
  520. {
  521. OutIsKnownDragOperation = false;
  522. TSharedPtr<FCollectionItem> CollectionItemPtr = CollectionItem.Pin();
  523. if (OnValidateDragDrop.IsBound() && CollectionItemPtr.IsValid())
  524. {
  525. return OnValidateDragDrop.Execute( CollectionItemPtr.ToSharedRef(), MyGeometry, DragDropEvent, OutIsKnownDragOperation );
  526. }
  527. return false;
  528. }
  529. void SCollectionTreeItem::OnDragEnter( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent )
  530. {
  531. ValidateDragDrop(MyGeometry, DragDropEvent, bDraggedOver); // updates bDraggedOver
  532. }
  533. void SCollectionTreeItem::OnDragLeave( const FDragDropEvent& DragDropEvent )
  534. {
  535. TSharedPtr<FDragDropOperation> Operation = DragDropEvent.GetOperation();
  536. if (Operation.IsValid())
  537. {
  538. Operation->SetCursorOverride(TOptional<EMouseCursor::Type>());
  539. if (Operation->IsOfType<FCollectionDragDropOp>() || Operation->IsOfType<FAssetDragDropOp>())
  540. {
  541. TSharedPtr<FDecoratedDragDropOp> DragDropOp = StaticCastSharedPtr<FDecoratedDragDropOp>(Operation);
  542. DragDropOp->ResetToDefaultToolTip();
  543. }
  544. }
  545. bDraggedOver = false;
  546. }
  547. FReply SCollectionTreeItem::OnDragOver( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent )
  548. {
  549. ValidateDragDrop(MyGeometry, DragDropEvent, bDraggedOver); // updates bDraggedOver
  550. return (bDraggedOver) ? FReply::Handled() : FReply::Unhandled();
  551. }
  552. FReply SCollectionTreeItem::OnDrop( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent )
  553. {
  554. if (ValidateDragDrop(MyGeometry, DragDropEvent, bDraggedOver) && OnHandleDragDrop.IsBound()) // updates bDraggedOver
  555. {
  556. bDraggedOver = false;
  557. return OnHandleDragDrop.Execute( CollectionItem.Pin().ToSharedRef(), MyGeometry, DragDropEvent );
  558. }
  559. if (bDraggedOver)
  560. {
  561. // 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
  562. bDraggedOver = false;
  563. return FReply::Handled();
  564. }
  565. return FReply::Unhandled();
  566. }
  567. void SCollectionTreeItem::HandleBeginNameChange( const FText& OldText )
  568. {
  569. TSharedPtr<FCollectionItem> CollectionItemPtr = CollectionItem.Pin();
  570. if ( CollectionItemPtr.IsValid() )
  571. {
  572. // If we get here via a context menu or input binding, bRenaming will already be set on the item.
  573. // If we got here by double clicking the editable text field, we need to set it now.
  574. CollectionItemPtr->bRenaming = true;
  575. OnBeginNameChange.ExecuteIfBound( CollectionItemPtr );
  576. }
  577. }
  578. void SCollectionTreeItem::HandleNameCommitted( const FText& NewText, ETextCommit::Type CommitInfo )
  579. {
  580. TSharedPtr<FCollectionItem> CollectionItemPtr = CollectionItem.Pin();
  581. if ( CollectionItemPtr.IsValid() )
  582. {
  583. if ( CollectionItemPtr->bRenaming )
  584. {
  585. CollectionItemPtr->bRenaming = false;
  586. if ( OnNameChangeCommit.IsBound() )
  587. {
  588. FText WarningMessage;
  589. bool bIsCommitted = (CommitInfo != ETextCommit::OnCleared);
  590. if ( !OnNameChangeCommit.Execute(CollectionItemPtr, NewText.ToString(), bIsCommitted, WarningMessage) && ParentWidget.IsValid() && bIsCommitted )
  591. {
  592. // Failed to rename/create a collection, display a warning.
  593. ContentBrowserUtils::DisplayMessage(WarningMessage, CachedGeometry.GetLayoutBoundingRect(), ParentWidget.ToSharedRef());
  594. }
  595. }
  596. }
  597. }
  598. }
  599. bool SCollectionTreeItem::HandleVerifyNameChanged( const FText& NewText, FText& OutErrorMessage )
  600. {
  601. TSharedPtr<FCollectionItem> CollectionItemPtr = CollectionItem.Pin();
  602. if (CollectionItemPtr.IsValid())
  603. {
  604. return !OnVerifyRenameCommit.IsBound() || OnVerifyRenameCommit.Execute(CollectionItemPtr, NewText.ToString(), CachedGeometry.GetLayoutBoundingRect(), OutErrorMessage);
  605. }
  606. return true;
  607. }
  608. FText SCollectionTreeItem::GetNameText() const
  609. {
  610. TSharedPtr<FCollectionItem> CollectionItemPtr = CollectionItem.Pin();
  611. if ( CollectionItemPtr.IsValid() )
  612. {
  613. return FText::FromName(CollectionItemPtr->CollectionName);
  614. }
  615. else
  616. {
  617. return FText();
  618. }
  619. }
  620. FSlateColor SCollectionTreeItem::GetCollectionColor() const
  621. {
  622. TSharedPtr<FCollectionItem> CollectionItemPtr = CollectionItem.Pin();
  623. if ( CollectionItemPtr.IsValid() )
  624. {
  625. const TSharedPtr<FLinearColor> Color = CollectionViewUtils::LoadColor(CollectionItemPtr->CollectionName.ToString(), CollectionItemPtr->CollectionType);
  626. if( Color.IsValid() )
  627. {
  628. return *Color.Get();
  629. }
  630. }
  631. return CollectionViewUtils::GetDefaultColor();
  632. }
  633. const FSlateBrush* SCollectionTreeItem::GetBorderImage() const
  634. {
  635. return bDraggedOver ? FAppStyle::GetBrush("Menu.Background") : FAppStyle::GetBrush("NoBorder");
  636. }
  637. FText SCollectionTreeItem::GetCollectionStorageModeIconText() const
  638. {
  639. TSharedPtr<FCollectionItem> CollectionItemPtr = CollectionItem.Pin();
  640. if (CollectionItemPtr.IsValid())
  641. {
  642. switch(CollectionItemPtr->StorageMode)
  643. {
  644. case ECollectionStorageMode::Static:
  645. return FEditorFontGlyphs::List_Alt;
  646. case ECollectionStorageMode::Dynamic:
  647. return FEditorFontGlyphs::Bolt;
  648. default:
  649. break;
  650. }
  651. }
  652. return FText::GetEmpty();
  653. }
  654. FText SCollectionTreeItem::GetCollectionStorageModeToolTipText() const
  655. {
  656. TSharedPtr<FCollectionItem> CollectionItemPtr = CollectionItem.Pin();
  657. if (CollectionItemPtr.IsValid())
  658. {
  659. return ECollectionStorageMode::GetDescription(CollectionItemPtr->StorageMode);
  660. }
  661. return FText::GetEmpty();
  662. }
  663. FSlateColor SCollectionTreeItem::GetCollectionStatusColor() const
  664. {
  665. TSharedPtr<FCollectionItem> CollectionItemPtr = CollectionItem.Pin();
  666. if (CollectionItemPtr.IsValid())
  667. {
  668. switch(CollectionItemPtr->CurrentStatus)
  669. {
  670. case ECollectionItemStatus::IsUpToDateAndPopulated:
  671. return FLinearColor(0.10616, 0.48777, 0.10616); // Green
  672. case ECollectionItemStatus::IsUpToDateAndEmpty:
  673. return FLinearColor::Gray;
  674. case ECollectionItemStatus::IsOutOfDate:
  675. return FLinearColor(0.87514, 0.42591, 0.07383); // Orange
  676. case ECollectionItemStatus::IsCheckedOutByAnotherUser:
  677. case ECollectionItemStatus::IsConflicted:
  678. case ECollectionItemStatus::IsMissingSCCProvider:
  679. return FLinearColor(0.70117, 0.08464, 0.07593); // Red
  680. case ECollectionItemStatus::HasLocalChanges:
  681. return FLinearColor(0.10363, 0.53564, 0.7372); // Blue
  682. default:
  683. break;
  684. }
  685. }
  686. return FLinearColor::White;
  687. }
  688. FText SCollectionTreeItem::GetCollectionStatusToolTipText() const
  689. {
  690. TSharedPtr<FCollectionItem> CollectionItemPtr = CollectionItem.Pin();
  691. if (CollectionItemPtr.IsValid())
  692. {
  693. switch(CollectionItemPtr->CurrentStatus)
  694. {
  695. case ECollectionItemStatus::IsUpToDateAndPopulated:
  696. return LOCTEXT("CollectionStatus_IsUpToDateAndPopulated", "Collection is up-to-date");
  697. case ECollectionItemStatus::IsUpToDateAndEmpty:
  698. return LOCTEXT("CollectionStatus_IsUpToDateAndEmpty", "Collection is empty");
  699. case ECollectionItemStatus::IsOutOfDate:
  700. return LOCTEXT("CollectionStatus_IsOutOfDate", "Collection is not at the latest revision");
  701. case ECollectionItemStatus::IsCheckedOutByAnotherUser:
  702. return LOCTEXT("CollectionStatus_IsCheckedOutByAnotherUser", "Collection is checked out by another user");
  703. case ECollectionItemStatus::IsConflicted:
  704. return LOCTEXT("CollectionStatus_IsConflicted", "Collection is conflicted - please use your external source control provider to resolve this conflict");
  705. case ECollectionItemStatus::IsMissingSCCProvider:
  706. return LOCTEXT("CollectionStatus_IsMissingSCCProvider", "Collection is missing its source control provider - please check your source control settings");
  707. case ECollectionItemStatus::HasLocalChanges:
  708. return LOCTEXT("CollectionStatus_HasLocalChanges", "Collection has local unsaved or uncomitted changes");
  709. default:
  710. break;
  711. }
  712. }
  713. return FText::GetEmpty();
  714. }
  715. #endif
  716. #undef LOCTEXT_NAMESPACE