blob: 8a776924443e9d3b23647756e0bd554b0544ab2b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#include "text_input_dialog.h"
GtkDialog *text_input_dialog_new(GtkWidget *parent, const gchar *msg) {
GtkWidget *dialog;
GtkWidget *entry;
GtkWidget *vbox;
dialog = gtk_message_dialog_new(GTK_WINDOW(parent), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, msg);
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
entry = gtk_entry_new();
gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
gtk_box_pack_end(GTK_BOX(vbox), entry, FALSE, FALSE, 0);
gtk_widget_show(entry);
return GTK_DIALOG(dialog);
}
gchar *text_input_dialog_get_text(GtkWidget *dialog) {
GtkWidget *vbox;
GtkWidget *entry;
GList *list;
GtkEntryBuffer *buf;
vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
list = gtk_container_get_children(GTK_CONTAINER(vbox));
entry = NULL;
for(int i = 0; i < g_list_length(list); i++)
if(GTK_IS_ENTRY(g_list_nth_data(list, i)))
entry = GTK_WIDGET(g_list_nth_data(list, i));
g_assert(entry != NULL);
buf = gtk_entry_get_buffer(GTK_ENTRY(entry));
return g_strdup(gtk_entry_buffer_get_text(buf));
}
|