Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

juce_UndoableAction.h 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. //==============================================================================
  16. /**
  17. Used by the UndoManager class to store an action which can be done
  18. and undone.
  19. @see UndoManager
  20. @tags{DataStructures}
  21. */
  22. class JUCE_API UndoableAction
  23. {
  24. protected:
  25. /** Creates an action. */
  26. UndoableAction() = default;
  27. public:
  28. /** Destructor. */
  29. virtual ~UndoableAction() = default;
  30. //==============================================================================
  31. /** Overridden by a subclass to perform the action.
  32. This method is called by the UndoManager, and shouldn't be used directly by
  33. applications.
  34. Be careful not to make any calls in a perform() method that could call
  35. recursively back into the UndoManager::perform() method
  36. @returns true if the action could be performed.
  37. @see UndoManager::perform
  38. */
  39. virtual bool perform() = 0;
  40. /** Overridden by a subclass to undo the action.
  41. This method is called by the UndoManager, and shouldn't be used directly by
  42. applications.
  43. Be careful not to make any calls in an undo() method that could call
  44. recursively back into the UndoManager::perform() method
  45. @returns true if the action could be undone without any errors.
  46. @see UndoManager::perform
  47. */
  48. virtual bool undo() = 0;
  49. //==============================================================================
  50. /** Returns a value to indicate how much memory this object takes up.
  51. Because the UndoManager keeps a list of UndoableActions, this is used
  52. to work out how much space each one will take up, so that the UndoManager
  53. can work out how many to keep.
  54. The default value returned here is 10 - units are arbitrary and
  55. don't have to be accurate.
  56. @see UndoManager::getNumberOfUnitsTakenUpByStoredCommands,
  57. UndoManager::setMaxNumberOfStoredUnits
  58. */
  59. virtual int getSizeInUnits() { return 10; }
  60. /** Allows multiple actions to be coalesced into a single action object, to reduce storage space.
  61. If possible, this method should create and return a single action that does the same job as
  62. this one followed by the supplied action.
  63. If it's not possible to merge the two actions, the method should return a nullptr.
  64. */
  65. virtual UndoableAction* createCoalescedAction (UndoableAction* nextAction) { ignoreUnused (nextAction); return nullptr; }
  66. };
  67. } // namespace juce