Add function ag_app_buttoned_dialog()

This is required to create dialogs with more than one buttons, like Yes/No
dialogs.
This commit is contained in:
Gergely Polonkai 2014-08-02 00:34:07 +02:00
parent defdc75eb0
commit 860638ed98

View File

@ -443,6 +443,48 @@ ag_app_class_init(AgAppClass *klass)
application_class->open = ag_app_open; application_class->open = ag_app_open;
} }
gint
ag_app_buttoned_dialog(GtkWidget *window,
GtkMessageType message_type,
const gchar *message,
const gchar *first_button_text,
...)
{
va_list ap;
const gchar *button_text;
gint response_id;
GtkWidget *dialog;
dialog = gtk_message_dialog_new(
GTK_WINDOW(window),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
message_type,
GTK_BUTTONS_NONE,
"%s",
message
);
if (first_button_text) {
button_text = first_button_text;
va_start(ap, first_button_text);
response_id = va_arg(ap, gint);
gtk_dialog_add_button(GTK_DIALOG(dialog), button_text, response_id);
while ((button_text = va_arg(ap, gchar *)) != NULL) {
response_id = va_arg(ap, gint);
gtk_dialog_add_button(GTK_DIALOG(dialog), button_text, response_id);
}
va_end(ap);
}
response_id = gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
return response_id;
}
void void
ag_app_message_dialog(GtkWidget *window, ag_app_message_dialog(GtkWidget *window,
GtkMessageType message_type, GtkMessageType message_type,
@ -450,21 +492,18 @@ ag_app_message_dialog(GtkWidget *window,
{ {
gchar *msg; gchar *msg;
va_list args; va_list args;
GtkWidget *dialog;
va_start(args, fmt); va_start(args, fmt);
msg = g_strdup_vprintf(fmt, args); msg = g_strdup_vprintf(fmt, args);
va_end(args); va_end(args);
dialog = gtk_message_dialog_new( ag_app_buttoned_dialog(
GTK_WINDOW(window), window,
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
message_type, message_type,
GTK_BUTTONS_OK, msg,
"%s", _("Close"), GTK_RESPONSE_CLOSE,
msg NULL
); );
g_free(msg); g_free(msg);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
} }