ExtDependencyHistoryManager.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright 2017-2021 marynate. All Rights Reserved.
  2. #pragma once
  3. #include "CoreMinimal.h"
  4. struct FExtAssetIdentifier;
  5. class FMenuBuilder;
  6. /** The history data object, storing all important history data */
  7. struct FExtDependencyViewerHistoryData
  8. {
  9. /** History Description */
  10. FText HistoryDesc;
  11. /** The list of package names to serve as the root */
  12. TArray<FExtAssetIdentifier> Identifiers;
  13. };
  14. /** The delegate for when history data should be applied */
  15. DECLARE_DELEGATE_OneParam(FOnApplyExtRefHistoryData, const FExtDependencyViewerHistoryData& /*Data*/);
  16. /** The delegate for when history data should be updated */
  17. DECLARE_DELEGATE_OneParam(FOnUpdateExtRefHistoryData, FExtDependencyViewerHistoryData& /*Data*/);
  18. /** The class responsible for managing all content browser history */
  19. class FExtDependencyViewerHistoryManager
  20. {
  21. public:
  22. /** Constructor */
  23. FExtDependencyViewerHistoryManager();
  24. /** Set the delegate for applying history data */
  25. void SetOnApplyHistoryData(const FOnApplyExtRefHistoryData& InOnApplyHistoryData);
  26. /** Set the delegate for updating history data */
  27. void SetOnUpdateHistoryData(const FOnUpdateExtRefHistoryData& InOnUpdateHistoryData);
  28. /** Goes back one history snapshot and returns the history data at that snapshot */
  29. bool GoBack();
  30. /** Goes forward one history snapshot and returns the history data at that snapshot */
  31. bool GoForward();
  32. /** Stores new history data. Called when creating a history snapshot */
  33. void AddHistoryData();
  34. /** Triggers an update for the current history data. This is typically done right before changing the history. */
  35. void UpdateHistoryData();
  36. /** Determines if a user can go forward in history */
  37. bool CanGoForward() const;
  38. /** Determines if a user can go back in history */
  39. bool CanGoBack() const;
  40. /** Gets the description of the previous history entry */
  41. FText GetBackDesc() const;
  42. /** Gets the description of the next history entry */
  43. FText GetForwardDesc() const;
  44. /**
  45. * Populates a list of menu items that can be added to a context menu
  46. * to allow a user to jump to different history snapshots instead of using the back and forward buttons
  47. *
  48. * @param bGetPrior If true gets history snapshots prior to the current history index(for navigating back). If false get history snapshots after the current history index (for navigating forward).
  49. * @param MenuBuilder The menubuilder to populate with menu items
  50. */
  51. void GetAvailableHistoryMenuItems(bool bGetPrior, FMenuBuilder& MenuBuilder);
  52. private:
  53. /** Notifies the owner to update to the state described by the current history data */
  54. void ApplyCurrentHistoryData();
  55. /** Notifies the owner to update the current history data */
  56. void UpdateCurrentHistoryData();
  57. /** Handler for when a history item is chosen in the GetAvailableHistroyMenuItems list */
  58. void ExecuteJumpToHistory(int32 HistoryIndex);
  59. private:
  60. /** The delegate for when history data should be applied */
  61. FOnApplyExtRefHistoryData OnApplyHistoryData;
  62. /** The delegate for when history data should be updated */
  63. FOnUpdateExtRefHistoryData OnUpdateHistoryData;
  64. /** A list of history snapshots */
  65. TArray<FExtDependencyViewerHistoryData> HistoryData;
  66. /** The current history index the user is at (changes when the user goes back,forward, or history snapshots are taken) */
  67. int32 CurrentHistoryIndex;
  68. /** Max number of history items that can be stored. Once the max is reached, the oldest history item is removed */
  69. int32 MaxHistoryEntries;
  70. };