[gimp] app: add boolean "cancelable" API to GimpImageMap and gimpdrawable-filter.[ch]



commit f4803af808f6675a1a6f3565239c404167f60351
Author: Michael Natterer <mitch gimp org>
Date:   Mon Jun 30 01:06:04 2014 +0200

    app: add boolean "cancelable" API to GimpImageMap and gimpdrawable-filter.[ch]
    
    Return booleans indicating success (FALSE == user has canceled), and
    allow canceling only in GimpImageMapTool for now.

 app/core/gimpdrawable-filter.c    |   13 ++++++++++---
 app/core/gimpdrawable-filter.h    |    5 +++--
 app/core/gimpimagemap.c           |   17 ++++++++++++-----
 app/core/gimpimagemap.h           |    5 +++--
 app/core/gimplayer-floating-sel.c |    2 +-
 app/tools/gimpcagetool.c          |    3 +--
 app/tools/gimpimagemaptool.c      |    3 +--
 app/tools/gimpseamlessclonetool.c |    4 ++--
 app/tools/gimpwarptool.c          |    2 +-
 9 files changed, 34 insertions(+), 20 deletions(-)
---
diff --git a/app/core/gimpdrawable-filter.c b/app/core/gimpdrawable-filter.c
index 4e1a0a6..5e72638 100644
--- a/app/core/gimpdrawable-filter.c
+++ b/app/core/gimpdrawable-filter.c
@@ -82,13 +82,15 @@ gimp_drawable_has_filter (GimpDrawable *drawable,
                               GIMP_OBJECT (filter));
 }
 
-void
+gboolean
 gimp_drawable_merge_filter (GimpDrawable *drawable,
                             GimpFilter   *filter,
                             GimpProgress *progress,
-                            const gchar  *undo_desc)
+                            const gchar  *undo_desc,
+                            gboolean      cancelable)
 {
   GeglRectangle rect;
+  gboolean      success = TRUE;
 
   g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
   g_return_if_fail (GIMP_IS_FILTER (filter));
@@ -141,7 +143,7 @@ gimp_drawable_merge_filter (GimpDrawable *drawable,
                                             gimp_drawable_get_buffer (drawable),
                                             &rect,
                                             cache, rects, n_rects,
-                                            TRUE))
+                                            cancelable))
         {
           gimp_drawable_push_undo (drawable, undo_desc, undo_buffer,
                                    rect.x, rect.y,
@@ -169,6 +171,9 @@ gimp_drawable_merge_filter (GimpDrawable *drawable,
                             GEGL_RECTANGLE (0, 0, rect.width, rect.height),
                             gimp_drawable_get_buffer (drawable),
                             GEGL_RECTANGLE (rect.x, rect.y, 0, 0));
+
+          /* canceled by the user */
+          success = FALSE;
         }
 
       g_object_unref (undo_buffer);
@@ -183,4 +188,6 @@ gimp_drawable_merge_filter (GimpDrawable *drawable,
                             rect.x, rect.y,
                             rect.width, rect.height);
     }
+
+  return success;
 }
diff --git a/app/core/gimpdrawable-filter.h b/app/core/gimpdrawable-filter.h
index 0fe5f77..0d2a871 100644
--- a/app/core/gimpdrawable-filter.h
+++ b/app/core/gimpdrawable-filter.h
@@ -31,10 +31,11 @@ void            gimp_drawable_remove_filter (GimpDrawable *drawable,
 gboolean        gimp_drawable_has_filter    (GimpDrawable *drawable,
                                              GimpFilter   *filter);
 
-void            gimp_drawable_merge_filter  (GimpDrawable *drawable,
+gboolean        gimp_drawable_merge_filter  (GimpDrawable *drawable,
                                              GimpFilter   *filter,
                                              GimpProgress *progress,
-                                             const gchar  *undo_desc);
+                                             const gchar  *undo_desc,
+                                             gboolean      cancelable);
 
 
 #endif /* __GIMP_DRAWABLE_FILTER_H__ */
diff --git a/app/core/gimpimagemap.c b/app/core/gimpimagemap.c
index 490ccfd..18fbd9a 100644
--- a/app/core/gimpimagemap.c
+++ b/app/core/gimpimagemap.c
@@ -397,23 +397,30 @@ gimp_image_map_apply (GimpImageMap        *image_map,
   gimp_image_map_update_drawable (image_map, &update_area);
 }
 
-void
+gboolean
 gimp_image_map_commit (GimpImageMap *image_map,
-                       GimpProgress *progress)
+                       GimpProgress *progress,
+                       gboolean      cancelable)
 {
+  gboolean success = TRUE;
+
   g_return_if_fail (GIMP_IS_IMAGE_MAP (image_map));
   g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
 
   if (gimp_image_map_is_filtering (image_map))
     {
-      gimp_drawable_merge_filter (image_map->drawable, image_map->filter,
-                                  progress,
-                                  image_map->undo_desc);
+      success = gimp_drawable_merge_filter (image_map->drawable,
+                                            image_map->filter,
+                                            progress,
+                                            image_map->undo_desc,
+                                            cancelable);
 
       gimp_image_map_remove_filter (image_map);
 
       g_signal_emit (image_map, image_map_signals[FLUSH], 0);
     }
+
+  return success;
 }
 
 void
