Convenience functionality for underline accelerators.




Consider the typical dialog box navigation accelerators - where You
have a label _Name and pressing Alt-N in the dialog focuses the "Name"
entry; and if the focus isn't in an entry, pressing 'N' focuses
the entry.

This is pretty clunky to do currently:

 entry = gtk_entry_new()
 label = gtk_label_new("Name");
 gtk_label_set_pattern (label, "_");
 
 gtk_widget_add_accelerator (entry,
		   	     "grab_focus",
			     accel_group,
			     GDK_n, GDK_MOD1_MASK,
			     GTK_ACCEL_LOCKED);
 gtk_widget_add_accelerator (entry,
		   	     "grab_focus",
			     accel_group,
			     GDK_n, 0,
			     GTK_ACCEL_LOCKED);

I'd like to add a convenience function:

 void gtk_label_set_uline_accel (GtkLabel      *label,
                                 const gchar   *string,
                                 GtkWidget     *widget,
                                 const gchar   *signal,
                                 GtkAccelGroup *accel_group,
                                 GtkAccelGroup *alt_accel_group);
So that becomes:

 entry = gtk_entry_new ();
 label = gtk_label_new (NULL);
 gtk_label_set_uline_accel (GTK_LABEL (label), "_Name",
                            entry, "grab_focus", accel_group, accel_group);


(
 The reason for splitting up the accelerator groups is this would
 be used for menus, in addition, and for menubars, the MOD1 accelerator,
 and the unmodified accelerator go in different accelerator groups.
 It could also be:

 void gtk_label_set_uline_accel (GtkLabel      *label,
                                 const gchar   *string,
                                 GtkWidget     *widget,
                                 const gchar   *signal,
                                 guint          ngroups,
                                 /* [ group, modifier ]... */
                                 ...);

 which would be more flexible.
)

The problem is that this doesn't map very well into into GUI
builders- the association between the label and the entry
is static, but that is not expressed in the widget arguments.

So an alternative would be to add a whole bunch of arguments
to AccelLabel or Label to express all this stuff:

 gtk_widget_new (GTK_TYPE_ACCEL_LABEL,
                 "uline_string", "_Name",
                 "uline_widget", entry,
                 "uline_signal", "grab_focus",
                 "uline_group",  accel_group);

But that seems like a bit of a waste to store this all for
each accel label, when it is only ever used once. Perhaps
the GUI-builder types have some better idea for how this
should work?

Regards,
                                        Owen


 



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