Plan document file saves in app core

This commit is contained in:
2026-06-02 22:42:51 +02:00
parent c8d769c02c
commit 5841878df9
9 changed files with 199 additions and 25 deletions

View File

@@ -1,5 +1,11 @@
#pragma once
#include "foundation/result.h"
#include <string>
#include <string_view>
#include <utility>
namespace pp::app {
enum class ProjectOpenDecision {
@@ -33,6 +39,17 @@ enum class DocumentWorkflowDecision {
prompt_save_before_continue,
};
enum class DocumentFileWriteDecision {
save_now,
prompt_overwrite,
};
struct DocumentFileTarget {
std::string name;
std::string directory;
std::string path;
};
[[nodiscard]] constexpr ProjectOpenDecision plan_project_open(bool has_unsaved_changes) noexcept
{
return has_unsaved_changes
@@ -97,4 +114,32 @@ enum class DocumentWorkflowDecision {
: DocumentWorkflowDecision::continue_now;
}
[[nodiscard]] inline pp::foundation::Result<DocumentFileTarget> make_document_file_target(
std::string_view work_directory,
std::string_view document_name)
{
if (document_name.empty()) {
return pp::foundation::Result<DocumentFileTarget>::failure(
pp::foundation::Status::invalid_argument("document name must not be empty"));
}
DocumentFileTarget target;
target.name = std::string(document_name);
target.directory = std::string(work_directory);
target.path.reserve(target.directory.size() + target.name.size() + 5);
target.path += target.directory;
target.path += "/";
target.path += target.name;
target.path += ".ppi";
return pp::foundation::Result<DocumentFileTarget>::success(std::move(target));
}
[[nodiscard]] constexpr DocumentFileWriteDecision plan_document_file_write(
bool target_exists) noexcept
{
return target_exists
? DocumentFileWriteDecision::prompt_overwrite
: DocumentFileWriteDecision::save_now;
}
}