From: kiirala Date: Mon, 2 Jun 2008 15:47:48 +0000 (+0000) Subject: Fixed conflicting result image names inside filter effects (bug 196126) X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=edb914131cdbaafc595358490cde08faec1a3be4;p=inkscape.git Fixed conflicting result image names inside filter effects (bug 196126) --- diff --git a/src/sp-filter.cpp b/src/sp-filter.cpp index 150033895..e020f6814 100644 --- a/src/sp-filter.cpp +++ b/src/sp-filter.cpp @@ -22,6 +22,8 @@ using std::map; using std::pair; +#include + #include "attributes.h" #include "document.h" #include "sp-filter.h" @@ -114,6 +116,7 @@ sp_filter_init(SPFilter *filter) filter->_image_name = new std::map; filter->_image_name->clear(); + filter->_image_number_next = 0; filter->filterRes = NumberOptNumber(); @@ -476,6 +479,28 @@ int sp_filter_set_image_name(SPFilter *filter, gchar const *name) { return value; } +Glib::ustring sp_filter_get_new_result_name(SPFilter *filter) { + g_assert(filter != NULL); + int largest = 0; + + SPObject *primitive_obj = filter->children; + while (primitive_obj) { + if (SP_IS_FILTER_PRIMITIVE(primitive_obj)) { + Inkscape::XML::Node *repr = SP_OBJECT_REPR(primitive_obj); + char const *result = repr->attribute("result"); + int index; + if (result && sscanf(result, "result%d", &index) == 1) { + if (index > largest) { + largest = index; + } + } + } + primitive_obj = primitive_obj->next; + } + + return "result" + Glib::Ascii::dtostr(largest + 1); +} + bool ltstr::operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) < 0; diff --git a/src/sp-filter.h b/src/sp-filter.h index 3e9bb3cb0..d0a449c47 100644 --- a/src/sp-filter.h +++ b/src/sp-filter.h @@ -16,6 +16,8 @@ #include +#include + #include "number-opt-number.h" #include "sp-object.h" #include "sp-filter-units.h" @@ -82,6 +84,11 @@ int sp_filter_primitive_count(SPFilter *filter); int sp_filter_get_image_name(SPFilter *filter, gchar const *name); int sp_filter_set_image_name(SPFilter *filter, gchar const *name); +/* + * Returns a result image name that is not in use inside this filter. + */ +Glib::ustring sp_filter_get_new_result_name(SPFilter *filter); + #endif /* !SP_FILTER_H_SEEN */ /* diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index c7694ef09..98951f28c 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -1917,7 +1917,7 @@ bool FilterEffectsDialog::PrimitiveList::on_button_release_event(GdkEventButton* // Make sure the target has a result const gchar *gres = repr->attribute("result"); if(!gres) { - result = "result" + Glib::Ascii::dtostr(SP_FILTER(prim->parent)->_image_number_next); + result = sp_filter_get_new_result_name(SP_FILTER(prim->parent)); repr->setAttribute("result", result.c_str()); in_val = result.c_str(); }