From 10fd075647c99a4baf8f9b3929a48f2459a33da0 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 23 Sep 2023 11:34:21 +0200 Subject: [PATCH 1/2] add selection actions without desktop --- src/actions/actions-selection.cpp | 142 +++++++++++++++++++++++++++--- 1 file changed, 128 insertions(+), 14 deletions(-) diff --git a/src/actions/actions-selection.cpp b/src/actions/actions-selection.cpp index 30c0e6967e..86ca04e95c 100644 --- a/src/actions/actions-selection.cpp +++ b/src/actions/actions-selection.cpp @@ -269,6 +269,105 @@ selection_empty_backup(InkscapeApplication* app) selection->emptyBackup(); } +void +select_all_layers(Glib::ustring layer, InkscapeApplication* app) +{ + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } + SPObject* object = document->getObjectById(layer.c_str()); + if (object) { + Inkscape::SelectionHelper::selectAllInAll(document, selection); + } else { + std::cerr << "No hay una capa con el id:" << layer.c_str() << std::endl; + } +} + +void +select_same_fill_and_stroke(InkscapeApplication* app) +{ + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } + + // Fill and Stroke + Inkscape::SelectionHelper::selectSameFillStroke(document, selection); +} + +void +select_same_fill(InkscapeApplication* app) +{ + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } + + // Fill Color + Inkscape::SelectionHelper::selectSameFillColor(document, selection); +} + +void +select_same_stroke_color(InkscapeApplication* app) +{ + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } + + // Stroke Color + Inkscape::SelectionHelper::selectSameStrokeColor(document, selection); +} + +void +select_same_stroke_style(InkscapeApplication* app) +{ + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } + + // Stroke Style + Inkscape::SelectionHelper::selectSameStrokeStyle(document, selection); +} + +void +select_same_object_type(InkscapeApplication* app) +{ + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } + + // Object Type + Inkscape::SelectionHelper::selectSameObjectType(document, selection); +} + +void +select_invert_all(Glib::ustring layer, InkscapeApplication* app) +{ + SPDocument* document = nullptr; + Inkscape::Selection* selection = nullptr; + if (!get_document_and_selection(app, &document, &selection)) { + return; + } + + // Invert Selection + SPObject* object = document->getObjectById(layer.c_str()); + if (object) { + Inkscape::SelectionHelper::invertAllInAll(document, selection); + } else { + std::cerr << "No hay una capa con el id:" << layer.c_str() << std::endl; + } +} + std::vector> raw_data_selection = { // clang-format offs @@ -281,6 +380,14 @@ std::vector> raw_data_selection = {"app.select-by-element", N_("Select by Element"), "Select", N_("Select by SVG element (e.g. 'rect')")}, {"app.select-by-selector", N_("Select by Selector"), "Select", N_("Select by CSS selector")}, {"app.select-all", N_("Select All Objects"), "Select", N_("Select all; options: 'all' (every object including groups), 'layers', 'no-layers' (top level objects in layers), 'groups' (all groups including layers), 'no-groups' (all objects other than groups and layers, default)")}, + {"app.select-all-layers", N_("Select All in All Layers"), "Select", N_("Select all objects in all visible and unlocked layers")}, + {"app.select-same-fill-and-stroke", N_("Fill and Stroke"), "Select", N_("Select all objects with the same fill and stroke as the selected objects")}, + {"app.select-same-fill", N_("Fill Color"), "Select", N_("Select all objects with the same fill as the selected objects")}, + {"app.select-same-stroke-color", N_("Stroke Color"), "Select", N_("Select all objects with the same stroke as the selected objects")}, + {"app.select-same-stroke-style", N_("Stroke Style"), "Select", N_("Select all objects with the same stroke style (width, dash, markers) as the selected objects")}, + {"app.select-same-object-type", N_("Object Type"), "Select", N_("Select all objects with the same object type (rect, arc, text, path, bitmap etc) as the selected objects")}, + {"app.select-invert", N_("Invert Selection"), "Select", N_("Invert selection (unselect what is selected and select everything else)")}, + {"app.select-invert-all", N_("Invert in All Layers"), "Select", N_("Invert selection in all visible and unlocked layers")}, {"app.select-list", N_("List Selection"), "Select", N_("Print a list of objects in current selection")}, {"app.selection-set-backup", N_("Set selection backup"), "Select", N_("Set backup of current selection of objects or nodes")}, {"app.selection-restore-backup", N_("Restore selection backup"), "Select", N_("Restore backup of stored selection of objects or nodes")}, @@ -294,20 +401,27 @@ add_actions_selection(InkscapeApplication* app) auto *gapp = app->gio_app(); // clang-format off - gapp->add_action( "select-clear", sigc::bind(sigc::ptr_fun(&select_clear), app) ); - gapp->add_action_radio_string( "select", sigc::bind(sigc::ptr_fun(&select_by_id), app), "null"); // Backwards compatible. - gapp->add_action_radio_string( "unselect", sigc::bind(sigc::ptr_fun(&unselect_by_id), app), "null"); // Match select. - gapp->add_action_radio_string( "select-by-id", sigc::bind(sigc::ptr_fun(&select_by_id), app), "null"); - gapp->add_action_radio_string( "unselect-by-id", sigc::bind(sigc::ptr_fun(&unselect_by_id), app), "null"); - gapp->add_action_radio_string( "select-by-class", sigc::bind(sigc::ptr_fun(&select_by_class), app), "null"); - gapp->add_action_radio_string( "select-by-element", sigc::bind(sigc::ptr_fun(&select_by_element), app), "null"); - gapp->add_action_radio_string( "select-by-selector", sigc::bind(sigc::ptr_fun(&select_by_selector), app), "null"); - gapp->add_action_radio_string( "select-all", sigc::bind(sigc::ptr_fun(&select_all), app), "null"); - gapp->add_action_radio_string( "select-invert", sigc::bind(sigc::ptr_fun(&select_invert), app), "null"); - gapp->add_action( "select-list", sigc::bind(sigc::ptr_fun(&select_list), app) ); - gapp->add_action( "selection-set-backup", sigc::bind(sigc::ptr_fun(&selection_set_backup), app) ); - gapp->add_action( "selection-restore-backup", sigc::bind(sigc::ptr_fun(&selection_restore_backup), app) ); - gapp->add_action( "selection-empty-backup", sigc::bind(sigc::ptr_fun(&selection_empty_backup), app) ); + gapp->add_action( "select-clear", sigc::bind(sigc::ptr_fun(&select_clear), app) ); + gapp->add_action_radio_string( "select", sigc::bind(sigc::ptr_fun(&select_by_id), app), "null"); // Backwards compatible. + gapp->add_action_radio_string( "unselect", sigc::bind(sigc::ptr_fun(&unselect_by_id), app), "null"); // Match select. + gapp->add_action_radio_string( "select-by-id", sigc::bind(sigc::ptr_fun(&select_by_id), app), "null"); + gapp->add_action_radio_string( "unselect-by-id", sigc::bind(sigc::ptr_fun(&unselect_by_id), app), "null"); + gapp->add_action_radio_string( "select-by-class", sigc::bind(sigc::ptr_fun(&select_by_class), app), "null"); + gapp->add_action_radio_string( "select-by-element", sigc::bind(sigc::ptr_fun(&select_by_element), app), "null"); + gapp->add_action_radio_string( "select-by-selector", sigc::bind(sigc::ptr_fun(&select_by_selector), app), "null"); + gapp->add_action_radio_string( "select-all", sigc::bind(sigc::ptr_fun(&select_all), app), "null"); + gapp->add_action( "select-list", sigc::bind(sigc::ptr_fun(&select_list), app) ); + gapp->add_action( "selection-set-backup", sigc::bind(sigc::ptr_fun(&selection_set_backup), app) ); + gapp->add_action( "selection-restore-backup", sigc::bind(sigc::ptr_fun(&selection_restore_backup), app) ); + gapp->add_action( "selection-empty-backup", sigc::bind(sigc::ptr_fun(&selection_empty_backup), app) ); + gapp->add_action_radio_string( "select-all-layers", sigc::bind(sigc::ptr_fun(&select_all_layers), app), "null"); + gapp->add_action( "select-same-fill-and-stroke", sigc::bind(sigc::ptr_fun(&select_same_fill_and_stroke), app) ); + gapp->add_action( "select-same-fill", sigc::bind(sigc::ptr_fun(&select_same_fill), app) ); + gapp->add_action( "select-same-stroke-color", sigc::bind(sigc::ptr_fun(&select_same_stroke_color), app) ); + gapp->add_action( "select-same-stroke-style", sigc::bind(sigc::ptr_fun(&select_same_stroke_style), app) ); + gapp->add_action( "select-same-object-type", sigc::bind(sigc::ptr_fun(&select_same_object_type), app) ); + gapp->add_action_radio_string( "select-invert", sigc::bind(sigc::ptr_fun(&select_invert), app), "null"); + gapp->add_action_radio_string( "select-invert-all", sigc::bind(sigc::ptr_fun(&select_invert_all), app), "null"); // clang-format on app->get_action_extra_data().add_data(raw_data_selection); -- GitLab From cd50a797adcfaa10aa23fd23824dd3eca5a659b6 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 23 Sep 2023 11:35:15 +0200 Subject: [PATCH 2/2] fixbulid --- src/ui/dialog/swatches.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp index b57bfc03af..f191a48343 100644 --- a/src/ui/dialog/swatches.cpp +++ b/src/ui/dialog/swatches.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include "desktop.h" @@ -560,7 +561,7 @@ void SwatchesPanel::rebuild() } bool SwatchesPanel::load_swatches() { - auto window = dynamic_cast(get_toplevel()); + auto window = dynamic_cast(_palette->get_toplevel()); auto file = choose_palette_file(window); auto loaded = false; if (load_swatches(file)) { -- GitLab