2 * @defgroup Fileselector Fileselector
4 * A fileselector is a widget that allows a user to navigate through a
5 * tree of files. It contains buttons for Home(~) and Up(..) as well
6 * as cancel/ok buttons to confirm/cancel a selection. This widget is
7 * currently very much in progress.
10 * child elements focusing support
11 * userdefined icon/label cb
12 * show/hide/add buttons ???
13 * show/Hide hidden files
14 * double click to choose a file
16 * make variable/function names that are sensible
19 * Signals that you can add callbacks for are:
21 * "selected" - the user clicks on a file
22 * "directory,open" - the list is populated with new content.
23 * event_info is a directory.
24 * "done" - the user clicks on the ok or cancel button
28 # include "elementary_config.h"
35 #include <Elementary.h>
38 typedef struct _Widget_Data Widget_Data;
45 Evas_Object *filename_entry;
46 Evas_Object *path_entry;
47 Evas_Object *files_list;
48 Evas_Object *files_grid;
49 Evas_Object *up_button;
50 Evas_Object *home_button;
52 Evas_Object *ok_button;
53 Evas_Object *cancel_button;
56 const char *selection;
57 Ecore_Idler *sel_idler;
59 const char *path_separator;
65 Elm_Fileselector_Mode mode;
67 Eina_Bool only_folder : 1;
77 typedef struct _Widget_Request Widget_Request;
78 struct _Widget_Request
81 Elm_Genlist_Item *parent;
93 } Elm_Fileselector_Type;
95 static Elm_Genlist_Item_Class list_itc[ELM_FILE_LAST] = {
96 { "default", { NULL, NULL, NULL, NULL, NULL }, NULL },
97 { "default", { NULL, NULL, NULL, NULL, NULL }, NULL },
98 { "default", { NULL, NULL, NULL, NULL, NULL }, NULL }
100 static Elm_Gengrid_Item_Class grid_itc[ELM_FILE_LAST] = {
101 { "default", { NULL, NULL, NULL, NULL } },
102 { "default", { NULL, NULL, NULL, NULL } },
103 { "default", { NULL, NULL, NULL, NULL } }
106 static const char *widtype = NULL;
108 static const char SIG_DIRECTORY_OPEN[] = "directory,open";
109 static const char SIG_DONE[] = "done";
110 static const char SIG_SELECTED[] = "selected";
111 static const Evas_Smart_Cb_Description _signals[] = {
112 {SIG_DIRECTORY_OPEN, "s"},
118 static void _populate(Evas_Object *obj,
120 Elm_Genlist_Item *parent);
121 static void _do_anchors(Evas_Object *obj,
124 /*** ELEMENTARY WIDGET ***/
126 _widget_data_free(Widget_Data *wd)
128 if (wd->path) eina_stringshare_del(wd->path);
129 if (wd->selection) eina_stringshare_del(wd->selection);
134 sd = ecore_idler_del(wd->sel_idler);
141 _del_hook(Evas_Object *obj)
145 wd = elm_widget_data_get(obj);
150 eio_file_cancel(wd->current);
153 wd->files_list = NULL;
154 wd->files_grid = NULL;
156 EINA_REFCOUNT_UNREF(wd, _widget_data_free);
160 _sizing_eval(Evas_Object *obj)
162 Widget_Data *wd = elm_widget_data_get(obj);
163 Evas_Coord minw = -1, minh = -1;
165 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
166 edje_object_size_min_restricted_calc(wd->edje, &minw, &minh, minw, minh);
167 evas_object_size_hint_min_set(obj, minw, minh);
171 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
173 Widget_Data *wd = elm_widget_data_get(obj);
175 elm_widget_mirrored_set(wd->cancel_button, rtl);
176 elm_widget_mirrored_set(wd->ok_button, rtl);
177 elm_widget_mirrored_set(wd->files_list, rtl);
178 elm_widget_mirrored_set(wd->up_button, rtl);
179 elm_widget_mirrored_set(wd->home_button, rtl);
180 edje_object_mirrored_set(wd->edje, rtl);
184 _theme_hook(Evas_Object *obj)
186 Widget_Data *wd = elm_widget_data_get(obj);
187 const char *style = elm_widget_style_get(obj);
192 _elm_widget_mirrored_reload(obj);
194 _elm_theme_object_set(obj, wd->edje, "fileselector", "base", style);
196 if (elm_object_disabled_get(obj))
197 edje_object_signal_emit(wd->edje, "elm,state,disabled", "elm");
199 data = edje_object_data_get(wd->edje, "path_separator");
201 wd->path_separator = data;
203 wd->path_separator = "/";
205 if (!style) style = "default";
206 snprintf(buf, sizeof(buf), "fileselector/%s", style);
208 #define SWALLOW(part_name, object_ptn) \
211 elm_widget_style_set(object_ptn, buf); \
212 if (edje_object_part_swallow(wd->edje, part_name, object_ptn)) \
213 evas_object_show(object_ptn); \
215 evas_object_hide(object_ptn); \
217 SWALLOW("elm.swallow.up", wd->up_button);
218 SWALLOW("elm.swallow.home", wd->home_button);
220 if (wd->mode == ELM_FILESELECTOR_LIST)
222 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
225 evas_object_show(wd->files_list);
226 evas_object_hide(wd->files_grid);
229 evas_object_hide(wd->files_list);
233 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
236 evas_object_show(wd->files_grid);
237 evas_object_hide(wd->files_list);
240 evas_object_hide(wd->files_grid);
243 SWALLOW("elm.swallow.filename", wd->filename_entry);
244 SWALLOW("elm.swallow.path", wd->path_entry);
246 snprintf(buf, sizeof(buf), "fileselector/actions/%s", style);
247 SWALLOW("elm.swallow.cancel", wd->cancel_button);
248 SWALLOW("elm.swallow.ok", wd->ok_button);
251 edje_object_message_signal_process(wd->edje);
252 _mirrored_set(obj, elm_widget_mirrored_get(obj));
253 edje_object_scale_set
254 (wd->edje, elm_widget_scale_get(obj) * _elm_config->scale);
258 /*** GENLIST "MODEL" ***/
260 _itc_label_get(void *data,
261 Evas_Object *obj __UNUSED__,
262 const char *source __UNUSED__)
264 return strdup(ecore_file_file_get(data)); /* NOTE this will be
270 _itc_icon_folder_get(void *data __UNUSED__,
276 if (strcmp(source, "elm.swallow.icon")) return NULL;
278 ic = elm_icon_add(obj);
279 elm_icon_standard_set(ic, "folder");
281 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
287 _itc_icon_image_get(void *data,
291 const char *filename = data;
294 if (strcmp(source, "elm.swallow.icon")) return NULL;
296 ic = elm_icon_add(obj);
297 elm_icon_standard_set(ic, "image");
298 elm_icon_thumb_set(ic, filename, NULL);
300 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
306 _itc_icon_file_get(void *data __UNUSED__,
312 if (strcmp(source, "elm.swallow.icon")) return NULL;
314 ic = elm_icon_add(obj);
315 elm_icon_standard_set(ic, "file");
317 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
323 _itc_state_get(void *data __UNUSED__,
324 Evas_Object *obj __UNUSED__,
325 const char *source __UNUSED__)
332 Evas_Object *obj __UNUSED__)
334 eina_stringshare_del(data);
338 _expand_done(void *data,
339 Evas_Object *obj __UNUSED__,
342 Elm_Genlist_Item *it = event_info;
343 const char *path = elm_genlist_item_data_get(it);
344 _populate(data, path, it);
348 _contract_done(void *data __UNUSED__,
349 Evas_Object *obj __UNUSED__,
352 Elm_Genlist_Item *it = event_info;
353 elm_genlist_item_subitems_clear(it);
357 _expand_req(void *data __UNUSED__,
358 Evas_Object *obj __UNUSED__,
361 Elm_Genlist_Item *it = event_info;
362 elm_genlist_item_expanded_set(it, 1);
366 _contract_req(void *data __UNUSED__,
367 Evas_Object *obj __UNUSED__,
370 Elm_Genlist_Item *it = event_info;
371 elm_genlist_item_expanded_set(it, 0);
384 wd = elm_widget_data_get(sd->fs);
387 if ((!wd->only_folder) && ecore_file_is_dir(path))
389 if (wd->expand && wd->mode == ELM_FILESELECTOR_LIST)
391 _do_anchors(sd->fs, path);
392 elm_entry_entry_set(wd->filename_entry, "");
396 /* keep a ref to path 'couse it will be destroyed by _populate */
397 p = eina_stringshare_add(path);
398 _populate(sd->fs, p, NULL);
399 eina_stringshare_del(p);
403 else /* navigating through folders only or file is not a dir. */
405 if (wd->expand && wd->mode == ELM_FILESELECTOR_LIST)
406 _do_anchors(sd->fs, path);
407 else if (wd->only_folder)
409 /* keep a ref to path 'couse it will be destroyed by _populate */
410 p = eina_stringshare_add(path);
411 _populate(sd->fs, p, NULL);
412 eina_stringshare_del(p);
414 elm_entry_entry_set(wd->filename_entry,
415 ecore_file_file_get(path));
418 evas_object_smart_callback_call(sd->fs, SIG_SELECTED, (void *)path);
421 wd->sel_idler = NULL;
423 return ECORE_CALLBACK_CANCEL;
428 Evas_Object *obj __UNUSED__,
436 wd = elm_widget_data_get(data);
439 sd = malloc(sizeof(*sd));
441 sd->path = wd->mode == ELM_FILESELECTOR_LIST ?
442 elm_genlist_item_data_get(event_info) :
443 elm_gengrid_item_data_get(event_info);
447 eina_stringshare_replace(&wd->path, "");
451 dir = wd->only_folder ? strdup(sd->path) : ecore_file_dir_get(sd->path);
454 eina_stringshare_replace(&wd->path, dir);
459 eina_stringshare_replace(&wd->path, "");
465 old_sd = ecore_idler_del(wd->sel_idler);
468 wd->sel_idler = ecore_idler_add(_sel_do, sd);
473 Evas_Object *obj __UNUSED__,
474 void *event_info __UNUSED__)
476 Evas_Object *fs = data;
479 Widget_Data *wd = elm_widget_data_get(fs);
481 parent = ecore_file_dir_get(wd->path);
482 _populate(fs, parent, NULL);
488 Evas_Object *obj __UNUSED__,
489 void *event_info __UNUSED__)
491 Evas_Object *fs = data;
492 _populate(fs, getenv("HOME"), NULL);
497 Evas_Object *obj __UNUSED__,
498 void *event_info __UNUSED__)
500 Evas_Object *fs = data;
501 evas_object_smart_callback_call(fs, SIG_DONE,
502 (void *)elm_fileselector_selected_get(fs));
507 Evas_Object *obj __UNUSED__,
508 void *event_info __UNUSED__)
510 Evas_Object *fs = data;
511 evas_object_smart_callback_call(fs, SIG_DONE, NULL);
515 _anchor_clicked(void *data,
516 Evas_Object *obj __UNUSED__,
519 Evas_Object *fs = data;
520 Widget_Data *wd = elm_widget_data_get(fs);
521 Elm_Entry_Anchor_Info *info = event_info;
524 // keep a ref to path 'couse it will be destroyed by _populate
525 p = eina_stringshare_add(info->name);
526 _populate(fs, p, NULL);
527 evas_object_smart_callback_call(data, SIG_SELECTED, (void *)p);
528 eina_stringshare_del(p);
532 _do_anchors(Evas_Object *obj,
535 Widget_Data *wd = elm_widget_data_get(obj);
536 char **tok, buf[PATH_MAX * 3];
540 tok = eina_str_split(path, "/", 0);
541 eina_strlcat(buf, "<a href=/>root</a>", sizeof(buf));
542 for (i = 0; tok[i]; i++)
544 if ((!tok[i]) || (!tok[i][0])) continue;
545 eina_strlcat(buf, wd->path_separator, sizeof(buf));
546 eina_strlcat(buf, "<a href=", sizeof(buf));
547 for (j = 0; j <= i; j++)
549 if (strlen(tok[j]) < 1) continue;
550 eina_strlcat(buf, "/", sizeof(buf));
551 eina_strlcat(buf, tok[j], sizeof(buf));
553 eina_strlcat(buf, ">", sizeof(buf));
554 eina_strlcat(buf, tok[i], sizeof(buf));
555 eina_strlcat(buf, "</a>", sizeof(buf));
560 elm_entry_entry_set(wd->path_entry, buf);
565 _filter_cb(void *data __UNUSED__, Eio_File *handler, const Eina_File_Direct_Info *info)
567 const char *filename;
569 if (info->path[info->name_start] == '.')
572 filename = eina_stringshare_add(info->path);
573 eio_file_associate_direct_add(handler, "filename", filename, EINA_FREE_CB(eina_stringshare_del));
575 if (info->type == EINA_FILE_DIR)
577 eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_DIRECTORY], NULL);
578 eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_DIRECTORY], NULL);
582 if (evas_object_image_extension_can_load_get(info->path + info->name_start))
584 eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_FILE_IMAGE], NULL);
585 eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_FILE_IMAGE], NULL);
589 eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_FILE_UNKNOW], NULL);
590 eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_FILE_UNKNOW], NULL);
598 _file_grid_cmp(const void *a, const void *b)
600 const Elm_Gengrid_Item *ga = a;
601 const Elm_Gengrid_Item *gb = b;
602 const Elm_Gengrid_Item_Class *ca = elm_gengrid_item_item_class_get(ga);
603 const Elm_Gengrid_Item_Class *cb = elm_gengrid_item_item_class_get(gb);
605 if (ca == &grid_itc[ELM_DIRECTORY])
607 if (cb != &grid_itc[ELM_DIRECTORY])
611 return strcoll(elm_gengrid_item_data_get(ga), elm_gengrid_item_data_get(gb));
615 _file_list_cmp(const void *a, const void *b)
617 const Elm_Genlist_Item *la = a;
618 const Elm_Genlist_Item *lb = b;
619 const Elm_Genlist_Item_Class *ca = elm_genlist_item_item_class_get(la);
620 const Elm_Genlist_Item_Class *cb = elm_genlist_item_item_class_get(lb);
622 if (ca == &list_itc[ELM_DIRECTORY])
624 if (cb != &list_itc[ELM_DIRECTORY])
628 return strcoll(elm_genlist_item_data_get(la), elm_genlist_item_data_get(lb));
632 _signal_first(Widget_Request *wr)
634 if (!wr->first) return ;
635 evas_object_smart_callback_call(wr->obj, SIG_DIRECTORY_OPEN, (void *)wr->path);
638 elm_genlist_clear(wr->wd->files_list);
639 elm_gengrid_clear(wr->wd->files_grid);
640 eina_stringshare_replace(&wr->wd->path, wr->path);
641 _do_anchors(wr->obj, wr->path);
644 if (wr->wd->filename_entry) elm_entry_entry_set(wr->wd->filename_entry, "");
646 wr->first = EINA_FALSE;
650 _main_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *info __UNUSED__)
652 Widget_Request *wr = data;
654 if (eio_file_check(handler))
656 if (!wr->wd->files_list || !wr->wd->files_grid || wr->wd->current != handler)
658 eio_file_cancel(handler);
664 if (wr->wd->mode == ELM_FILESELECTOR_LIST)
665 elm_genlist_item_direct_sorted_insert(wr->wd->files_list, eio_file_associate_find(handler, "type/list"),
666 eina_stringshare_ref(eio_file_associate_find(handler, "filename")),
667 wr->parent, ELM_GENLIST_ITEM_NONE, _file_list_cmp, NULL, NULL);
668 else if (wr->wd->mode == ELM_FILESELECTOR_GRID)
669 elm_gengrid_item_direct_sorted_insert(wr->wd->files_grid, eio_file_associate_find(handler, "type/grid"),
670 eina_stringshare_ref(eio_file_associate_find(handler, "filename")),
671 _file_grid_cmp, NULL, NULL);
675 _widget_request_cleanup(Widget_Request *wr)
677 EINA_REFCOUNT_UNREF(wr->wd, _widget_data_free);
679 eina_stringshare_del(wr->path);
684 _done_cb(void *data, Eio_File *handler __UNUSED__)
686 Widget_Request *wr = data;
691 wr->wd->current = NULL;
693 _widget_request_cleanup(wr);
697 _error_cb(void *data, Eio_File *handler, int error __UNUSED__)
699 Widget_Request *wr = data;
702 if (wr->wd->current == handler)
703 wr->wd->current = NULL;
705 _widget_request_cleanup(wr);
711 _populate(Evas_Object *obj,
713 Elm_Genlist_Item *parent)
715 Widget_Data *wd = elm_widget_data_get(obj);
719 Eina_File_Direct_Info *file;
722 Eina_List *files = NULL, *dirs = NULL;
727 if (!ecore_file_is_dir(path)) return ;
728 it = eina_file_stat_ls(path);
730 evas_object_smart_callback_call(obj, SIG_DIRECTORY_OPEN, (void *)path);
733 elm_genlist_clear(wd->files_list);
734 elm_gengrid_clear(wd->files_grid);
735 eina_stringshare_replace(&wd->path, path);
736 _do_anchors(obj, path);
739 if (wd->filename_entry) elm_entry_entry_set(wd->filename_entry, "");
740 EINA_ITERATOR_FOREACH(it, file)
742 const char *filename;
744 if (file->path[file->name_start] == '.')
747 filename = eina_stringshare_add(file->path);
748 if (file->type == EINA_FILE_DIR)
749 dirs = eina_list_append(dirs, filename);
750 else if (!wd->only_folder)
751 files = eina_list_append(files, filename);
753 eina_iterator_free(it);
755 files = eina_list_sort(files, eina_list_count(files),
756 EINA_COMPARE_CB(strcoll));
757 dirs = eina_list_sort(dirs, eina_list_count(dirs), EINA_COMPARE_CB(strcoll));
758 EINA_LIST_FREE(dirs, real)
760 if (wd->mode == ELM_FILESELECTOR_LIST)
761 elm_genlist_item_append(wd->files_list, &list_itc[ELM_DIRECTORY],
762 real, /* item data */
764 wd->expand ? ELM_GENLIST_ITEM_SUBITEMS :
765 ELM_GENLIST_ITEM_NONE,
767 else if (wd->mode == ELM_FILESELECTOR_GRID)
768 elm_gengrid_item_append(wd->files_grid, &grid_itc[ELM_DIRECTORY],
769 real, /* item data */
773 EINA_LIST_FREE(files, real)
775 Elm_Fileselector_Type type = evas_object_image_extension_can_load_fast_get(real) ?
776 ELM_FILE_IMAGE : ELM_FILE_UNKNOW;
778 if (wd->mode == ELM_FILESELECTOR_LIST)
779 elm_genlist_item_append(wd->files_list, &list_itc[type],
780 real, /* item data */
781 parent, ELM_GENLIST_ITEM_NONE,
783 else if (wd->mode == ELM_FILESELECTOR_GRID)
784 elm_gengrid_item_append(wd->files_grid, &grid_itc[type],
785 real, /* item data */
790 eio_file_cancel(wd->current);
791 wr = malloc(sizeof (Widget_Request));
794 EINA_REFCOUNT_REF(wr->wd);
795 wr->parent = parent; /* FIXME: should we refcount the parent ? */
797 wr->path = eina_stringshare_add(path);
798 wr->first = EINA_TRUE;
800 wd->current = eio_file_stat_ls(path,
812 * Add a new Fileselector object
814 * @param parent The parent object
815 * @return The new object or NULL if it cannot be created
817 * @ingroup Fileselector
820 elm_fileselector_add(Evas_Object *parent)
823 Evas_Object *obj, *ic, *bt, *li, *en, *grid;
828 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
830 EINA_REFCOUNT_INIT(wd);
832 ELM_SET_WIDTYPE(widtype, "fileselector");
833 elm_widget_type_set(obj, "fileselector");
834 elm_widget_sub_object_add(parent, obj);
835 elm_widget_data_set(obj, wd);
836 elm_widget_del_hook_set(obj, _del_hook);
837 elm_widget_theme_hook_set(obj, _theme_hook);
838 elm_widget_can_focus_set(obj, EINA_FALSE);
840 wd->expand = !!_elm_config->fileselector_expand_enable;
842 wd->edje = edje_object_add(e);
843 _elm_theme_object_set(obj, wd->edje, "fileselector", "base", "default");
844 elm_widget_resize_object_set(obj, wd->edje);
847 ic = elm_icon_add(parent);
848 elm_icon_standard_set(ic, "arrow_up");
849 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
850 bt = elm_button_add(parent);
851 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
852 elm_button_icon_set(bt, ic);
853 elm_object_text_set(bt, E_("Up"));
854 evas_object_size_hint_align_set(bt, 0.0, 0.0);
856 evas_object_smart_callback_add(bt, "clicked", _up, obj);
858 elm_widget_sub_object_add(obj, bt);
862 ic = elm_icon_add(parent);
863 elm_icon_standard_set(ic, "home");
864 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
865 bt = elm_button_add(parent);
866 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
867 elm_button_icon_set(bt, ic);
868 elm_object_text_set(bt, E_("Home"));
869 evas_object_size_hint_align_set(bt, 0.0, 0.0);
871 evas_object_smart_callback_add(bt, "clicked", _home, obj);
873 elm_widget_sub_object_add(obj, bt);
874 wd->home_button = bt;
876 list_itc[ELM_DIRECTORY].func.icon_get = grid_itc[ELM_DIRECTORY].func.icon_get = _itc_icon_folder_get;
877 list_itc[ELM_FILE_IMAGE].func.icon_get = grid_itc[ELM_FILE_IMAGE].func.icon_get = _itc_icon_image_get;
878 list_itc[ELM_FILE_UNKNOW].func.icon_get = grid_itc[ELM_FILE_UNKNOW].func.icon_get = _itc_icon_file_get;
880 for (i = 0; i < ELM_FILE_LAST; ++i)
882 list_itc[i].func.label_get = grid_itc[i].func.label_get = _itc_label_get;
883 list_itc[i].func.state_get = grid_itc[i].func.state_get = _itc_state_get;
884 list_itc[i].func.del = grid_itc[i].func.del = _itc_del;
887 li = elm_genlist_add(parent);
888 elm_widget_mirrored_automatic_set(li, EINA_FALSE);
889 evas_object_size_hint_align_set(li, EVAS_HINT_FILL, EVAS_HINT_FILL);
890 evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
891 evas_object_size_hint_min_set(li, 100, 100);
893 grid = elm_gengrid_add(parent);
894 elm_widget_mirrored_automatic_set(grid, EINA_FALSE);
895 evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
896 evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
898 s = elm_finger_size_get() * 2;
899 elm_gengrid_item_size_set(grid, s, s);
900 elm_gengrid_align_set(grid, 0.0, 0.0);
902 evas_object_smart_callback_add(li, "selected", _sel, obj);
903 evas_object_smart_callback_add(li, "expand,request", _expand_req, obj);
904 evas_object_smart_callback_add(li, "contract,request", _contract_req, obj);
905 evas_object_smart_callback_add(li, "expanded", _expand_done, obj);
906 evas_object_smart_callback_add(li, "contracted", _contract_done, obj);
908 evas_object_smart_callback_add(grid, "selected", _sel, obj);
910 elm_widget_sub_object_add(obj, li);
911 elm_widget_sub_object_add(obj, grid);
913 wd->files_grid = grid;
916 en = elm_entry_add(parent);
917 elm_entry_scrollable_set(en, EINA_TRUE);
918 elm_widget_mirrored_automatic_set(en, EINA_FALSE);
919 elm_entry_editable_set(en, EINA_FALSE);
920 elm_entry_single_line_set(en, EINA_TRUE);
921 elm_entry_line_wrap_set(en, ELM_WRAP_CHAR);
922 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
923 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
925 evas_object_smart_callback_add(en, "anchor,clicked", _anchor_clicked, obj);
927 elm_widget_sub_object_add(obj, en);
931 en = elm_entry_add(parent);
932 elm_entry_scrollable_set(en, EINA_TRUE);
933 elm_widget_mirrored_automatic_set(en, EINA_FALSE);
934 elm_entry_editable_set(en, EINA_TRUE);
935 elm_entry_single_line_set(en, EINA_TRUE);
936 elm_entry_line_wrap_set(en, ELM_WRAP_CHAR);
937 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
938 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
940 elm_widget_sub_object_add(obj, en);
941 wd->filename_entry = en;
943 elm_fileselector_buttons_ok_cancel_set(obj, EINA_TRUE);
944 elm_fileselector_is_save_set(obj, EINA_FALSE);
948 evas_object_smart_callbacks_descriptions_set(obj, _signals);
953 * This enables/disables the file name entry box where the user can
954 * type in a name for the file to be saved as.
956 * @param obj The fileselector object
957 * @param is_save If true, the fileselector is a save dialog
959 * @ingroup Fileselector
962 elm_fileselector_is_save_set(Evas_Object *obj,
965 ELM_CHECK_WIDTYPE(obj, widtype);
966 Widget_Data *wd = elm_widget_data_get(obj);
969 elm_object_disabled_set(wd->filename_entry, !is_save);
972 edje_object_signal_emit(wd->edje, "elm,state,save,on", "elm");
974 edje_object_signal_emit(wd->edje, "elm,state,save,off", "elm");
978 * This returns whether the fileselector is a "save" type fileselector
980 * @param obj The fileselector object
981 * @return If true, the fileselector is a save type.
983 * @ingroup Fileselector
986 elm_fileselector_is_save_get(const Evas_Object *obj)
988 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
989 Widget_Data *wd = elm_widget_data_get(obj);
990 if (!wd) return EINA_FALSE;
991 return elm_object_disabled_get(wd->filename_entry);
995 * This enables/disables folder-only view in the fileselector.
997 * @param obj The fileselector object
998 * @param only If true, the fileselector will only display directories.
999 * If false, files are displayed also.
1001 * @ingroup Fileselector
1004 elm_fileselector_folder_only_set(Evas_Object *obj,
1007 ELM_CHECK_WIDTYPE(obj, widtype);
1008 Widget_Data *wd = elm_widget_data_get(obj);
1010 if (wd->only_folder == only) return;
1011 wd->only_folder = !!only;
1012 if (wd->path) _populate(obj, wd->path, NULL);
1016 * This gets the state of file display in the fileselector.
1018 * @param obj The fileselector object
1019 * @return If true, files are not being shown in the fileselector.
1020 * If false, files are being shown.
1022 * @ingroup Fileselector
1025 elm_fileselector_folder_only_get(const Evas_Object *obj)
1027 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1028 Widget_Data *wd = elm_widget_data_get(obj);
1029 if (!wd) return EINA_FALSE;
1030 return wd->only_folder;
1034 * This enables/disables the ok,cancel buttons.
1036 * @param obj The fileselector object
1037 * @param only If true, a box containing ok and cancel buttons is created.
1038 * If false, the box and the buttons are destroyed.
1040 * @ingroup Fileselector
1043 elm_fileselector_buttons_ok_cancel_set(Evas_Object *obj,
1046 ELM_CHECK_WIDTYPE(obj, widtype);
1047 Widget_Data *wd = elm_widget_data_get(obj);
1054 bt = elm_button_add(obj);
1055 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
1056 elm_object_text_set(bt, E_("Cancel"));
1058 evas_object_smart_callback_add(bt, "clicked", _canc, obj);
1060 elm_widget_sub_object_add(obj, bt);
1061 wd->cancel_button = bt;
1064 bt = elm_button_add(obj);
1065 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
1066 elm_object_text_set(bt, E_("OK"));
1068 evas_object_smart_callback_add(bt, "clicked", _ok, obj);
1070 elm_widget_sub_object_add(obj, bt);
1077 evas_object_del(wd->cancel_button);
1078 wd->cancel_button = NULL;
1079 evas_object_del(wd->ok_button);
1080 wd->ok_button = NULL;
1085 * This gets the state of the box containing ok and cancel buttons.
1087 * @param obj The fileselector object
1088 * @return If true, the box exists.
1089 * If false, the box does not exist.
1091 * @ingroup Fileselector
1094 elm_fileselector_buttons_ok_cancel_get(const Evas_Object *obj)
1096 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1097 Widget_Data *wd = elm_widget_data_get(obj);
1098 if (!wd) return EINA_FALSE;
1099 return wd->ok_button ? EINA_TRUE : EINA_FALSE;
1103 * This enables a tree view in the fileselector, <b>if in @c
1104 * ELM_FILESELECTOR_LIST mode</b>. If it's in other mode, the changes
1105 * made by this function will only be visible when one switches back
1108 * @param obj The fileselector object
1109 * @param expand If true, tree view is enabled.
1110 * If false, tree view is disabled.
1112 * In a tree view, arrows are created on the sides of directories,
1113 * allowing them to expand in place.
1115 * @ingroup Fileselector
1118 elm_fileselector_expandable_set(Evas_Object *obj,
1121 ELM_CHECK_WIDTYPE(obj, widtype);
1124 wd = elm_widget_data_get(obj);
1127 wd->expand = !!expand;
1129 if (wd->path) _populate(obj, wd->path, NULL);
1133 * This gets the state of tree view in the fileselector.
1135 * @param obj The fileselector object
1136 * @return If true, tree view is enabled and folders will be expandable.
1137 * If false, tree view is disabled.
1139 * @ingroup Fileselector
1142 elm_fileselector_expandable_get(const Evas_Object *obj)
1144 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1145 Widget_Data *wd = elm_widget_data_get(obj);
1146 if (!wd) return EINA_FALSE;
1151 * This sets the path that the fileselector will display.
1153 * @param obj The fileselector object
1154 * @param path The path of the fileselector
1156 * @ingroup Fileselector
1159 elm_fileselector_path_set(Evas_Object *obj,
1162 ELM_CHECK_WIDTYPE(obj, widtype);
1163 _populate(obj, path, NULL);
1167 * This gets the path that the fileselector displays.
1169 * @param obj The fileselector object
1170 * @return The path that the fileselector is displaying
1172 * @ingroup Fileselector
1175 elm_fileselector_path_get(const Evas_Object *obj)
1177 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1178 Widget_Data *wd = elm_widget_data_get(obj);
1179 if (!wd) return NULL;
1184 * This sets the mode in which the fileselector will display files.
1186 * @param obj The fileselector object
1188 * @param mode The mode of the fileselector, being it one of @c
1189 * ELM_FILESELECTOR_LIST (default) or @c ELM_FILESELECTOR_GRID. The
1190 * first one, naturally, will display the files in a list. By using
1191 * elm_fileselector_expandable_set(), the user will trigger a tree
1192 * view for that list. The latter will make the widget to display its
1193 * entries in a grid form.
1195 * @see elm_fileselector_expandable_set().
1197 * @ingroup Fileselector
1200 elm_fileselector_mode_set(Evas_Object *obj,
1201 Elm_Fileselector_Mode mode)
1203 ELM_CHECK_WIDTYPE(obj, widtype);
1205 Widget_Data *wd = elm_widget_data_get(obj);
1208 if (mode == wd->mode) return;
1210 if (mode == ELM_FILESELECTOR_LIST)
1212 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
1215 evas_object_show(wd->files_list);
1216 evas_object_hide(wd->files_grid);
1219 evas_object_hide(wd->files_list);
1223 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
1226 evas_object_show(wd->files_grid);
1227 evas_object_hide(wd->files_list);
1230 evas_object_hide(wd->files_grid);
1235 _populate(obj, wd->path, NULL);
1239 * This gets the mode in which the fileselector is displaying files.
1241 * @param obj The fileselector object
1242 * @return The mode in which the fileselector is at
1244 * @ingroup Fileselector
1246 EAPI Elm_Fileselector_Mode
1247 elm_fileselector_mode_get(const Evas_Object *obj)
1249 ELM_CHECK_WIDTYPE(obj, widtype) ELM_FILESELECTOR_LAST;
1251 Widget_Data *wd = elm_widget_data_get(obj);
1252 if (!wd) return ELM_FILESELECTOR_LAST;
1258 * This gets the currently selected path in the file selector.
1260 * @param obj The file selector object
1261 * @return The absolute path of the selected object in the fileselector
1263 * @ingroup Fileselector
1266 elm_fileselector_selected_get(const Evas_Object *obj)
1268 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1269 Widget_Data *wd = elm_widget_data_get(obj);
1270 if (!wd) return NULL;
1272 if (wd->filename_entry)
1277 name = elm_entry_entry_get(wd->filename_entry);
1278 snprintf(buf, sizeof(buf), "%s/%s",
1279 wd->only_folder ? ecore_file_dir_get(wd->path) : wd->path,
1281 eina_stringshare_replace(&wd->selection, buf);
1282 return wd->selection;
1285 if (wd->mode == ELM_FILESELECTOR_LIST)
1287 Elm_Genlist_Item *it;
1288 it = elm_genlist_selected_item_get(wd->files_list);
1289 if (it) return elm_genlist_item_data_get(it);
1293 Elm_Gengrid_Item *it;
1294 it = elm_gengrid_selected_item_get(wd->files_grid);
1295 if (it) return elm_gengrid_item_data_get(it);
1302 * This sets the currently selected path in the file selector.
1304 * @param obj The file selector object
1305 * @param path The path to a file or directory
1306 * @return @c EINA_TRUE on success, @c EINA_FALSE on failure. The
1307 * latter case occurs if the directory or file pointed to do not
1310 * @ingroup Fileselector
1313 elm_fileselector_selected_set(Evas_Object *obj,
1316 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1317 Widget_Data *wd = elm_widget_data_get(obj);
1318 if (!wd) return EINA_FALSE;
1320 if (ecore_file_is_dir(path))
1321 _populate(obj, path, NULL);
1324 if (!ecore_file_exists(path))
1327 _populate(obj, ecore_file_dir_get(path), NULL);
1328 if (wd->filename_entry)
1330 elm_entry_entry_set(wd->filename_entry,
1331 ecore_file_file_get(path));
1332 eina_stringshare_replace(&wd->selection, path);