~attente/unity-gtk-module/eclipse-accelerators

« back to all changes in this revision

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

  • Committer: William Hua
  • Date: 2014-03-29 23:28:34 UTC
  • Revision ID: william.hua@canonical.com-20140329232834-79mepi7xxvmdydfj
Try to detect accelerator from closure.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
  return GPOINTER_TO_INT (a) - GPOINTER_TO_INT (b);
36
36
}
37
37
 
 
38
static gboolean
 
39
g_closure_equal (GtkAccelKey *key,
 
40
                 GClosure    *closure,
 
41
                 gpointer     data)
 
42
{
 
43
  return closure == data;
 
44
}
 
45
 
38
46
static void
39
47
unity_gtk_menu_section_set_parent_shell (UnityGtkMenuSection *section,
40
48
                                         UnityGtkMenuShell   *parent_shell)
166
174
        }
167
175
 
168
176
      if (accel_name == NULL)
 
177
        {
 
178
          GList *closures = gtk_widget_list_accel_closures (GTK_WIDGET (item->menu_item));
 
179
          GList *iter;
 
180
 
 
181
          for (iter = closures; iter != NULL && accel_name == NULL; iter = g_list_next (iter))
 
182
            {
 
183
              GClosure *closure = iter->data;
 
184
              GtkAccelGroup *accel_group = gtk_accel_group_from_accel_closure (closure);
 
185
 
 
186
              if (accel_group != NULL)
 
187
                {
 
188
                  GtkAccelKey *accel_key = gtk_accel_group_find (accel_group, g_closure_equal, closure);
 
189
 
 
190
                  if (accel_key != NULL)
 
191
                    accel_name = gtk_accelerator_name (accel_key->accel_key, accel_key->accel_mods);
 
192
                }
 
193
            }
 
194
 
 
195
          g_list_free (closures);
 
196
        }
 
197
 
 
198
      if (accel_name == NULL)
169
199
        accel_name = g_strdup (gtk_menu_item_get_nth_label_label (item->menu_item, 1));
170
200
 
171
201
      if (accel_name != NULL)