Pressing return in a dialog



Hello,

When prompted to enter some text in a dialog box, I want the user to be
able to complete the entry by pressing the <enter> key instead of having
to click on the OK button.  With gtk 1.x one could use

   gnome_dialog_editable_enters (-)

but this has been deprecated and it's not clear to me how to do it with
gtk 2.2.  Here's a snippet of the code so far:

=== begin included code snippet ===

#define BUFLEN 255

   GtkWidget *input_dialog = NULL;
   gint button;
   static gchar dialog_title[] = "dialog title";

[snip]

   input_dialog = gtk_dialog_new_with_buttons (
      dialog_title,
      (GtkWindow *) main_window,
      GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
      GTK_STOCK_OK,
      GTK_RESPONSE_ACCEPT,
      NULL);

   gnomeentry = gnome_entry_new (NULL);
   gtk_widget_show (gnomeentry);
   gtkentry = gnome_entry_gtk_entry (GNOME_ENTRY (gnomeentry));
   gtk_entry_set_text ((GtkEntry *) gtkentry, "BLAH");
   gtk_entry_set_max_length ((GtkEntry *) gtkentry, BUFLEN);
   gtk_entry_set_activates_default ((GtkEntry *) gtkentry, TRUE);
   gtk_widget_show (gtkentry);

   gtk_box_pack_start (
      GTK_BOX (GTK_DIALOG (input_dialog)->vbox),
      gnomeentry, TRUE, TRUE, 2);

/* with gtk 1.2 I'd put a call to gnome_dialog_editable_enters (-) here */

   gtk_widget_show_all (input_dialog);
   button = gtk_dialog_run ((GtkDialog *) input_dialog);

[snip]

=== end included code snippet ===

I originally thought that the call to gtk_entry_set_activates_default(-)
would do it, but it doesn't and the user still has to click on the OK
button.

So, how does one do it with gtk 2.2?

Thanks,

Bryan


*---------------------------------------------------------------
* Bryan Brown      <*>              bbrown radix net
* http://www.radix.net/~bbrown
*---------------------------------------------------------------




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