117 lines
3.4 KiB
Elixir
117 lines
3.4 KiB
Elixir
|
|
---------------------------------------------------------------------------------
|
|
--# GtkFileChooserDialog
|
|
-- See also GtkFileSelector.e for 'pre-built' file methods
|
|
-------------------------------------------------------------------------------
|
|
|
|
include GtkEngine.e
|
|
|
|
constant docs = `<u><b>FileChooserDialog</b></u>
|
|
|
|
the same dialog can be used to either open a file, save a file,
|
|
or select a folder, by changing the action.
|
|
|
|
`
|
|
constant win = create(GtkWindow,{
|
|
{"border width",10},
|
|
{"position",GTK_WIN_POS_CENTER},
|
|
{"default size",300},
|
|
{"connect","destroy","Quit"}})
|
|
|
|
constant panel = create(GtkBox,VERTICAL)
|
|
add(win,panel)
|
|
|
|
constant lbl = create(GtkLabel)
|
|
set(lbl,"markup",docs)
|
|
add(panel,lbl)
|
|
|
|
constant box = pack_end(panel,create(GtkButtonBox,HORIZONTAL))
|
|
add(box,{
|
|
create(GtkButton,"gtk-quit","Quit"),
|
|
create(GtkButton,"folder-open#_Open",call_back(routine_id("Open"))),
|
|
create(GtkButton,"gtk-save",call_back(routine_id("Save"))),
|
|
create(GtkButton,"folder#_Folder",call_back(routine_id("ChooseFolder")))})
|
|
|
|
-----------------------------------------------------------
|
|
function Open()
|
|
-----------------------------------------------------------
|
|
|
|
object dlg = create(GtkFileChooserDialog,{
|
|
{"title","Open a file"},
|
|
{"transient for",win},
|
|
{"action",GTK_FILE_CHOOSER_ACTION_OPEN},
|
|
{"select multiple",TRUE},
|
|
{"add button","gtk-cancel",-1},
|
|
{"add button","gtk-ok",1},
|
|
{"add shortcut folder","../gtk3"}, -- I store GTK3 docs here;
|
|
{"add shortcut folder","../docs/html"}}) -- and Eu docs here;
|
|
|
|
if get(dlg,"run") = 1 then
|
|
|
|
Info(win,"Open","Open the file",get(dlg,"filename"),GTK_BUTTONS_CLOSE)
|
|
|
|
-- single;
|
|
-- get(dlg,"file") -- gets a GFile handle;
|
|
-- get(dlg,"filename") -- gets /home/folder/file.ext format;
|
|
-- get(dlg,"uri") -- gets file:///home/folder/file.ext format;
|
|
|
|
-- multiple;
|
|
-- get(dlg,"filenames") -- retuns sequence of all selected names;
|
|
-- get(dlg,"files") -- returns a list of GFile handles;
|
|
-- get(dlg,"uris") -- returns sequence of all selected uris;
|
|
-- filename and uri return first file if multiple selected;
|
|
|
|
end if
|
|
set(dlg,"hide")
|
|
|
|
return 1
|
|
end function
|
|
|
|
------------------------------------------------------------
|
|
function Save()
|
|
------------------------------------------------------------
|
|
object dlg = create(GtkFileChooserDialog,{
|
|
{"title","Save this file"},
|
|
{"transient for",win},
|
|
{"action",GTK_FILE_CHOOSER_ACTION_SAVE},
|
|
{"add button","gtk-cancel",-1},
|
|
{"add button","gtk-ok",1},
|
|
{"current name","My Wonderful Program.ex"}})
|
|
|
|
if get(dlg,"run") = 1 then
|
|
Info(win,"Save","Save the file","My Wonderful Program.ex",GTK_BUTTONS_CLOSE)
|
|
end if
|
|
set(dlg,"hide")
|
|
|
|
return 1
|
|
end function
|
|
|
|
------------------------------------------------------------
|
|
function ChooseFolder()
|
|
------------------------------------------------------------
|
|
object dlg = create(GtkFileChooserDialog,{
|
|
{"title","Choose a folder"},
|
|
{"transient for",win},
|
|
{"action",GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER},
|
|
{"add button","gtk-cancel",-1},
|
|
{"add button","gtk-ok",1}})
|
|
|
|
ifdef WINDOWS then -- skip this
|
|
elsedef
|
|
set(dlg,"filter", create(GtkFileFilter,{ -- ng on Windows
|
|
{"name","Directories"},{"add mime type","inode/directory"}}))
|
|
end ifdef
|
|
|
|
if get(dlg,"run") = 1 then
|
|
Info(win,"Folder","You chose folder:",get(dlg,"filename"),GTK_BUTTONS_CLOSE)
|
|
end if
|
|
set(dlg,"hide")
|
|
|
|
return 1
|
|
end function
|
|
|
|
show_all(win)
|
|
main()
|
|
|
|
|