Audacity 3.2.0
UndoTracks.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file UndoTracks.cpp
6
7 Paul Licameli
8
9 **********************************************************************/
10#include "UndoTracks.h"
11#include "PendingTracks.h"
12#include "Track.h"
13#include "UndoManager.h"
14
15// Undo/redo handling of selection changes
16namespace {
19 : mpTracks{ TrackList::Create(nullptr) }
20 {
21 for (auto pTrack : TrackList::Get(project)) {
22 if (pTrack->GetId() == TrackId{})
23 // Don't copy a pending added track
24 continue;
25 mpTracks->Add(pTrack->Duplicate());
26 }
27 }
29 auto &dstTracks = TrackList::Get(project);
30 dstTracks.Clear();
31 for (auto pTrack : *mpTracks)
32 dstTracks.Add(pTrack->Duplicate());
33 }
34 bool CanUndoOrRedo(const AudacityProject &project) override {
36 }
37 const std::shared_ptr<TrackList> mpTracks;
38};
39
41 [](AudacityProject &project) -> std::shared_ptr<UndoStateExtension> {
42 return std::make_shared<TrackListRestorer>(project);
43 }
44};
45}
46
48{
49 auto &exts = state.state.extensions;
50 auto end = exts.end(),
51 iter = std::find_if(exts.begin(), end, [](auto &pExt){
52 return dynamic_cast<TrackListRestorer*>(pExt.get());
53 });
54 if (iter != end)
55 return static_cast<TrackListRestorer*>(iter->get())->mpTracks.get();
56 return nullptr;
57}
static const auto exts
Definition: ImportAUP.cpp:56
const auto project
declares abstract base class Track, TrackList, and iterators over TrackList
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
bool HasPendingTracks() const
static PendingTracks & Get(AudacityProject &project)
An in-session identifier of track objects across undo states. It does not persist between sessions.
Definition: Track.h:79
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:850
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
TrackKind * Add(const std::shared_ptr< TrackKind > &t, bool assignIds=true)
Definition: Track.h:1048
Base class for extra information attached to undo/redo states.
Definition: UndoManager.h:83
TRACK_API TrackList * Find(const UndoStackElem &state)
Definition: UndoTracks.cpp:47
UndoRedoExtensionRegistry::Entry sEntry
Definition: UndoTracks.cpp:40
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
Typically statically constructed.
Definition: UndoManager.h:102
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
bool CanUndoOrRedo(const AudacityProject &project) override
Whether undo or redo is now permitted; default returns true.
Definition: UndoTracks.cpp:34
void RestoreUndoRedoState(AudacityProject &project) override
Modify the project when undoing or redoing to some state in history.
Definition: UndoTracks.cpp:28
const std::shared_ptr< TrackList > mpTracks
Definition: UndoTracks.cpp:37