[gtk/gbsneto/shortcuts-rebased: 56/99] accellabel: Get rid of class variables



commit 239c75cd3f5fe28fbccd3f37e3d73893c41d0894
Author: Benjamin Otte <otte redhat com>
Date:   Mon Aug 13 04:51:03 2018 +0200

    accellabel: Get rid of class variables
    
    We can just look them up as-needed, no need to cache them.

 gtk/gtkaccellabel.c | 102 ++++++++++++++++++++++++++++------------------------
 gtk/gtkaccellabel.h |   5 ---
 2 files changed, 56 insertions(+), 51 deletions(-)
---
diff --git a/gtk/gtkaccellabel.c b/gtk/gtkaccellabel.c
index 92090faaf2..57d7e3c36a 100644
--- a/gtk/gtkaccellabel.c
+++ b/gtk/gtkaccellabel.c
@@ -191,38 +191,6 @@ gtk_accel_label_class_init (GtkAccelLabelClass *class)
 
   gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_ACCEL_LABEL);
 
-#ifndef GDK_WINDOWING_QUARTZ
-  /* This is the text that should appear next to menu accelerators
-   * that use the shift key. If the text on this key isn't typically
-   * translated on keyboards used for your language, don't translate
-   * this.
-   */
-  class->mod_name_shift = g_strdup (C_("keyboard label", "Shift"));
-  /* This is the text that should appear next to menu accelerators
-   * that use the control key. If the text on this key isn't typically
-   * translated on keyboards used for your language, don't translate
-   * this.
-   */
-  class->mod_name_control = g_strdup (C_("keyboard label", "Ctrl"));
-  /* This is the text that should appear next to menu accelerators
-   * that use the alt key. If the text on this key isn't typically
-   * translated on keyboards used for your language, don't translate
-   * this.
-   */
-  class->mod_name_alt = g_strdup (C_("keyboard label", "Alt"));
-  class->mod_separator = g_strdup ("+");
-#else /* GDK_WINDOWING_QUARTZ */
-
-  /* U+21E7 UPWARDS WHITE ARROW */
-  class->mod_name_shift = g_strdup ("\xe2\x87\xa7");
-  /* U+2303 UP ARROWHEAD */
-  class->mod_name_control = g_strdup ("\xe2\x8c\x83");
-  /* U+2325 OPTION KEY */
-  class->mod_name_alt = g_strdup ("\xe2\x8c\xa5");
-  class->mod_separator = g_strdup ("");
-
-#endif /* GDK_WINDOWING_QUARTZ */
-
   props[PROP_ACCEL_CLOSURE] =
     g_param_spec_boxed ("accel-closure",
                         P_("Accelerator Closure"),
@@ -719,6 +687,16 @@ append_keyval_symbol (guint    accelerator_key,
 #endif
 }
 
+static void
+append_separator (GString *string)
+{
+#ifndef GDK_WINDOWING_QUARTZ
+  g_string_append (string, "+");
+#else
+  /* no separator on quartz */
+#endif
+}
+
 gchar *
 _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
                                              guint               accelerator_key,
@@ -732,30 +710,62 @@ _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
 
   if (accelerator_mods & GDK_SHIFT_MASK)
     {
-      g_string_append (gstring, klass->mod_name_shift);
+#ifndef GDK_WINDOWING_QUARTZ
+      /* This is the text that should appear next to menu accelerators
+       * that use the shift key. If the text on this key isn't typically
+       * translated on keyboards used for your language, don't translate
+       * this.
+       */
+      g_string_append (gstring, C_("keyboard label", "Shift"));
+#else
+      /* U+21E7 UPWARDS WHITE ARROW */
+      g_string_append (gstring, "\xe2\x87\xa7");
+#endif
       seen_mod = TRUE;
     }
 
   if (accelerator_mods & GDK_CONTROL_MASK)
     {
       if (seen_mod)
-        g_string_append (gstring, klass->mod_separator);
-      g_string_append (gstring, klass->mod_name_control);
+        append_separator (gstring);
+
+#ifndef GDK_WINDOWING_QUARTZ
+      /* This is the text that should appear next to menu accelerators
+       * that use the control key. If the text on this key isn't typically
+       * translated on keyboards used for your language, don't translate
+       * this.
+       */
+      g_string_append (gstring, C_("keyboard label", "Ctrl"));
+#else
+      /* U+2303 UP ARROWHEAD */
+      g_string_append (gstring, "\xe2\x8c\x83");
+#endif
       seen_mod = TRUE;
     }
 
   if (accelerator_mods & GDK_MOD1_MASK)
     {
       if (seen_mod)
-        g_string_append (gstring, klass->mod_separator);
-      g_string_append (gstring, klass->mod_name_alt);
+        append_separator (gstring);
+
+#ifndef GDK_WINDOWING_QUARTZ
+      /* This is the text that should appear next to menu accelerators
+       * that use the alt key. If the text on this key isn't typically
+       * translated on keyboards used for your language, don't translate
+       * this.
+       */
+      g_string_append (gstring, C_("keyboard label", "Alt"));
+#else
+      /* U+2325 OPTION KEY */
+      g_string_append (gstring, "\xe2\x8c\xa5");
+#endif
       seen_mod = TRUE;
     }
 
   if (accelerator_mods & GDK_MOD2_MASK)
     {
       if (seen_mod)
-        g_string_append (gstring, klass->mod_separator);
+        append_separator (gstring);
 
       g_string_append (gstring, "Mod2");
       seen_mod = TRUE;
@@ -764,7 +774,7 @@ _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
   if (accelerator_mods & GDK_MOD3_MASK)
     {
       if (seen_mod)
-        g_string_append (gstring, klass->mod_separator);
+        append_separator (gstring);
 
       g_string_append (gstring, "Mod3");
       seen_mod = TRUE;
@@ -773,7 +783,7 @@ _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
   if (accelerator_mods & GDK_MOD4_MASK)
     {
       if (seen_mod)
-        g_string_append (gstring, klass->mod_separator);
+        append_separator (gstring);
 
       g_string_append (gstring, "Mod4");
       seen_mod = TRUE;
@@ -782,7 +792,7 @@ _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
   if (accelerator_mods & GDK_MOD5_MASK)
     {
       if (seen_mod)
-        g_string_append (gstring, klass->mod_separator);
+        append_separator (gstring);
 
       g_string_append (gstring, "Mod5");
       seen_mod = TRUE;
@@ -791,7 +801,7 @@ _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
   if (accelerator_mods & GDK_SUPER_MASK)
     {
       if (seen_mod)
-        g_string_append (gstring, klass->mod_separator);
+        append_separator (gstring);
 
       /* This is the text that should appear next to menu accelerators
        * that use the super key. If the text on this key isn't typically
@@ -805,7 +815,7 @@ _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
   if (accelerator_mods & GDK_HYPER_MASK)
     {
       if (seen_mod)
-        g_string_append (gstring, klass->mod_separator);
+        append_separator (gstring);
 
       /* This is the text that should appear next to menu accelerators
        * that use the hyper key. If the text on this key isn't typically
@@ -819,7 +829,7 @@ _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
   if (accelerator_mods & GDK_META_MASK)
     {
       if (seen_mod)
-        g_string_append (gstring, klass->mod_separator);
+        append_separator (gstring);
 
 #ifndef GDK_WINDOWING_QUARTZ
       /* This is the text that should appear next to menu accelerators
@@ -839,7 +849,7 @@ _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
   if (ch && (ch == ' ' || g_unichar_isgraph (ch)))
     {
       if (seen_mod)
-        g_string_append (gstring, klass->mod_separator);
+        append_separator (gstring);
 
       switch (ch)
        {
@@ -862,7 +872,7 @@ _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
       if (tmp != NULL)
        {
           if (seen_mod)
-            g_string_append (gstring, klass->mod_separator);
+            append_separator (gstring);
 
          if (tmp[0] != 0 && tmp[1] == 0)
            g_string_append_c (gstring, g_ascii_toupper (tmp[0]));
diff --git a/gtk/gtkaccellabel.h b/gtk/gtkaccellabel.h
index 4c5a2cbf3c..e56018761b 100644
--- a/gtk/gtkaccellabel.h
+++ b/gtk/gtkaccellabel.h
@@ -61,11 +61,6 @@ struct _GtkAccelLabelClass
 {
   GtkWidgetClass parent_class;
 
-  gchar                *mod_name_shift;
-  gchar                *mod_name_control;
-  gchar                *mod_name_alt;
-  gchar                *mod_separator;
-
   /* Padding for future expansion */
   void (*_gtk_reserved1) (void);
   void (*_gtk_reserved2) (void);


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