Expose layer history intent in app core
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
void rename_layer(std::string_view old_name, std::string_view new_name) override
|
||||
void record_layer_rename_undo(std::string_view old_name, std::string_view new_name) override
|
||||
{
|
||||
if (!app_.layers || !app_.layers->m_current_layer || !app_.canvas || !app_.canvas->m_canvas)
|
||||
return;
|
||||
@@ -65,6 +65,16 @@ public:
|
||||
new_name_copy,
|
||||
layer_node,
|
||||
layer));
|
||||
}
|
||||
|
||||
void set_current_layer_name(std::string_view new_name) override
|
||||
{
|
||||
if (!app_.layers || !app_.layers->m_current_layer || !app_.canvas || !app_.canvas->m_canvas)
|
||||
return;
|
||||
|
||||
auto layer_node = std::static_pointer_cast<NodeLayer>(app_.layers->m_current_layer->shared_from_this());
|
||||
auto* layer = app_.canvas->m_canvas->m_layers[app_.canvas->m_canvas->m_current_layer_idx].get();
|
||||
const std::string new_name_copy(new_name);
|
||||
layer_node->set_name(new_name_copy.c_str());
|
||||
layer->m_name = new_name_copy;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user