Centralize legacy document file saves

This commit is contained in:
2026-06-04 13:47:43 +02:00
parent 8a0810acb3
commit ab6223c256
8 changed files with 257 additions and 37 deletions

View File

@@ -106,6 +106,21 @@ struct DocumentFileSavePlan {
DocumentFileWriteDecision write_decision = DocumentFileWriteDecision::save_now;
};
class DocumentFileSaveServices {
public:
virtual ~DocumentFileSaveServices() = default;
virtual void save_document_file(const DocumentFileSavePlan& plan) = 0;
virtual void prompt_overwrite_document_file(const DocumentFileSavePlan& plan) = 0;
};
class DocumentVersionSaveServices {
public:
virtual ~DocumentVersionSaveServices() = default;
virtual void save_document_version(const DocumentVersionTarget& target) = 0;
};
struct NewDocumentPlan {
DocumentFileTarget target;
int resolution = 0;
@@ -339,6 +354,22 @@ template <typename ExistsPredicate>
return pp::foundation::Result<DocumentFileSavePlan>::success(std::move(plan));
}
[[nodiscard]] inline pp::foundation::Status execute_document_file_save_plan(
const DocumentFileSavePlan& plan,
DocumentFileSaveServices& services)
{
switch (plan.write_decision) {
case DocumentFileWriteDecision::save_now:
services.save_document_file(plan);
return pp::foundation::Status::success();
case DocumentFileWriteDecision::prompt_overwrite:
services.prompt_overwrite_document_file(plan);
return pp::foundation::Status::success();
}
return pp::foundation::Status::invalid_argument("unknown document file save write decision");
}
[[nodiscard]] constexpr pp::foundation::Result<int> document_resolution_from_index(int index) noexcept
{
constexpr std::array<int, 6> resolutions{ 512, 1024, 1536, 2048, 4096, 8192 };
@@ -471,4 +502,16 @@ template <typename ExistsPredicate>
pp::foundation::Status::out_of_range("no available document version target"));
}
[[nodiscard]] inline pp::foundation::Status execute_document_version_save(
const DocumentVersionTarget& target,
DocumentVersionSaveServices& services)
{
if (target.name.empty() || target.path.empty()) {
return pp::foundation::Status::invalid_argument("document version target requires a name and path");
}
services.save_document_version(target);
return pp::foundation::Status::success();
}
}