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 */
/* enable the fs file name entry */
/* custom list view */
/* start the fileselector in the /tmp/ dir */
elm_box_pack_end(vbox, fs);

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,
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!*");
}

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:

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.

EINA_UNUSED
#define EINA_UNUSED
Definition: eina_types.h:339
EINA_FALSE
#define EINA_FALSE
Definition: eina_types.h:533
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_Object
Efl_Canvas_Object Evas_Object
Definition: Evas_Common.h:185
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
evas_object_size_hint_weight_set
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
elm_fileselector_mode_set
EAPI 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
evas_object_size_hint_align_set
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
elm_fileselector_expandable_set
EAPI 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
elm_exit
void elm_exit(void)
Ask to exit Elementary's main loop.
Definition: elm_main.c:1378
evas_object_show
void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1814
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
Definition: eina_types.h:539
ELM_FILESELECTOR_GRID
@ ELM_FILESELECTOR_GRID
Layout as a grid.
Definition: elm_interface_fileselector_eo.h:22
elm_fileselector_add
EAPI 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
EAPI 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_path_set
EAPI 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