Re: gnome-dialog question

On Tue, 16 Jun 1998, Dietmar Maurer wrote:
> The CANCEL button schould close the dialog, so i've done the following:
> list = g_list_nth (GNOME_DIALOG(d)->buttons,0);
> gtk_signal_connect_object(GTK_OBJECT(list->data), "clicked",
>                        GTK_SIGNAL_FUNC(gtk_widget_destroy),(gpointer)d);

Yuck, don't play around in the struct like that. I might gratuitously
change it. :-) 

You want to use gnome_dialog_close instead of gtk_widget_destroy. This
will normally do a destroy anyway; but there are two advantages:

- You can later change to "hide" behavior by simply calling
- You can connect to the "close" signal and be sure your callback is
  called no matter how the close happens - delete_event, cancel button, 
  escape key, whatever.

> gnome_dialog_button_connect(GNOME_DIALOG(d),1,
>                               GTK_SIGNAL_FUNC(partition_create),
>                               NULL);

It looks like you have "OK" on the right, and "Cancel" on the left; that's
the opposite of most Gnome apps, I think.

> Is there a better way? I think I nedd something like this:
> gnome_dialog_button_connect_object(GNOME_DIALOG(d),0,
>                               GTK_SIGNAL_FUNC(gtk_widget_destroy),
>                               (gpointer)d);

This would be easy to add, if you'd find it useful I'll throw it in.

If both buttons cause a close eventually, you can also use the _set_close
method. That's how most dialogs work. The final option is just a wrapper

gint close_callback(GtkButton * b, GnomeDialog * gd)
	return FALSE;

and use that with the existing button_connect.

Ah, another advantage to the "close" signal is that you can block the
close by returning TRUE from your callback; for example, if the user
clicks OK without entering all the necessary information. Unlike
delete_event, the block works no matter how the user tries to close the

Sorry there's no good documentation (I need to update the dialog docs on
the web page).


Havoc Pennington ====

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