
--# Simple ListView test

include GtkEngine.e

constant win = create(GtkWindow,"border=10,size=300x200,$destroy=Quit")

constant panel = create(GtkBox,"orientation=VERTICAL")
	add(win,panel)

constant scroller = create(GtkScrolledWindow)
	pack(panel,scroller,1,1)

constant fruits = {
	{"Apples",	"doz", 5.00},
	{"Cherries",	"lb",  3.69},
	{"Limes",	"ea",   .99},
	{"Oranges",	"ea",  0.79},
	{"Bananas",	"lb",   .89},
	$}
-- note: even though the 3rd column is numeric, we can for convenience store it
-- in a string 'slot' declared below. if stored as a float, we would have to 
-- write a formatting routine to handle it properly. change the 3rd param
-- below to gFLT or gDBL to see what I mean:
constant store = create(GtkListStore,{gSTR,gSTR,gSTR}) 
	 set(store,"data",fruits)
	
constant  tv = create(GtkTreeView,{
	{"model",store},    
	{"reorderable",TRUE},
	{"headers clickable",TRUE},
	{"set grid lines",GTK_TREE_VIEW_GRID_LINES_BOTH},
	{"rules hint",TRUE},
	{"connect","row-activated",_("ShowChoice")}})
	add(scroller,tv)

constant  
	col1 = create(GtkColumn,"title=Name,type=text,text=1,sort_column_id=1"),
	col2 = create(GtkColumn,"title=Quantity,type=text,text=2"),
	col3 = create(GtkColumn,"title=Price,type=text,text=3,sort_column_id=3") 

set(tv,"append columns",{col1,col2,col3})

constant selection = get(tv,"selection") -- this 'tracks' the current selection for use later;

show_all(win)
main()

---------------------
function ShowChoice()
---------------------
object choice = get(selection,"selected row data")
Info(,,choice[1],format("Price: $[3] per [2]",choice))
return 1
end function

