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
27 #include <Elementary.h>
34 typedef struct _Widget_Data Widget_Data;
41 Evas_Object *filename_entry;
42 Evas_Object *path_entry;
43 Evas_Object *files_list;
44 Evas_Object *files_grid;
45 Evas_Object *up_button;
46 Evas_Object *home_button;
48 Evas_Object *ok_button;
49 Evas_Object *cancel_button;
52 const char *selection;
53 Ecore_Idler *sel_idler;
55 const char *path_separator;
61 Elm_Fileselector_Mode mode;
63 Eina_Bool only_folder : 1;
73 typedef struct _Widget_Request Widget_Request;
74 struct _Widget_Request
77 Elm_Genlist_Item *parent;
89 } Elm_Fileselector_Type;
91 static Elm_Genlist_Item_Class list_itc[ELM_FILE_LAST] = {
92 { "default", { NULL, NULL, NULL, NULL, NULL }, NULL },
93 { "default", { NULL, NULL, NULL, NULL, NULL }, NULL },
94 { "default", { NULL, NULL, NULL, NULL, NULL }, NULL }
96 static Elm_Gengrid_Item_Class grid_itc[ELM_FILE_LAST] = {
97 { "default", { NULL, NULL, NULL, NULL } },
98 { "default", { NULL, NULL, NULL, NULL } },
99 { "default", { NULL, NULL, NULL, NULL } }
102 static const char *widtype = NULL;
104 static const char SIG_DIRECTORY_OPEN[] = "directory,open";
105 static const char SIG_DONE[] = "done";
106 static const char SIG_SELECTED[] = "selected";
107 static const Evas_Smart_Cb_Description _signals[] = {
108 {SIG_DIRECTORY_OPEN, "s"},
114 static void _populate(Evas_Object *obj,
116 Elm_Genlist_Item *parent);
117 static void _do_anchors(Evas_Object *obj,
120 /*** ELEMENTARY WIDGET ***/
122 _widget_data_free(Widget_Data *wd)
124 if (wd->path) eina_stringshare_del(wd->path);
125 if (wd->selection) eina_stringshare_del(wd->selection);
130 sd = ecore_idler_del(wd->sel_idler);
137 _del_hook(Evas_Object *obj)
141 wd = elm_widget_data_get(obj);
146 eio_file_cancel(wd->current);
149 wd->files_list = NULL;
150 wd->files_grid = NULL;
152 EINA_REFCOUNT_UNREF(wd)
153 _widget_data_free(wd);
157 _sizing_eval(Evas_Object *obj)
159 Widget_Data *wd = elm_widget_data_get(obj);
160 Evas_Coord minw = -1, minh = -1;
162 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
163 edje_object_size_min_restricted_calc(wd->edje, &minw, &minh, minw, minh);
164 evas_object_size_hint_min_set(obj, minw, minh);
168 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
170 Widget_Data *wd = elm_widget_data_get(obj);
172 elm_widget_mirrored_set(wd->cancel_button, rtl);
173 elm_widget_mirrored_set(wd->ok_button, rtl);
174 elm_widget_mirrored_set(wd->files_list, rtl);
175 elm_widget_mirrored_set(wd->up_button, rtl);
176 elm_widget_mirrored_set(wd->home_button, rtl);
177 edje_object_mirrored_set(wd->edje, rtl);
181 _theme_hook(Evas_Object *obj)
183 Widget_Data *wd = elm_widget_data_get(obj);
184 const char *style = elm_widget_style_get(obj);
189 _elm_widget_mirrored_reload(obj);
191 _elm_theme_object_set(obj, wd->edje, "fileselector", "base", style);
193 if (elm_object_disabled_get(obj))
194 edje_object_signal_emit(wd->edje, "elm,state,disabled", "elm");
196 data = edje_object_data_get(wd->edje, "path_separator");
198 wd->path_separator = data;
200 wd->path_separator = "/";
202 if (!style) style = "default";
203 snprintf(buf, sizeof(buf), "fileselector/%s", style);
205 #define SWALLOW(part_name, object_ptn) \
208 elm_widget_style_set(object_ptn, buf); \
209 if (edje_object_part_swallow(wd->edje, part_name, object_ptn)) \
210 evas_object_show(object_ptn); \
212 evas_object_hide(object_ptn); \
214 SWALLOW("elm.swallow.up", wd->up_button);
215 SWALLOW("elm.swallow.home", wd->home_button);
217 if (wd->mode == ELM_FILESELECTOR_LIST)
219 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
222 evas_object_show(wd->files_list);
223 evas_object_hide(wd->files_grid);
226 evas_object_hide(wd->files_list);
230 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
233 evas_object_show(wd->files_grid);
234 evas_object_hide(wd->files_list);
237 evas_object_hide(wd->files_grid);
240 SWALLOW("elm.swallow.filename", wd->filename_entry);
241 SWALLOW("elm.swallow.path", wd->path_entry);
243 snprintf(buf, sizeof(buf), "fileselector/actions/%s", style);
244 SWALLOW("elm.swallow.cancel", wd->cancel_button);
245 SWALLOW("elm.swallow.ok", wd->ok_button);
248 edje_object_message_signal_process(wd->edje);
249 _mirrored_set(obj, elm_widget_mirrored_get(obj));
250 edje_object_scale_set
251 (wd->edje, elm_widget_scale_get(obj) * _elm_config->scale);
255 /*** GENLIST "MODEL" ***/
257 _itc_label_get(void *data,
258 Evas_Object *obj __UNUSED__,
259 const char *source __UNUSED__)
261 return strdup(ecore_file_file_get(data)); /* NOTE this will be
267 _itc_icon_folder_get(void *data __UNUSED__,
273 if (strcmp(source, "elm.swallow.icon")) return NULL;
275 ic = elm_icon_add(obj);
276 elm_icon_standard_set(ic, "folder");
278 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
284 _itc_icon_image_get(void *data,
288 const char *filename = data;
291 if (strcmp(source, "elm.swallow.icon")) return NULL;
293 ic = elm_icon_add(obj);
294 elm_icon_standard_set(ic, "image");
295 elm_icon_thumb_set(ic, filename, NULL);
297 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
303 _itc_icon_file_get(void *data __UNUSED__,
309 if (strcmp(source, "elm.swallow.icon")) return NULL;
311 ic = elm_icon_add(obj);
312 elm_icon_standard_set(ic, "file");
314 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
320 _itc_state_get(void *data __UNUSED__,
321 Evas_Object *obj __UNUSED__,
322 const char *source __UNUSED__)
329 Evas_Object *obj __UNUSED__)
331 eina_stringshare_del(data);
335 _expand_done(void *data,
336 Evas_Object *obj __UNUSED__,
339 Elm_Genlist_Item *it = event_info;
340 const char *path = elm_genlist_item_data_get(it);
341 _populate(data, path, it);
345 _contract_done(void *data __UNUSED__,
346 Evas_Object *obj __UNUSED__,
349 Elm_Genlist_Item *it = event_info;
350 elm_genlist_item_subitems_clear(it);
354 _expand_req(void *data __UNUSED__,
355 Evas_Object *obj __UNUSED__,
358 Elm_Genlist_Item *it = event_info;
359 elm_genlist_item_expanded_set(it, 1);
363 _contract_req(void *data __UNUSED__,
364 Evas_Object *obj __UNUSED__,
367 Elm_Genlist_Item *it = event_info;
368 elm_genlist_item_expanded_set(it, 0);
381 wd = elm_widget_data_get(sd->fs);
384 if ((!wd->only_folder) && ecore_file_is_dir(path))
386 if (wd->expand && wd->mode == ELM_FILESELECTOR_LIST)
388 _do_anchors(sd->fs, path);
389 elm_entry_entry_set(wd->filename_entry, "");
393 /* keep a ref to path 'couse it will be destroyed by _populate */
394 p = eina_stringshare_add(path);
395 _populate(sd->fs, p, NULL);
396 eina_stringshare_del(p);
400 else /* navigating through folders only or file is not a dir. */
402 if (wd->expand && wd->mode == ELM_FILESELECTOR_LIST)
403 _do_anchors(sd->fs, path);
404 else if (wd->only_folder)
406 /* keep a ref to path 'couse it will be destroyed by _populate */
407 p = eina_stringshare_add(path);
408 _populate(sd->fs, p, NULL);
409 eina_stringshare_del(p);
411 elm_entry_entry_set(wd->filename_entry,
412 ecore_file_file_get(path));
415 evas_object_smart_callback_call(sd->fs, SIG_SELECTED, (void *)path);
418 wd->sel_idler = NULL;
420 return ECORE_CALLBACK_CANCEL;
425 Evas_Object *obj __UNUSED__,
433 wd = elm_widget_data_get(data);
436 sd = malloc(sizeof(*sd));
438 sd->path = wd->mode == ELM_FILESELECTOR_LIST ?
439 elm_genlist_item_data_get(event_info) :
440 elm_gengrid_item_data_get(event_info);
444 eina_stringshare_replace(&wd->path, "");
448 dir = wd->only_folder ? strdup(sd->path) : ecore_file_dir_get(sd->path);
451 eina_stringshare_replace(&wd->path, dir);
456 eina_stringshare_replace(&wd->path, "");
462 old_sd = ecore_idler_del(wd->sel_idler);
465 wd->sel_idler = ecore_idler_add(_sel_do, sd);
470 Evas_Object *obj __UNUSED__,
471 void *event_info __UNUSED__)
473 Evas_Object *fs = data;
476 Widget_Data *wd = elm_widget_data_get(fs);
478 parent = ecore_file_dir_get(wd->path);
479 _populate(fs, parent, NULL);
485 Evas_Object *obj __UNUSED__,
486 void *event_info __UNUSED__)
488 Evas_Object *fs = data;
489 _populate(fs, getenv("HOME"), NULL);
494 Evas_Object *obj __UNUSED__,
495 void *event_info __UNUSED__)
497 Evas_Object *fs = data;
498 evas_object_smart_callback_call(fs, SIG_DONE,
499 (void *)elm_fileselector_selected_get(fs));
504 Evas_Object *obj __UNUSED__,
505 void *event_info __UNUSED__)
507 Evas_Object *fs = data;
508 evas_object_smart_callback_call(fs, SIG_DONE, NULL);
512 _anchor_clicked(void *data,
513 Evas_Object *obj __UNUSED__,
516 Evas_Object *fs = data;
517 Widget_Data *wd = elm_widget_data_get(fs);
518 Elm_Entry_Anchor_Info *info = event_info;
521 // keep a ref to path 'couse it will be destroyed by _populate
522 p = eina_stringshare_add(info->name);
523 _populate(fs, p, NULL);
524 evas_object_smart_callback_call(data, SIG_SELECTED, (void *)p);
525 eina_stringshare_del(p);
529 _do_anchors(Evas_Object *obj,
532 Widget_Data *wd = elm_widget_data_get(obj);
533 char **tok, buf[PATH_MAX * 3];
537 tok = eina_str_split(path, "/", 0);
538 eina_strlcat(buf, "<a href=/>root</a>", sizeof(buf));
539 for (i = 0; tok[i]; i++)
541 if ((!tok[i]) || (!tok[i][0])) continue;
542 eina_strlcat(buf, wd->path_separator, sizeof(buf));
543 eina_strlcat(buf, "<a href=", sizeof(buf));
544 for (j = 0; j <= i; j++)
546 if (strlen(tok[j]) < 1) continue;
547 eina_strlcat(buf, "/", sizeof(buf));
548 eina_strlcat(buf, tok[j], sizeof(buf));
550 eina_strlcat(buf, ">", sizeof(buf));
551 eina_strlcat(buf, tok[i], sizeof(buf));
552 eina_strlcat(buf, "</a>", sizeof(buf));
557 elm_entry_entry_set(wd->path_entry, buf);
562 _filter_cb(void *data __UNUSED__, Eio_File *handler, const Eina_File_Direct_Info *info)
564 const char *filename;
566 if (info->path[info->name_start] == '.')
569 filename = eina_stringshare_add(info->path);
570 eio_file_associate_direct_add(handler, "filename", filename, EINA_FREE_CB(eina_stringshare_del));
572 if (info->type == EINA_FILE_DIR)
574 eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_DIRECTORY], NULL);
575 eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_DIRECTORY], NULL);
579 if (evas_object_image_extension_can_load_get(info->path + info->name_start))
581 eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_FILE_IMAGE], NULL);
582 eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_FILE_IMAGE], NULL);
586 eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_FILE_UNKNOW], NULL);
587 eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_FILE_UNKNOW], NULL);
595 _file_grid_cmp(const void *a, const void *b)
597 const Elm_Gengrid_Item *ga = a;
598 const Elm_Gengrid_Item *gb = b;
599 const Elm_Gengrid_Item_Class *ca = elm_gengrid_item_item_class_get(ga);
600 const Elm_Gengrid_Item_Class *cb = elm_gengrid_item_item_class_get(gb);
602 if (ca == &grid_itc[ELM_DIRECTORY])
604 if (cb != &grid_itc[ELM_DIRECTORY])
608 return strcoll(elm_gengrid_item_data_get(ga), elm_gengrid_item_data_get(gb));
612 _file_list_cmp(const void *a, const void *b)
614 const Elm_Genlist_Item *la = a;
615 const Elm_Genlist_Item *lb = b;
616 const Elm_Genlist_Item_Class *ca = elm_genlist_item_item_class_get(la);
617 const Elm_Genlist_Item_Class *cb = elm_genlist_item_item_class_get(lb);
619 if (ca == &list_itc[ELM_DIRECTORY])
621 if (cb != &list_itc[ELM_DIRECTORY])
625 return strcoll(elm_genlist_item_data_get(la), elm_genlist_item_data_get(lb));
629 _signal_first(Widget_Request *wr)
631 if (!wr->first) return ;
632 evas_object_smart_callback_call(wr->obj, SIG_DIRECTORY_OPEN, (void *)wr->path);
635 elm_genlist_clear(wr->wd->files_list);
636 elm_gengrid_clear(wr->wd->files_grid);
637 eina_stringshare_replace(&wr->wd->path, wr->path);
638 _do_anchors(wr->obj, wr->path);
641 if (wr->wd->filename_entry) elm_entry_entry_set(wr->wd->filename_entry, "");
643 wr->first = EINA_FALSE;
647 _main_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *info __UNUSED__)
649 Widget_Request *wr = data;
651 if (eio_file_check(handler))
653 if (!wr->wd->files_list || !wr->wd->files_grid || wr->wd->current != handler)
655 eio_file_cancel(handler);
661 if (wr->wd->mode == ELM_FILESELECTOR_LIST)
662 elm_genlist_item_direct_sorted_insert(wr->wd->files_list, eio_file_associate_find(handler, "type/list"),
663 eina_stringshare_ref(eio_file_associate_find(handler, "filename")),
664 wr->parent, ELM_GENLIST_ITEM_NONE, _file_list_cmp, NULL, NULL);
665 else if (wr->wd->mode == ELM_FILESELECTOR_GRID)
666 elm_gengrid_item_direct_sorted_insert(wr->wd->files_grid, eio_file_associate_find(handler, "type/grid"),
667 eina_stringshare_ref(eio_file_associate_find(handler, "filename")),
668 _file_grid_cmp, NULL, NULL);
672 _widget_request_cleanup(Widget_Request *wr)
674 EINA_REFCOUNT_UNREF(wr->wd)
675 _widget_data_free(wr->wd);
677 eina_stringshare_del(wr->path);
682 _done_cb(void *data, Eio_File *handler __UNUSED__)
684 Widget_Request *wr = data;
689 wr->wd->current = NULL;
691 _widget_request_cleanup(wr);
695 _error_cb(void *data, Eio_File *handler, int error __UNUSED__)
697 Widget_Request *wr = data;
700 if (wr->wd->current == handler)
701 wr->wd->current = NULL;
703 _widget_request_cleanup(wr);
709 _populate(Evas_Object *obj,
711 Elm_Genlist_Item *parent)
713 Widget_Data *wd = elm_widget_data_get(obj);
717 Eina_File_Direct_Info *file;
720 Eina_List *files = NULL, *dirs = NULL;
725 if (!ecore_file_is_dir(path)) return ;
726 it = eina_file_stat_ls(path);
728 evas_object_smart_callback_call(obj, SIG_DIRECTORY_OPEN, (void *)path);
731 elm_genlist_clear(wd->files_list);
732 elm_gengrid_clear(wd->files_grid);
733 eina_stringshare_replace(&wd->path, path);
734 _do_anchors(obj, path);
737 if (wd->filename_entry) elm_entry_entry_set(wd->filename_entry, "");
738 EINA_ITERATOR_FOREACH(it, file)
740 const char *filename;
742 if (file->path[file->name_start] == '.')
745 filename = eina_stringshare_add(file->path);
746 if (file->type == EINA_FILE_DIR)
747 dirs = eina_list_append(dirs, filename);
748 else if (!wd->only_folder)
749 files = eina_list_append(files, filename);
751 eina_iterator_free(it);
753 files = eina_list_sort(files, eina_list_count(files),
754 EINA_COMPARE_CB(strcoll));
755 dirs = eina_list_sort(dirs, eina_list_count(dirs), EINA_COMPARE_CB(strcoll));
756 EINA_LIST_FREE(dirs, real)
758 if (wd->mode == ELM_FILESELECTOR_LIST)
759 elm_genlist_item_append(wd->files_list, &list_itc[ELM_DIRECTORY],
760 real, /* item data */
762 wd->expand ? ELM_GENLIST_ITEM_SUBITEMS :
763 ELM_GENLIST_ITEM_NONE,
765 else if (wd->mode == ELM_FILESELECTOR_GRID)
766 elm_gengrid_item_append(wd->files_grid, &grid_itc[ELM_DIRECTORY],
767 real, /* item data */
771 EINA_LIST_FREE(files, real)
773 Elm_Fileselector_Type type = evas_object_image_extension_can_load_fast_get(real) ?
774 ELM_FILE_IMAGE : ELM_FILE_UNKNOW;
776 if (wd->mode == ELM_FILESELECTOR_LIST)
777 elm_genlist_item_append(wd->files_list, &list_itc[type],
778 real, /* item data */
779 parent, ELM_GENLIST_ITEM_NONE,
781 else if (wd->mode == ELM_FILESELECTOR_GRID)
782 elm_gengrid_item_append(wd->files_grid, &grid_itc[type],
783 real, /* item data */
788 eio_file_cancel(wd->current);
789 wr = malloc(sizeof (Widget_Request));
792 EINA_REFCOUNT_REF(wr->wd);
793 wr->parent = parent; /* FIXME: should we refcount the parent ? */
795 wr->path = eina_stringshare_add(path);
796 wr->first = EINA_TRUE;
798 wd->current = eio_file_stat_ls(path,
810 * Add a new Fileselector object
812 * @param parent The parent object
813 * @return The new object or NULL if it cannot be created
815 * @ingroup Fileselector
818 elm_fileselector_add(Evas_Object *parent)
821 Evas_Object *obj, *ic, *bt, *li, *en, *grid;
826 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
828 EINA_REFCOUNT_INIT(wd);
830 ELM_SET_WIDTYPE(widtype, "fileselector");
831 elm_widget_type_set(obj, "fileselector");
832 elm_widget_sub_object_add(parent, obj);
833 elm_widget_data_set(obj, wd);
834 elm_widget_del_hook_set(obj, _del_hook);
835 elm_widget_theme_hook_set(obj, _theme_hook);
836 elm_widget_can_focus_set(obj, EINA_FALSE);
838 wd->expand = !!_elm_config->fileselector_expand_enable;
840 wd->edje = edje_object_add(e);
841 _elm_theme_object_set(obj, wd->edje, "fileselector", "base", "default");
842 elm_widget_resize_object_set(obj, wd->edje);
845 ic = elm_icon_add(parent);
846 elm_icon_standard_set(ic, "arrow_up");
847 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
848 bt = elm_button_add(parent);
849 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
850 elm_button_icon_set(bt, ic);
851 elm_button_label_set(bt, E_("Up"));
852 evas_object_size_hint_align_set(bt, 0.0, 0.0);
854 evas_object_smart_callback_add(bt, "clicked", _up, obj);
856 elm_widget_sub_object_add(obj, bt);
860 ic = elm_icon_add(parent);
861 elm_icon_standard_set(ic, "home");
862 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
863 bt = elm_button_add(parent);
864 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
865 elm_button_icon_set(bt, ic);
866 elm_button_label_set(bt, E_("Home"));
867 evas_object_size_hint_align_set(bt, 0.0, 0.0);
869 evas_object_smart_callback_add(bt, "clicked", _home, obj);
871 elm_widget_sub_object_add(obj, bt);
872 wd->home_button = bt;
874 list_itc[ELM_DIRECTORY].func.icon_get = grid_itc[ELM_DIRECTORY].func.icon_get = _itc_icon_folder_get;
875 list_itc[ELM_FILE_IMAGE].func.icon_get = grid_itc[ELM_FILE_IMAGE].func.icon_get = _itc_icon_image_get;
876 list_itc[ELM_FILE_UNKNOW].func.icon_get = grid_itc[ELM_FILE_UNKNOW].func.icon_get = _itc_icon_file_get;
878 for (i = 0; i < ELM_FILE_LAST; ++i)
880 list_itc[i].func.label_get = grid_itc[i].func.label_get = _itc_label_get;
881 list_itc[i].func.state_get = grid_itc[i].func.state_get = _itc_state_get;
882 list_itc[i].func.del = grid_itc[i].func.del = _itc_del;
885 li = elm_genlist_add(parent);
886 elm_widget_mirrored_automatic_set(li, EINA_FALSE);
887 evas_object_size_hint_align_set(li, EVAS_HINT_FILL, EVAS_HINT_FILL);
888 evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
889 evas_object_size_hint_min_set(li, 100, 100);
891 grid = elm_gengrid_add(parent);
892 elm_widget_mirrored_automatic_set(grid, EINA_FALSE);
893 evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
894 evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
896 s = elm_finger_size_get() * 2;
897 elm_gengrid_item_size_set(grid, s, s);
898 elm_gengrid_align_set(grid, 0.0, 0.0);
900 evas_object_smart_callback_add(li, "selected", _sel, obj);
901 evas_object_smart_callback_add(li, "expand,request", _expand_req, obj);
902 evas_object_smart_callback_add(li, "contract,request", _contract_req, obj);
903 evas_object_smart_callback_add(li, "expanded", _expand_done, obj);
904 evas_object_smart_callback_add(li, "contracted", _contract_done, obj);
906 evas_object_smart_callback_add(grid, "selected", _sel, obj);
908 elm_widget_sub_object_add(obj, li);
909 elm_widget_sub_object_add(obj, grid);
911 wd->files_grid = grid;
914 en = elm_entry_add(parent);
915 elm_entry_scrollable_set(en, EINA_TRUE);
916 elm_widget_mirrored_automatic_set(en, EINA_FALSE);
917 elm_entry_editable_set(en, EINA_FALSE);
918 elm_entry_single_line_set(en, EINA_TRUE);
919 elm_entry_line_wrap_set(en, ELM_WRAP_CHAR);
920 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
921 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
923 evas_object_smart_callback_add(en, "anchor,clicked", _anchor_clicked, obj);
925 elm_widget_sub_object_add(obj, en);
929 en = elm_entry_add(parent);
930 elm_entry_scrollable_set(en, EINA_TRUE);
931 elm_widget_mirrored_automatic_set(en, EINA_FALSE);
932 elm_entry_editable_set(en, EINA_TRUE);
933 elm_entry_single_line_set(en, EINA_TRUE);
934 elm_entry_line_wrap_set(en, ELM_WRAP_CHAR);
935 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
936 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
938 elm_widget_sub_object_add(obj, en);
939 wd->filename_entry = en;
941 elm_fileselector_buttons_ok_cancel_set(obj, EINA_TRUE);
942 elm_fileselector_is_save_set(obj, EINA_FALSE);
946 evas_object_smart_callbacks_descriptions_set(obj, _signals);
951 * This enables/disables the file name entry box where the user can
952 * type in a name for the file to be saved as.
954 * @param obj The fileselector object
955 * @param is_save If true, the fileselector is a save dialog
957 * @ingroup Fileselector
960 elm_fileselector_is_save_set(Evas_Object *obj,
963 ELM_CHECK_WIDTYPE(obj, widtype);
964 Widget_Data *wd = elm_widget_data_get(obj);
967 elm_object_disabled_set(wd->filename_entry, !is_save);
970 edje_object_signal_emit(wd->edje, "elm,state,save,on", "elm");
972 edje_object_signal_emit(wd->edje, "elm,state,save,off", "elm");
976 * This returns whether the fileselector is a "save" type fileselector
978 * @param obj The fileselector object
979 * @return If true, the fileselector is a save type.
981 * @ingroup Fileselector
984 elm_fileselector_is_save_get(const Evas_Object *obj)
986 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
987 Widget_Data *wd = elm_widget_data_get(obj);
988 if (!wd) return EINA_FALSE;
989 return elm_object_disabled_get(wd->filename_entry);
993 * This enables/disables folder-only view in the fileselector.
995 * @param obj The fileselector object
996 * @param only If true, the fileselector will only display directories.
997 * If false, files are displayed also.
999 * @ingroup Fileselector
1002 elm_fileselector_folder_only_set(Evas_Object *obj,
1005 ELM_CHECK_WIDTYPE(obj, widtype);
1006 Widget_Data *wd = elm_widget_data_get(obj);
1008 if (wd->only_folder == only) return;
1009 wd->only_folder = !!only;
1010 if (wd->path) _populate(obj, wd->path, NULL);
1014 * This gets the state of file display in the fileselector.
1016 * @param obj The fileselector object
1017 * @return If true, files are not being shown in the fileselector.
1018 * If false, files are being shown.
1020 * @ingroup Fileselector
1023 elm_fileselector_folder_only_get(const Evas_Object *obj)
1025 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1026 Widget_Data *wd = elm_widget_data_get(obj);
1027 if (!wd) return EINA_FALSE;
1028 return wd->only_folder;
1032 * This enables/disables the ok,cancel buttons.
1034 * @param obj The fileselector object
1035 * @param only If true, a box containing ok and cancel buttons is created.
1036 * If false, the box and the buttons are destroyed.
1038 * @ingroup Fileselector
1041 elm_fileselector_buttons_ok_cancel_set(Evas_Object *obj,
1044 ELM_CHECK_WIDTYPE(obj, widtype);
1045 Widget_Data *wd = elm_widget_data_get(obj);
1052 bt = elm_button_add(obj);
1053 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
1054 elm_button_label_set(bt, E_("Cancel"));
1056 evas_object_smart_callback_add(bt, "clicked", _canc, obj);
1058 elm_widget_sub_object_add(obj, bt);
1059 wd->cancel_button = bt;
1062 bt = elm_button_add(obj);
1063 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
1064 elm_button_label_set(bt, E_("OK"));
1066 evas_object_smart_callback_add(bt, "clicked", _ok, obj);
1068 elm_widget_sub_object_add(obj, bt);
1075 evas_object_del(wd->cancel_button);
1076 wd->cancel_button = NULL;
1077 evas_object_del(wd->ok_button);
1078 wd->ok_button = NULL;
1083 * This gets the state of the box containing ok and cancel buttons.
1085 * @param obj The fileselector object
1086 * @return If true, the box exists.
1087 * If false, the box does not exist.
1089 * @ingroup Fileselector
1092 elm_fileselector_buttons_ok_cancel_get(const Evas_Object *obj)
1094 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1095 Widget_Data *wd = elm_widget_data_get(obj);
1096 if (!wd) return EINA_FALSE;
1097 return wd->ok_button ? EINA_TRUE : EINA_FALSE;
1101 * This enables a tree view in the fileselector, <b>if in @c
1102 * ELM_FILESELECTOR_LIST mode</b>. If it's in other mode, the changes
1103 * made by this function will only be visible when one switches back
1106 * @param obj The fileselector object
1107 * @param expand If true, tree view is enabled.
1108 * If false, tree view is disabled.
1110 * In a tree view, arrows are created on the sides of directories,
1111 * allowing them to expand in place.
1113 * @ingroup Fileselector
1116 elm_fileselector_expandable_set(Evas_Object *obj,
1119 ELM_CHECK_WIDTYPE(obj, widtype);
1122 wd = elm_widget_data_get(obj);
1125 wd->expand = !!expand;
1127 if (wd->path) _populate(obj, wd->path, NULL);
1131 * This gets the state of tree view in the fileselector.
1133 * @param obj The fileselector object
1134 * @return If true, tree view is enabled and folders will be expandable.
1135 * If false, tree view is disabled.
1137 * @ingroup Fileselector
1140 elm_fileselector_expandable_get(const Evas_Object *obj)
1142 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1143 Widget_Data *wd = elm_widget_data_get(obj);
1144 if (!wd) return EINA_FALSE;
1149 * This sets the path that the fileselector will display.
1151 * @param obj The fileselector object
1152 * @param path The path of the fileselector
1154 * @ingroup Fileselector
1157 elm_fileselector_path_set(Evas_Object *obj,
1160 ELM_CHECK_WIDTYPE(obj, widtype);
1161 _populate(obj, path, NULL);
1165 * This gets the path that the fileselector displays.
1167 * @param obj The fileselector object
1168 * @return The path that the fileselector is displaying
1170 * @ingroup Fileselector
1173 elm_fileselector_path_get(const Evas_Object *obj)
1175 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1176 Widget_Data *wd = elm_widget_data_get(obj);
1177 if (!wd) return NULL;
1182 * This sets the mode in which the fileselector will display files.
1184 * @param obj The fileselector object
1186 * @param mode The mode of the fileselector, being it one of @c
1187 * ELM_FILESELECTOR_LIST (default) or @c ELM_FILESELECTOR_GRID. The
1188 * first one, naturally, will display the files in a list. By using
1189 * elm_fileselector_expandable_set(), the user will trigger a tree
1190 * view for that list. The latter will make the widget to display its
1191 * entries in a grid form.
1193 * @see elm_fileselector_expandable_set().
1195 * @ingroup Fileselector
1198 elm_fileselector_mode_set(Evas_Object *obj,
1199 Elm_Fileselector_Mode mode)
1201 ELM_CHECK_WIDTYPE(obj, widtype);
1203 Widget_Data *wd = elm_widget_data_get(obj);
1206 if (mode == wd->mode) return;
1208 if (mode == ELM_FILESELECTOR_LIST)
1210 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
1213 evas_object_show(wd->files_list);
1214 evas_object_hide(wd->files_grid);
1217 evas_object_hide(wd->files_list);
1221 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
1224 evas_object_show(wd->files_grid);
1225 evas_object_hide(wd->files_list);
1228 evas_object_hide(wd->files_grid);
1233 _populate(obj, wd->path, NULL);
1237 * This gets the mode in which the fileselector is displaying files.
1239 * @param obj The fileselector object
1240 * @return The mode in which the fileselector is at
1242 * @ingroup Fileselector
1244 EAPI Elm_Fileselector_Mode
1245 elm_fileselector_mode_get(const Evas_Object *obj)
1247 ELM_CHECK_WIDTYPE(obj, widtype) ELM_FILESELECTOR_LAST;
1249 Widget_Data *wd = elm_widget_data_get(obj);
1250 if (!wd) return ELM_FILESELECTOR_LAST;
1256 * This gets the currently selected path in the file selector.
1258 * @param obj The file selector object
1259 * @return The absolute path of the selected object in the fileselector
1261 * @ingroup Fileselector
1264 elm_fileselector_selected_get(const Evas_Object *obj)
1266 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1267 Widget_Data *wd = elm_widget_data_get(obj);
1268 if (!wd) return NULL;
1270 if (wd->filename_entry)
1275 name = elm_entry_entry_get(wd->filename_entry);
1276 snprintf(buf, sizeof(buf), "%s/%s",
1277 wd->only_folder ? ecore_file_dir_get(wd->path) : wd->path,
1279 eina_stringshare_replace(&wd->selection, buf);
1280 return wd->selection;
1283 if (wd->mode == ELM_FILESELECTOR_LIST)
1285 Elm_Genlist_Item *it;
1286 it = elm_genlist_selected_item_get(wd->files_list);
1287 if (it) return elm_genlist_item_data_get(it);
1291 Elm_Gengrid_Item *it;
1292 it = elm_gengrid_selected_item_get(wd->files_grid);
1293 if (it) return elm_gengrid_item_data_get(it);
1300 * This sets the currently selected path in the file selector.
1302 * @param obj The file selector object
1303 * @param path The path to a file or directory
1304 * @return @c EINA_TRUE on success, @c EINA_FALSE on failure. The
1305 * latter case occurs if the directory or file pointed to do not
1308 * @ingroup Fileselector
1311 elm_fileselector_selected_set(Evas_Object *obj,
1314 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1315 Widget_Data *wd = elm_widget_data_get(obj);
1316 if (!wd) return EINA_FALSE;
1318 if (ecore_file_is_dir(path))
1319 _populate(obj, path, NULL);
1322 if (!ecore_file_exists(path))
1325 _populate(obj, ecore_file_dir_get(path), NULL);
1326 if (wd->filename_entry)
1328 elm_entry_entry_set(wd->filename_entry,
1329 ecore_file_file_get(path));
1330 eina_stringshare_replace(&wd->selection, path);