From c900403bf742878a950de63509161d033721b026 Mon Sep 17 00:00:00 2001 From: duffscs Date: Sat, 27 Sep 2025 14:43:06 +0200 Subject: [PATCH] Implement object-remove-attribute and object-remove-property commands --- src/actions/actions-object.cpp | 41 ++++++++++++++++++++++++++++++ testfiles/cli_tests/CMakeLists.txt | 11 ++++++++ 2 files changed, 52 insertions(+) diff --git a/src/actions/actions-object.cpp b/src/actions/actions-object.cpp index 3d1685f784..1d359ee383 100644 --- a/src/actions/actions-object.cpp +++ b/src/actions/actions-object.cpp @@ -139,6 +139,43 @@ object_get_property(const Glib::VariantBase& value, InkscapeApplication *app) } } +void +object_remove_attribute(Glib::VariantBase const &value, InkscapeApplication *app) +{ + Inkscape::Selection *selection = app->get_active_selection(); + if (selection->isEmpty()) { + show_output("action:object_remove_attribute: selection empty!"); + return; + } + auto const attribute = Glib::VariantBase::cast_dynamic>(value).get(); + + for (auto obj : selection->objects()) { + Inkscape::XML::Node *repr = obj->getRepr(); + repr->removeAttribute(attribute); + } + Inkscape::DocumentUndo::done(app->get_active_document(), _("Action remove attribute from objects"), ""); +} + +void +object_remove_property(Glib::VariantBase const &value, InkscapeApplication *app) +{ + Inkscape::Selection *selection = app->get_active_selection(); + if (selection->isEmpty()) { + show_output("action:object_remove_property: selection empty!"); + return; + } + auto const property = Glib::VariantBase::cast_dynamic>(value).get(); + + for (auto obj : selection->objects()) { + Inkscape::XML::Node *repr = obj->getRepr(); + SPCSSAttr *css = sp_repr_css_attr(repr, "style"); + sp_repr_css_set_property(css, property.c_str(), nullptr); + sp_repr_css_set(repr, css, "style"); + sp_repr_css_attr_unref(css); + } + Inkscape::DocumentUndo::done(app->get_active_document(), _("Action remove property from objects"), ""); +} + // No sanity checking is done... should probably add. void object_set_attribute(const Glib::VariantBase& value, InkscapeApplication *app) @@ -416,6 +453,8 @@ std::vector> raw_data_object = {"app.object-set-property", N_("Set Property"), SECTION, N_("Set or update a property on selected objects; usage: object-set-property:property name, property value;")}, {"app.object-get-attribute", N_("Get Attribute"), SECTION, N_("Get the value of an attribute of selected objects; usage: object-get-attribute:attribute name;")}, {"app.object-get-property", N_("Get Property"), SECTION, N_("Get the value of a property on selected objects; usage: object-get-property:property name;")}, + {"app.object-remove-attribute", N_("Remove Attribute"), SECTION, N_("Remove an attribute on selected objects; usage: object-remove-attribute:property name;")}, + {"app.object-remove-property", N_("Remove Property"), SECTION, N_("Remove a property on selected objects; usage: object-remove-property:property name;")}, {"app.object-unlink-clones", N_("Unlink Clones"), SECTION, N_("Unlink clones and symbols")}, {"app.object-to-path", N_("Object To Path"), SECTION, N_("Convert shapes to paths")}, @@ -462,6 +501,8 @@ add_actions_object(InkscapeApplication* app) gapp->add_action_with_parameter( "object-set-property", String, sigc::bind(sigc::ptr_fun(&object_set_property), app)); gapp->add_action_with_parameter( "object-get-attribute", String, sigc::bind(sigc::ptr_fun(&object_get_attribute), app)); gapp->add_action_with_parameter( "object-get-property", String, sigc::bind(sigc::ptr_fun(&object_get_property), app)); + gapp->add_action_with_parameter( "object-remove-attribute", String, sigc::bind(sigc::ptr_fun(&object_remove_attribute), app)); + gapp->add_action_with_parameter( "object-remove-property", String, sigc::bind(sigc::ptr_fun(&object_remove_property), app)); gapp->add_action_with_parameter( "object-trace", String, sigc::bind(sigc::ptr_fun(&object_trace), app)); gapp->add_action( "object-unlink-clones", sigc::bind(sigc::ptr_fun(&object_unlink_clones), app)); diff --git a/testfiles/cli_tests/CMakeLists.txt b/testfiles/cli_tests/CMakeLists.txt index 58c0d49c8f..03701d72bf 100644 --- a/testfiles/cli_tests/CMakeLists.txt +++ b/testfiles/cli_tests/CMakeLists.txt @@ -843,6 +843,11 @@ add_cli_test(actions-object-get-attribute INPUT_FILENAME rects.svg add_cli_test(actions-object-get-attribute_nonexistant INPUT_FILENAME rects.svg PARAMETERS --actions=select-by-id:rect1$object-get-attribute:z PASS_FOR_OUTPUT "\n$") +# object-remove-attribute +add_cli_test(actions-object-remove-attribute INPUT_FILENAME export-mask-on-transformed-image.svg + PARAMETERS --actions=select-by-id:circle-48$object-remove-attribute:style + OUTPUT_FILENAME actions-object-remove-attribute.svg + TEST_SCRIPT match_regex_fail.sh actions-object-remove-attribute.svg "style=\"fill: #ffff00; stroke: none;\"") # object-set-property add_cli_test(actions-object-set-property INPUT_FILENAME areas.svg @@ -864,6 +869,12 @@ add_cli_test(actions-object-get-property_nonexistant INPUT_FILENAME areas.svg PARAMETERS --actions=select-by-id:MyStar$object-get-attribute:full PASS_FOR_OUTPUT "\n$") +# object-remove-attribute +add_cli_test(actions-object-remove-property INPUT_FILENAME export-mask-on-transformed-image.svg + PARAMETERS --actions=select-by-id:circle-48$object-remove-property:fill + OUTPUT_FILENAME actions-object-remove-property.svg + TEST_SCRIPT match_regex_fail.sh actions-object-remove-property.svg "fill: #ffff00;") + # path-simplify add_cli_test(actions-path-simplify INPUT_FILENAME path.svg PARAMETERS --actions=select-by-id:gates$path-simplify$export-id:gates$export-id-only -- GitLab