diff options
author | TingPing <tingping@tingping.se> | 2013-12-31 17:06:58 -0500 |
---|---|---|
committer | TingPing <tingping@tingping.se> | 2014-02-04 20:46:43 -0500 |
commit | 10d3c151438c5580756b6a66a059742ace51333b (patch) | |
tree | 04b9293bcd65978d0a11d719902ec79f6820be9c /src/fe-gtk | |
parent | 3a7fb4d8e1896eced87e3ccbf9369d76fa10d7e0 (diff) |
Add /getbool command
Diffstat (limited to 'src/fe-gtk')
-rw-r--r-- | src/fe-gtk/gtkutil.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/fe-gtk/gtkutil.c b/src/fe-gtk/gtkutil.c index 282b952c..a6870253 100644 --- a/src/fe-gtk/gtkutil.c +++ b/src/fe-gtk/gtkutil.c @@ -374,6 +374,28 @@ gtkutil_get_number_response (GtkDialog *dialog, gint arg1, gpointer spin) } } +static void +gtkutil_get_bool_response (GtkDialog *dialog, gint arg1, gpointer spin) +{ + void (*callback) (int value, void *user_data); + void *user_data; + + callback = g_object_get_data (G_OBJECT (dialog), "cb"); + user_data = g_object_get_data (G_OBJECT (dialog), "ud"); + + switch (arg1) + { + case GTK_RESPONSE_REJECT: + callback (0, user_data); + gtk_widget_destroy (GTK_WIDGET (dialog)); + break; + case GTK_RESPONSE_ACCEPT: + callback (1, user_data); + gtk_widget_destroy (GTK_WIDGET (dialog)); + break; + } +} + void fe_get_int (char *msg, int def, void *callback, void *userdata) { @@ -417,6 +439,35 @@ fe_get_int (char *msg, int def, void *callback, void *userdata) gtk_widget_show_all (dialog); } +void +fe_get_bool (char *title, char *prompt, void *callback, void *userdata) +{ + GtkWidget *dialog; + GtkWidget *prompt_label; + extern GtkWidget *parent_window; + + dialog = gtk_dialog_new_with_buttons (title, NULL, 0, + GTK_STOCK_NO, GTK_RESPONSE_REJECT, + GTK_STOCK_YES, GTK_RESPONSE_ACCEPT, + NULL); + gtk_box_set_homogeneous (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), TRUE); + gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE); + gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent_window)); + + + g_object_set_data (G_OBJECT (dialog), "cb", callback); + g_object_set_data (G_OBJECT (dialog), "ud", userdata); + + prompt_label = gtk_label_new (prompt); + + g_signal_connect (G_OBJECT (dialog), "response", + G_CALLBACK (gtkutil_get_bool_response), NULL); + + gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), prompt_label); + + gtk_widget_show_all (dialog); +} + GtkWidget * gtkutil_button (GtkWidget *box, char *stock, char *tip, void *callback, void *userdata, char *labeltext) |