Code

Change paint bucket path union to properly create only one undo event, rather than two
authorjohncoswell <johncoswell@users.sourceforge.net>
Sat, 31 Mar 2007 12:42:17 +0000 (12:42 +0000)
committerjohncoswell <johncoswell@users.sourceforge.net>
Sat, 31 Mar 2007 12:42:17 +0000 (12:42 +0000)
src/flood-context.cpp
src/splivarot.cpp
src/splivarot.h

index f377d6b943c016ce5a1f6623dfc7252fe0ffd28f..3d6bc1272923be5434e4ab64e0e5303591fc8298 100644 (file)
@@ -324,7 +324,7 @@ static bool try_add_to_queue(std::queue<NR::Point> *fill_queue, guchar *px, guch
     return true;
 }
 
-static void do_trace(GdkPixbuf *px, SPDesktop *desktop, NR::Matrix transform) {
+static void do_trace(GdkPixbuf *px, SPDesktop *desktop, NR::Matrix transform, bool union_with_selection) {
     SPDocument *document = sp_desktop_document(desktop);
     
     Inkscape::Trace::Potrace::PotraceTracingEngine pte;
@@ -420,12 +420,20 @@ static void do_trace(GdkPixbuf *px, SPDesktop *desktop, NR::Matrix transform) {
             }
 
             Inkscape::Selection *selection = sp_desktop_selection(desktop);
-            selection->set(reprobj);
+
             pathRepr->setPosition(-1);
 
-            desktop->messageStack()->flashF(Inkscape::WARNING_MESSAGE, _("Area filled, path with <b>%d</b> nodes created."), sp_nodes_in_path(SP_PATH(reprobj)));
+            if (union_with_selection) {
+                desktop->messageStack()->flashF(Inkscape::WARNING_MESSAGE, _("Area filled, path with <b>%d</b> nodes created and unioned with selection."), sp_nodes_in_path(SP_PATH(reprobj)));
+                selection->add(reprobj);
+                sp_selected_path_union_skip_undo();
+            } else {
+                desktop->messageStack()->flashF(Inkscape::WARNING_MESSAGE, _("Area filled, path with <b>%d</b> nodes created."), sp_nodes_in_path(SP_PATH(reprobj)));
+                selection->set(reprobj);
+            }
+
         }
-        
+
         Inkscape::GC::release(pathRepr);
 
     }
@@ -501,7 +509,7 @@ static ScanlineCheckResult perform_bitmap_scanline_check(std::queue<NR::Point> *
     return SCANLINE_CHECK_OK;
 }
 
-static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *event) {
+static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *event, bool union_with_selection) {
     SPDesktop *desktop = event_context->desktop;
     SPDocument *document = sp_desktop_document(desktop);
 
@@ -730,7 +738,7 @@ static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *even
 
     NR::Matrix inverted_affine = NR::Matrix(affine).inverse();
     
-    do_trace(pixbuf, desktop, inverted_affine);
+    do_trace(pixbuf, desktop, inverted_affine, union_with_selection);
 
     g_free(trace_px);
     
@@ -784,15 +792,7 @@ static gint sp_flood_context_root_handler(SPEventContext *event_context, GdkEven
                     // Since setWaitingCursor runs main loop iterations, we may have already left this tool!
                     // So check if the tool is valid before doing anything
 
-                    Inkscape::Selection *selection = sp_desktop_selection(desktop);
-                    GSList *items = g_slist_copy((GSList *) selection->itemList());
-
-                    sp_flood_do_flood_fill(event_context, event);
-
-                    if (event->button.state & GDK_SHIFT_MASK) {
-                        selection->addList(items);
-                        sp_selected_path_union();
-                    }
+                    sp_flood_do_flood_fill(event_context, event, event->button.state & GDK_SHIFT_MASK);
                     
                     // restore cursor when done; note that it may already be different if e.g. user 
                     // switched to another tool during interruptible tracing or drawing, in which case do nothing
index 3035cb1a7ae022a5c633b425f664be203d87949f..f1ce029f4f36b95c17bcb3c718e2bf9234dbd678 100644 (file)
@@ -66,6 +66,12 @@ sp_selected_path_union()
     sp_selected_path_boolop(bool_op_union, SP_VERB_SELECTION_UNION, _("Union"));
 }
 
+void
+sp_selected_path_union_skip_undo()
+{
+    sp_selected_path_boolop(bool_op_union, SP_VERB_NONE, _("Union"));
+}
+
 void
 sp_selected_path_intersect()
 {
@@ -573,7 +579,9 @@ sp_selected_path_boolop(bool_op bop, const unsigned int verb, const Glib::ustrin
 
     g_free(transform);
 
-    sp_document_done(sp_desktop_document(desktop), verb, description);
+    if (verb != SP_VERB_NONE) {
+        sp_document_done(sp_desktop_document(desktop), verb, description);
+    }
 
     delete res;
 }
index cf1ebcd9400f2777088dde90e1fdafb000628310..3d01f41e0650a48bc4695a0e71ce73287561610b 100644 (file)
@@ -13,6 +13,7 @@
 // work on the current selection
 // selection has 2 contain exactly 2 items
 void sp_selected_path_union ();
+void sp_selected_path_union_skip_undo ();
 void sp_selected_path_intersect ();
 void sp_selected_path_diff ();
 void sp_selected_path_symdiff ();