Audacity 3.2.0
ProjectHistory.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5ProjectHistory.cpp
6
7Paul Licameli split from ProjectManager.cpp
8
9**********************************************************************/
10
11#include "ProjectHistory.h"
12
13#include "Project.h"
14#include "UndoManager.h"
15
18 return std::make_shared< ProjectHistory >( project );
19 }
20};
21
23{
24 return project.AttachedObjects::Get< ProjectHistory >( sProjectHistoryKey );
25}
26
28{
29 return Get( const_cast< AudacityProject & >( project ) );
30}
31
33
34//
35// Undo/History methods
36//
37
39{
40 auto &project = mProject;
41 auto &undoManager = UndoManager::Get( project );
42
43 undoManager.ClearStates();
44
45 undoManager.PushState(XO("Created new project"), {});
46
47 undoManager.StateSaved();
48}
49
51{
52 auto &project = mProject;
53 auto &undoManager = UndoManager::Get( project );
54 return undoManager.UndoAvailable();
55}
56
58{
59 auto &project = mProject;
60 auto &undoManager = UndoManager::Get( project );
61 return undoManager.RedoAvailable();
62}
63
65 const TranslatableString &desc, const TranslatableString &shortDesc)
66{
67 PushState(desc, shortDesc, UndoPush::NONE);
68}
69
71 const TranslatableString &shortDesc,
72 UndoPush flags )
73{
74 auto &project = mProject;
77
78 // remaining no-fail operations "commit" the changes of undo manager state
79 auto &undoManager = UndoManager::Get( project );
80 undoManager.PushState(desc, shortDesc, flags);
81
82 mDirty = true;
83}
84
86{
87 auto &project = mProject;
88 auto &undoManager = UndoManager::Get( project );
89 SetStateTo( undoManager.GetCurrentState(), false );
90}
91
92void ProjectHistory::ModifyState(bool bWantsAutoSave)
93{
94 auto &project = mProject;
95 if (bWantsAutoSave)
97
98 // remaining no-fail operations "commit" the changes of undo manager state
99 auto &undoManager = UndoManager::Get( project );
100 undoManager.ModifyState();
101}
102
103// LL: Is there a memory leak here as "l" and "t" are not deleted???
104// Vaughan, 2010-08-29: No, as "l" is a TrackList* of an Undo stack state.
105// Need to keep it and its tracks "t" available for Undo/Redo/SetStateTo.
106void ProjectHistory::PopState(const UndoState &state, bool doAutosave)
107{
108 auto &project = mProject;
109 if (doAutosave)
111
112 // remaining no-fail operations "commit" the changes of undo manager state
113
114 // Restore extra state
115 for (auto &pExtension : state.extensions)
116 if (pExtension)
117 pExtension->RestoreUndoRedoState(project);
118}
119
120void ProjectHistory::SetStateTo(unsigned int n, bool doAutosave)
121{
122 auto &project = mProject;
123 auto &undoManager = UndoManager::Get( project );
124
125 undoManager.SetStateTo(n,
126 [this, doAutosave]( const UndoStackElem &elem ){
127 PopState(elem.state, doAutosave); } );
128}
XO("Cut/Copy/Paste")
static AudacityProject::AttachedObjects::RegisteredFactory sProjectHistoryKey
const auto project
UndoPush
Definition: UndoManager.h:138
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:275
static result_type Call(Arguments &&...arguments)
Null check of the installed function is done for you.
bool UndoAvailable() const
~ProjectHistory() override
void SetStateTo(unsigned int n, bool doAutosave=true)
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
void PopState(const UndoState &state, bool doAutosave=true)
bool RedoAvailable() const
void ModifyState(bool bWantsAutoSave)
static ProjectHistory & Get(AudacityProject &project)
AudacityProject & mProject
Holds a msgid for the translation catalog; may also bind format arguments.
static UndoManager & Get(AudacityProject &project)
Definition: UndoManager.cpp:71
const TranslatableString desc
Definition: ExportPCM.cpp:51
Holds one item with description and time range for the UndoManager.
Definition: UndoManager.h:117
UndoState state
Definition: UndoManager.h:128
Extensions extensions
Definition: UndoManager.h:114