openshot-audio  0.1.4
Classes | Public Member Functions | Friends | List of all members
juce::UndoManager Class Reference

#include <juce_data_structures.h>

Inheritance diagram for juce::UndoManager:
juce::ChangeBroadcaster

Classes

struct  ActionSet
 

Public Member Functions

 UndoManager (int maxNumberOfUnitsToKeep=30000, int minimumTransactionsToKeep=30)
 
 ~UndoManager ()
 
void clearUndoHistory ()
 
int getNumberOfUnitsTakenUpByStoredCommands () const
 
void setMaxNumberOfStoredUnits (int maxNumberOfUnitsToKeep, int minimumTransactionsToKeep)
 
bool perform (UndoableAction *action)
 
bool perform (UndoableAction *action, const String &actionName)
 
void beginNewTransaction () noexcept
 
void beginNewTransaction (const String &actionName) noexcept
 
void setCurrentTransactionName (const String &newName) noexcept
 
String getCurrentTransactionName () const noexcept
 
bool canUndo () const noexcept
 
String getUndoDescription () const
 
bool undo ()
 
bool undoCurrentTransactionOnly ()
 
void getActionsInCurrentTransaction (Array< const UndoableAction *> &actionsFound) const
 
int getNumActionsInCurrentTransaction () const
 
Time getTimeOfUndoTransaction () const
 
Time getTimeOfRedoTransaction () const
 
bool canRedo () const noexcept
 
String getRedoDescription () const
 
bool redo ()
 
- Public Member Functions inherited from juce::ChangeBroadcaster
 ChangeBroadcaster () noexcept
 
virtual ~ChangeBroadcaster ()
 
void addChangeListener (ChangeListener *listener)
 
void removeChangeListener (ChangeListener *listener)
 
void removeAllChangeListeners ()
 
void sendChangeMessage ()
 
void sendSynchronousChangeMessage ()
 
void dispatchPendingMessages ()
 

Friends

struct ContainerDeletePolicy< ActionSet >
 

Detailed Description

Manages a list of undo/redo commands.

An UndoManager object keeps a list of past actions and can use these actions to move backwards and forwards through an undo history.

To use it, create subclasses of UndoableAction which perform all the actions you need, then when you need to actually perform an action, create one and pass it to the UndoManager's perform() method.

The manager also uses the concept of 'transactions' to group the actions together - all actions performed between calls to beginNewTransaction() are grouped together and are all undone/redone as a group.

The UndoManager is a ChangeBroadcaster, so listeners can register to be told when actions are performed or undone.

See also
UndoableAction

Constructor & Destructor Documentation

◆ UndoManager()

UndoManager::UndoManager ( int  maxNumberOfUnitsToKeep = 30000,
int  minimumTransactionsToKeep = 30 
)

Creates an UndoManager.

Parameters
maxNumberOfUnitsToKeepeach UndoableAction object returns a value to indicate how much storage it takes up (UndoableAction::getSizeInUnits()), so this lets you specify the maximum total number of units that the undomanager is allowed to keep in memory before letting the older actions drop off the end of the list.
minimumTransactionsToKeepthis specifies the minimum number of transactions that will be kept, even if this involves exceeding the amount of space specified in maxNumberOfUnitsToKeep

◆ ~UndoManager()

UndoManager::~UndoManager ( )

Destructor.

Member Function Documentation

◆ beginNewTransaction() [1/2]

void UndoManager::beginNewTransaction ( )
noexcept

Starts a new group of actions that together will be treated as a single transaction.

All actions that are passed to the perform() method between calls to this method are grouped together and undone/redone together by a single call to undo() or redo().

◆ beginNewTransaction() [2/2]

void UndoManager::beginNewTransaction ( const String actionName)
noexcept

Starts a new group of actions that together will be treated as a single transaction.

All actions that are passed to the perform() method between calls to this method are grouped together and undone/redone together by a single call to undo() or redo().

Parameters
actionNamea description of the transaction that is about to be performed

◆ canRedo()

bool UndoManager::canRedo ( ) const
noexcept

Returns true if there's at least one action in the list to redo.

See also
getRedoDescription, redo, canUndo

◆ canUndo()

bool UndoManager::canUndo ( ) const
noexcept

Returns true if there's at least one action in the list to undo.

See also
getUndoDescription, undo, canRedo

◆ clearUndoHistory()

void UndoManager::clearUndoHistory ( )

Deletes all stored actions in the list.

◆ getActionsInCurrentTransaction()

void UndoManager::getActionsInCurrentTransaction ( Array< const UndoableAction *> &  actionsFound) const

