From: cilix42 Date: Wed, 4 Jun 2008 13:12:05 +0000 (+0000) Subject: Factor out 'create and apply' code for LPEs so that it can be called from everywhere X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=6656f193fdace606d1b162d6dea0223bc295f0a6;p=inkscape.git Factor out 'create and apply' code for LPEs so that it can be called from everywhere --- diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 639ad93a4..765d0a59b 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -16,6 +16,8 @@ #include "desktop.h" #include "inkscape.h" #include "document.h" +#include "document-private.h" +#include "xml/document.h" #include #include "live_effects/lpeobject.h" @@ -147,6 +149,32 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj) return neweffect; } +void +Effect::createAndApply(const char* name, SPDocument *doc, SPItem *item) +{ + // Path effect definition + Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); + Inkscape::XML::Node *repr = xml_doc->createElement("inkscape:path-effect"); + repr->setAttribute("effect", name); + + SP_OBJECT_REPR(SP_DOCUMENT_DEFS(doc))->addChild(repr, NULL); // adds to and assigns the 'id' attribute + const gchar * repr_id = repr->attribute("id"); + Inkscape::GC::release(repr); + + gchar *href = g_strdup_printf("#%s", repr_id); + sp_lpe_item_add_path_effect(SP_LPE_ITEM(item), href, true); + g_free(href); + + sp_document_done(doc, SP_VERB_DIALOG_LIVE_PATH_EFFECT, + _("Create and apply path effect")); +} + +void +Effect::createAndApply(EffectType type, SPDocument *doc, SPItem *item) +{ + createAndApply(LPETypeConverter.get_key(type).c_str(), doc, item); +} + Effect::Effect(LivePathEffectObject *lpeobject) : oncanvasedit_it(0), is_visible(_("Is visible?"), _("If unchecked, the effect remains applied to the object but is temporarily disabled on canvas"), "is_visible", &wr, this, true), diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 6d72a5615..c04f248e3 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -80,6 +80,8 @@ extern const Util::EnumDataConverter LPETypeConverter; class Effect { public: static Effect* New(EffectType lpenr, LivePathEffectObject *lpeobj); + static void createAndApply(const char* name, SPDocument *doc, SPItem *item); + static void createAndApply(EffectType type, SPDocument *doc, SPItem *item); virtual ~Effect(); diff --git a/src/ui/dialog/livepatheffect-editor.cpp b/src/ui/dialog/livepatheffect-editor.cpp index c92d015f5..2dc4fda71 100644 --- a/src/ui/dialog/livepatheffect-editor.cpp +++ b/src/ui/dialog/livepatheffect-editor.cpp @@ -32,9 +32,8 @@ #include "inkscape.h" #include "desktop-handles.h" #include "desktop.h" -#include "document-private.h" +#include "document.h" #include "xml/node.h" -#include "xml/document.h" #include #include @@ -320,21 +319,7 @@ LivePathEffectEditor::onApply() item = sel->singleItem(); // get new item } - // Path effect definition - Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); - Inkscape::XML::Node *repr = xml_doc->createElement("inkscape:path-effect"); - repr->setAttribute("effect", data->key.c_str() ); - - SP_OBJECT_REPR(SP_DOCUMENT_DEFS(doc))->addChild(repr, NULL); // adds to and assigns the 'id' attribute - const gchar * repr_id = repr->attribute("id"); - Inkscape::GC::release(repr); - - gchar *href = g_strdup_printf("#%s", repr_id); - sp_lpe_item_add_path_effect(SP_LPE_ITEM(item), href, true); - g_free(href); - - sp_document_done(doc, SP_VERB_DIALOG_LIVE_PATH_EFFECT, - _("Create and apply path effect")); + LivePathEffect::Effect::createAndApply(data->key.c_str(), doc, item); onSelectionChanged(sel); }