1 module DemoCustomList;
2 
3 import CustomList;
4 
5 import gio.Application : GioApplication = Application;
6 import glib.RandG;
7 import gtk.Application;
8 import gtk.ApplicationWindow;
9 import gtk.CellRendererText;
10 import gtk.ListStore;
11 import gtk.ScrolledWindow;
12 import gtk.TreeView;
13 import gtk.TreeViewColumn;
14 
15 class CustomListWindow : ApplicationWindow
16 {
17 	this(Application application)
18 	{
19 		super(application);
20 		setTitle("GtkD - Custom TreeModel");
21 		setDefaultSize(300, 400);
22 		
23 		ScrolledWindow scrollwin = new ScrolledWindow();
24 		TreeView view = createViewAndModel();
25 
26 		scrollwin.add(view);
27 		add(scrollwin);
28 
29 		showAll();
30 	}
31 
32 	TreeView createViewAndModel()
33 	{
34 		TreeViewColumn   col;
35 		CellRendererText renderer;
36 		CustomList       customlist;
37 		TreeView         view;
38 
39 		customlist = new CustomList();
40 		fillModel(customlist);
41 		
42 		view = new TreeView(customlist);
43 		
44 		col = new TreeViewColumn();
45 		renderer  = new CellRendererText();
46 		col.packStart(renderer, true);
47 		col.addAttribute(renderer, "text", CustomListColumn.Name);
48 		col.setTitle("Name");
49 		view.appendColumn(col);
50 
51 		col = new TreeViewColumn();
52 		renderer  = new CellRendererText();
53 		col.packStart(renderer, true);
54 		col.addAttribute(renderer, "text", CustomListColumn.YearBorn);
55 		col.setTitle("Year Born");
56 		view.appendColumn(col);
57 
58 		return view;
59 	}
60 
61 	void fillModel (CustomList customlist)
62 	{
63 		string[]  firstnames = [ "Joe", "Jane", "William", "Hannibal", "Timothy", "Gargamel" ];
64 		string[]  surnames   = [ "Grokowich", "Twitch", "Borheimer", "Bork" ];
65 
66 		foreach (sname; surnames)
67 		{
68 			foreach (fname; firstnames)
69 			{
70 				customlist.appendRecord(fname ~" "~ sname, 1900 + (RandG.randomInt() % 100));
71 			}
72 		}
73 	}
74 }
75 
76 int main (string[] args)
77 {
78 	auto application = new Application("org.gtkd.demo.customlist", GApplicationFlags.FLAGS_NONE);
79 	application.addOnActivate(delegate void(GioApplication app) { new CustomListWindow(application); });
80 	return application.run(args);
81 }