comparison finch/gntrequest.c @ 18333:f23a7736586f

Consider closing a request dialog equivalent to cancelling it.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Thu, 28 Jun 2007 18:32:22 +0000
parents ef65d43190e5
children a90f9a0b90c8
comparison
equal deleted inserted replaced
18332:1862a23b1751 18333:f23a7736586f
65 GINT_TO_POINTER(type)); 65 GINT_TO_POINTER(type));
66 66
67 return window; 67 return window;
68 } 68 }
69 69
70 /**
71 * If the window is closed by the wm (ie, without triggering any of
72 * the buttons, then do some default callback.
73 */
74 static void
75 setup_default_callback(GntWidget *window, gpointer default_cb, gpointer data)
76 {
77 g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(default_cb), data);
78 }
79
80 static void
81 action_performed(GntWidget *button, gpointer data)
82 {
83 g_signal_handlers_disconnect_matched(data, G_SIGNAL_MATCH_FUNC,
84 0, 0, NULL, setup_default_callback, NULL);
85 }
86
87 /**
88 * window: this is the window
89 * userdata: the userdata to pass to the primary callbacks
90 * cb: the callback
91 * data: data for the callback
92 * (text, primary-callback) pairs, ended by a NULL
93 */
70 static GntWidget * 94 static GntWidget *
71 setup_button_box(gpointer userdata, gpointer cb, gpointer data, ...) 95 setup_button_box(GntWidget *win, gpointer userdata, gpointer cb, gpointer data, ...)
72 { 96 {
73 GntWidget *box, *button; 97 GntWidget *box, *button;
74 va_list list; 98 va_list list;
75 const char *text; 99 const char *text;
76 gpointer callback; 100 gpointer callback;
85 button = gnt_button_new(text); 109 button = gnt_button_new(text);
86 gnt_box_add_widget(GNT_BOX(box), button); 110 gnt_box_add_widget(GNT_BOX(box), button);
87 g_object_set_data(G_OBJECT(button), "activate-callback", callback); 111 g_object_set_data(G_OBJECT(button), "activate-callback", callback);
88 g_object_set_data(G_OBJECT(button), "activate-userdata", userdata); 112 g_object_set_data(G_OBJECT(button), "activate-userdata", userdata);
89 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(cb), data); 113 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(cb), data);
114 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(action_performed), win);
90 } 115 }
91 116
92 va_end(list); 117 va_end(list);
93 return box; 118 return box;
94 } 119 }
125 entry = gnt_entry_new(default_value); 150 entry = gnt_entry_new(default_value);
126 if (masked) 151 if (masked)
127 gnt_entry_set_masked(GNT_ENTRY(entry), TRUE); 152 gnt_entry_set_masked(GNT_ENTRY(entry), TRUE);
128 gnt_box_add_widget(GNT_BOX(window), entry); 153 gnt_box_add_widget(GNT_BOX(window), entry);
129 154
130 box = setup_button_box(user_data, notify_input_cb, entry, 155 box = setup_button_box(window, user_data, notify_input_cb, entry,
131 ok_text, ok_cb, cancel_text, cancel_cb, NULL); 156 ok_text, ok_cb, cancel_text, cancel_cb, NULL);
132 gnt_box_add_widget(GNT_BOX(window), box); 157 gnt_box_add_widget(GNT_BOX(window), box);
133 158
159 setup_default_callback(window, cancel_cb, user_data);
134 gnt_widget_show(window); 160 gnt_widget_show(window);
135 161
136 return window; 162 return window;
137 } 163 }
138 164
187 val = va_arg(choices, int); 213 val = va_arg(choices, int);
188 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), GINT_TO_POINTER(val + 1), text); 214 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), GINT_TO_POINTER(val + 1), text);
189 } 215 }
190 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), GINT_TO_POINTER(default_value + 1)); 216 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), GINT_TO_POINTER(default_value + 1));
191 217
192 box = setup_button_box(user_data, request_choice_cb, combo, 218 box = setup_button_box(window, user_data, request_choice_cb, combo,
193 ok_text, ok_cb, cancel_text, cancel_cb, NULL); 219 ok_text, ok_cb, cancel_text, cancel_cb, NULL);
194 gnt_box_add_widget(GNT_BOX(window), box); 220 gnt_box_add_widget(GNT_BOX(window), box);
195 221
222 setup_default_callback(window, cancel_cb, user_data);
196 gnt_widget_show(window); 223 gnt_widget_show(window);
197 224
198 return window; 225 return window;
199 } 226 }
200 227
536 if (grlist->next) 563 if (grlist->next)
537 gnt_box_add_widget(GNT_BOX(box), gnt_hline_new()); 564 gnt_box_add_widget(GNT_BOX(box), gnt_hline_new());
538 } 565 }
539 gnt_box_add_widget(GNT_BOX(window), box); 566 gnt_box_add_widget(GNT_BOX(window), box);
540 567
541 box = setup_button_box(userdata, request_fields_cb, allfields, 568 box = setup_button_box(window, userdata, request_fields_cb, allfields,
542 ok, ok_cb, cancel, cancel_cb, NULL); 569 ok, ok_cb, cancel, cancel_cb, NULL);
543 gnt_box_add_widget(GNT_BOX(window), box); 570 gnt_box_add_widget(GNT_BOX(window), box);
544 571
572 setup_default_callback(window, cancel_cb, userdata);
545 gnt_widget_show(window); 573 gnt_widget_show(window);
546 574
547 g_object_set_data(G_OBJECT(window), "fields", allfields); 575 g_object_set_data(G_OBJECT(window), "fields", allfields);
548 576
549 return window; 577 return window;