AssetContextMenu.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. // Copyright 2017-2021 marynate. All Rights Reserved.
  2. #pragma once
  3. #include "CoreMinimal.h"
  4. #include "Input/Reply.h"
  5. #include "Widgets/SWidget.h"
  6. #include "AssetRegistry/AssetData.h"
  7. #include "ContentBrowserDelegates.h"
  8. #include "SourcesData.h"
  9. class UToolMenu;
  10. struct FExtAssetData;
  11. class SExtAssetView;
  12. class FUICommandList;
  13. class SWindow;
  14. /**
  15. * Provide context menu support for asset view and asset items
  16. */
  17. class FAssetContextMenu : public TSharedFromThis<FAssetContextMenu>
  18. {
  19. public:
  20. /** Constructor */
  21. FAssetContextMenu(const TWeakPtr<SExtAssetView>& InAssetView);
  22. /** Binds the commands used by the asset view context menu to the content browser command list */
  23. void BindCommands(TSharedPtr< FUICommandList >& Commands);
  24. /** Makes the context menu widget */
  25. TSharedRef<SWidget> MakeContextMenu(const TArray<FExtAssetData>& SelectedAssets, const FSourcesData& InSourcesData, TSharedPtr< FUICommandList > InCommandList);
  26. /** Updates the list of currently selected assets to those passed in */
  27. void SetSelectedAssets(const TArray<FExtAssetData>& InSelectedAssets);
  28. /** Delegate for when the context menu requests a rename */
  29. //void SetOnFindInAssetTreeRequested(const FOnFindInAssetTreeRequested& InOnFindInAssetTreeRequested);
  30. /** Delegate for when the context menu requests a rename */
  31. DECLARE_DELEGATE_OneParam(FOnRenameRequested, const FAssetData& /*AssetToRename*/);
  32. void SetOnRenameRequested(const FOnRenameRequested& InOnRenameRequested);
  33. /** Delegate for when the context menu requests a rename of a folder */
  34. DECLARE_DELEGATE_OneParam(FOnRenameFolderRequested, const FString& /*FolderToRename*/);
  35. void SetOnRenameFolderRequested(const FOnRenameFolderRequested& InOnRenameFolderRequested);
  36. /** Delegate for when the context menu requests a rename */
  37. DECLARE_DELEGATE_OneParam(FOnDuplicateRequested, const TWeakObjectPtr<UObject>& /*OriginalObject*/);
  38. void SetOnDuplicateRequested(const FOnDuplicateRequested& InOnDuplicateRequested);
  39. /** Delegate for when the context menu requests an asset view refresh */
  40. DECLARE_DELEGATE(FOnAssetViewRefreshRequested);
  41. void SetOnAssetViewRefreshRequested(const FOnAssetViewRefreshRequested& InOnAssetViewRefreshRequested);
  42. /** Handler to check to see if a rename command is allowed */
  43. bool CanExecuteRename() const;
  44. /** Handler to check to see if a delete command is allowed */
  45. bool CanExecuteDelete() const;
  46. /** Handler for Delete */
  47. void ExecuteDelete();
  48. /** Handler to check to see if a reload command is allowed */
  49. bool CanExecuteReload() const;
  50. /** Handler for Reload */
  51. void ExecuteReload();
  52. /** Handler to check to see if "Save Asset" can be executed */
  53. bool CanExecuteSaveAsset() const;
  54. /** Handler for when "Save Asset" is selected */
  55. void ExecuteSaveAsset();
  56. private:
  57. struct FSourceAssetsState
  58. {
  59. TSet<FName> SelectedAssets;
  60. TSet<FName> CurrentAssets;
  61. };
  62. struct FLocalizedAssetsState
  63. {
  64. FCulturePtr Culture;
  65. TSet<FName> NewAssets;
  66. TSet<FName> CurrentAssets;
  67. };
  68. private:
  69. /** Helper to load selected assets and sort them by UClass */
  70. void GetSelectedAssetsByClass(TMap<UClass*, TArray<UObject*> >& OutSelectedAssetsByClass) const;
  71. /** Helper to collect resolved filepaths for all selected assets */
  72. void GetSelectedAssetSourceFilePaths(TArray<FString>& OutFilePaths, TArray<FString>& OutUniqueSourceFileLabels, int32 &OutValidSelectedAssetCount) const;
  73. /** Handler to check to see if a imported asset actions should be visible in the menu */
  74. bool AreImportedAssetActionsVisible() const;
  75. /** Handler to check to see if imported asset actions are allowed */
  76. bool CanExecuteImportedAssetActions(const TArray<FString> ResolvedFilePaths) const;
  77. /** Handler for FindInExplorer */
  78. void ExecuteFindSourceInExplorer(const TArray<FString> ResolvedFilePaths);
  79. /** Handler for OpenInExternalEditor */
  80. void ExecuteOpenInExternalEditor(const TArray<FString> ResolvedFilePaths);
  81. private:
  82. /** Registers all unregistered menus in the hierarchy for a class */
  83. static void RegisterMenuHierarchy(UClass* InClass);
  84. /** Adds options to menu */
  85. void AddMenuOptions(UToolMenu* InMenu);
  86. /** Adds asset type-specific menu options to a menu builder. Returns true if any options were added. */
  87. bool AddAssetTypeMenuOptions(UToolMenu* Menu, bool bHasObjectsSelected);
  88. /** Adds asset type-specific menu options to a menu builder. Returns true if any options were added. */
  89. bool AddImportedAssetMenuOptions(UToolMenu* Menu);
  90. /** Adds common menu options to a menu builder. Returns true if any options were added. */
  91. bool AddCommonMenuOptions(UToolMenu* Menu);
  92. /** Adds explore menu options to a menu builder. */
  93. void AddExploreMenuOptions(UToolMenu* Menu);
  94. /** Adds Asset Actions sub-menu to a menu builder. */
  95. void MakeAssetActionsSubMenu(UToolMenu* Menu);
  96. /** Handler to check to see if "Asset Actions" are allowed */
  97. bool CanExecuteAssetActions() const;
  98. /** Find the given assets in the Content Browser */
  99. void ExecuteFindInAssetTree(TArray<FName> InAssets);
  100. /** Open the given assets in their respective editors */
  101. void ExecuteOpenEditorsForAssets(TArray<FName> InAssets);
  102. /** Adds asset reference menu options to a menu builder. Returns true if any options were added. */
  103. bool AddReferenceMenuOptions(UToolMenu* Menu);
  104. /** Adds copy file path menu options to a menu builder. Returns true if any options were added. */
  105. bool AddCopyMenuOptions(UToolMenu* Menu);
  106. /** Adds menu options related to working with collections */
  107. bool AddCollectionMenuOptions(FMenuBuilder& MenuBuilder);
  108. /** Handler for when sync to asset tree is selected */
  109. void ExecuteSyncToAssetTree();
  110. /** Handler for when find in explorer is selected */
  111. void ExecuteFindInExplorer();
  112. /** Handler for when validate asset is selected */
  113. void ExecuteValidateAsset();
  114. void ExecuteRevalidateAsset();
  115. /** Handler for when import asset is selected */
  116. void ExecuteImportAsset();
  117. /** Handler for when flat import asset is selected */
  118. void ExecuteFlatImportAsset();
  119. /** Handler for when direct copy asset is selected */
  120. void ExecuteDirectCopyAsset();
  121. void ExecuteReparseAsset();
  122. /** Handler for when sync in content browser is selected */
  123. void ExecuteSyncToContentBrowser();
  124. /** Handler for when create using asset is selected */
  125. void ExecuteCreateBlueprintUsing();
  126. /** Handler for when "Find in World" is selected */
  127. void ExecuteFindAssetInWorld();
  128. /** Handler for when "Property Matrix..." is selected */
  129. void ExecutePropertyMatrix();
  130. /** Handler for when "Show MetaData" is selected */
  131. void ExecuteShowAssetMetaData();
  132. /** Handler for when "Edit Asset" is selected */
  133. void ExecuteEditAsset();
  134. /** Handler for when "Diff Selected" is selected */
  135. void ExecuteDiffSelected() const;
  136. /** Handler for when "Migrate Asset" is selected */
  137. void ExecuteMigrateAsset();
  138. /** Handler for GoToAssetCode */
  139. void ExecuteGoToCodeForAsset(UClass* SelectedClass);
  140. /** Handler for GoToAssetDocs */
  141. void ExecuteGoToDocsForAsset(UClass* SelectedClass);
  142. /** Handler for GoToAssetDocs */
  143. void ExecuteGoToDocsForAsset(UClass* SelectedClass, const FString ExcerptSection);
  144. /** Handler for CopyReference */
  145. void ExecuteCopyReference();
  146. /** Handler for CopyFilePath */
  147. void ExecuteCopyFilePath();
  148. /** Handler to copy the given text to the clipboard */
  149. void ExecuteCopyTextToClipboard(FString InText);
  150. /** Handler for showing the cached list of localized texts stored in the package header */
  151. void ExecuteShowLocalizationCache(const FString InPackageFilename);
  152. /** Handler for Dump */
  153. void ExecuteDumpExport();
  154. /** Handler to check to see if dump export command is allowed */
  155. bool CanExecuteDumpExport() const;
  156. /** Handler for Export */
  157. void ExecuteExport();
  158. /** Handler for Bulk Export */
  159. void ExecuteBulkExport();
  160. /** Handler for when "Remove from collection" is selected */
  161. void ExecuteRemoveFromCollection();
  162. /** Handler for when source control is disabled */
  163. void ExecuteEnableSourceControl();
  164. /** Handler to remove a single ChunkID assignment from a selection of assets */
  165. void ExecuteRemoveChunkID(int32 ChunkID);
  166. /** Handler to export the selected asset(s) to experimental text format */
  167. void ExportSelectedAssetsToText();
  168. /** Handler to check if we can export the selected asset(s) to experimental text format */
  169. bool CanExportSelectedAssetsToText() const;
  170. /** Handler to check to see if a sync to asset tree command is allowed */
  171. bool CanExecuteSyncToAssetTree() const;
  172. /** Handler to check to see if a sync to content browser command is allowed */
  173. bool CanExecuteSyncToContentBrowser() const;
  174. /** Handler to check to see if a find in explorer command is allowed */
  175. bool CanCopyFilePath() const;
  176. /** Handler to check to see if a find in explorer command is allowed */
  177. bool CanExecuteFindInExplorer() const;
  178. /** Handler to check to see if validate asset command is allowed */
  179. bool CanExecuteValidateAsset() const;
  180. bool CanExecuteRevalidateAsset() const;
  181. /** Handler to check to see if import asset command is allowed */
  182. bool CanExecuteImportAsset() const;
  183. /** Handler to check to see if import asset command is allowed */
  184. bool CanExecuteFlatImportAsset() const;
  185. /** Handler to check to see if direct copy asset command is allowed */
  186. bool CanExecuteDirectCopyAsset() const;
  187. bool CanExecuteReparseAsset() const;
  188. /** Handler to check if we can create blueprint using selected asset */
  189. bool CanExecuteCreateBlueprintUsing() const;
  190. /** Handler to check to see if a find in world command is allowed */
  191. bool CanExecuteFindAssetInWorld() const;
  192. /** Handler to check to see if a properties command is allowed */
  193. bool CanExecuteProperties() const;
  194. /** Handler to check to see if a property matrix command is allowed */
  195. bool CanExecutePropertyMatrix(FText& OutErrorMessage) const;
  196. bool CanExecutePropertyMatrix() const;
  197. /** Handler to check to see if a "Show MetaData" command is allowed */
  198. bool CanExecuteShowAssetMetaData() const;
  199. /** Handler to check to see if a "Remove from collection" command is allowed */
  200. bool CanExecuteRemoveFromCollection() const;
  201. /** Handler to check to see if "Diff Selected" can be executed */
  202. bool CanExecuteDiffSelected() const;
  203. /** Handler to check to see if "Capture Thumbnail" can be executed */
  204. bool CanExecuteCaptureThumbnail() const;
  205. /** Handler to check to see if "Clear Thumbnail" can be executed */
  206. bool CanExecuteClearThumbnail() const;
  207. /** Handler to check to see if "Clear Thumbnail" should be visible */
  208. bool CanClearCustomThumbnails() const;
  209. /** Helper function to gather the package names of all selected assets */
  210. void GetSelectedPackageNames(TArray<FString>& OutPackageNames) const;
  211. /** Helper function to gather the packages containing all selected assets */
  212. void GetSelectedPackages(TArray<UPackage*>& OutPackages) const;
  213. /** Generates tooltip for the Property Matrix menu option */
  214. FText GetExecutePropertyMatrixTooltip() const;
  215. private:
  216. /** Registers the base context menu for assets */
  217. void RegisterContextMenu(const FName MenuName);
  218. /** Generates a list of selected assets in the content browser */
  219. void GetSelectedAssets(TArray<UObject*>& Assets, bool SkipRedirectors) const;
  220. TArray<FExtAssetData> SelectedAssets;
  221. FSourcesData SourcesData;
  222. /** The asset view this context menu is a part of */
  223. TWeakPtr<SExtAssetView> AssetView;
  224. //FOnFindInAssetTreeRequested OnFindInAssetTreeRequested;
  225. FOnRenameRequested OnRenameRequested;
  226. FOnRenameFolderRequested OnRenameFolderRequested;
  227. FOnDuplicateRequested OnDuplicateRequested;
  228. FOnAssetViewRefreshRequested OnAssetViewRefreshRequested;
  229. /** Cached CanExecute vars */
  230. bool bAtLeastOneNonRedirectorSelected;
  231. bool bAtLeastOneClassSelected;
  232. bool bCanExecuteSCCMerge;
  233. bool bCanExecuteSCCCheckOut;
  234. bool bCanExecuteSCCOpenForAdd;
  235. bool bCanExecuteSCCCheckIn;
  236. bool bCanExecuteSCCHistory;
  237. bool bCanExecuteSCCRevert;
  238. bool bCanExecuteSCCSync;
  239. /** */
  240. int32 ChunkIDSelected;
  241. };