-
Notifications
You must be signed in to change notification settings - Fork 0
/
gtkutils.c
75 lines (68 loc) · 2.08 KB
/
gtkutils.c
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "gtkutils.h"
#include "lib/bytes.h"
void show_message_dialog(
GtkMessageType type,
const gchar *message,
GtkWindow *parent
) {
const gchar *text = NULL;
switch (type) {
case GTK_MESSAGE_INFO:
text = "Información";
break;
case GTK_MESSAGE_WARNING:
text = "Advertencia";
break;
case GTK_MESSAGE_ERROR:
text = "Error";
break;
default:
break;
}
GtkWidget *error_dialog = gtk_message_dialog_new(
parent,
GTK_DIALOG_MODAL,
type,
GTK_BUTTONS_CLOSE,
text
);
gtk_message_dialog_format_secondary_text(
GTK_MESSAGE_DIALOG(error_dialog),
message
);
gtk_dialog_run(GTK_DIALOG(error_dialog));
gtk_widget_destroy(error_dialog);
}
gchar *get_text_view_text(GtkTextView *text_view, gsize *length_ptr) {
GtkTextBuffer *buffer = gtk_text_view_get_buffer(text_view);
GtkTextIter start;
GtkTextIter end;
gchar *text = NULL;
gtk_text_buffer_get_bounds(buffer, &start, &end);
*length_ptr = gtk_text_iter_get_offset(&end) - gtk_text_iter_get_offset(&start);
text = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
return text;
}
void set_text_view_text(GtkTextView *text_view, const gchar *text, gssize size) {
GtkTextBuffer *text_buffer = gtk_text_view_get_buffer(text_view);
gtk_text_buffer_set_text(text_buffer, text, size);
}
GFile *get_native_file(GtkFileChooserNative *native, const gchar *name) {
GtkFileChooserAction action = \
gtk_file_chooser_get_action(GTK_FILE_CHOOSER(native));
gint res = -1;
if (
name != NULL &&
(
action == GTK_FILE_CHOOSER_ACTION_SAVE ||
action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
)
) {
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(native), "");
}
res = gtk_native_dialog_run(GTK_NATIVE_DIALOG(native));
if (res != GTK_RESPONSE_ACCEPT) {
return NULL;
}
return gtk_file_chooser_get_file(GTK_FILE_CHOOSER(native));
}