Audacity 3.2.0
ProjectFileIOExtension.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 ProjectFileIOExtension.cpp
7
8 Dmitry Vedenko
9
10**********************************************************************/
12
13#include <vector>
14
15namespace
16{
17std::vector<ProjectFileIOExtension*>& GetExtensions()
18{
19 static std::vector<ProjectFileIOExtension*> extensions;
20 return extensions;
21}
22} // namespace
23
25
28{
29 GetExtensions().push_back(&extension);
30}
31
33 AudacityProject& project, const std::string& path)
34{
35 for (auto& extension : GetExtensions())
36 if (extension->OnOpen(project, path) == OnOpenAction::Cancel)
38
40}
41
43{
44 for (auto& extension : GetExtensions())
45 extension->OnLoad(project);
46}
47
49 AudacityProject& project, const ProjectSaveCallback& projectSaveCallback)
50{
51 for (auto& extension : GetExtensions())
52 {
53 if (auto action = extension->OnSave(project, projectSaveCallback);
54 action != OnSaveAction::Continue)
55 return action;
56 }
57
59}
60
62{
63 for (auto& extension : GetExtensions())
64 {
65 if (extension->OnClose(project) == OnCloseAction::Veto)
67 }
68
70}
71
73 AudacityProject& project, const ProjectSerializer& serializer)
74{
75 for (auto& extension : GetExtensions())
76 extension->OnUpdateSaved(project, serializer);
77}
78
80 const AudacityProject& project, int64_t blockId)
81{
82 for (auto& extension : GetExtensions())
83 {
84 if (extension->IsBlockLocked(project, blockId))
85 return true;
86 }
87
88 return false;
89}
std::function< bool(const std::string &path, bool nameChanged)> ProjectSaveCallback
OnOpenAction
Action the ProjectManager should take after the open hooks were called.
@ Continue
ProjectManager should continue with the open.
@ Cancel
Open was cancelled by the extension.
OnSaveAction
Action the ProjectManager should take after the save hooks were called.
@ Continue
Save was not handled by the extension.
OnCloseAction
Action the ProjectManager should take after the close hooks were called.
@ Veto
Extension vetoed the close.
@ Continue
Extension did not veto the close.
const auto project
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
Set of hooks for project file I/O.
virtual ~ProjectFileIOExtension()
a class used to (de)serialize the project catalog
std::vector< ProjectFileIOExtension * > & GetExtensions()
Extension(ProjectFileIOExtension &extension)
static void OnUpdateSaved(AudacityProject &project, const ProjectSerializer &serializer)
static bool IsBlockLocked(const AudacityProject &project, int64_t blockId)
static void OnLoad(AudacityProject &project)
static OnOpenAction OnOpen(AudacityProject &project, const std::string &path)
static OnSaveAction OnSave(AudacityProject &project, const ProjectSaveCallback &projectSaveCallback)
static OnCloseAction OnClose(AudacityProject &project)