File selector widget example

This code places two Elementary file selector widgets on a window.

The one on the left is layouting file system items in a list, while the the other is layouting them in a grid.

The one having the majority of hooks of interest is on the left, which we create as follows:

/* first file selector, in list mode */
fs = elm_fileselector_add(win);
/* enable the fs file name entry */
elm_fileselector_is_save_set(fs, EINA_TRUE);
/* custom list view */
elm_fileselector_expandable_set(fs, EINA_FALSE);
/* start the fileselector in the /tmp/ dir */
elm_fileselector_path_set(fs, "/tmp");
evas_object_size_hint_weight_set(fs, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(fs, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(vbox, fs);
evas_object_show(fs);
EVAS_HINT_EXPAND
#define EVAS_HINT_EXPAND
Use with evas_object_size_hint_weight_set(), evas_object_size_hint_weight_get(), evas_object_size_hin...
Definition Evas_Common.h:297
EVAS_HINT_FILL
#define EVAS_HINT_FILL
Use with evas_object_size_hint_align_set(), evas_object_size_hint_align_get(), evas_object_size_hint_...
Definition Evas_Common.h:298
EINA_TRUE
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition eina_types.h:539
EINA_FALSE
#define EINA_FALSE
boolean value FALSE (numerical value 0)
Definition eina_types.h:533
elm_box_pack_end
void elm_box_pack_end(Elm_Box *obj, Efl_Canvas_Object *subobj)
Add an object at the end of the pack list.
Definition elm_box_eo.legacy.c:57
elm_fileselector_path_set
void elm_fileselector_path_set(Evas_Object *obj, const char *_path)
Set, programmatically, the directory that a given file selector widget will display contents from.
Definition elc_fileselector.c:2153
elm_fileselector_add
Evas_Object * elm_fileselector_add(Evas_Object *parent)
Add a new file selector widget to the given parent Elementary (container) object.
Definition elc_fileselector.c:1918
elm_fileselector_is_save_set
void elm_fileselector_is_save_set(Evas_Object *obj, Eina_Bool is_save)
Enable/disable the file name entry box where the user can type in a name for a file,...
Definition elc_fileselector.c:2013
elm_fileselector_expandable_set
void elm_fileselector_expandable_set(Evas_Object *obj, Eina_Bool expand)
Enable/disable a tree view in the given file selector widget, if it's in ELM_FILESELECTOR_LIST mode.
Definition elc_fileselector.c:2121
evas_object_show
EVAS_API void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition evas_object_main.c:1814
evas_object_size_hint_weight_set
EVAS_API void evas_object_size_hint_weight_set(Evas_Object *obj, double x, double y)
Sets the hints for an object's weight.
Definition evas_object_main.c:2638
evas_object_size_hint_align_set
EVAS_API void evas_object_size_hint_align_set(Evas_Object *obj, double x, double y)
Sets the hints for an object's alignment.
Definition evas_object_main.c:2650

Note that we enable custom edition of file/directory selection, via the text entry it has on its bottom, via elm_fileselector_is_save_set(). It starts with the list view, which is the default, and we make it not expandable in place (elm_fileselector_expandable_set()), so that it replaces its view's contents with the current directory's entries each time one navigates to a different folder. For both of file selectors we are starting to list the contents found in the `"/tmp"` directory (elm_fileselector_path_set()).

Note the code setting it to "grid mode" and observe the differences in the file selector's views, in the example. We also hide the second file selector's Ok/Cancel buttons – since it's there just to show the grid view (and navigation) – via elm_fileselector_buttons_ok_cancel_set().

The `"done"` event, which triggers the callback below

/* 'done' cb */
static void
_fs_done(void *data EINA_UNUSED,
Evas_Object *obj EINA_UNUSED,
void *event_info)
{
const char *selected = event_info;
/* event_info contains the full path of the selected file or NULL
* if none is selected (or cancel is pressed) */
printf("We're done! Selected file is: %s\n",
selected ? selected : "*none!*");
elm_exit();
}
EINA_UNUSED
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition eina_types.h:339
elm_exit
void elm_exit(void)
Ask to exit Elementary's main loop.
Definition elm_main.c:1373
Evas_Object
Efl_Canvas_Object Evas_Object
An Evas Object handle.
Definition Evas_Common.h:185

will be called at the time one clicks the "Ok"/"Cancel" buttons of the file selector (on the left). Note that it will print the path to the current selection, if any.

The `"selected"` event, which triggers the callback below

takes place when one selects a file (if the file selector is not under folders-only mode) or when one selects a folder (when in folders-only mode). Experiment it by selecting different file system entries.

What comes next is the code creating the three check boxes and two buttons below the file selector in the right. They will exercise a bunch of functions on the file selector's API, for the instance on the left. Experiment with them, specially the buttons, to get the difference between elm_fileselector_path_get() and elm_fileselector_selected_get().

Finally, there's the code adding the second file selector, on the right:

/* second file selector, now with grid view */
fs = elm_fileselector_add(win);
elm_fileselector_is_save_set(fs, EINA_TRUE);
elm_fileselector_mode_set(fs, ELM_FILESELECTOR_GRID);
elm_fileselector_buttons_ok_cancel_set(fs, EINA_FALSE);
elm_fileselector_path_set(fs, "/tmp");
evas_object_size_hint_weight_set(fs, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(fs, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(bx, fs);
evas_object_show(fs);
elm_fileselector_mode_set
void elm_fileselector_mode_set(Evas_Object *obj, Elm_Fileselector_Mode mode)
Set the mode in which a given file selector widget will display (layout) file system entries in its v...
Definition elc_fileselector.c:2222
ELM_FILESELECTOR_GRID
@ ELM_FILESELECTOR_GRID
Layout as a grid.
Definition elm_interface_fileselector_eo.h:22

Pay attention to the code setting it to "grid mode" and observe the differences in the file selector's views, in the example. We also hide the second file selector's Ok/Cancel buttons – since it's there just to show the grid view (and navigation) – via elm_fileselector_buttons_ok_cancel_set().

See the full example, whose window should look like this picture:

See the full source code for this example.