Audacity 3.2.0
ProjectFileIOExtension.h
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.h
7
8 Dmitry Vedenko
9
10**********************************************************************/
11#pragma once
12
13#include <cstdint>
14#include <functional>
15#include <string>
16
17class AudacityProject;
19
21 std::function<bool(const std::string& path, bool nameChanged)>;
22
24enum class OnSaveAction
25{
27 Handled,
32};
33
35enum class OnCloseAction
36{
38 Veto,
41};
42
44enum class OnOpenAction
45{
47 Cancel,
50};
51
53class PROJECT_FILE_IO_API ProjectFileIOExtension /* not final */
54{
55public:
57
59 virtual OnOpenAction
60 OnOpen(AudacityProject& project, const std::string& path) = 0;
62 virtual void OnLoad(AudacityProject& project) = 0;
66 const ProjectSaveCallback& projectSaveCallback) = 0;
70 virtual void OnUpdateSaved(
71 AudacityProject& project, const ProjectSerializer& serializer) = 0;
73 virtual bool
74 IsBlockLocked(const AudacityProject& project, int64_t blockId) const = 0;
75};
76
78struct PROJECT_FILE_IO_API ProjectFileIOExtensionRegistry final
79{
80 struct PROJECT_FILE_IO_API Extension final
81 {
83 };
84
85 static OnOpenAction
86 OnOpen(AudacityProject& project, const std::string& path);
87 static void OnLoad(AudacityProject& project);
88 static OnSaveAction OnSave(
89 AudacityProject& project, const ProjectSaveCallback& projectSaveCallback);
91 static void
92 OnUpdateSaved(AudacityProject& project, const ProjectSerializer& serializer);
93 static bool IsBlockLocked(const AudacityProject& project, int64_t blockId);
94};
std::function< bool(const std::string &path, bool nameChanged)> ProjectSaveCallback
OnOpenAction
Action the ProjectManager should take after the open hooks were called.
@ Cancel
Open was cancelled by the extension.
OnSaveAction
Action the ProjectManager should take after the save hooks were called.
@ Handled
Save was handled by the extension.
@ 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.
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 void OnLoad(AudacityProject &project)=0
This hook is called after the project is loaded.
virtual OnCloseAction OnClose(AudacityProject &project)=0
This hook is called before the project is closed.
virtual bool IsBlockLocked(const AudacityProject &project, int64_t blockId) const =0
This hook is called to check if a block is locked.
virtual void OnUpdateSaved(AudacityProject &project, const ProjectSerializer &serializer)=0
This hook is called after the project blob is saved.
virtual ~ProjectFileIOExtension()
virtual OnOpenAction OnOpen(AudacityProject &project, const std::string &path)=0
This hook is called before the project is opened.
virtual OnSaveAction OnSave(AudacityProject &project, const ProjectSaveCallback &projectSaveCallback)=0
This hook is called before the project is saved.
a class used to (de)serialize the project catalog
void OnSave(const CommandContext &context)
Definition: FileMenus.cpp:254
void OnClose(const CommandContext &context)
Definition: FileMenus.cpp:241
void OnOpen(const CommandContext &context)
Definition: FileMenus.cpp:195
Extension registry for project file I/O extensions.