mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Misc ScopedPointer changes to start using reset() and get() rather than assignments and casts (part of an ongoing drift towards more std::unique_ptr compatibility)
This commit is contained in:
parent
c1bdfc6a55
commit
2dc9316420
131 changed files with 574 additions and 576 deletions
|
|
@ -36,8 +36,8 @@ struct UndoManager::ActionSet
|
|||
|
||||
bool perform() const
|
||||
{
|
||||
for (int i = 0; i < actions.size(); ++i)
|
||||
if (! actions.getUnchecked(i)->perform())
|
||||
for (auto* a : actions)
|
||||
if (! a->perform())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -56,8 +56,8 @@ struct UndoManager::ActionSet
|
|||
{
|
||||
int total = 0;
|
||||
|
||||
for (int i = actions.size(); --i >= 0;)
|
||||
total += actions.getUnchecked(i)->getSizeInUnits();
|
||||
for (auto* a : actions)
|
||||
total += a->getSizeInUnits();
|
||||
|
||||
return total;
|
||||
}
|
||||
|
|
@ -68,15 +68,9 @@ struct UndoManager::ActionSet
|
|||
};
|
||||
|
||||
//==============================================================================
|
||||
UndoManager::UndoManager (const int maxNumberOfUnitsToKeep,
|
||||
const int minimumTransactions)
|
||||
: totalUnitsStored (0),
|
||||
nextIndex (0),
|
||||
newTransaction (true),
|
||||
reentrancyCheck (false)
|
||||
UndoManager::UndoManager (int maxNumberOfUnitsToKeep, int minimumTransactions)
|
||||
{
|
||||
setMaxNumberOfStoredUnits (maxNumberOfUnitsToKeep,
|
||||
minimumTransactions);
|
||||
setMaxNumberOfStoredUnits (maxNumberOfUnitsToKeep, minimumTransactions);
|
||||
}
|
||||
|
||||
UndoManager::~UndoManager()
|
||||
|
|
@ -97,11 +91,10 @@ int UndoManager::getNumberOfUnitsTakenUpByStoredCommands() const
|
|||
return totalUnitsStored;
|
||||
}
|
||||
|
||||
void UndoManager::setMaxNumberOfStoredUnits (const int maxNumberOfUnitsToKeep,
|
||||
const int minimumTransactions)
|
||||
void UndoManager::setMaxNumberOfStoredUnits (int maxUnits, int minTransactions)
|
||||
{
|
||||
maxNumUnitsToKeep = jmax (1, maxNumberOfUnitsToKeep);
|
||||
minimumTransactionsToKeep = jmax (1, minimumTransactions);
|
||||
maxNumUnitsToKeep = jmax (1, maxUnits);
|
||||
minimumTransactionsToKeep = jmax (1, minTransactions);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -118,7 +111,7 @@ bool UndoManager::perform (UndoableAction* const newAction, const String& action
|
|||
return false;
|
||||
}
|
||||
|
||||
bool UndoManager::perform (UndoableAction* const newAction)
|
||||
bool UndoManager::perform (UndoableAction* newAction)
|
||||
{
|
||||
if (newAction != nullptr)
|
||||
{
|
||||
|
|
@ -133,15 +126,15 @@ bool UndoManager::perform (UndoableAction* const newAction)
|
|||
|
||||
if (action->perform())
|
||||
{
|
||||
ActionSet* actionSet = getCurrentSet();
|
||||
auto* actionSet = getCurrentSet();
|
||||
|
||||
if (actionSet != nullptr && ! newTransaction)
|
||||
{
|
||||
if (UndoableAction* const lastAction = actionSet->actions.getLast())
|
||||
if (auto* lastAction = actionSet->actions.getLast())
|
||||
{
|
||||
if (UndoableAction* const coalescedAction = lastAction->createCoalescedAction (action))
|
||||
if (auto coalescedAction = lastAction->createCoalescedAction (action.get()))
|
||||
{
|
||||
action = coalescedAction;
|
||||
action.reset (coalescedAction);
|
||||
totalUnitsStored -= lastAction->getSizeInUnits();
|
||||
actionSet->actions.removeLast();
|
||||
}
|
||||
|
|
@ -176,7 +169,7 @@ void UndoManager::moveFutureTransactionsToStash()
|
|||
|
||||
while (nextIndex < transactions.size())
|
||||
{
|
||||
ActionSet* removed = transactions.removeAndReturn (nextIndex);
|
||||
auto* removed = transactions.removeAndReturn (nextIndex);
|
||||
stashedFutureTransactions.add (removed);
|
||||
totalUnitsStored -= removed->getTotalSize();
|
||||
}
|
||||
|
|
@ -191,11 +184,10 @@ void UndoManager::restoreStashedFutureTransactions()
|
|||
transactions.remove (nextIndex);
|
||||
}
|
||||
|
||||
for (int i = 0; i < stashedFutureTransactions.size(); ++i)
|
||||
for (auto* stashed : stashedFutureTransactions)
|
||||
{
|
||||
ActionSet* action = stashedFutureTransactions.removeAndReturn (i);
|
||||
totalUnitsStored += action->getTotalSize();
|
||||
transactions.add (action);
|
||||
transactions.add (stashed);
|
||||
totalUnitsStored += stashed->getTotalSize();
|
||||
}
|
||||
|
||||
stashedFutureTransactions.clearQuick (false);
|
||||
|
|
@ -219,7 +211,7 @@ void UndoManager::dropOldTransactionsIfTooLarge()
|
|||
|
||||
void UndoManager::beginNewTransaction() noexcept
|
||||
{
|
||||
beginNewTransaction (String());
|
||||
beginNewTransaction ({});
|
||||
}
|
||||
|
||||
void UndoManager::beginNewTransaction (const String& actionName) noexcept
|
||||
|
|
@ -232,13 +224,13 @@ void UndoManager::setCurrentTransactionName (const String& newName) noexcept
|
|||
{
|
||||
if (newTransaction)
|
||||
newTransactionName = newName;
|
||||
else if (ActionSet* action = getCurrentSet())
|
||||
else if (auto* action = getCurrentSet())
|
||||
action->name = newName;
|
||||
}
|
||||
|
||||
String UndoManager::getCurrentTransactionName() const noexcept
|
||||
{
|
||||
if (ActionSet* action = getCurrentSet())
|
||||
if (auto* action = getCurrentSet())
|
||||
return action->name;
|
||||
|
||||
return newTransactionName;
|
||||
|
|
@ -253,7 +245,7 @@ bool UndoManager::canRedo() const noexcept { return getNextSet() != nullptr
|
|||
|
||||
bool UndoManager::undo()
|
||||
{
|
||||
if (const ActionSet* const s = getCurrentSet())
|
||||
if (auto* s = getCurrentSet())
|
||||
{
|
||||
const ScopedValueSetter<bool> setter (reentrancyCheck, true);
|
||||
|
||||
|
|
@ -272,7 +264,7 @@ bool UndoManager::undo()
|
|||
|
||||
bool UndoManager::redo()
|
||||
{
|
||||
if (const ActionSet* const s = getNextSet())
|
||||
if (auto* s = getNextSet())
|
||||
{
|
||||
const ScopedValueSetter<bool> setter (reentrancyCheck, true);
|
||||
|
||||
|
|
@ -335,15 +327,15 @@ bool UndoManager::undoCurrentTransactionOnly()
|
|||
void UndoManager::getActionsInCurrentTransaction (Array<const UndoableAction*>& actionsFound) const
|
||||
{
|
||||
if (! newTransaction)
|
||||
if (const ActionSet* const s = getCurrentSet())
|
||||
for (int i = 0; i < s->actions.size(); ++i)
|
||||
actionsFound.add (s->actions.getUnchecked(i));
|
||||
if (auto* s = getCurrentSet())
|
||||
for (auto* a : s->actions)
|
||||
actionsFound.add (a);
|
||||
}
|
||||
|
||||
int UndoManager::getNumActionsInCurrentTransaction() const
|
||||
{
|
||||
if (! newTransaction)
|
||||
if (const ActionSet* const s = getCurrentSet())
|
||||
if (auto* s = getCurrentSet())
|
||||
return s->actions.size();
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -232,8 +232,8 @@ private:
|
|||
friend struct ContainerDeletePolicy<ActionSet>;
|
||||
OwnedArray<ActionSet> transactions, stashedFutureTransactions;
|
||||
String newTransactionName;
|
||||
int totalUnitsStored, maxNumUnitsToKeep, minimumTransactionsToKeep, nextIndex;
|
||||
bool newTransaction, reentrancyCheck;
|
||||
int totalUnitsStored = 0, maxNumUnitsToKeep = 0, minimumTransactionsToKeep = 0, nextIndex = 0;
|
||||
bool newTransaction = true, reentrancyCheck = false;
|
||||
ActionSet* getCurrentSet() const noexcept;
|
||||
ActionSet* getNextSet() const noexcept;
|
||||
void moveFutureTransactionsToStash();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue