From 0b954d5cc1a1e398c561c32faf8e198efb860ac6 Mon Sep 17 00:00:00 2001 From: Samuel Buttigieg Date: Sat, 10 Nov 2018 10:06:31 +0100 Subject: Fix Bug #1796261 update markers in groups --- src/widgets/stroke-style.cpp | 64 +++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 22 deletions(-) mode change 100644 => 100755 src/widgets/stroke-style.cpp (limited to 'src/widgets/stroke-style.cpp') diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp old mode 100644 new mode 100755 index 21e8068af..d3dfbbe8a --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -495,8 +495,6 @@ void StrokeStyle::markerSelectCB(MarkerComboBox *marker_combo, StrokeStyle *spw, Inkscape::XML::Node *selrepr = item->getRepr(); if (selrepr) { sp_repr_css_change_recursive(selrepr, css, "style"); - SPObject *markerObj = getMarkerObj(marker, document); - spw->setMarkerColor(markerObj, marker_combo->get_loc(), item); } item->requestModified(SP_OBJECT_MODIFIED_FLAG); @@ -1210,6 +1208,22 @@ StrokeStyle::setPaintOrderButtons(Gtk::ToggleButton *active) } +/** + * Recursively builds a simple list from an arbitrarily complex selection + * of items and grouped items + */ +static void buildGroupedItemList(SPObject *element, std::vector &simple_list) +{ + if (SP_IS_GROUP(element)) { + for (SPObject *i = element->firstChild(); i; i = i->getNext()) { + buildGroupedItemList(i, simple_list); + } + } else { + simple_list.push_back(element); + } +} + + /** * Updates the marker combobox to highlight the appropriate marker and scroll to * that marker. @@ -1231,15 +1245,19 @@ StrokeStyle::updateAllMarkers(std::vector const &objects, bool skip_und } } + auto simplified_list = std::vector(); + for (SPItem *item : objects) { + buildGroupedItemList(item, simplified_list); + } + for (unsigned i = 0; i < G_N_ELEMENTS(keyloc); ++i) { MarkerComboBox *combo = static_cast(keyloc[i].key); // Per SVG spec, text objects cannot have markers; disable combobox if only texts are selected combo->set_sensitive(!all_texts); } - // We show markers of the first object in the list only + // We show markers of the last object in the list only // FIXME: use the first in the list that has the marker of each type, if any - SPObject *object = objects[0]; for (unsigned i = 0; i < G_N_ELEMENTS(keyloc); ++i) { // For all three marker types, @@ -1254,30 +1272,32 @@ StrokeStyle::updateAllMarkers(std::vector const &objects, bool skip_und combo->setDesktop(desktop); - if (object->style->marker_ptrs[keyloc[i].loc]->value != nullptr && !all_texts) { - // If the object has this type of markers, + for (SPObject *object : simplified_list) { + if (object->style->marker_ptrs[keyloc[i].loc]->value != nullptr && !all_texts) { + // If the object has this type of markers, - // Extract the name of the marker that the object uses - SPObject *marker = getMarkerObj(object->style->marker_ptrs[keyloc[i].loc]->value, object->document); - // Scroll the combobox to that marker - combo->set_current(marker); + // Extract the name of the marker that the object uses + SPObject *marker = getMarkerObj(object->style->marker_ptrs[keyloc[i].loc]->value, object->document); + // Scroll the combobox to that marker + combo->set_current(marker); - // Set the marker color - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - gboolean update = prefs->getBool("/options/markers/colorUpdateMarkers", true); + // Set the marker color + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean update = prefs->getBool("/options/markers/colorUpdateMarkers", true); - if (update) { - setMarkerColor(marker, combo->get_loc(), SP_ITEM(object)); + if (update) { + setMarkerColor(marker, combo->get_loc(), SP_ITEM(object)); - if (!skip_undo) { - SPDocument *document = desktop->getDocument(); - DocumentUndo::maybeDone(document, "UaM", SP_VERB_DIALOG_FILL_STROKE, - _("Set marker color")); + if (!skip_undo) { + SPDocument *document = desktop->getDocument(); + DocumentUndo::maybeDone(document, "UaM", SP_VERB_DIALOG_FILL_STROKE, + _("Set marker color")); + } } - } - } else { - combo->set_current(nullptr); + } else { + combo->set_current(nullptr); + } } } -- cgit v1.2.3