eumandy/eugtk/examples/test120.ex
2016-11-25 00:33:18 -07:00

58 lines
1.7 KiB
Elixir

-----------------------------------------------------------------
--# GtkFileChooserButton
-----------------------------------------------------------------
include GtkEngine.e
constant docs = `<b><u>GtkFileChooserButton</u></b>
a widget which can be added to any container
to pop up a file-chooser dialog.
`
constant win = create(GtkWindow,"size=400x80,border_width=10,position=1,$destroy=Quit")
constant panel = create(GtkBox,"orientation=VERTICAL")
add(win,panel)
constant lbl = create(GtkLabel)
set(lbl,"markup",docs)
add(panel,lbl)
constant box = create(GtkBox,"orientation=HORIZONTAL, spacing=5")
pack(panel,-box)
constant btn1 = create(GtkButton,"gtk-quit","Quit")
set(btn1,"tooltip text","Click to exit")
add(box,btn1)
constant fcb = create(GtkFileChooserButton,"Select a file",GTK_FILE_CHOOSER_ACTION_OPEN)
set(fcb,"tooltip text","Click to open a file chooser dialog")
pack(box,fcb,TRUE,TRUE)
constant btn2 = create(GtkButton,"gtk-ok",_("Foo"))
set(btn2,"tooltip text","Click to try to open the selected file")
add(box,btn2)
show_all(win)
main()
------------------------------------------------------------------------
function Foo() --calls show_uri which handles most files
------------------------------------------------------------------------
object selected = get(fcb,"filename")
if atom(selected) then -- directory was clicked, not a file
return 1
end if
if Question(win,"File Chooser",
"Open \n" & selected,
"with default handler?") = MB_YES then
ifdef WINDOWS then
system("explorer " & selected,0)
return 1
end ifdef
show_uri(selected) -- this line is all that's needed for UNIX
end if
return 1
end function