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

89 lines
2.3 KiB
Elixir

---------------------------------------------------------------
--# GtkRecentFilter
---------------------------------------------------------------
include GtkEngine.e
include std/net/url.e
constant docs = `<b><u>Recent Filter</u></b>
This shows how to filter types of files
displayed by the RecentChooser.
I've limited it to the most recent 50.`
constant win = create(GtkWindow,"size=300x300,border=10,position=1,$destroy=Quit")
constant panel = create(GtkBox,"orientation=VERTICAL")
add(win,panel)
constant lbl = create(GtkLabel,{{"markup",docs}})
add(panel,lbl)
constant rf1 = create(GtkRecentFilter, -- filter by extension
"name=Euphoria,add pattern=*.ex,add pattern=*.e")
constant rf2 = create(GtkRecentFilter, -- filter by format
"name=images,add pixbuf formats=TRUE")
constant rf3 = create(GtkRecentFilter, -- filter by mime type
"name=html,add mime type=text/html")
constant rf4 = create(GtkRecentFilter, -- filter by app
"name=pdf,add mime type=application/pdf")
constant rf5 = create(GtkRecentFilter, -- wildcard filter
"name=all files,add pattern=*")
constant rc = create(GtkRecentChooserWidget,{
{"show tips",TRUE}, -- display filepath in tooltips
{"show not found",FALSE},
{"sort type",GTK_RECENT_SORT_MRU}, -- sort most-recently-used first
{"add filter",rf1},
{"add filter",rf2},
{"add filter",rf3},
{"add filter",rf4},
{"add filter",rf5},
{"limit",50}})
pack(panel,rc,TRUE,TRUE,10)
constant btnbox = create(GtkButtonBox)
pack(panel,-btnbox)
constant btn1 = create(GtkButton,"gtk-quit","Quit")
constant btn2 = create(GtkButton,"gtk-ok","getFile")
add(btnbox,{btn1,btn2})
show_all(win)
main()
---------------------------------
global function getFile()
---------------------------------
object info = get(rc,"current item")
if info = 0 then return 1 end if
object icon = get(info,"gicon")
object name = get(info,"uri")
name = url:decode(name)
if match("file://",name) then
name = name[9..$]
end if
if not file_exists(name) then
Error(win,,"File not found",name,,GTK_BUTTONS_OK)
else
if Question(win,"Selected Item",name) = MB_YES then
ifdef WINDOWS then
system(sprintf("explorer %s",{abbreviate_path(name)}),0)
return 1
end ifdef
show_uri(name)
end if
end if
return 1
end function