[gimp] plug-ins: set "Save layers" toggle unsensitive for single-layer images.



commit 7a73e9e76cfa70d2758b45dcdfbf5f2fcbbee927
Author: Jehan <jehan girinstud io>
Date:   Sat Jun 29 14:57:04 2019 +0200

    plug-ins: set "Save layers" toggle unsensitive for single-layer images.

 plug-ins/file-tiff/file-tiff-save.c | 19 ++++++++++++++-----
 plug-ins/file-tiff/file-tiff-save.h |  1 +
 plug-ins/file-tiff/file-tiff.c      | 30 ++++++++++++++++++++++--------
 3 files changed, 37 insertions(+), 13 deletions(-)
---
diff --git a/plug-ins/file-tiff/file-tiff-save.c b/plug-ins/file-tiff/file-tiff-save.c
index 653fb0d7c4..ed1df6aa97 100644
--- a/plug-ins/file-tiff/file-tiff-save.c
+++ b/plug-ins/file-tiff/file-tiff-save.c
@@ -1121,6 +1121,7 @@ save_dialog (TiffSaveVals  *tsvals,
              gboolean       has_alpha,
              gboolean       is_monochrome,
              gboolean       is_indexed,
+             gboolean       is_multi_layer,
              gchar        **image_comment)
 {
   GError      *error = NULL;
@@ -1254,11 +1255,19 @@ save_dialog (TiffSaveVals  *tsvals,
 #endif
 
   toggle = GTK_WIDGET (gtk_builder_get_object (builder, "save-layers"));
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
-                                tsvals->save_layers);
-  g_signal_connect (toggle, "toggled",
-                    G_CALLBACK (gimp_toggle_button_update),
-                    &tsvals->save_layers);
+  if (is_multi_layer)
+    {
+      /* If single-layer TIFF, set the toggle insensitive and show it as
+       * unchecked though I don't actually change the tsvals value to
+       * keep storing previously chosen value.
+       */
+      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
+                                    tsvals->save_layers);
+      g_signal_connect (toggle, "toggled",
+                        G_CALLBACK (gimp_toggle_button_update),
+                        &tsvals->save_layers);
+    }
+  gtk_widget_set_sensitive (toggle, is_multi_layer);
 
   gtk_widget_show (dialog);
 
diff --git a/plug-ins/file-tiff/file-tiff-save.h b/plug-ins/file-tiff/file-tiff-save.h
index 24e4f85ba1..0a8762c4c6 100644
--- a/plug-ins/file-tiff/file-tiff-save.h
+++ b/plug-ins/file-tiff/file-tiff-save.h
@@ -52,6 +52,7 @@ gboolean  save_dialog (TiffSaveVals *tsvals,
                        gboolean      has_alpha,
                        gboolean      is_monochrome,
                        gboolean      is_indexed,
+                       gboolean      is_multi_layer,
                        gchar       **image_comment);
 
 
diff --git a/plug-ins/file-tiff/file-tiff.c b/plug-ins/file-tiff/file-tiff.c
index e1a80e8c5b..91b568e161 100644
--- a/plug-ins/file-tiff/file-tiff.c
+++ b/plug-ins/file-tiff/file-tiff.c
@@ -60,14 +60,15 @@
 #define PLUG_IN_BINARY "file-tiff"
 
 
-static void       query               (void);
-static void       run                 (const gchar      *name,
-                                       gint              nparams,
-                                       const GimpParam  *param,
-                                       gint             *nreturn_vals,
-                                       GimpParam       **return_vals);
+static void       query                (void);
+static void       run                  (const gchar      *name,
+                                        gint              nparams,
+                                        const GimpParam  *param,
+                                        gint             *nreturn_vals,
+                                        GimpParam       **return_vals);
 
-static gboolean   image_is_monochrome (gint32            image);
+static gboolean   image_is_monochrome  (gint32            image);
+static gboolean   image_is_multi_layer (gint32            image);
 
 
 const GimpPlugInInfo PLUG_IN_INFO =
@@ -320,6 +321,7 @@ run (const gchar      *name,
                              gimp_drawable_has_alpha (drawable),
                              image_is_monochrome (image),
                              gimp_image_base_type (image) == GIMP_INDEXED,
+                             image_is_multi_layer (image),
                              &image_comment))
             {
               status = GIMP_PDB_CANCEL;
@@ -389,7 +391,7 @@ run (const gchar      *name,
                                GIMP_EXPORT_CAN_HANDLE_INDEXED |
                                GIMP_EXPORT_CAN_HANDLE_ALPHA;
 
-              if (tsvals.save_layers)
+              if (tsvals.save_layers && image_is_multi_layer (image))
                 capabilities |= GIMP_EXPORT_CAN_HANDLE_LAYERS;
 
               export = gimp_export_image (&image, &drawable, "TIFF", capabilities);
@@ -477,3 +479,15 @@ image_is_monochrome (gint32 image)
 
   return monochrome;
 }
+
+static gboolean
+image_is_multi_layer (gint32 image)
+{
+  gint32 *layers;
+  gint32  n_layers;
+
+  layers = gimp_image_get_layers (image, &n_layers);
+  g_free (layers);
+
+  return (n_layers > 1);
+}


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