[gimp/alxsa-empty-symmetry-dockable: 104/104] app: Disabled symmetry menu when no image is set




commit 239d1a40c90b3b306d16814904ba8d532fc008e9
Author: Alx Sa <cmyk student gmail com>
Date:   Fri Sep 9 11:39:03 2022 +0000

    app: Disabled symmetry menu when no image is set
    
    To improve discoverability, the symmetry dockable's combobox menu is now
    shown (but disabled) when no image is set.

 app/widgets/gimpsymmetryeditor.c | 98 +++++++++++++++++++++++-----------------
 1 file changed, 56 insertions(+), 42 deletions(-)
---
diff --git a/app/widgets/gimpsymmetryeditor.c b/app/widgets/gimpsymmetryeditor.c
index cedf7a15bc..4897667e0a 100644
--- a/app/widgets/gimpsymmetryeditor.c
+++ b/app/widgets/gimpsymmetryeditor.c
@@ -106,12 +106,20 @@ gimp_symmetry_editor_init (GimpSymmetryEditor *editor)
   gtk_container_set_border_width (GTK_CONTAINER (editor->p->options_vbox), 2);
   gtk_container_add (GTK_CONTAINER (viewport), editor->p->options_vbox);
   gtk_widget_show (editor->p->options_vbox);
+
+  gimp_symmetry_editor_set_image (GIMP_IMAGE_EDITOR (editor), NULL);
 }
 
 static void
 gimp_symmetry_editor_set_image (GimpImageEditor *image_editor,
                                 GimpImage       *image)
 {
+  GtkListStore *store;
+  GtkTreeIter   iter;
+  GList        *syms;
+  GList        *sym_iter;
+  GimpSymmetry *symmetry;
+
   GimpSymmetryEditor *editor = GIMP_SYMMETRY_EDITOR (image_editor);
 
   if (image_editor->image)
@@ -130,56 +138,56 @@ gimp_symmetry_editor_set_image (GimpImageEditor *image_editor,
       editor->p->menu = NULL;
     }
 
-  if (image_editor->image)
+  store = g_object_new (GIMP_TYPE_INT_STORE, NULL);
+
+  /* The menu of available symmetries. */
+  syms = gimp_image_symmetry_list ();
+  for (sym_iter = syms; sym_iter; sym_iter = g_list_next (sym_iter))
     {
-      GtkListStore *store;
-      GtkTreeIter   iter;
-      GList        *syms;
-      GList        *sym_iter;
-      GimpSymmetry *symmetry;
-
-      store = g_object_new (GIMP_TYPE_INT_STORE, NULL);
-
-      /* The menu of available symmetries. */
-      syms = gimp_image_symmetry_list ();
-      for (sym_iter = syms; sym_iter; sym_iter = g_list_next (sym_iter))
-        {
-          GimpSymmetryClass *klass;
-          GType              type;
-
-          type = (GType) sym_iter->data;
-          klass = g_type_class_ref (type);
-
-          gtk_list_store_prepend (store, &iter);
-          gtk_list_store_set (store, &iter,
-                              GIMP_INT_STORE_LABEL,
-                              klass->label,
-                              GIMP_INT_STORE_USER_DATA,
-                              sym_iter->data,
-                              -1);
-          g_type_class_unref (klass);
-        }
-      g_list_free (syms);
+      GimpSymmetryClass *klass;
+      GType              type;
+
+      type = (GType) sym_iter->data;
+      klass = g_type_class_ref (type);
 
       gtk_list_store_prepend (store, &iter);
       gtk_list_store_set (store, &iter,
-                          GIMP_INT_STORE_LABEL, _("None"),
-                          GIMP_INT_STORE_USER_DATA, GIMP_TYPE_SYMMETRY,
+                          GIMP_INT_STORE_LABEL,
+                          klass->label,
+                          GIMP_INT_STORE_USER_DATA,
+                          sym_iter->data,
                           -1);
-      editor->p->menu =
-        gimp_prop_pointer_combo_box_new (G_OBJECT (image_editor->image),
-                                         "symmetry",
-                                         GIMP_INT_STORE (store));
-      g_object_unref (store);
+      g_type_class_unref (klass);
+    }
+  g_list_free (syms);
+
+  gtk_list_store_prepend (store, &iter);
+  gtk_list_store_set (store, &iter,
+                      GIMP_INT_STORE_LABEL, _("None"),
+                      GIMP_INT_STORE_USER_DATA, GIMP_TYPE_SYMMETRY,
+                      -1);
+  if (image_editor->image)
+    editor->p->menu =
+      gimp_prop_pointer_combo_box_new (G_OBJECT (image_editor->image),
+                                       "symmetry",
+                                       GIMP_INT_STORE (store));
+  else
+    editor->p->menu =
+      gimp_int_combo_box_new (_("None"), 0,
+                              NULL);
 
-      gimp_int_combo_box_set_label (GIMP_INT_COMBO_BOX (editor->p->menu),
-                                    _("Symmetry"));
-      g_object_set (editor->p->menu, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
+  g_object_unref (store);
 
-      gtk_box_pack_start (GTK_BOX (editor), editor->p->menu,
-                          FALSE, FALSE, 0);
-      gtk_box_reorder_child (GTK_BOX (editor), editor->p->menu, 0);
+  gimp_int_combo_box_set_label (GIMP_INT_COMBO_BOX (editor->p->menu),
+                                _("Symmetry"));
+  g_object_set (editor->p->menu, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
 
+  gtk_box_pack_start (GTK_BOX (editor), editor->p->menu,
+                      FALSE, FALSE, 0);
+  gtk_box_reorder_child (GTK_BOX (editor), editor->p->menu, 0);
+
+  if (image_editor->image)
+    {
       /* Connect to symmetry change. */
       g_signal_connect (image_editor->image, "notify::symmetry",
                         G_CALLBACK (gimp_symmetry_editor_symmetry_notify),
@@ -189,6 +197,12 @@ gimp_symmetry_editor_set_image (GimpImageEditor *image_editor,
       symmetry = gimp_image_get_active_symmetry (image_editor->image);
       gimp_symmetry_editor_set_options (editor, symmetry);
     }
+  else
+    {
+      gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (editor->p->menu), 0);
+      gtk_widget_set_sensitive (editor->p->menu, FALSE);
+      gtk_widget_show (editor->p->menu);
+    }
 }
 
 static void


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