ExtSourcesViewWidgets.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. // Copyright 2017-2021 marynate. All Rights Reserved.
  2. #pragma once
  3. #include "SExtPathView.h"
  4. #include "CoreMinimal.h"
  5. #include "Misc/Attribute.h"
  6. #include "Layout/Visibility.h"
  7. #include "Widgets/DeclarativeSyntaxSupport.h"
  8. #include "Layout/Geometry.h"
  9. #include "Input/Reply.h"
  10. #include "Styling/SlateColor.h"
  11. #include "Widgets/SCompoundWidget.h"
  12. #include "AssetRegistry/AssetData.h"
  13. //#include "CollectionViewTypes.h"
  14. #include "Widgets/Input/SCheckBox.h"
  15. class SEditableTextBox;
  16. struct FTreeItem;
  17. /** A single item in the asset tree. Represents a folder. */
  18. class SExtAssetTreeItem : public SCompoundWidget
  19. {
  20. public:
  21. DECLARE_DELEGATE_FourParams( FOnNameChanged, const TSharedPtr<FTreeItem>& /*TreeItem*/, const FString& /*OldPath*/, const FVector2D& /*MessageLocation*/, const ETextCommit::Type /*CommitType*/);
  22. DECLARE_DELEGATE_RetVal_ThreeParams( bool, FOnVerifyNameChanged, const FString& /*InName*/, FText& /*OutErrorMessage*/, const FString& /*FolderPath*/);
  23. DECLARE_DELEGATE_ThreeParams( FOnAssetsOrPathsDragDropped, const TArray<FAssetData>& /*AssetList*/, const TArray<FString>& /*AssetPaths*/, const TSharedPtr<FTreeItem>& /*TreeItem*/);
  24. DECLARE_DELEGATE_TwoParams( FOnFilesDragDropped, const TArray<FString>& /*FileNames*/, const TSharedPtr<FTreeItem>& /*TreeItem*/);
  25. SLATE_BEGIN_ARGS( SExtAssetTreeItem )
  26. : _TreeItem( TSharedPtr<FTreeItem>() )
  27. , _IsItemExpanded( false )
  28. {}
  29. /** Data for the folder this item represents */
  30. SLATE_ARGUMENT( TSharedPtr<FTreeItem>, TreeItem )
  31. /** Delegate for when the user commits a new name to the folder */
  32. SLATE_EVENT( FOnNameChanged, OnNameChanged )
  33. /** Delegate for when the user is typing a new name for the folder */
  34. SLATE_EVENT( FOnVerifyNameChanged, OnVerifyNameChanged )
  35. /** Delegate for when assets or asset paths are dropped on this folder */
  36. SLATE_EVENT( FOnAssetsOrPathsDragDropped, OnAssetsOrPathsDragDropped )
  37. /** Delegate for when a list of files is dropped on this folder from an external source */
  38. SLATE_EVENT( FOnFilesDragDropped, OnFilesDragDropped )
  39. /** True when this item has children and is expanded */
  40. SLATE_ATTRIBUTE( bool, IsItemExpanded )
  41. /** The string in the title to highlight (used when searching folders) */
  42. SLATE_ATTRIBUTE( FText, HighlightText)
  43. SLATE_ATTRIBUTE( FSlateFontInfo, FontOverride)
  44. /** Callback to check if the widget is selected, should only be hooked up if parent widget is handling selection or focus. */
  45. SLATE_EVENT( FIsSelected, IsSelected )
  46. SLATE_END_ARGS()
  47. /** Constructs this widget with InArgs */
  48. void Construct( const FArguments& InArgs );
  49. ~SExtAssetTreeItem();
  50. virtual void OnDragEnter( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent ) override;
  51. virtual void OnDragLeave( const FDragDropEvent& DragDropEvent ) override;
  52. virtual FReply OnDragOver( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent ) override;
  53. virtual FReply OnDrop( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent ) override;
  54. virtual void Tick( const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime ) override;
  55. private:
  56. /** Used by OnDragEnter, OnDragOver, and OnDrop to check and update the validity of the drag operation */
  57. bool ValidateDragDrop( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent, bool& OutIsKnownDragOperation ) const;
  58. /** Handles verifying name changes */
  59. bool VerifyNameChanged(const FText& InName, FText& OutError) const;
  60. /** Handles committing a name change */
  61. void HandleNameCommitted( const FText& NewText, ETextCommit::Type /*CommitInfo*/ );
  62. /** Returns false if this folder is in the process of being created */
  63. bool IsReadOnly() const;
  64. /** Returns true if this folder is special and not a real path (like the Classes folder) */
  65. bool IsValidAssetPath() const;
  66. /** Gets the brush used to draw the folder icon */
  67. const FSlateBrush* GetFolderIcon() const;
  68. /** Gets the color used to draw the folder icon */
  69. FSlateColor GetFolderColor() const;
  70. /** Returns the text of the folder name */
  71. FText GetNameText() const;
  72. /** Returns the text of the current loading folder name */
  73. FText GetStatusText() const;
  74. EVisibility GetStatusTextVisibility() const;
  75. /** Returns the text to use for the folder tooltip */
  76. FText GetToolTipText() const;
  77. /** Returns the image for the border around this item. Used for drag/drop operations */
  78. const FSlateBrush* GetBorderImage() const;
  79. /** Returns the visibility of the editable folder name */
  80. EVisibility GetEditableTextVisibility() const;
  81. /** Returns the visibility of the non-editable folder name */
  82. EVisibility GetStaticTextVisibility() const;
  83. private:
  84. enum class EFolderType : uint8
  85. {
  86. Normal,
  87. Code,
  88. Developer,
  89. Project,
  90. VaultCache,
  91. Plugin,
  92. };
  93. /** The data for this item */
  94. TWeakPtr<FTreeItem> TreeItem;
  95. /** The name of the asset as an editable text box */
  96. TSharedPtr<SEditableTextBox> EditableName;
  97. /** Delegate for when a list of assets or asset paths are dropped on this folder */
  98. FOnAssetsOrPathsDragDropped OnAssetsOrPathsDragDropped;
  99. /** Delegate for when a list of files is dropped on this folder from an external source */
  100. FOnFilesDragDropped OnFilesDragDropped;
  101. /** Delegate for when the user commits a new name to the folder */
  102. FOnNameChanged OnNameChanged;
  103. /** Delegate for when a user is typing a name for the folder */
  104. FOnVerifyNameChanged OnVerifyNameChanged;
  105. /** True when this item has children and is expanded */
  106. TAttribute<bool> IsItemExpanded;
  107. /** The geometry last frame. Used when telling popup messages where to appear. */
  108. FGeometry LastGeometry;
  109. /** Brushes for the different folder states */
  110. const FSlateBrush* FolderOpenBrush;
  111. const FSlateBrush* FolderClosedBrush;
  112. const FSlateBrush* FolderOpenCodeBrush;
  113. const FSlateBrush* FolderClosedCodeBrush;
  114. const FSlateBrush* FolderDeveloperBrush;
  115. const FSlateBrush* FolderClosedPluginBrush;
  116. const FSlateBrush* FolderOpenPluginBrush;
  117. const FSlateBrush* FolderClosedProjectBrush;
  118. const FSlateBrush* FolderOpenProjectBrush;
  119. const FSlateBrush* FolderClosedVaultCacheBrush;
  120. const FSlateBrush* FolderOpenVaultCacheBrush;
  121. /** True when a drag is over this item with a drag operation that we know how to handle. The operation itself may not be valid to drop. */
  122. bool bDraggedOver;
  123. /** What type of stuff does this folder hold */
  124. EFolderType FolderType;
  125. /** Widget to display the name of the asset item and allows for renaming */
  126. TSharedPtr< SInlineEditableTextBlock > InlineRenameWidget;
  127. /** Handle to the registered EnterEditingMode delegate. */
  128. FDelegateHandle EnterEditingModeDelegateHandle;
  129. EVisibility GetLoadingIndicatorVisibility() const;
  130. EVisibility GetFolderIconVisibility() const;
  131. FSlateColor GetTreeItemColor() const;
  132. };
  133. #if ECB_WIP_COLLECTION
  134. /** A single item in the collection tree. */
  135. class SCollectionTreeItem : public SCompoundWidget
  136. {
  137. public:
  138. /** Delegates for when a collection is renamed. If returning false, OutWarningMessage will be displayed over the collection. */
  139. DECLARE_DELEGATE_OneParam( FOnBeginNameChange, const TSharedPtr<FCollectionItem>& /*Item*/);
  140. DECLARE_DELEGATE_RetVal_FourParams( bool, FOnNameChangeCommit, const TSharedPtr<FCollectionItem>& /*Item*/, const FString& /*NewName*/, bool /*bChangeConfirmed*/, FText& /*OutWarningMessage*/);
  141. DECLARE_DELEGATE_RetVal_FourParams( bool, FOnVerifyRenameCommit, const TSharedPtr<FCollectionItem>& /*Item*/, const FString& /*NewName*/, const FSlateRect& /*MessageAnchor*/, FText& /*OutErrorMessage*/)
  142. /** Delegates for when a collection item has something dropped into it */
  143. DECLARE_DELEGATE_RetVal_FourParams( bool, FOnValidateDragDrop, TSharedRef<FCollectionItem> /*CollectionItem*/, const FGeometry& /*Geometry*/, const FDragDropEvent& /*DragDropEvent*/, bool& /*OutIsKnownDragOperation*/ );
  144. DECLARE_DELEGATE_RetVal_ThreeParams( FReply, FOnHandleDragDrop, TSharedRef<FCollectionItem> /*CollectionItem*/, const FGeometry& /*Geometry*/, const FDragDropEvent& /*DragDropEvent*/ );
  145. SLATE_BEGIN_ARGS( SCollectionTreeItem )
  146. : _CollectionItem( TSharedPtr<FCollectionItem>() )
  147. , _ParentWidget()
  148. {}
  149. /** Data for the collection this item represents */
  150. SLATE_ARGUMENT( TSharedPtr<FCollectionItem>, CollectionItem )
  151. /** The parent widget */
  152. SLATE_ARGUMENT( TSharedPtr<SWidget>, ParentWidget )
  153. /** Delegate for when the user begins to rename the item */
  154. SLATE_EVENT( FOnBeginNameChange, OnBeginNameChange )
  155. /** Delegate for when the user commits a new name to the folder */
  156. SLATE_EVENT( FOnNameChangeCommit, OnNameChangeCommit )
  157. /** Delegate for when a collection name has been entered for an item to verify the name before commit */
  158. SLATE_EVENT( FOnVerifyRenameCommit, OnVerifyRenameCommit )
  159. /** Delegate to validate a drag drop operation on this collection item */
  160. SLATE_EVENT( FOnValidateDragDrop, OnValidateDragDrop )
  161. /** Delegate to handle a drag drop operation on this collection item */
  162. SLATE_EVENT( FOnHandleDragDrop, OnHandleDragDrop )
  163. /** Callback to check if the widget is selected, should only be hooked up if parent widget is handling selection or focus. */
  164. SLATE_EVENT( FIsSelected, IsSelected )
  165. /** True if the item is read-only. It will not be able to be renamed if read-only */
  166. SLATE_ATTRIBUTE( bool, IsReadOnly )
  167. /** Text to highlight for this item */
  168. SLATE_ATTRIBUTE( FText, HighlightText )
  169. /** True if the check box of the collection item is enabled */
  170. SLATE_ATTRIBUTE( bool, IsCheckBoxEnabled )
  171. /** Whether the check box of the collection item is currently in a checked state (if unset, no check box will be shown) */
  172. SLATE_ATTRIBUTE( ECheckBoxState, IsCollectionChecked )
  173. /** Delegate for when the checked state of the collection item check box is changed */
  174. SLATE_EVENT( FOnCheckStateChanged, OnCollectionCheckStateChanged )
  175. SLATE_END_ARGS()
  176. /** Constructs this widget with InArgs */
  177. void Construct( const FArguments& InArgs );
  178. ~SCollectionTreeItem();
  179. virtual void Tick( const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime ) override;
  180. virtual void OnDragEnter( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent ) override;
  181. virtual void OnDragLeave( const FDragDropEvent& DragDropEvent ) override;
  182. virtual FReply OnDragOver( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent ) override;
  183. virtual FReply OnDrop( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent ) override;
  184. private:
  185. /** Used by OnDragEnter, OnDragOver, and OnDrop to check and update the validity of the drag operation */
  186. bool ValidateDragDrop( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent, bool& OutIsKnownDragOperation ) const;
  187. /** Handles beginning a name change */
  188. void HandleBeginNameChange( const FText& OldText );
  189. /** Handles committing a name change */
  190. void HandleNameCommitted( const FText& NewText, ETextCommit::Type CommitInfo );
  191. /** Handles verifying a name change */
  192. bool HandleVerifyNameChanged( const FText& NewText, FText& OutErrorMessage );
  193. /** Returns the text of the collection name */
  194. FText GetNameText() const;
  195. /** Returns the color of the collection name */
  196. FSlateColor GetCollectionColor() const;
  197. /** Returns the image for the border around this item. Used for drag/drop operations */
  198. const FSlateBrush* GetBorderImage() const;
  199. /** Get the FontAwesome icon corresponding to the current collection storage mode */
  200. FText GetCollectionStorageModeIconText() const;
  201. /** Get the tooltip corresponding to the current collection storage mode */
  202. FText GetCollectionStorageModeToolTipText() const;
  203. /** Get the color to use for the collection item status */
  204. FSlateColor GetCollectionStatusColor() const;
  205. /** Get the tooltip corresponding to the current collection item status */
  206. FText GetCollectionStatusToolTipText() const;
  207. private:
  208. /** A shared pointer to the parent widget. */
  209. TSharedPtr<SWidget> ParentWidget;
  210. /** The data for this item */
  211. TWeakPtr<FCollectionItem> CollectionItem;
  212. /** The name of the asset as an editable text box */
  213. TSharedPtr<SEditableTextBox> EditableName;
  214. /** True when a drag is over this item with a drag operation that we know how to handle. The operation itself may not be valid to drop. */
  215. bool bDraggedOver;
  216. /** Delegate to validate a drag drop operation on this collection item */
  217. FOnValidateDragDrop OnValidateDragDrop;
  218. /** Delegate to handle a drag drop operation on this collection item */
  219. FOnHandleDragDrop OnHandleDragDrop;
  220. /** The geometry as of the last frame. Used to open warning messages over the item */
  221. FGeometry CachedGeometry;
  222. /** Delegate for when the user starts to rename an item */
  223. FOnBeginNameChange OnBeginNameChange;
  224. /** Delegate for when the user commits a new name to the collection */
  225. FOnNameChangeCommit OnNameChangeCommit;
  226. /** Delegate for when a collection name has been entered for an item to verify the name before commit */
  227. FOnVerifyRenameCommit OnVerifyRenameCommit;
  228. /** Widget to display the name of the collection item and allows for renaming */
  229. TSharedPtr< SInlineEditableTextBlock > InlineRenameWidget;
  230. /** Handle to the registered EnterEditingMode delegate. */
  231. FDelegateHandle EnterEditingModeDelegateHandle;
  232. };
  233. #endif