mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-15 15:49:36 +02:00
TransactionScope for performance also when abandoning redo states
This commit is contained in:
parent
495b4afe46
commit
a2e22dc17b
@ -269,7 +269,7 @@ void HistoryDialog::OnDiscard(wxCommandEvent & WXUNUSED(event))
|
|||||||
int i = mLevels->GetValue();
|
int i = mLevels->GetValue();
|
||||||
|
|
||||||
mSelected -= i;
|
mSelected -= i;
|
||||||
mManager->RemoveStates(i);
|
mManager->RemoveStates(0, i);
|
||||||
ProjectHistory::Get( *mProject ).SetStateTo(mSelected);
|
ProjectHistory::Get( *mProject ).SetStateTo(mSelected);
|
||||||
|
|
||||||
while(--i >= 0)
|
while(--i >= 0)
|
||||||
|
@ -899,7 +899,7 @@ AudacityProject *ProjectManager::OpenProject(
|
|||||||
window.Zoom( window.GetZoomOfToFit() );
|
window.Zoom( window.GetZoomOfToFit() );
|
||||||
// "Project was recovered" replaces "Create new project" in Undo History.
|
// "Project was recovered" replaces "Create new project" in Undo History.
|
||||||
auto &undoManager = UndoManager::Get( *pProject );
|
auto &undoManager = UndoManager::Get( *pProject );
|
||||||
undoManager.RemoveStates(1);
|
undoManager.RemoveStates(0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pProject;
|
return pProject;
|
||||||
|
@ -180,18 +180,20 @@ void UndoManager::RemoveStateAt(int n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UndoManager::RemoveStates(int num)
|
void UndoManager::RemoveStates(size_t begin, size_t end)
|
||||||
{
|
{
|
||||||
Optional<TransactionScope> pTrans;
|
Optional<TransactionScope> pTrans;
|
||||||
auto pConnection = ConnectionPtr::Get(mProject).mpConnection.get();
|
auto pConnection = ConnectionPtr::Get(mProject).mpConnection.get();
|
||||||
if (pConnection)
|
if (pConnection)
|
||||||
pTrans.emplace(*pConnection, "DiscardingUndoStates");
|
pTrans.emplace(*pConnection, "DiscardingUndoStates");
|
||||||
|
|
||||||
for (int i = 0; i < num; i++) {
|
for (size_t ii = begin; ii < end; ++ii) {
|
||||||
RemoveStateAt(0);
|
RemoveStateAt(begin);
|
||||||
|
|
||||||
current -= 1;
|
if (current > begin)
|
||||||
saved -= 1;
|
--current;
|
||||||
|
if (saved > begin)
|
||||||
|
--saved;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTrans)
|
if (pTrans)
|
||||||
@ -200,7 +202,7 @@ void UndoManager::RemoveStates(int num)
|
|||||||
|
|
||||||
void UndoManager::ClearStates()
|
void UndoManager::ClearStates()
|
||||||
{
|
{
|
||||||
RemoveStates(stack.size());
|
RemoveStates(0, stack.size());
|
||||||
current = -1;
|
current = -1;
|
||||||
saved = -1;
|
saved = -1;
|
||||||
}
|
}
|
||||||
@ -264,8 +266,6 @@ void UndoManager::PushState(const TrackList * l,
|
|||||||
const TranslatableString &shortDescription,
|
const TranslatableString &shortDescription,
|
||||||
UndoPush flags)
|
UndoPush flags)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
if ( (flags & UndoPush::CONSOLIDATE) != UndoPush::NONE &&
|
if ( (flags & UndoPush::CONSOLIDATE) != UndoPush::NONE &&
|
||||||
// compare full translations not msgids!
|
// compare full translations not msgids!
|
||||||
lastAction.Translation() == longDescription.Translation() &&
|
lastAction.Translation() == longDescription.Translation() &&
|
||||||
@ -289,10 +289,11 @@ void UndoManager::PushState(const TrackList * l,
|
|||||||
|
|
||||||
mayConsolidate = true;
|
mayConsolidate = true;
|
||||||
|
|
||||||
i = current + 1;
|
// Abandon redo states
|
||||||
while (i < stack.size()) {
|
if (saved >= current) {
|
||||||
RemoveStateAt(i);
|
saved = -1;
|
||||||
}
|
}
|
||||||
|
RemoveStates( current + 1, stack.size() );
|
||||||
|
|
||||||
// Assume tags was duplicated before any changes.
|
// Assume tags was duplicated before any changes.
|
||||||
// Just save a NEW shared_ptr to it.
|
// Just save a NEW shared_ptr to it.
|
||||||
@ -304,10 +305,6 @@ void UndoManager::PushState(const TrackList * l,
|
|||||||
|
|
||||||
current++;
|
current++;
|
||||||
|
|
||||||
if (saved >= current) {
|
|
||||||
saved = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
lastAction = longDescription;
|
lastAction = longDescription;
|
||||||
|
|
||||||
// wxWidgets will own the event object
|
// wxWidgets will own the event object
|
||||||
|
@ -132,7 +132,10 @@ class AUDACITY_DLL_API UndoManager final
|
|||||||
void ModifyState(const TrackList * l,
|
void ModifyState(const TrackList * l,
|
||||||
const SelectedRegion &selectedRegion, const std::shared_ptr<Tags> &tags);
|
const SelectedRegion &selectedRegion, const std::shared_ptr<Tags> &tags);
|
||||||
void ClearStates();
|
void ClearStates();
|
||||||
void RemoveStates(int num); // removes the 'num' oldest states
|
void RemoveStates(
|
||||||
|
size_t begin, //!< inclusive start of range
|
||||||
|
size_t end //!< exclusive end of range
|
||||||
|
);
|
||||||
unsigned int GetNumStates();
|
unsigned int GetNumStates();
|
||||||
unsigned int GetCurrentState();
|
unsigned int GetCurrentState();
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@ void OnCompact(const CommandContext &context)
|
|||||||
|
|
||||||
// Now we can remove all previous states.
|
// Now we can remove all previous states.
|
||||||
auto numStates = undoManager.GetNumStates();
|
auto numStates = undoManager.GetNumStates();
|
||||||
undoManager.RemoveStates(numStates - 1);
|
undoManager.RemoveStates(0, numStates - 1);
|
||||||
|
|
||||||
// And clear the clipboard
|
// And clear the clipboard
|
||||||
clipboard.Clear();
|
clipboard.Clear();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user