diff --git a/app/core/gimpimagemap.h b/app/core/gimpimagemap.h
index 1b17403..f287d8c 100644
--- a/app/core/gimpimagemap.h
+++ b/app/core/gimpimagemap.h
@@ -66,8 +66,9 @@ void       gimp_image_map_set_gamma_hack (GimpImageMap         *image_map,
 void           gimp_image_map_apply      (GimpImageMap         *image_map,
                                           const GeglRectangle  *area);
 
-void           gimp_image_map_commit     (GimpImageMap         *image_map,
-                                          GimpProgress         *progress);
+gboolean       gimp_image_map_commit     (GimpImageMap         *image_map,
+                                          GimpProgress         *progress,
+                                          gboolean              cancelable);
 void           gimp_image_map_abort      (GimpImageMap         *image_map);
 
 
diff --git a/app/core/gimplayer-floating-sel.c b/app/core/gimplayer-floating-sel.c
index a73d1e0..6d80d71 100644
--- a/app/core/gimplayer-floating-sel.c
+++ b/app/core/gimplayer-floating-sel.c
@@ -121,7 +121,7 @@ floating_sel_anchor (GimpLayer *layer)
 
   if (filter)
     {
-      gimp_drawable_merge_filter (drawable, filter, NULL, NULL);
+      gimp_drawable_merge_filter (drawable, filter, NULL, NULL, FALSE);
       g_object_unref (filter);
     }
 
diff --git a/app/tools/gimpcagetool.c b/app/tools/gimpcagetool.c
index c35c556..43ae3b0 100644
--- a/app/tools/gimpcagetool.c
+++ b/app/tools/gimpcagetool.c
@@ -944,8 +944,7 @@ gimp_cage_tool_commit (GimpCageTool *ct)
 
   gimp_tool_control_push_preserve (tool->control, TRUE);
 
-  gimp_image_map_commit (ct->image_map,
-                         GIMP_PROGRESS (tool));
+  gimp_image_map_commit (ct->image_map, GIMP_PROGRESS (tool), FALSE);
   g_object_unref (ct->image_map);
   ct->image_map = NULL;
 
diff --git a/app/tools/gimpimagemaptool.c b/app/tools/gimpimagemaptool.c
index fedcdc1..4963e39 100644
--- a/app/tools/gimpimagemaptool.c
+++ b/app/tools/gimpimagemaptool.c
@@ -651,8 +651,7 @@ gimp_image_map_tool_commit (GimpImageMapTool *im_tool)
       if (! options->preview)
         gimp_image_map_tool_map (im_tool);
 
-      gimp_image_map_commit (im_tool->image_map,
-                             GIMP_PROGRESS (tool));
+      gimp_image_map_commit (im_tool->image_map, GIMP_PROGRESS (tool), TRUE);
       g_object_unref (im_tool->image_map);
       im_tool->image_map = NULL;
 
diff --git a/app/tools/gimpseamlessclonetool.c b/app/tools/gimpseamlessclonetool.c
index 2d599c0..f955e51 100644
--- a/app/tools/gimpseamlessclonetool.c
+++ b/app/tools/gimpseamlessclonetool.c
@@ -375,7 +375,7 @@ gimp_seamless_clone_tool_commit (GimpSeamlessCloneTool *sc)
     {
       gimp_tool_control_push_preserve (tool->control, TRUE);
 
-      gimp_image_map_commit (sc->image_map, GIMP_PROGRESS (tool));
+      gimp_image_map_commit (sc->image_map, GIMP_PROGRESS (tool), FALSE);
       g_object_unref (sc->image_map);
       sc->image_map = NULL;
 
@@ -525,7 +525,7 @@ gimp_seamless_clone_tool_key_press (GimpTool    *tool,
            *       rectangle each time (in the update function) or by
            *       invalidating and re-rendering all now (expensive and
            *       perhaps useless */
-          gimp_image_map_commit (sct->image_map, GIMP_PROGRESS (tool));
+          gimp_image_map_commit (sct->image_map, GIMP_PROGRESS (tool), FALSE);
           g_object_unref (sct->image_map);
           sct->image_map = NULL;
 
diff --git a/app/tools/gimpwarptool.c b/app/tools/gimpwarptool.c
index 42f8db9..79efe15 100644
--- a/app/tools/gimpwarptool.c
+++ b/app/tools/gimpwarptool.c
@@ -614,7 +614,7 @@ gimp_warp_tool_commit (GimpWarpTool *wt)
     {
       gimp_tool_control_push_preserve (tool->control, TRUE);
 
-      gimp_image_map_commit (wt->image_map, GIMP_PROGRESS (tool));
+      gimp_image_map_commit (wt->image_map, GIMP_PROGRESS (tool), FALSE);
       g_object_unref (wt->image_map);
       wt->image_map = NULL;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]