Extract layer rename planning

This commit is contained in:
2026-06-03 10:10:08 +02:00
parent 5d5bb24711
commit 07ed23c2d1
8 changed files with 242 additions and 4 deletions

View File

@@ -0,0 +1,48 @@
#pragma once
#include "foundation/result.h"
#include <cstddef>
#include <string>
#include <string_view>
#include <utility>
namespace pp::app {
inline constexpr std::size_t document_layer_name_max_length = 128;
enum class DocumentLayerRenameAction {
no_op_same_name,
rename_and_record_undo,
};
struct DocumentLayerRenamePlan {
std::string old_name;
std::string new_name;
DocumentLayerRenameAction action = DocumentLayerRenameAction::no_op_same_name;
};
[[nodiscard]] inline pp::foundation::Result<DocumentLayerRenamePlan> plan_document_layer_rename(
std::string_view old_name,
std::string_view requested_name)
{
if (requested_name.empty()) {
return pp::foundation::Result<DocumentLayerRenamePlan>::failure(
pp::foundation::Status::invalid_argument("layer name must not be empty"));
}
if (requested_name.size() > document_layer_name_max_length) {
return pp::foundation::Result<DocumentLayerRenamePlan>::failure(
pp::foundation::Status::out_of_range("layer name length exceeds the configured limit"));
}
DocumentLayerRenamePlan plan;
plan.old_name = std::string(old_name);
plan.new_name = std::string(requested_name);
plan.action = old_name == requested_name
? DocumentLayerRenameAction::no_op_same_name
: DocumentLayerRenameAction::rename_and_record_undo;
return pp::foundation::Result<DocumentLayerRenamePlan>::success(std::move(plan));
}
}