
---------------------------------------------------------------------------
--# GtkAppChooserWidget
---------------------------------------------------------------------------

include GtkEngine.e	

sequence docs = `<b><u>App Chooser Widget</u></b>

Displays default app, recommended apps, and 
others, if requested, for files of a given type.
Choose types below.

`
ifdef WINDOWS then
    docs &= "<span color='red'>Doesn't seem to work on Windows</span>"
end ifdef

constant ctypes = {
    "text/plain",
    "text/html",
    "image/gif",
    "inode/directory",
    "application/pdf",
    "application/x-compressed-tar",
$}

object content_type = ctypes[1]

constant win = create(GtkWindow,"size=200x100,border=10,position=1,$destroy=Quit")

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

constant lbl = create(GtkLabel)
    set(lbl,"markup",docs)
    add(panel,lbl)

constant 
    btn1 = create(GtkButton,"gtk-quit","Quit"),
    btnbox = create(GtkButtonBox)
    pack(panel,-btnbox)
	
constant combo = create(GtkComboBoxText,{
    {"tooltip markup","Drop down list of content-types"},
    {"signal","changed","UpdateContentType"}})
    for i = 1 to length(ctypes) do
	set(combo,"append text",ctypes[i])
    end for

    add(btnbox,{btn1,combo})
  
object apcw = create(GtkAppChooserWidget,content_type)
add(panel,apcw)

show_all(win)

set(combo,"active",1)

UpdateContentType() 

-- line above is a hack to remove the shadowy "no applications found" 
-- overlay which appears when using GTK3.14, even if apps are found.
-- That is probably a bug in the GTK3.14 version of the app chooser
	
main()

------------------------------------
global function UpdateContentType()
------------------------------------
content_type = get(combo,"active text")
    set(apcw,"destroy") -- get rid of the old one;
    apcw = create(GtkAppChooserWidget,content_type) -- create new with new content-type;
    set(apcw,"show other",TRUE)
    set(apcw,"default text",sprintf("Sorry, can't find an app for %s",{content_type}))
    show(apcw)
    add(panel,apcw)
	
return 1
end function








