1
0
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:
Paul Licameli 2020-09-06 16:27:19 -04:00
parent 495b4afe46
commit a2e22dc17b
5 changed files with 19 additions and 19 deletions

View File

@ -269,7 +269,7 @@ void HistoryDialog::OnDiscard(wxCommandEvent & WXUNUSED(event))
int i = mLevels->GetValue();
mSelected -= i;
mManager->RemoveStates(i);
mManager->RemoveStates(0, i);
ProjectHistory::Get( *mProject ).SetStateTo(mSelected);
while(--i >= 0)

View File

@ -899,7 +899,7 @@ AudacityProject *ProjectManager::OpenProject(
window.Zoom( window.GetZoomOfToFit() );
// "Project was recovered" replaces "Create new project" in Undo History.
auto &undoManager = UndoManager::Get( *pProject );
undoManager.RemoveStates(1);
undoManager.RemoveStates(0, 1);
}
return pProject;

View File

@ -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;
auto pConnection = ConnectionPtr::Get(mProject).mpConnection.get();
if (pConnection)
pTrans.emplace(*pConnection, "DiscardingUndoStates");
for (int i = 0; i < num; i++) {
RemoveStateAt(0);
for (size_t ii = begin; ii < end; ++ii) {
RemoveStateAt(begin);
current -= 1;
saved -= 1;
if (current > begin)
--current;
if (saved > begin)
--saved;
}
if (pTrans)
@ -200,7 +202,7 @@ void UndoManager::RemoveStates(int num)
void UndoManager::ClearStates()
{
RemoveStates(stack.size());
RemoveStates(0, stack.size());
current = -1;
saved = -1;
}
@ -264,8 +266,6 @@ void UndoManager::PushState(const TrackList * l,
const TranslatableString &shortDescription,
UndoPush flags)
{
unsigned int i;
if ( (flags & UndoPush::CONSOLIDATE) != UndoPush::NONE &&
// compare full translations not msgids!
lastAction.Translation() == longDescription.Translation() &&
@ -289,10 +289,11 @@ void UndoManager::PushState(const TrackList * l,
mayConsolidate = true;
i = current + 1;
while (i < stack.size()) {
RemoveStateAt(i);
// Abandon redo states
if (saved >= current) {
saved = -1;
}
RemoveStates( current + 1, stack.size() );
// Assume tags was duplicated before any changes.
// Just save a NEW shared_ptr to it.
@ -304,10 +305,6 @@ void UndoManager::PushState(const TrackList * l,
current++;
if (saved >= current) {
saved = -1;
}
lastAction = longDescription;
// wxWidgets will own the event object

View File

@ -132,7 +132,10 @@ class AUDACITY_DLL_API UndoManager final
void ModifyState(const TrackList * l,
const SelectedRegion &selectedRegion, const std::shared_ptr<Tags> &tags);
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 GetCurrentState();

View File

@ -235,7 +235,7 @@ void OnCompact(const CommandContext &context)
// Now we can remove all previous states.
auto numStates = undoManager.GetNumStates();
undoManager.RemoveStates(numStates - 1);
undoManager.RemoveStates(0, numStates - 1);
// And clear the clipboard
clipboard.Clear();