[gimp/metadata-browser] app: make gimp_get_mod_string() a bit nicer



commit 533b9feef8829c2541165d428002469c44ba8fda
Author: Michael Natterer <mitch gimp org>
Date:   Wed Oct 5 18:47:37 2011 +0200

    app: make gimp_get_mod_string() a bit nicer

 app/widgets/gimpwidgets-utils.c |   37 +++++++++++++++++++------------------
 1 files changed, 19 insertions(+), 18 deletions(-)
---
diff --git a/app/widgets/gimpwidgets-utils.c b/app/widgets/gimpwidgets-utils.c
index 81db2b9..22d9407 100644
--- a/app/widgets/gimpwidgets-utils.c
+++ b/app/widgets/gimpwidgets-utils.c
@@ -476,9 +476,7 @@ const gchar *
 gimp_get_mod_string (GdkModifierType modifiers)
 {
   static GHashTable *mod_labels;
-
-  GtkAccelLabelClass *accel_label_class;
-  gchar              *label;
+  gchar             *label;
 
   if (! modifiers)
     return NULL;
@@ -488,27 +486,30 @@ gimp_get_mod_string (GdkModifierType modifiers)
 
   label = g_hash_table_lookup (mod_labels, &modifiers);
 
-  if (label)
-    return label;
+  if (! label)
+    {
+      GtkAccelLabelClass *accel_label_class;
 
-  label = gtk_accelerator_get_label (0, modifiers);
+      label = gtk_accelerator_get_label (0, modifiers);
 
-  accel_label_class = g_type_class_ref (GTK_TYPE_ACCEL_LABEL);
+      accel_label_class = g_type_class_ref (GTK_TYPE_ACCEL_LABEL);
 
-  if (accel_label_class->mod_separator &&
-      strlen (accel_label_class->mod_separator))
-    {
-      gchar *sep = g_strrstr (label, accel_label_class->mod_separator);
+      if (accel_label_class->mod_separator &&
+          *accel_label_class->mod_separator)
+        {
+          gchar *sep = g_strrstr (label, accel_label_class->mod_separator);
 
-      if (sep - label == strlen (label) - strlen (accel_label_class->mod_separator))
-        *sep = '\0';
-    }
+          if (sep - label ==
+              strlen (label) - strlen (accel_label_class->mod_separator))
+            *sep = '\0';
+        }
 
-  g_type_class_unref (accel_label_class);
+      g_type_class_unref (accel_label_class);
 
-  g_hash_table_insert (mod_labels,
-                       g_memdup (&modifiers, sizeof (GdkModifierType)),
-                       label);
+      g_hash_table_insert (mod_labels,
+                           g_memdup (&modifiers, sizeof (GdkModifierType)),
+                           label);
+    }
 
   return label;
 }



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