mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-16 16:10:06 +02:00
Bug2759: A failed macro command should not leave vacuous undo item
This commit is contained in:
parent
38e0a982ce
commit
c1c8c373d4
@ -41,6 +41,7 @@ processing. See also MacrosWindow and ApplyMacroDialog.
|
|||||||
#include "SelectUtilities.h"
|
#include "SelectUtilities.h"
|
||||||
#include "Shuttle.h"
|
#include "Shuttle.h"
|
||||||
#include "Track.h"
|
#include "Track.h"
|
||||||
|
#include "UndoManager.h"
|
||||||
|
|
||||||
#include "AllThemeResources.h"
|
#include "AllThemeResources.h"
|
||||||
|
|
||||||
@ -728,6 +729,9 @@ bool MacroCommands::ApplyMacro(
|
|||||||
|
|
||||||
// Save the project state before making any changes. It will be rolled
|
// Save the project state before making any changes. It will be rolled
|
||||||
// back if an error occurs.
|
// back if an error occurs.
|
||||||
|
// It also causes any calls to ModifyState (such as by simple
|
||||||
|
// view-changing commands) to append changes to this state, not to the
|
||||||
|
// previous state in history. See Bug 2076
|
||||||
if (proj) {
|
if (proj) {
|
||||||
ProjectHistory::Get(*proj).PushState(longDesc, shortDesc);
|
ProjectHistory::Get(*proj).PushState(longDesc, shortDesc);
|
||||||
}
|
}
|
||||||
@ -736,8 +740,18 @@ bool MacroCommands::ApplyMacro(
|
|||||||
// Upon exit of the top level apply, roll back the state if an error occurs.
|
// Upon exit of the top level apply, roll back the state if an error occurs.
|
||||||
auto cleanup2 = finally([&, macroReentryCount = MacroReentryCount] {
|
auto cleanup2 = finally([&, macroReentryCount = MacroReentryCount] {
|
||||||
if (macroReentryCount == 1 && !res && proj) {
|
if (macroReentryCount == 1 && !res && proj) {
|
||||||
// Macro failed or was cancelled; revert to the previous state
|
// Be sure that exceptions do not escape this destructor
|
||||||
ProjectHistory::Get(*proj).RollbackState();
|
GuardedCall([&]{
|
||||||
|
// Macro failed or was cancelled; revert to the previous state
|
||||||
|
auto &history = ProjectHistory::Get(*proj);
|
||||||
|
history.RollbackState();
|
||||||
|
// The added undo state is now vacuous. Remove it (Bug 2759)
|
||||||
|
auto &undoManager = UndoManager::Get(*proj);
|
||||||
|
undoManager.Undo(
|
||||||
|
[&]( const UndoStackElem &elem ){
|
||||||
|
history.PopState( elem.state ); } );
|
||||||
|
undoManager.AbandonRedo();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user