ExtContentBrowserUtils.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. // Copyright 2017-2021 marynate. All Rights Reserved.
  2. #pragma once
  3. #include "CoreMinimal.h"
  4. #include "Widgets/SWidget.h"
  5. #include "Framework/SlateDelegates.h"
  6. #include "AssetRegistry/AssetData.h"
  7. #include "CollectionManagerTypes.h"
  8. #include "Interfaces/IPluginManager.h"
  9. #include "ExtContentBrowser.h"
  10. struct FExtAssetData;
  11. class SExtAssetView;
  12. class SExtPathView;
  13. class FViewport;
  14. namespace ExtContentBrowserUtils
  15. {
  16. enum class ECBFolderCategory : uint8
  17. {
  18. GameContent,
  19. EngineContent,
  20. PluginContent,
  21. DeveloperContent,
  22. GameClasses,
  23. EngineClasses,
  24. PluginClasses,
  25. ProjectContent,
  26. VaultCacheContent,
  27. OrphanContent,
  28. };
  29. /** Loads the specified object if needed and opens the asset editor for it */
  30. bool OpenEditorForAsset(const FString& ObjectPath);
  31. /** Opens the asset editor for the specified asset */
  32. bool OpenEditorForAsset(UObject* Asset);
  33. /** Opens the asset editor for the specified assets */
  34. bool OpenEditorForAsset(const TArray<UObject*>& Assets);
  35. /**
  36. * Makes sure the specified assets are loaded into memory.
  37. *
  38. * @param ObjectPaths The paths to the objects to load.
  39. * @param LoadedObjects The returned list of objects that were already loaded or loaded by this method.
  40. * @return false if user canceled after being warned about loading very many packages.
  41. */
  42. bool LoadAssetsIfNeeded(const TArray<FString>& ObjectPaths, TArray<UObject*>& LoadedObjects, bool bAllowedToPromptToLoadAssets = true, bool bLoadRedirects = false);
  43. /**
  44. * Determines the unloaded assets that need loading
  45. *
  46. * @param ObjectPaths Paths to assets that may need to be loaded
  47. * @param OutUnloadedObjects List of the unloaded object paths
  48. * @return true if the user should be prompted to load assets
  49. */
  50. void GetUnloadedAssets(const TArray<FString>& ObjectPaths, TArray<FString>& OutUnloadedObjects);
  51. /**
  52. * Prompts the user to load the list of unloaded objects
  53. *
  54. * @param UnloadedObjects The list of unloaded objects that we should prompt for loading
  55. * @param true if the user allows the objects to be loaded
  56. */
  57. bool PromptToLoadAssets(const TArray<FString>& UnloadedObjects);
  58. /** Checks to see if the given folder can be renamed */
  59. bool CanRenameFolder(const FString& InFolderPath);
  60. /** Checks to see if the given asset can be renamed */
  61. bool CanRenameAsset(const FAssetData& InAssetData);
  62. /** Renames an asset */
  63. void RenameAsset(UObject* Asset, const FString& NewName, FText& ErrorMessage);
  64. /**
  65. * Copies assets to a new path
  66. * @param Assets The assets to copy
  67. * @param DestPath The destination folder in which to copy the assets
  68. */
  69. void CopyAssets(const TArray<UObject*>& Assets, const FString& DestPath);
  70. /**
  71. * Moves assets to a new path
  72. *
  73. * @param Assets The assets to move
  74. * @param DestPath The destination folder in which to move the assets
  75. * @param SourcePath If non-empty, this will specify the base folder which will cause the move to maintain folder structure
  76. */
  77. void MoveAssets(const TArray<UObject*>& Assets, const FString& DestPath, const FString& SourcePath = FString());
  78. /** Attempts to deletes the specified assets. Returns the number of assets deleted */
  79. int32 DeleteAssets(const TArray<UObject*>& AssetsToDelete);
  80. /** Attempts to delete the specified folders and all assets inside them. Returns true if the operation succeeded. */
  81. bool DeleteFolders(const TArray<FString>& PathsToDelete);
  82. /** Gets an array of assets inside the specified folders */
  83. void GetAssetsInPaths(const TArray<FString>& InPaths, TArray<FExtAssetData>& OutAssetDataList);
  84. /** Saves all the specified packages */
  85. bool SavePackages(const TArray<UPackage*>& Packages);
  86. /** Prompts to save all modified packages */
  87. bool SaveDirtyPackages();
  88. /** Loads all the specified packages */
  89. TArray<UPackage*> LoadPackages(const TArray<FString>& PackageNames);
  90. void NotifyMessage(const FText& Message, bool bAlsoPrintToSonle = false, float InDuration = 3.f);
  91. void NotifyMessage(const FString& Message, float InDuration = 3.f);
  92. void DisplayMessagePopup(const FText& Message);
  93. /** Displays a modeless message at the specified anchor. It is fine to specify a zero-size anchor, just use the top and left fields */
  94. void DisplayMessage(const FText& Message, const FSlateRect& ScreenAnchor, const TSharedRef<SWidget>& ParentContent);
  95. /** Displays a modeless message asking yes or no type question */
  96. void DisplayConfirmationPopup(const FText& Message, const FText& YesString, const FText& NoString, const TSharedRef<SWidget>& ParentContent, const FOnClicked& OnYesClicked, const FOnClicked& OnNoClicked = FOnClicked());
  97. #if ECB_LEGACY
  98. /** Moves all assets from the source path to the destination path, preserving path structure, deletes source path afterwards if possible */
  99. bool RenameFolder(const FString& DestPath, const FString& SourcePath);
  100. #endif
  101. /** Copies all assets in all source paths to the destination path, preserving path structure */
  102. bool CopyFolders(const TArray<FString>& InSourcePathNames, const FString& DestPath);
  103. #if ECB_LEGACY
  104. /** Moves all assets in all source paths to the destination path, preserving path structure */
  105. bool MoveFolders(const TArray<FString>& InSourcePathNames, const FString& DestPath);
  106. #endif
  107. /**
  108. * A helper function for folder drag/drop which loads all assets in a path (including sub-paths) and returns the assets found
  109. *
  110. * @param SourcePathNames The paths to the folders to drag/drop
  111. * @param OutSourcePathToLoadedAssets The map of source folder paths to assets found
  112. */
  113. bool PrepareFoldersForDragDrop(const TArray<FString>& SourcePathNames, TMap< FString, TArray<UObject*> >& OutSourcePathToLoadedAssets);
  114. /** Copies references to the specified assets to the clipboard */
  115. void CopyAssetReferencesToClipboard(const TArray<FAssetData>& AssetsToCopy);
  116. /** Copies file paths on disk to the specified assets to the clipboard */
  117. void CopyFilePathsToClipboard(const TArray<FExtAssetData>& AssetsToCopy);
  118. /**
  119. * Capture active viewport to thumbnail and assigns that thumbnail to incoming assets
  120. *
  121. * @param InViewport - viewport to sample from
  122. * @param InAssetsToAssign - assets that should receive the new thumbnail ONLY if they are assets that use GenericThumbnails
  123. */
  124. void CaptureThumbnailFromViewport(FViewport* InViewport, const TArray<FAssetData>& InAssetsToAssign);
  125. /**
  126. * Clears custom thumbnails for the selected assets
  127. *
  128. * @param InAssetsToAssign - assets that should have their thumbnail cleared
  129. */
  130. void ClearCustomThumbnails(const TArray<FAssetData>& InAssetsToAssign);
  131. /** Returns true if the specified asset that uses shared thumbnails has a thumbnail assigned to it */
  132. bool AssetHasCustomThumbnail( const FAssetData& AssetData );
  133. /** Extract the category of the given path */
  134. ECBFolderCategory GetFolderCategory( const FString& InPath );
  135. ECBFolderCategory GetRootFolderCategory(const FString& InPath);
  136. /** Returns true if the passed-in path is a engine folder */
  137. bool IsEngineFolder( const FString& InPath );
  138. /** Returns true if the passed-in path is a developers folder */
  139. bool IsDevelopersFolder( const FString& InPath );
  140. /** Returns true if the passed-in path is a plugin folder, optionally reporting where the plugin was loaded from */
  141. bool IsPluginFolder(const FString& InPath, EPluginLoadedFrom* OutPluginSource = nullptr);
  142. /** Returns true if the passed-in path is a plugin folder, optionally reporting where the plugin was loaded from.
  143. * Pass in a prefiltered list of plugins to consider -- more efficient when called many times.
  144. */
  145. bool IsPluginFolder(const FString& InPath, const TArray<TSharedRef<IPlugin>>& InPlugins, EPluginLoadedFrom* OutPluginSource = nullptr);
  146. /** Returns true if the passed-in path is a C++ classes folder */
  147. bool IsClassesFolder( const FString& InPath );
  148. /** Returns true if the passed-in path is a localization folder */
  149. bool IsLocalizationFolder( const FString& InPath );
  150. /** Get all the objects in a list of asset data */
  151. void GetObjectsInAssetData(const TArray<FAssetData>& AssetList, TArray<UObject*>& OutDroppedObjects);
  152. /** Returns true if the supplied folder name can be used as part of a package name */
  153. bool IsValidFolderName(const FString& FolderName, FText& Reason);
  154. /** Returns true if the path specified exists as a folder in the asset registry */
  155. bool DoesFolderExist(const FString& FolderPath);
  156. /**
  157. * @return true if the path specified is an empty folder (contains no assets or classes).
  158. * @note Does *not* test whether the folder is empty on disk, so do not use it to validate filesystem deletion!
  159. */
  160. bool IsEmptyFolder(const FString& FolderPath, const bool bRecursive = false);
  161. /** Check to see whether the given path is a root directory (either for asset or classes) */
  162. bool IsRootDir(const FString& FolderPath);
  163. /** Check to see whether the given path is a root asset directory */
  164. bool IsAssetRootDir(const FString& FolderPath);
  165. /** Check to see whether the given path is a root class directory */
  166. bool IsClassRootDir(const FString& FolderPath);
  167. /** Get the localized display name to use for the given root directory */
  168. FText GetRootDirDisplayName(const FString& FolderPath);
  169. /** If the folder is currently in background gathering progress */
  170. bool IsFolderBackgroundGathering(const FString& InFolder);
  171. FName GetCurrentGatheringFolder();
  172. /** Check to see whether the given path is rooted against a class directory */
  173. bool IsClassPath(const FString& InPath);
  174. /** Check to see whether the given path is rooted against a collection directory, optionally extracting the collection name and share type from the path */
  175. bool IsCollectionPath(const FString& InPath, FName* OutCollectionName = nullptr, ECollectionShareType::Type* OutCollectionShareType = nullptr);
  176. /** Given an array of paths, work out how many are rooted against class roots, and how many are rooted against asset roots */
  177. void CountPathTypes(const TArray<FString>& InPaths, int32& OutNumAssetPaths, int32& OutNumClassPaths);
  178. /** Given an array of paths, work out how many are rooted against class roots, and how many are rooted against asset roots */
  179. void CountPathTypes(const TArray<FName>& InPaths, int32& OutNumAssetPaths, int32& OutNumClassPaths);
  180. /** Given an array of "asset" data, work out how many are assets, and how many are classes */
  181. void CountItemTypes(const TArray<FAssetData>& InItems, int32& OutNumAssetItems, int32& OutNumClassItems);
  182. /** Check to see whether the given path is a valid location in which to create new classes */
  183. bool IsValidPathToCreateNewClass(const FString& InPath);
  184. /** Check to see whether the given path is a valid location in which to create a new folder */
  185. bool IsValidPathToCreateNewFolder(const FString& InPath);
  186. /**
  187. * Loads the color of this path from the config
  188. *
  189. * @param FolderPath - The path to the folder
  190. * @return The color the folder should appear as, will be NULL if not customized
  191. */
  192. const TSharedPtr<FLinearColor> LoadColor(const FString& FolderPath, bool bNoCache = false);
  193. bool LoadFolderColor(const FString& FolderPath, FLinearColor& OutFolderColor);
  194. /**
  195. * Saves the color of the path to the config
  196. *
  197. * @param FolderPath - The path to the folder
  198. * @param FolderColor - The color the folder should appear as
  199. * @param bForceAdd - If true, force the color to be added for the path
  200. */
  201. void SaveColor(const FString& FolderPath, const TSharedPtr<FLinearColor>& FolderColor, bool bForceAdd = false);
  202. /**
  203. * Checks to see if any folder has a custom color, optionally outputs them to a list
  204. *
  205. * @param OutColors - If specified, returns all the custom colors being used
  206. * @return true, if custom colors are present
  207. */
  208. bool HasCustomColors( TArray< FLinearColor >* OutColors = NULL );
  209. /** Gets the default color the folder should appear as */
  210. FLinearColor GetDefaultColor();
  211. /** Gets the platform specific text for the "explore" command (FPlatformProcess::ExploreFolder) */
  212. FText GetExploreFolderText();
  213. #if ECB_DISABLE
  214. /** Returns true if the specified path is available for object creation */
  215. bool IsValidObjectPathForCreate(const FString& ObjectPath, FText& OutErrorMessage, bool bAllowExistingAsset = false);
  216. #endif
  217. /** Returns true if the specified folder name in the specified path is available for folder creation */
  218. bool IsValidFolderPathForCreate(const FString& FolderPath, const FString& NewFolderName, FText& OutErrorMessage);
  219. /** Returns the length of the computed cooked package name and path wether it's run on a build machine or locally */
  220. int32 GetPackageLengthForCooking(const FString& PackageName, bool IsInternalBuild);
  221. /** Checks to see whether the path is within the size restrictions for cooking */
  222. bool IsValidPackageForCooking(const FString& PackageName, FText& OutErrorMessage);
  223. /** Returns if this folder has been marked as a favorite folder */
  224. bool IsFavoriteFolder(const FString& FolderPath);
  225. void AddFavoriteFolder(const FString& FolderPath, bool bFlushConfig = true);
  226. void RemoveFavoriteFolder(const FString& FolderPath, bool bFlushConfig = true);
  227. const TArray<FString>& GetFavoriteFolders();
  228. /** Gets the maximum path length for a cooked file. Changes behavior based on whether the editor experimental setting for long paths is enabled. */
  229. int32 GetMaxCookPathLen();
  230. void BeginAdvancedCopyPackages(TArray<FAssetData>& AssetList, TArray<FString>& AssetPaths, FString& DestinationPath);
  231. }