Skip to content

Commit c15ddb0

Browse files
[gnc-ui.h] gnc_action_dialog to offer Action/Cancel buttons
Instead of gnc_verify_dialog with YES/NO buttons, or gnc_ok_cancel_dialog with OK/CANCEL buttons, it is safer to offer explicit ACTION/CANCEL buttons whereby ACTION is customisable. The action_default boolean would typically be TRUE for safe actions (e.g. Open Readonly) and FALSE for destructive actions (e.g. Delete Transaction).
1 parent 435735e commit c15ddb0

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

gnucash/gnome-utils/gnc-gui-query.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,37 @@ gnc_ok_cancel_dialog(GtkWindow *parent,
8282
return(result);
8383
}
8484

85+
gboolean
86+
gnc_action_dialog (GtkWindow *parent, const gchar *action,
87+
gboolean action_default, const gchar *format, ...)
88+
{
89+
g_return_val_if_fail (action, FALSE);
90+
91+
if (!parent)
92+
parent = gnc_ui_get_main_window (NULL);
93+
94+
va_list args;
95+
va_start(args, format);
96+
gchar *buffer = g_strdup_vprintf(format, args);
97+
va_end(args);
98+
99+
GtkWidget *dialog = gtk_message_dialog_new (parent,
100+
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
101+
GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
102+
"%s", buffer);
103+
104+
gtk_dialog_add_button (GTK_DIALOG(dialog), action, GTK_RESPONSE_ACCEPT);
105+
gtk_dialog_add_button (GTK_DIALOG(dialog), _("_Cancel"), GTK_RESPONSE_CANCEL);
106+
gtk_dialog_set_default_response (GTK_DIALOG(dialog), action_default ?
107+
GTK_RESPONSE_ACCEPT : GTK_RESPONSE_CANCEL);
108+
109+
gint result = gtk_dialog_run(GTK_DIALOG(dialog));
85110

111+
gtk_widget_destroy (dialog);
112+
g_free(buffer);
113+
114+
return result == GTK_RESPONSE_ACCEPT;
115+
}
86116

87117
/********************************************************************\
88118
* gnc_verify_dialog *

gnucash/gnome-utils/gnc-ui.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ gnc_ok_cancel_dialog (GtkWindow *parent,
100100
gint default_result,
101101
const char *format, ...) G_GNUC_PRINTF (3, 4);
102102

103+
extern gboolean
104+
gnc_action_dialog (GtkWindow *parent,
105+
const gchar *action,
106+
gboolean action_default,
107+
const gchar *format, ...) G_GNUC_PRINTF (4, 5);
108+
103109
extern void
104110
gnc_warning_dialog (GtkWindow *parent,
105111
const char *format, ...) G_GNUC_PRINTF (2, 3);

0 commit comments

Comments
 (0)