~attente/unity-gtk-module/blacklist-anjuta

« back to all changes in this revision

Viewing changes to lib/unity-gtk-menu-section.c

  • Committer: CI bot
  • Author(s): William Hua
  • Date: 2014-04-03 17:12:41 UTC
  • mfrom: (324.1.2 eclipse-accelerators)
  • Revision ID: ps-jenkins@lists.canonical.com-20140403171241-z10l7xb8hap9gu0t
Forward original accelerator text for Eclipse, Inkscape, Emacs. Fixes: 1208019

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#define G_MENU_ATTRIBUTE_ACCEL "accel"
24
24
#endif
25
25
 
 
26
#ifndef G_MENU_ATTRIBUTE_ACCEL_TEXT
 
27
#define G_MENU_ATTRIBUTE_ACCEL_TEXT "x-canonical-accel"
 
28
#endif
 
29
 
26
30
G_DEFINE_TYPE (UnityGtkMenuSection,
27
31
               unity_gtk_menu_section,
28
32
               G_TYPE_MENU_MODEL);
35
39
  return GPOINTER_TO_INT (a) - GPOINTER_TO_INT (b);
36
40
}
37
41
 
 
42
static gboolean
 
43
g_closure_equal (GtkAccelKey *key,
 
44
                 GClosure    *closure,
 
45
                 gpointer     data)
 
46
{
 
47
  return closure == data;
 
48
}
 
49
 
38
50
static void
39
51
unity_gtk_menu_section_set_parent_shell (UnityGtkMenuSection *section,
40
52
                                         UnityGtkMenuShell   *parent_shell)
166
178
        }
167
179
 
168
180
      if (accel_name == NULL)
169
 
        accel_name = g_strdup (gtk_menu_item_get_nth_label_label (item->menu_item, 1));
 
181
        {
 
182
          GList *closures = gtk_widget_list_accel_closures (GTK_WIDGET (item->menu_item));
 
183
          GList *iter;
 
184
 
 
185
          for (iter = closures; iter != NULL && accel_name == NULL; iter = g_list_next (iter))
 
186
            {
 
187
              GClosure *closure = iter->data;
 
188
              GtkAccelGroup *accel_group = gtk_accel_group_from_accel_closure (closure);
 
189
 
 
190
              if (accel_group != NULL)
 
191
                {
 
192
                  GtkAccelKey *accel_key = gtk_accel_group_find (accel_group, g_closure_equal, closure);
 
193
 
 
194
                  if (accel_key != NULL)
 
195
                    accel_name = gtk_accelerator_name (accel_key->accel_key, accel_key->accel_mods);
 
196
                }
 
197
            }
 
198
 
 
199
          g_list_free (closures);
 
200
        }
170
201
 
171
202
      if (accel_name != NULL)
172
203
        g_hash_table_insert (*attributes, G_MENU_ATTRIBUTE_ACCEL, g_variant_ref_sink (g_variant_new_string (accel_name)));
 
204
      else
 
205
        {
 
206
#if GTK_MAJOR_VERSION == 2
 
207
          /* LP: #1208019 */
 
208
          GtkLabel *accel_label = gtk_menu_item_get_nth_label (item->menu_item, 0);
 
209
 
 
210
          if (GTK_IS_ACCEL_LABEL (accel_label))
 
211
            {
 
212
              /* Eclipse uses private API. */
 
213
              if (GTK_ACCEL_LABEL (accel_label)->accel_string != NULL)
 
214
                accel_name = g_strdup (GTK_ACCEL_LABEL (accel_label)->accel_string);
 
215
            }
 
216
#endif
 
217
 
 
218
          if (accel_name == NULL)
 
219
            accel_name = g_strdup (gtk_menu_item_get_nth_label_label (item->menu_item, 1));
 
220
 
 
221
          if (accel_name != NULL)
 
222
            g_hash_table_insert (*attributes, G_MENU_ATTRIBUTE_ACCEL_TEXT, g_variant_ref_sink (g_variant_new_string (accel_name)));
 
223
        }
173
224
 
174
225
      g_free (accel_name);
175
226
    }