Some of you might have noticed that my previous message assumes that
there is a PDB call allowing a script to check if undo is enabled or
disabled on the current image.  Alas, there is not such thing in the
current version of the GIMP.  I don't know if this was a design
decision ("no plug-in is supposed to mess with this undo stuff") or if
it was an oversight, but this would be very useful in the scenario
that I described.

So here is a small patch (2 KB) that adds this function.  You can see
this patch as a bugfix (because it will be used to fix the undo bugs
in Script-Fu) or as a new feature that should therefore be rejected
because of the feature freeze...

Note about the code: I didn't use the image_accessors subroutine in
pdbgen/pdb/gimage.pdb because there should be no "set" operation for
undo (we already have enable-undo and disable-undo) and because that
subroutine did not produce a useful help text.  But if someone can
code that in a better way (it is trivial anyway), feel free to do it.

-Raphael



--- app/gimpimage.h.orig        Sun Oct 17 02:07:36 1999
+++ app/gimpimage.h     Tue Nov 23 11:14:37 1999
@@ -248,6 +248,7 @@
 GimpImageBaseType  gimp_image_base_type            (GimpImage *);
 GimpImageType     gimp_image_base_type_with_alpha (GimpImage *);
 gchar *            gimp_image_filename             (GimpImage *);
+gboolean           gimp_image_get_undo             (GimpImage *);
 gboolean           gimp_image_undo_enable          (GimpImage *);
 gboolean           gimp_image_undo_disable         (GimpImage *);
 gboolean           gimp_image_undo_freeze          (GimpImage *);
--- app/gimpimage.c.orig        Fri Oct 29 02:10:23 1999
+++ app/gimpimage.c     Tue Nov 23 11:14:22 1999
@@ -3155,6 +3155,12 @@
 }
 
 gboolean
+gimp_image_get_undo (GimpImage *gimage)
+{
+  return gimage->undo_on;
+}
+
+gboolean
 gimp_image_undo_freeze (GimpImage *gimage)
 {
   gimage->undo_on = FALSE;
--- tools/pdbgen/pdb/gimage.pdb.orig    Wed Oct 27 22:29:36 1999
+++ tools/pdbgen/pdb/gimage.pdb Tue Nov 23 16:14:58 1999
@@ -819,6 +819,29 @@
     );
 }
 
+sub image_get_undo {
+    $blurb = "Check if the image's undo stack is enabled.";
+
+    $help = <<'HELP';
+This procedure checks if the image's undo stack is currently enabled or
+disabled.  This is useful when several plugins or scripts call each other
+and want to check if their caller has already used 'gimp_image_undo_disable'
+or 'gimp_image_undo_freeze'.
+HELP
+
+    $author = $copyright = 'Raphael Quinet';
+    $date = '1999';
+
+    @inargs = ( &std_image_arg );
+
+    @outargs = (
+       { name => 'enabled', type => 'boolean',
+         desc => 'True if undo is enabled for this image' }
+    );
+
+    %invoke = ( code => 'enabled = gimp_image_get_undo (gimage);' );
+}
+
 sub image_undo_enable {
     $blurb = "Enable the image's undo stack.";
 
@@ -1324,10 +1347,10 @@
                   image_remove_layer_mask image_raise_channel
                   image_lower_channel image_add_channel image_remove_channel
                   image_active_drawable image_base_type image_get_cmap
-                  image_set_cmap image_undo_enable image_undo_disable
-                  image_undo_freeze image_undo_thaw image_clean_all
-                  image_floating_selection image_floating_sel_attached_to
-                  image_thumbnail);
+                  image_set_cmap image_get_undo image_undo_enable
+                  image_undo_disable image_undo_freeze image_undo_thaw
+                  image_clean_all image_floating_selection
+                  image_floating_sel_attached_to image_thumbnail);
 %exports = (app => [@procs]);
 
 $desc = 'Image';

Reply via email to