
------------------------------------------------------------------------
--# displays the x-color names and samples;
------------------------------------------------------------------------

include GtkEngine.e

constant xcolors = canonical_path("~/demos/resources/xcolors.txt")

constant win = create(GtkWindow,{
    {"icon","~/demos/thumbnails/preferences-color.svg"},
    {"default size",400,800},
    {"position",GTK_WIN_POS_CENTER}})
    connect(win,"destroy","Quit")

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

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

constant rend1 = create(GtkCellRendererText),
    col1 = create(GtkTreeViewColumn,{
    {"pack start",rend1},
    {"title","Name"},
    {"sort column id",1},
    {"add attribute",rend1,"text",1}})

constant rend2 = create(GtkCellRendererText),
    col2 = create(GtkTreeViewColumn,{
    {"pack start",rend2},
    {"title","Color"},
    {"add attribute",rend2,"background",1}})
	
constant store = create(GtkListStore,{gSTR,gSTR,gINT})

sequence names = read_lines(xcolors)
    set(store,"data",names)

constant tv = add(scroller,create(GtkTreeView,{
    {"model",store},
    {"headers clickable",TRUE},
    {"grid lines",GTK_TREE_VIEW_GRID_LINES_BOTH},
    {"append columns",{col1,col2}}}))

constant 
    btn1 = create(GtkButton,"gtk-quit","Quit"),
    btn2 = create(GtkButton,"gtk-refresh","Restore")
    set(btn2,"tooltip text","Restore original (unsorted) order")

constant box = add(panel,create(GtkButtonBox,{
    {"layout",GTK_BUTTONBOX_SPREAD},
    {"margin top",10},
    {"margin bottom",10}}))
    add(box,{btn1,btn2})

show_all(win)
main()

-------------------------
global function Restore() -- returns list to original order
-------------------------
	set(store,"clear")
	set(store,"sort column id",UNSORTED)
	set(store,"data",names)
return 1
end function