Returns a list of the UndoableAction objects that have been performed during the transaction that is currently open.

Effectively, this is the list of actions that would be undone if undoCurrentTransactionOnly() were to be called now.

The first item in the list is the earliest action performed.

◆ getCurrentTransactionName()

String UndoManager::getCurrentTransactionName ( ) const
noexcept

Returns the name of the current transaction.

See also
setCurrentTransactionName

◆ getNumActionsInCurrentTransaction()

int UndoManager::getNumActionsInCurrentTransaction ( ) const

Returns the number of UndoableAction objects that have been performed during the transaction that is currently open.

See also
getActionsInCurrentTransaction

◆ getNumberOfUnitsTakenUpByStoredCommands()

int UndoManager::getNumberOfUnitsTakenUpByStoredCommands ( ) const

Returns the current amount of space to use for storing UndoableAction objects.

See also
setMaxNumberOfStoredUnits

◆ getRedoDescription()

String UndoManager::getRedoDescription ( ) const

Returns the name of the transaction that will be redone when redo() is called.

See also
redo

◆ getTimeOfRedoTransaction()

Time UndoManager::getTimeOfRedoTransaction ( ) const

Returns the time to which the state would be restored if redo() was to be called. If a redo isn't currently possible, it'll return Time::getCurrentTime().

◆ getTimeOfUndoTransaction()

Time UndoManager::getTimeOfUndoTransaction ( ) const

Returns the time to which the state would be restored if undo() was to be called. If an undo isn't currently possible, it'll return Time().

◆ getUndoDescription()

String UndoManager::getUndoDescription ( ) const

Returns the name of the transaction that will be rolled-back when undo() is called.

See also
undo

◆ perform() [1/2]

bool UndoManager::perform ( UndoableAction action)

Performs an action and adds it to the undo history list.

Parameters
actionthe action to perform - this object will be deleted by the UndoManager when no longer needed
Returns
true if the command succeeds - see UndoableAction::perform
See also
beginNewTransaction

◆ perform() [2/2]

bool UndoManager::perform ( UndoableAction action,
const String actionName 
)

Performs an action and also gives it a name.

Parameters
actionthe action to perform - this object will be deleted by the UndoManager when no longer needed
actionNameif this string is non-empty, the current transaction will be given this name; if it's empty, the current transaction name will be left unchanged. See setCurrentTransactionName()
Returns
true if the command succeeds - see UndoableAction::perform
See also
beginNewTransaction

◆ redo()

bool UndoManager::redo ( )

Tries to redo the last transaction that was undone.

Returns
true if the transaction can be redone, and false if it fails, or if there aren't any transactions to redo

◆ setCurrentTransactionName()

void UndoManager::setCurrentTransactionName ( const String newName)
noexcept

Changes the name stored for the current transaction.

Each transaction is given a name when the beginNewTransaction() method is called, but this can be used to change that name without starting a new transaction.

◆ setMaxNumberOfStoredUnits()

void UndoManager::setMaxNumberOfStoredUnits ( int  maxNumberOfUnitsToKeep,
int  minimumTransactionsToKeep 
)

Sets the amount of space that can be used for storing UndoableAction objects.

Parameters
maxNumberOfUnitsToKeepeach UndoableAction object returns a value to indicate how much storage it takes up (UndoableAction::getSizeInUnits()), so this lets you specify the maximum total number of units that the undomanager is allowed to keep in memory before letting the older actions drop off the end of the list.
minimumTransactionsToKeepthis specifies the minimum number of transactions that will be kept, even if this involves exceeding the amount of space specified in maxNumberOfUnitsToKeep
See also
getNumberOfUnitsTakenUpByStoredCommands

◆ undo()

bool UndoManager::undo ( )

Tries to roll-back the last transaction.

Returns
true if the transaction can be undone, and false if it fails, or if there aren't any transactions to undo

◆ undoCurrentTransactionOnly()

bool UndoManager::undoCurrentTransactionOnly ( )

Tries to roll-back any actions that were added to the current transaction.

This will perform an undo() only if there are some actions in the undo list that were added after the last call to beginNewTransaction().

This is useful because it lets you call beginNewTransaction(), then perform an operation which may or may not actually perform some actions, and then call this method to get rid of any actions that might have been done without it rolling back the previous transaction if nothing was actually done.

Returns
true if any actions were undone.

Friends And Related Function Documentation

◆ ContainerDeletePolicy< ActionSet >

friend struct ContainerDeletePolicy< ActionSet >
friend

The documentation for this class was generated from the following files: