-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgtktest.nt
103 lines (80 loc) · 2.85 KB
/
gtktest.nt
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
module gtktest;
import std.lib.gtk;
import std.string, std.file;
bool delete_event(void* widget, void* event, gpointer data) {
/* If you return FALSE in the "delete-event" signal handler,
* GTK will emit the "destroy" signal. Returning TRUE means
* you don't want the window to be destroyed.
* This is useful for popping up 'are you sure you want to quit?'
* type dialogs. */
g_print ("delete event occurred\n");
/* Change TRUE to FALSE and the main window will be destroyed with
* a "delete-event". */
return true;
}
alias G_TYPE_STRING = GType:(16 << 2);
int main (int argc, char **argv) {
gtk_init (&argc, &argv);
auto window = GTK_WINDOW _new _TOPLEVEL;
window.set_title "Hello Buttons!";
auto model = GTK_TREE_STORE _new (2, G_TYPE_STRING, G_TYPE_STRING);
string line;
GtkTreeIter[auto~] iters;
alias current = &iters[$-1];
alias prev = &iters[$-2];
bool reading;
writeln "Building model. ";
while line <- splitAt(castIter!string readfile open "xmldump.txt", "\n") {
// writeln "> $line";
if (auto rest = line.startsWith "----module ") {
auto restp = toStringz rest;
iters ~= GtkTreeIter iter;
model.append (current, null);
model.set (current, 0, restp, 1, null, -1);
reading = true;
}
if (line.startsWith "----done") {
iters = type-of iters: iters[0 .. $-1];
reading = false;
}
if (reading) {
if (line.startsWith "<node") {
auto classnamep = toStringz line.between(" classname=\"", "\"");
auto namep = toStringz line.between (" name=\"", "\" ");
auto infop = toStringz line.between (" info=\"", "\" ");
if (!line.find " info=") infop = namep;
iters ~= GtkTreeIter iter;
model.append (current, prev);
model.set (current, 0, classnamep, 1, infop, -1);
}
if (line == "</node>") {
iters = type-of iters: iters[0 .. $-1];
}
}
}
auto sw = GTK_SCROLLED_WINDOW _new (null, null);
sw.set_policy (GTK_POLICY_AUTOMATIC x 2);
auto tree = GTK_TREE_VIEW _new ();
tree.set_headers_visible true;
sw.add tree;
window.add sw;
{
auto renderer = GTK_CELL_RENDERER_TEXT _new ();
tree.append_column GTK_TREE_VIEW_COLUMN _new_with_attributes
("Class", renderer, "text".ptr, 0, null);
tree.append_column GTK_TREE_VIEW_COLUMN _new_with_attributes
("Info", renderer, "text".ptr, 1, null);
tree.set_model GTK_TREE_MODEL GtkWidget*:model;
g_object_unref (model);
}
g_signal_connect_data (gpointer:window,
"delete-event",
GCallback:function bool(void* widget, event, data) { return false; },
void*: null, void*: null, GConnectFlags: 0
);
g_signal_connect (window, "destroy", \(GtkWidget*) { gtk_main_quit(); });
window.set_border_width 10;
window.show_all ();
gtk_main ();
return 0;
}