From 6f808bed60362652003a94cd51fea129009d58cf Mon Sep 17 00:00:00 2001 From: bryce Date: Wed, 21 Feb 2007 09:32:19 +0000 Subject: [PATCH] Fixes issue where a modified stock marker's preview image appears in the marker dropdown with the same preview image as the unmodified stock marker. This adds the source document's uri to the cache index. --- src/dialogs/stroke-style.cpp | 3 ++- src/ui/cache/svg_preview_cache.cpp | 12 ++++++++---- src/ui/cache/svg_preview_cache.h | 4 ++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/dialogs/stroke-style.cpp b/src/dialogs/stroke-style.cpp index 334b01dd1..0d22a90f7 100644 --- a/src/dialogs/stroke-style.cpp +++ b/src/dialogs/stroke-style.cpp @@ -619,7 +619,7 @@ sp_marker_prev_new(unsigned psize, gchar const *mname, double sf = 0.8; GdkPixbuf* pixbuf = NULL; - Glib::ustring key = svg_preview_cache.cache_key(mname, psize); + Glib::ustring key = svg_preview_cache.cache_key(source->uri, mname, psize); pixbuf = svg_preview_cache.get_preview_from_cache(key); if (pixbuf == NULL) { @@ -687,6 +687,7 @@ sp_marker_menu_build (GtkWidget *m, GSList *marker_list, SPDocument *source, SPD gtk_widget_show(hb); // generate preview + GtkWidget *prv = sp_marker_prev_new (22, markid, source, sandbox, menu_id, arena, visionkey, root); gtk_widget_show(prv); gtk_box_pack_start(GTK_BOX(hb), prv, FALSE, FALSE, 6); diff --git a/src/ui/cache/svg_preview_cache.cpp b/src/ui/cache/svg_preview_cache.cpp index 4aa46af2b..cee1db715 100644 --- a/src/ui/cache/svg_preview_cache.cpp +++ b/src/ui/cache/svg_preview_cache.cpp @@ -109,8 +109,11 @@ SvgPreview::~SvgPreview() { } -Glib::ustring SvgPreview::cache_key(gchar const *name, unsigned psize) const { - Glib::ustring key = name; +Glib::ustring SvgPreview::cache_key(gchar const *uri, gchar const *name, unsigned psize) const { + Glib::ustring key; + key += (uri!=NULL) ? uri : ""; + key += ":"; + key += (name!=NULL) ? name : "unknown"; key += ":"; key += psize; return key; @@ -128,10 +131,10 @@ void SvgPreview::set_preview_in_cache(const Glib::ustring& key, GdkPixbuf* px) { _pixmap_cache[key] = px; } -GdkPixbuf* SvgPreview::get_preview(const gchar* id, NRArenaItem *root, +GdkPixbuf* SvgPreview::get_preview(const gchar* uri, const gchar* id, NRArenaItem *root, double scale_factor, unsigned int psize) { // First try looking up the cached preview in the cache map - Glib::ustring key = cache_key(id, psize); + Glib::ustring key = cache_key(uri, id, psize); GdkPixbuf* px = get_preview_from_cache(key); if (px == NULL) { @@ -140,6 +143,7 @@ GdkPixbuf* SvgPreview::get_preview(const gchar* id, NRArenaItem *root, set_preview_in_cache(key, px); */ } + return px; } }; diff --git a/src/ui/cache/svg_preview_cache.h b/src/ui/cache/svg_preview_cache.h index 14e05d2f8..79ea80239 100644 --- a/src/ui/cache/svg_preview_cache.h +++ b/src/ui/cache/svg_preview_cache.h @@ -25,10 +25,10 @@ class SvgPreview { SvgPreview(); ~SvgPreview(); - Glib::ustring cache_key(gchar const *name, unsigned psize) const; + Glib::ustring cache_key(gchar const *uri, gchar const *name, unsigned psize) const; GdkPixbuf* get_preview_from_cache(const Glib::ustring& key); void set_preview_in_cache(const Glib::ustring& key, GdkPixbuf* px); - GdkPixbuf* get_preview(const gchar* id, NRArenaItem *root, double scale_factor, unsigned int psize); + GdkPixbuf* get_preview(const gchar* uri, const gchar* id, NRArenaItem *root, double scale_factor, unsigned int psize); }; }; // namespace Cache -- 2.30.2