Expose layer history intent in app core

This commit is contained in:
2026-06-12 19:07:19 +02:00
parent 8cd384012f
commit ae24285203
5 changed files with 192 additions and 15 deletions

View File

@@ -126,7 +126,8 @@ class DocumentLayerRenameServices {
public:
virtual ~DocumentLayerRenameServices() = default;
virtual void rename_layer(std::string_view old_name, std::string_view new_name) = 0;
virtual void record_layer_rename_undo(std::string_view old_name, std::string_view new_name) = 0;
virtual void set_current_layer_name(std::string_view new_name) = 0;
virtual void finish_layer_rename() = 0;
};
@@ -156,6 +157,40 @@ public:
virtual void merge_layers(int from_index, int to_index, bool create_history) = 0;
};
[[nodiscard]] inline bool document_layer_rename_records_history(
const DocumentLayerRenamePlan& plan) noexcept
{
return plan.action == DocumentLayerRenameAction::rename_and_record_undo;
}
[[nodiscard]] inline bool document_layer_operation_records_history(
const DocumentLayerOperationPlan& plan) noexcept
{
switch (plan.operation) {
case DocumentLayerOperation::add:
case DocumentLayerOperation::duplicate:
case DocumentLayerOperation::remove:
case DocumentLayerOperation::set_opacity:
case DocumentLayerOperation::set_visibility:
case DocumentLayerOperation::set_alpha_lock:
case DocumentLayerOperation::set_blend_mode:
return plan.mutates_document;
case DocumentLayerOperation::reorder:
return plan.mutates_document;
case DocumentLayerOperation::select:
case DocumentLayerOperation::set_highlight:
return false;
}
return false;
}
[[nodiscard]] inline bool document_layer_merge_records_history(
const DocumentLayerMergePlan& plan) noexcept
{
return plan.create_history;
}
[[nodiscard]] inline pp::foundation::Status validate_layer_index(
int layer_count,
int index) noexcept
@@ -596,7 +631,12 @@ public:
if (plan.old_name == plan.new_name) {
return pp::foundation::Status::invalid_argument("layer rename plan must change the name");
}
services.rename_layer(plan.old_name, plan.new_name);
if (!document_layer_rename_records_history(plan)) {
return pp::foundation::Status::invalid_argument(
"layer rename plan must record history when the name changes");
}
services.record_layer_rename_undo(plan.old_name, plan.new_name);
services.set_current_layer_name(plan.new_name);
services.finish_layer_rename();
return pp::foundation::Status::success();
}