Code

noop: be more consistent with function names (get_pathvector => set_pathvector)
[inkscape.git] / src / node-context.cpp
index 40b98336095ff5e84f2d5bc6f52f99ac3420497e..9a4bff88e361f17f8b2321fa6d25eaaa4bad56b4 100644 (file)
@@ -37,6 +37,8 @@
 #include "shape-editor.h"
 #include "live_effects/effect.h"
 
+#include "sp-lpe-item.h"
+
 // needed for flash nodepath upon mouseover:
 #include "display/canvas-bpath.h"
 #include "display/curve.h"
@@ -116,15 +118,15 @@ sp_node_context_dispose(GObject *object)
 
     ec->enableGrDrag(false);
 
-    if (nc->flash_permitem) {
-        // hack!!! (we add a temporary canvasitem with life time 1 ms)
-        nc->flash_tempitem = nc->event_context.desktop->add_temporary_canvasitem (nc->flash_permitem, 1);
-        nc->flash_permitem = NULL;
-    }
-
     nc->sel_changed_connection.disconnect();
     nc->sel_changed_connection.~connection();
 
+    // TODO: should this be here?
+    SPItem *item = sp_desktop_selection(ec->desktop)->singleItem();
+    if (item && SP_IS_LPE_ITEM(item)) {
+        sp_lpe_item_remove_temporary_canvasitems(SP_LPE_ITEM(item), ec->desktop);
+    }
+
     delete nc->shape_editor;
 
     if (nc->_node_message_context) {
@@ -142,10 +144,11 @@ sp_node_context_setup(SPEventContext *ec)
     if (((SPEventContextClass *) parent_class)->setup)
         ((SPEventContextClass *) parent_class)->setup(ec);
 
+    Inkscape::Selection *selection = sp_desktop_selection (ec->desktop);
     nc->sel_changed_connection.disconnect();
-    nc->sel_changed_connection = sp_desktop_selection(ec->desktop)->connectChanged(sigc::bind(sigc::ptr_fun(&sp_node_context_selection_changed), (gpointer)nc));
+    nc->sel_changed_connection =
+        selection->connectChanged(sigc::bind(sigc::ptr_fun(&sp_node_context_selection_changed), (gpointer)nc));
 
-    Inkscape::Selection *selection = sp_desktop_selection(ec->desktop);
     SPItem *item = selection->singleItem();
 
     nc->shape_editor = new ShapeEditor(ec->desktop);
@@ -177,23 +180,6 @@ sp_node_context_setup(SPEventContext *ec)
     nc->shape_editor->update_statusbar();
 }
 
-static SPCanvasItem *
-sp_node_context_generate_helperpath(SPDesktop *desktop, SPPath *path) {
-    // This should be put somewhere else under the name of "generate helperpath" or something. Because basically this is copied of code from nodepath...
-    SPCurve *curve_new = sp_path_get_curve_for_edit(path);
-    SPCurve *flash_curve = curve_new->copy();
-    flash_curve->transform(from_2geom(sp_item_i2d_affine(SP_ITEM(path))));
-    SPCanvasItem * canvasitem = sp_canvas_bpath_new(sp_desktop_tempgroup(desktop), flash_curve);
-    // would be nice if its color could be XORed or something, now it is invisible for red stroked objects...
-    // unless we also flash the nodes...
-    guint32 color = prefs_get_int_attribute("tools.nodes", "highlight_color", 0xff0000ff);
-    sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(canvasitem), color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
-    sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(canvasitem), 0, SP_WIND_RULE_NONZERO);
-    sp_canvas_item_show(canvasitem);
-    flash_curve->unref();
-    return canvasitem;
-}
-
 static void
 sp_node_context_flash_path(SPEventContext *event_context, SPItem *item, guint timeout) {
     SPNodeContext *nc = SP_NODE_CONTEXT(event_context);
@@ -209,7 +195,7 @@ sp_node_context_flash_path(SPEventContext *event_context, SPItem *item, guint ti
         }
 
         if (SP_IS_PATH(item)) {
-            SPCanvasItem *canvasitem = sp_node_context_generate_helperpath(desktop, SP_PATH(item));
+            SPCanvasItem *canvasitem = sp_nodepath_generate_helperpath(desktop, SP_PATH(item));
             nc->flash_tempitem = desktop->add_temporary_canvasitem (canvasitem, timeout);
         }
     }
@@ -228,22 +214,6 @@ sp_node_context_selection_changed(Inkscape::Selection *selection, gpointer data)
     nc->shape_editor->unset_item();
     SPItem *item = selection->singleItem(); 
     nc->shape_editor->set_item(item);
-
-    if (nc->flash_permitem) {
-        // hack!!! (we add a temporary canvasitem with life time 1 ms)
-        nc->flash_tempitem = nc->event_context.desktop->add_temporary_canvasitem (nc->flash_permitem, 1);
-        nc->flash_permitem = NULL;
-    }
-    if (SP_IS_LPE_ITEM(item)) {
-        Inkscape::LivePathEffect::Effect *lpe = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
-        if (lpe && lpe->pathFlashType() == Inkscape::LivePathEffect::PERMANENT_FLASH) {
-            if (SP_IS_PATH(item)) {
-                SPCanvasItem *canvasitem = sp_node_context_generate_helperpath(nc->event_context.desktop, SP_PATH(item));
-                nc->flash_permitem = canvasitem;
-            }
-        }
-    }
-
     nc->shape_editor->update_statusbar();
 }
 
@@ -266,15 +236,11 @@ sp_node_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEve
         guint timeout = prefs_get_int_attribute("tools.nodes", "pathflash_timeout", 500);
         if (SP_IS_LPE_ITEM(item)) {
             Inkscape::LivePathEffect::Effect *lpe = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
-            if (lpe) {
-                if (lpe->pathFlashType() == Inkscape::LivePathEffect::SUPPRESS_FLASH) {
-                    // return if flash is suppressed or if we want a permanent "flash" (this is handled
-                    // in sp_node_context_selection_changed()
-                    return ret;
-                }
-                if (lpe->pathFlashType() == Inkscape::LivePathEffect::PERMANENT_FLASH) {
-                    timeout = 0;
-                }
+            if (lpe && (lpe->providesOwnFlashPaths() ||
+                        lpe->pathFlashType() == Inkscape::LivePathEffect::SUPPRESS_FLASH)) {
+                // path should be suppressed or permanent; this is handled in
+                // sp_node_context_selection_changed()
+                return ret;
             }
         }
         sp_node_context_flash_path(event_context, item, timeout);