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, _widget_data_free);
156 _sizing_eval(Evas_Object *obj)
158 Widget_Data *wd = elm_widget_data_get(obj);
159 Evas_Coord minw = -1, minh = -1;
161 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
162 edje_object_size_min_restricted_calc(wd->edje, &minw, &minh, minw, minh);
163 evas_object_size_hint_min_set(obj, minw, minh);
167 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
169 Widget_Data *wd = elm_widget_data_get(obj);
171 elm_widget_mirrored_set(wd->cancel_button, rtl);
172 elm_widget_mirrored_set(wd->ok_button, rtl);
173 elm_widget_mirrored_set(wd->files_list, rtl);
174 elm_widget_mirrored_set(wd->up_button, rtl);
175 elm_widget_mirrored_set(wd->home_button, rtl);
176 edje_object_mirrored_set(wd->edje, rtl);
180 _theme_hook(Evas_Object *obj)
182 Widget_Data *wd = elm_widget_data_get(obj);
183 const char *style = elm_widget_style_get(obj);
188 _elm_widget_mirrored_reload(obj);
190 _elm_theme_object_set(obj, wd->edje, "fileselector", "base", style);
192 if (elm_object_disabled_get(obj))
193 edje_object_signal_emit(wd->edje, "elm,state,disabled", "elm");
195 data = edje_object_data_get(wd->edje, "path_separator");
197 wd->path_separator = data;
199 wd->path_separator = "/";
201 if (!style) style = "default";
202 snprintf(buf, sizeof(buf), "fileselector/%s", style);
204 #define SWALLOW(part_name, object_ptn) \
207 elm_widget_style_set(object_ptn, buf); \
208 if (edje_object_part_swallow(wd->edje, part_name, object_ptn)) \
209 evas_object_show(object_ptn); \
211 evas_object_hide(object_ptn); \
213 SWALLOW("elm.swallow.up", wd->up_button);
214 SWALLOW("elm.swallow.home", wd->home_button);
216 if (wd->mode == ELM_FILESELECTOR_LIST)
218 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
221 evas_object_show(wd->files_list);
222 evas_object_hide(wd->files_grid);
225 evas_object_hide(wd->files_list);
229 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
232 evas_object_show(wd->files_grid);
233 evas_object_hide(wd->files_list);
236 evas_object_hide(wd->files_grid);
239 SWALLOW("elm.swallow.filename", wd->filename_entry);
240 SWALLOW("elm.swallow.path", wd->path_entry);
242 snprintf(buf, sizeof(buf), "fileselector/actions/%s", style);
243 SWALLOW("elm.swallow.cancel", wd->cancel_button);
244 SWALLOW("elm.swallow.ok", wd->ok_button);
247 edje_object_message_signal_process(wd->edje);
248 _mirrored_set(obj, elm_widget_mirrored_get(obj));
249 edje_object_scale_set
250 (wd->edje, elm_widget_scale_get(obj) * _elm_config->scale);
254 /*** GENLIST "MODEL" ***/
256 _itc_label_get(void *data,
257 Evas_Object *obj __UNUSED__,
258 const char *source __UNUSED__)
260 return strdup(ecore_file_file_get(data)); /* NOTE this will be
266 _itc_icon_folder_get(void *data __UNUSED__,
272 if (strcmp(source, "elm.swallow.icon")) return NULL;
274 ic = elm_icon_add(obj);
275 elm_icon_standard_set(ic, "folder");
277 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
283 _itc_icon_image_get(void *data,
287 const char *filename = data;
290 if (strcmp(source, "elm.swallow.icon")) return NULL;
292 ic = elm_icon_add(obj);
293 elm_icon_standard_set(ic, "image");
294 elm_icon_thumb_set(ic, filename, NULL);
296 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
302 _itc_icon_file_get(void *data __UNUSED__,
308 if (strcmp(source, "elm.swallow.icon")) return NULL;
310 ic = elm_icon_add(obj);
311 elm_icon_standard_set(ic, "file");
313 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
319 _itc_state_get(void *data __UNUSED__,
320 Evas_Object *obj __UNUSED__,
321 const char *source __UNUSED__)
328 Evas_Object *obj __UNUSED__)
330 eina_stringshare_del(data);
334 _expand_done(void *data,
335 Evas_Object *obj __UNUSED__,
338 Elm_Genlist_Item *it = event_info;
339 const char *path = elm_genlist_item_data_get(it);
340 _populate(data, path, it);
344 _contract_done(void *data __UNUSED__,
345 Evas_Object *obj __UNUSED__,
348 Elm_Genlist_Item *it = event_info;
349 elm_genlist_item_subitems_clear(it);
353 _expand_req(void *data __UNUSED__,
354 Evas_Object *obj __UNUSED__,
357 Elm_Genlist_Item *it = event_info;
358 elm_genlist_item_expanded_set(it, 1);
362 _contract_req(void *data __UNUSED__,
363 Evas_Object *obj __UNUSED__,
366 Elm_Genlist_Item *it = event_info;
367 elm_genlist_item_expanded_set(it, 0);
380 wd = elm_widget_data_get(sd->fs);
383 if ((!wd->only_folder) && ecore_file_is_dir(path))
385 if (wd->expand && wd->mode == ELM_FILESELECTOR_LIST)
387 _do_anchors(sd->fs, path);
388 elm_entry_entry_set(wd->filename_entry, "");
392 /* keep a ref to path 'couse it will be destroyed by _populate */
393 p = eina_stringshare_add(path);
394 _populate(sd->fs, p, NULL);
395 eina_stringshare_del(p);
399 else /* navigating through folders only or file is not a dir. */
401 if (wd->expand && wd->mode == ELM_FILESELECTOR_LIST)
402 _do_anchors(sd->fs, path);
403 else if (wd->only_folder)
405 /* keep a ref to path 'couse it will be destroyed by _populate */
406 p = eina_stringshare_add(path);
407 _populate(sd->fs, p, NULL);
408 eina_stringshare_del(p);
410 elm_entry_entry_set(wd->filename_entry,
411 ecore_file_file_get(path));
414 evas_object_smart_callback_call(sd->fs, SIG_SELECTED, (void *)path);
417 wd->sel_idler = NULL;
419 return ECORE_CALLBACK_CANCEL;
424 Evas_Object *obj __UNUSED__,
432 wd = elm_widget_data_get(data);
435 sd = malloc(sizeof(*sd));
437 sd->path = wd->mode == ELM_FILESELECTOR_LIST ?
438 elm_genlist_item_data_get(event_info) :
439 elm_gengrid_item_data_get(event_info);
443 eina_stringshare_replace(&wd->path, "");
447 dir = wd->only_folder ? strdup(sd->path) : ecore_file_dir_get(sd->path);
450 eina_stringshare_replace(&wd->path, dir);
455 eina_stringshare_replace(&wd->path, "");
461 old_sd = ecore_idler_del(wd->sel_idler);
464 wd->sel_idler = ecore_idler_add(_sel_do, sd);
469 Evas_Object *obj __UNUSED__,
470 void *event_info __UNUSED__)
472 Evas_Object *fs = data;
475 Widget_Data *wd = elm_widget_data_get(fs);
477 parent = ecore_file_dir_get(wd->path);
478 _populate(fs, parent, NULL);
484 Evas_Object *obj __UNUSED__,
485 void *event_info __UNUSED__)
487 Evas_Object *fs = data;
488 _populate(fs, getenv("HOME"), NULL);
493 Evas_Object *obj __UNUSED__,
494 void *event_info __UNUSED__)
496 Evas_Object *fs = data;
497 evas_object_smart_callback_call(fs, SIG_DONE,
498 (void *)elm_fileselector_selected_get(fs));
503 Evas_Object *obj __UNUSED__,
504 void *event_info __UNUSED__)
506 Evas_Object *fs = data;
507 evas_object_smart_callback_call(fs, SIG_DONE, NULL);
511 _anchor_clicked(void *data,
512 Evas_Object *obj __UNUSED__,
515 Evas_Object *fs = data;
516 Widget_Data *wd = elm_widget_data_get(fs);
517 Elm_Entry_Anchor_Info *info = event_info;
520 // keep a ref to path 'couse it will be destroyed by _populate
521 p = eina_stringshare_add(info->name);
522 _populate(fs, p, NULL);
523 evas_object_smart_callback_call(data, SIG_SELECTED, (void *)p);
524 eina_stringshare_del(p);
528 _do_anchors(Evas_Object *obj,
531 Widget_Data *wd = elm_widget_data_get(obj);
532 char **tok, buf[PATH_MAX * 3];
536 tok = eina_str_split(path, "/", 0);
537 eina_strlcat(buf, "<a href=/>root</a>", sizeof(buf));
538 for (i = 0; tok[i]; i++)
540 if ((!tok[i]) || (!tok[i][0])) continue;
541 eina_strlcat(buf, wd->path_separator, sizeof(buf));
542 eina_strlcat(buf, "<a href=", sizeof(buf));
543 for (j = 0; j <= i; j++)
545 if (strlen(tok[j]) < 1) continue;
546 eina_strlcat(buf, "/", sizeof(buf));
547 eina_strlcat(buf, tok[j], sizeof(buf));
549 eina_strlcat(buf, ">", sizeof(buf));
550 eina_strlcat(buf, tok[i], sizeof(buf));
551 eina_strlcat(buf, "</a>", sizeof(buf));
556 elm_entry_entry_set(wd->path_entry, buf);
561 _filter_cb(void *data __UNUSED__, Eio_File *handler, const Eina_File_Direct_Info *info)
563 const char *filename;
565 if (info->path[info->name_start] == '.')
568 filename = eina_stringshare_add(info->path);
569 eio_file_associate_direct_add(handler, "filename", filename, EINA_FREE_CB(eina_stringshare_del));
571 if (info->type == EINA_FILE_DIR)
573 eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_DIRECTORY], NULL);
574 eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_DIRECTORY], NULL);
578 if (evas_object_image_extension_can_load_get(info->path + info->name_start))
580 eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_FILE_IMAGE], NULL);
581 eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_FILE_IMAGE], NULL);
585 eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_FILE_UNKNOW], NULL);
586 eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_FILE_UNKNOW], NULL);
594 _file_grid_cmp(const void *a, const void *b)
596 const Elm_Gengrid_Item *ga = a;
597 const Elm_Gengrid_Item *gb = b;
598 const Elm_Gengrid_Item_Class *ca = elm_gengrid_item_item_class_get(ga);
599 const Elm_Gengrid_Item_Class *cb = elm_gengrid_item_item_class_get(gb);
601 if (ca == &grid_itc[ELM_DIRECTORY])
603 if (cb != &grid_itc[ELM_DIRECTORY])
607 return strcoll(elm_gengrid_item_data_get(ga), elm_gengrid_item_data_get(gb));
611 _file_list_cmp(const void *a, const void *b)
613 const Elm_Genlist_Item *la = a;
614 const Elm_Genlist_Item *lb = b;
615 const Elm_Genlist_Item_Class *ca = elm_genlist_item_item_class_get(la);
616 const Elm_Genlist_Item_Class *cb = elm_genlist_item_item_class_get(lb);
618 if (ca == &list_itc[ELM_DIRECTORY])
620 if (cb != &list_itc[ELM_DIRECTORY])
624 return strcoll(elm_genlist_item_data_get(la), elm_genlist_item_data_get(lb));
628 _signal_first(Widget_Request *wr)
630 if (!wr->first) return ;
631 evas_object_smart_callback_call(wr->obj, SIG_DIRECTORY_OPEN, (void *)wr->path);
634 elm_genlist_clear(wr->wd->files_list);
635 elm_gengrid_clear(wr->wd->files_grid);
636 eina_stringshare_replace(&wr->wd->path, wr->path);
637 _do_anchors(wr->obj, wr->path);
640 if (wr->wd->filename_entry) elm_entry_entry_set(wr->wd->filename_entry, "");
642 wr->first = EINA_FALSE;
646 _main_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *info __UNUSED__)
648 Widget_Request *wr = data;
650 if (eio_file_check(handler))
652 if (!wr->wd->files_list || !wr->wd->files_grid || wr->wd->current != handler)
654 eio_file_cancel(handler);
660 if (wr->wd->mode == ELM_FILESELECTOR_LIST)
661 elm_genlist_item_direct_sorted_insert(wr->wd->files_list, eio_file_associate_find(handler, "type/list"),
662 eina_stringshare_ref(eio_file_associate_find(handler, "filename")),
663 wr->parent, ELM_GENLIST_ITEM_NONE, _file_list_cmp, NULL, NULL);
664 else if (wr->wd->mode == ELM_FILESELECTOR_GRID)
665 elm_gengrid_item_direct_sorted_insert(wr->wd->files_grid, eio_file_associate_find(handler, "type/grid"),
666 eina_stringshare_ref(eio_file_associate_find(handler, "filename")),
667 _file_grid_cmp, NULL, NULL);
671 _widget_request_cleanup(Widget_Request *wr)
673 EINA_REFCOUNT_UNREF(wr->wd, _widget_data_free);
675 eina_stringshare_del(wr->path);
680 _done_cb(void *data, Eio_File *handler __UNUSED__)
682 Widget_Request *wr = data;
687 wr->wd->current = NULL;
689 _widget_request_cleanup(wr);
693 _error_cb(void *data, Eio_File *handler, int error __UNUSED__)
695 Widget_Request *wr = data;
698 if (wr->wd->current == handler)
699 wr->wd->current = NULL;
701 _widget_request_cleanup(wr);
707 _populate(Evas_Object *obj,
709 Elm_Genlist_Item *parent)
711 Widget_Data *wd = elm_widget_data_get(obj);
715 Eina_File_Direct_Info *file;
718 Eina_List *files = NULL, *dirs = NULL;
723 if (!ecore_file_is_dir(path)) return ;
724 it = eina_file_stat_ls(path);
726 evas_object_smart_callback_call(obj, SIG_DIRECTORY_OPEN, (void *)path);
729 elm_genlist_clear(wd->files_list);
730 elm_gengrid_clear(wd->files_grid);
731 eina_stringshare_replace(&wd->path, path);
732 _do_anchors(obj, path);
735 if (wd->filename_entry) elm_entry_entry_set(wd->filename_entry, "");
736 EINA_ITERATOR_FOREACH(it, file)
738 const char *filename;
740 if (file->path[file->name_start] == '.')
743 filename = eina_stringshare_add(file->path);
744 if (file->type == EINA_FILE_DIR)
745 dirs = eina_list_append(dirs, filename);
746 else if (!wd->only_folder)
747 files = eina_list_append(files, filename);
749 eina_iterator_free(it);
751 files = eina_list_sort(files, eina_list_count(files),
752 EINA_COMPARE_CB(strcoll));
753 dirs = eina_list_sort(dirs, eina_list_count(dirs), EINA_COMPARE_CB(strcoll));
754 EINA_LIST_FREE(dirs, real)
756 if (wd->mode == ELM_FILESELECTOR_LIST)
757 elm_genlist_item_append(wd->files_list, &list_itc[ELM_DIRECTORY],
758 real, /* item data */
760 wd->expand ? ELM_GENLIST_ITEM_SUBITEMS :
761 ELM_GENLIST_ITEM_NONE,
763 else if (wd->mode == ELM_FILESELECTOR_GRID)
764 elm_gengrid_item_append(wd->files_grid, &grid_itc[ELM_DIRECTORY],
765 real, /* item data */
769 EINA_LIST_FREE(files, real)
771 Elm_Fileselector_Type type = evas_object_image_extension_can_load_fast_get(real) ?
772 ELM_FILE_IMAGE : ELM_FILE_UNKNOW;
774 if (wd->mode == ELM_FILESELECTOR_LIST)
775 elm_genlist_item_append(wd->files_list, &list_itc[type],
776 real, /* item data */
777 parent, ELM_GENLIST_ITEM_NONE,
779 else if (wd->mode == ELM_FILESELECTOR_GRID)
780 elm_gengrid_item_append(wd->files_grid, &grid_itc[type],
781 real, /* item data */
786 eio_file_cancel(wd->current);
787 wr = malloc(sizeof (Widget_Request));
790 EINA_REFCOUNT_REF(wr->wd);
791 wr->parent = parent; /* FIXME: should we refcount the parent ? */
793 wr->path = eina_stringshare_add(path);
794 wr->first = EINA_TRUE;
796 wd->current = eio_file_stat_ls(path,
808 * Add a new Fileselector object
810 * @param parent The parent object
811 * @return The new object or NULL if it cannot be created
813 * @ingroup Fileselector
816 elm_fileselector_add(Evas_Object *parent)
819 Evas_Object *obj, *ic, *bt, *li, *en, *grid;
824 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
826 EINA_REFCOUNT_INIT(wd);
828 ELM_SET_WIDTYPE(widtype, "fileselector");
829 elm_widget_type_set(obj, "fileselector");
830 elm_widget_sub_object_add(parent, obj);
831 elm_widget_data_set(obj, wd);
832 elm_widget_del_hook_set(obj, _del_hook);
833 elm_widget_theme_hook_set(obj, _theme_hook);
834 elm_widget_can_focus_set(obj, EINA_FALSE);
836 wd->expand = !!_elm_config->fileselector_expand_enable;
838 wd->edje = edje_object_add(e);
839 _elm_theme_object_set(obj, wd->edje, "fileselector", "base", "default");
840 elm_widget_resize_object_set(obj, wd->edje);
843 ic = elm_icon_add(parent);
844 elm_icon_standard_set(ic, "arrow_up");
845 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
846 bt = elm_button_add(parent);
847 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
848 elm_button_icon_set(bt, ic);
849 elm_object_text_set(bt, E_("Up"));
850 evas_object_size_hint_align_set(bt, 0.0, 0.0);
852 evas_object_smart_callback_add(bt, "clicked", _up, obj);
854 elm_widget_sub_object_add(obj, bt);
858 ic = elm_icon_add(parent);
859 elm_icon_standard_set(ic, "home");
860 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
861 bt = elm_button_add(parent);
862 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
863 elm_button_icon_set(bt, ic);
864 elm_object_text_set(bt, E_("Home"));
865 evas_object_size_hint_align_set(bt, 0.0, 0.0);
867 evas_object_smart_callback_add(bt, "clicked", _home, obj);
869 elm_widget_sub_object_add(obj, bt);
870 wd->home_button = bt;
872 list_itc[ELM_DIRECTORY].func.icon_get = grid_itc[ELM_DIRECTORY].func.icon_get = _itc_icon_folder_get;
873 list_itc[ELM_FILE_IMAGE].func.icon_get = grid_itc[ELM_FILE_IMAGE].func.icon_get = _itc_icon_image_get;
874 list_itc[ELM_FILE_UNKNOW].func.icon_get = grid_itc[ELM_FILE_UNKNOW].func.icon_get = _itc_icon_file_get;
876 for (i = 0; i < ELM_FILE_LAST; ++i)
878 list_itc[i].func.label_get = grid_itc[i].func.label_get = _itc_label_get;
879 list_itc[i].func.state_get = grid_itc[i].func.state_get = _itc_state_get;
880 list_itc[i].func.del = grid_itc[i].func.del = _itc_del;
883 li = elm_genlist_add(parent);
884 elm_widget_mirrored_automatic_set(li, EINA_FALSE);
885 evas_object_size_hint_align_set(li, EVAS_HINT_FILL, EVAS_HINT_FILL);
886 evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
887 evas_object_size_hint_min_set(li, 100, 100);
889 grid = elm_gengrid_add(parent);
890 elm_widget_mirrored_automatic_set(grid, EINA_FALSE);
891 evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
892 evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
894 s = elm_finger_size_get() * 2;
895 elm_gengrid_item_size_set(grid, s, s);
896 elm_gengrid_align_set(grid, 0.0, 0.0);
898 evas_object_smart_callback_add(li, "selected", _sel, obj);
899 evas_object_smart_callback_add(li, "expand,request", _expand_req, obj);
900 evas_object_smart_callback_add(li, "contract,request", _contract_req, obj);
901 evas_object_smart_callback_add(li, "expanded", _expand_done, obj);
902 evas_object_smart_callback_add(li, "contracted", _contract_done, obj);
904 evas_object_smart_callback_add(grid, "selected", _sel, obj);
906 elm_widget_sub_object_add(obj, li);
907 elm_widget_sub_object_add(obj, grid);
909 wd->files_grid = grid;
912 en = elm_entry_add(parent);
913 elm_entry_scrollable_set(en, EINA_TRUE);
914 elm_widget_mirrored_automatic_set(en, EINA_FALSE);
915 elm_entry_editable_set(en, EINA_FALSE);
916 elm_entry_single_line_set(en, EINA_TRUE);
917 elm_entry_line_wrap_set(en, ELM_WRAP_CHAR);
918 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
919 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
921 evas_object_smart_callback_add(en, "anchor,clicked", _anchor_clicked, obj);
923 elm_widget_sub_object_add(obj, en);
927 en = elm_entry_add(parent);
928 elm_entry_scrollable_set(en, EINA_TRUE);
929 elm_widget_mirrored_automatic_set(en, EINA_FALSE);
930 elm_entry_editable_set(en, EINA_TRUE);
931 elm_entry_single_line_set(en, EINA_TRUE);
932 elm_entry_line_wrap_set(en, ELM_WRAP_CHAR);
933 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
934 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
936 elm_widget_sub_object_add(obj, en);
937 wd->filename_entry = en;
939 elm_fileselector_buttons_ok_cancel_set(obj, EINA_TRUE);
940 elm_fileselector_is_save_set(obj, EINA_FALSE);
944 evas_object_smart_callbacks_descriptions_set(obj, _signals);
949 * This enables/disables the file name entry box where the user can
950 * type in a name for the file to be saved as.
952 * @param obj The fileselector object
953 * @param is_save If true, the fileselector is a save dialog
955 * @ingroup Fileselector
958 elm_fileselector_is_save_set(Evas_Object *obj,
961 ELM_CHECK_WIDTYPE(obj, widtype);
962 Widget_Data *wd = elm_widget_data_get(obj);
965 elm_object_disabled_set(wd->filename_entry, !is_save);
968 edje_object_signal_emit(wd->edje, "elm,state,save,on", "elm");
970 edje_object_signal_emit(wd->edje, "elm,state,save,off", "elm");
974 * This returns whether the fileselector is a "save" type fileselector
976 * @param obj The fileselector object
977 * @return If true, the fileselector is a save type.
979 * @ingroup Fileselector
982 elm_fileselector_is_save_get(const Evas_Object *obj)
984 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
985 Widget_Data *wd = elm_widget_data_get(obj);
986 if (!wd) return EINA_FALSE;
987 return elm_object_disabled_get(wd->filename_entry);
991 * This enables/disables folder-only view in the fileselector.
993 * @param obj The fileselector object
994 * @param only If true, the fileselector will only display directories.
995 * If false, files are displayed also.
997 * @ingroup Fileselector
1000 elm_fileselector_folder_only_set(Evas_Object *obj,
1003 ELM_CHECK_WIDTYPE(obj, widtype);
1004 Widget_Data *wd = elm_widget_data_get(obj);
1006 if (wd->only_folder == only) return;
1007 wd->only_folder = !!only;
1008 if (wd->path) _populate(obj, wd->path, NULL);
1012 * This gets the state of file display in the fileselector.
1014 * @param obj The fileselector object
1015 * @return If true, files are not being shown in the fileselector.
1016 * If false, files are being shown.
1018 * @ingroup Fileselector
1021 elm_fileselector_folder_only_get(const Evas_Object *obj)
1023 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1024 Widget_Data *wd = elm_widget_data_get(obj);
1025 if (!wd) return EINA_FALSE;
1026 return wd->only_folder;
1030 * This enables/disables the ok,cancel buttons.
1032 * @param obj The fileselector object
1033 * @param only If true, a box containing ok and cancel buttons is created.
1034 * If false, the box and the buttons are destroyed.
1036 * @ingroup Fileselector
1039 elm_fileselector_buttons_ok_cancel_set(Evas_Object *obj,
1042 ELM_CHECK_WIDTYPE(obj, widtype);
1043 Widget_Data *wd = elm_widget_data_get(obj);
1050 bt = elm_button_add(obj);
1051 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
1052 elm_object_text_set(bt, E_("Cancel"));
1054 evas_object_smart_callback_add(bt, "clicked", _canc, obj);
1056 elm_widget_sub_object_add(obj, bt);
1057 wd->cancel_button = bt;
1060 bt = elm_button_add(obj);
1061 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
1062 elm_object_text_set(bt, E_("OK"));
1064 evas_object_smart_callback_add(bt, "clicked", _ok, obj);
1066 elm_widget_sub_object_add(obj, bt);
1073 evas_object_del(wd->cancel_button);
1074 wd->cancel_button = NULL;
1075 evas_object_del(wd->ok_button);
1076 wd->ok_button = NULL;
1081 * This gets the state of the box containing ok and cancel buttons.
1083 * @param obj The fileselector object
1084 * @return If true, the box exists.
1085 * If false, the box does not exist.
1087 * @ingroup Fileselector
1090 elm_fileselector_buttons_ok_cancel_get(const Evas_Object *obj)
1092 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1093 Widget_Data *wd = elm_widget_data_get(obj);
1094 if (!wd) return EINA_FALSE;
1095 return wd->ok_button ? EINA_TRUE : EINA_FALSE;
1099 * This enables a tree view in the fileselector, <b>if in @c
1100 * ELM_FILESELECTOR_LIST mode</b>. If it's in other mode, the changes
1101 * made by this function will only be visible when one switches back
1104 * @param obj The fileselector object
1105 * @param expand If true, tree view is enabled.
1106 * If false, tree view is disabled.
1108 * In a tree view, arrows are created on the sides of directories,
1109 * allowing them to expand in place.
1111 * @ingroup Fileselector
1114 elm_fileselector_expandable_set(Evas_Object *obj,
1117 ELM_CHECK_WIDTYPE(obj, widtype);
1120 wd = elm_widget_data_get(obj);
1123 wd->expand = !!expand;
1125 if (wd->path) _populate(obj, wd->path, NULL);
1129 * This gets the state of tree view in the fileselector.
1131 * @param obj The fileselector object
1132 * @return If true, tree view is enabled and folders will be expandable.
1133 * If false, tree view is disabled.
1135 * @ingroup Fileselector
1138 elm_fileselector_expandable_get(const Evas_Object *obj)
1140 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1141 Widget_Data *wd = elm_widget_data_get(obj);
1142 if (!wd) return EINA_FALSE;
1147 * This sets the path that the fileselector will display.
1149 * @param obj The fileselector object
1150 * @param path The path of the fileselector
1152 * @ingroup Fileselector
1155 elm_fileselector_path_set(Evas_Object *obj,
1158 ELM_CHECK_WIDTYPE(obj, widtype);
1159 _populate(obj, path, NULL);
1163 * This gets the path that the fileselector displays.
1165 * @param obj The fileselector object
1166 * @return The path that the fileselector is displaying
1168 * @ingroup Fileselector
1171 elm_fileselector_path_get(const Evas_Object *obj)
1173 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1174 Widget_Data *wd = elm_widget_data_get(obj);
1175 if (!wd) return NULL;
1180 * This sets the mode in which the fileselector will display files.
1182 * @param obj The fileselector object
1184 * @param mode The mode of the fileselector, being it one of @c
1185 * ELM_FILESELECTOR_LIST (default) or @c ELM_FILESELECTOR_GRID. The
1186 * first one, naturally, will display the files in a list. By using
1187 * elm_fileselector_expandable_set(), the user will trigger a tree
1188 * view for that list. The latter will make the widget to display its
1189 * entries in a grid form.
1191 * @see elm_fileselector_expandable_set().
1193 * @ingroup Fileselector
1196 elm_fileselector_mode_set(Evas_Object *obj,
1197 Elm_Fileselector_Mode mode)
1199 ELM_CHECK_WIDTYPE(obj, widtype);
1201 Widget_Data *wd = elm_widget_data_get(obj);
1204 if (mode == wd->mode) return;
1206 if (mode == ELM_FILESELECTOR_LIST)
1208 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
1211 evas_object_show(wd->files_list);
1212 evas_object_hide(wd->files_grid);
1215 evas_object_hide(wd->files_list);
1219 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
1222 evas_object_show(wd->files_grid);
1223 evas_object_hide(wd->files_list);
1226 evas_object_hide(wd->files_grid);
1231 _populate(obj, wd->path, NULL);
1235 * This gets the mode in which the fileselector is displaying files.
1237 * @param obj The fileselector object
1238 * @return The mode in which the fileselector is at
1240 * @ingroup Fileselector
1242 EAPI Elm_Fileselector_Mode
1243 elm_fileselector_mode_get(const Evas_Object *obj)
1245 ELM_CHECK_WIDTYPE(obj, widtype) ELM_FILESELECTOR_LAST;
1247 Widget_Data *wd = elm_widget_data_get(obj);
1248 if (!wd) return ELM_FILESELECTOR_LAST;
1254 * This gets the currently selected path in the file selector.
1256 * @param obj The file selector object
1257 * @return The absolute path of the selected object in the fileselector
1259 * @ingroup Fileselector
1262 elm_fileselector_selected_get(const Evas_Object *obj)
1264 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1265 Widget_Data *wd = elm_widget_data_get(obj);
1266 if (!wd) return NULL;
1268 if (wd->filename_entry)
1273 name = elm_entry_entry_get(wd->filename_entry);
1274 snprintf(buf, sizeof(buf), "%s/%s",
1275 wd->only_folder ? ecore_file_dir_get(wd->path) : wd->path,
1277 eina_stringshare_replace(&wd->selection, buf);
1278 return wd->selection;
1281 if (wd->mode == ELM_FILESELECTOR_LIST)
1283 Elm_Genlist_Item *it;
1284 it = elm_genlist_selected_item_get(wd->files_list);
1285 if (it) return elm_genlist_item_data_get(it);
1289 Elm_Gengrid_Item *it;
1290 it = elm_gengrid_selected_item_get(wd->files_grid);
1291 if (it) return elm_gengrid_item_data_get(it);
1298 * This sets the currently selected path in the file selector.
1300 * @param obj The file selector object
1301 * @param path The path to a file or directory
1302 * @return @c EINA_TRUE on success, @c EINA_FALSE on failure. The
1303 * latter case occurs if the directory or file pointed to do not
1306 * @ingroup Fileselector
1309 elm_fileselector_selected_set(Evas_Object *obj,
1312 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1313 Widget_Data *wd = elm_widget_data_get(obj);
1314 if (!wd) return EINA_FALSE;
1316 if (ecore_file_is_dir(path))
1317 _populate(obj, path, NULL);
1320 if (!ecore_file_exists(path))
1323 _populate(obj, ecore_file_dir_get(path), NULL);
1324 if (wd->filename_entry)
1326 elm_entry_entry_set(wd->filename_entry,
1327 ecore_file_file_get(path));
1328 eina_stringshare_replace(&wd->selection, path);