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);
144 eio_file_cancel(wd->current);
146 wd->files_list = NULL;
147 wd->files_grid = NULL;
149 EINA_REFCOUNT_UNREF(wd)
150 _widget_data_free(wd);
154 _sizing_eval(Evas_Object *obj)
156 Widget_Data *wd = elm_widget_data_get(obj);
157 Evas_Coord minw = -1, minh = -1;
159 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
160 edje_object_size_min_restricted_calc(wd->edje, &minw, &minh, minw, minh);
161 evas_object_size_hint_min_set(obj, minw, minh);
165 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
167 Widget_Data *wd = elm_widget_data_get(obj);
169 elm_widget_mirrored_set(wd->cancel_button, rtl);
170 elm_widget_mirrored_set(wd->ok_button, rtl);
171 elm_widget_mirrored_set(wd->files_list, rtl);
172 elm_widget_mirrored_set(wd->up_button, rtl);
173 elm_widget_mirrored_set(wd->home_button, rtl);
174 edje_object_mirrored_set(wd->edje, rtl);
178 _theme_hook(Evas_Object *obj)
180 Widget_Data *wd = elm_widget_data_get(obj);
181 const char *style = elm_widget_style_get(obj);
186 _elm_widget_mirrored_reload(obj);
188 _elm_theme_object_set(obj, wd->edje, "fileselector", "base", style);
190 if (elm_object_disabled_get(obj))
191 edje_object_signal_emit(wd->edje, "elm,state,disabled", "elm");
193 data = edje_object_data_get(wd->edje, "path_separator");
195 wd->path_separator = data;
197 wd->path_separator = "/";
199 if (!style) style = "default";
200 snprintf(buf, sizeof(buf), "fileselector/%s", style);
202 #define SWALLOW(part_name, object_ptn) \
205 elm_widget_style_set(object_ptn, buf); \
206 if (edje_object_part_swallow(wd->edje, part_name, object_ptn)) \
207 evas_object_show(object_ptn); \
209 evas_object_hide(object_ptn); \
211 SWALLOW("elm.swallow.up", wd->up_button);
212 SWALLOW("elm.swallow.home", wd->home_button);
214 if (wd->mode == ELM_FILESELECTOR_LIST)
216 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
219 evas_object_show(wd->files_list);
220 evas_object_hide(wd->files_grid);
223 evas_object_hide(wd->files_list);
227 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
230 evas_object_show(wd->files_grid);
231 evas_object_hide(wd->files_list);
234 evas_object_hide(wd->files_grid);
237 SWALLOW("elm.swallow.filename", wd->filename_entry);
238 SWALLOW("elm.swallow.path", wd->path_entry);
240 snprintf(buf, sizeof(buf), "fileselector/actions/%s", style);
241 SWALLOW("elm.swallow.cancel", wd->cancel_button);
242 SWALLOW("elm.swallow.ok", wd->ok_button);
245 edje_object_message_signal_process(wd->edje);
246 _mirrored_set(obj, elm_widget_mirrored_get(obj));
247 edje_object_scale_set
248 (wd->edje, elm_widget_scale_get(obj) * _elm_config->scale);
252 /*** GENLIST "MODEL" ***/
254 _itc_label_get(void *data,
255 Evas_Object *obj __UNUSED__,
256 const char *source __UNUSED__)
258 return strdup(ecore_file_file_get(data)); /* NOTE this will be
264 _itc_icon_folder_get(void *data __UNUSED__,
270 if (strcmp(source, "elm.swallow.icon")) return NULL;
272 ic = elm_icon_add(obj);
273 elm_icon_standard_set(ic, "folder");
275 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
281 _itc_icon_image_get(void *data,
285 const char *filename = data;
288 if (strcmp(source, "elm.swallow.icon")) return NULL;
290 ic = elm_icon_add(obj);
291 elm_icon_standard_set(ic, "image");
292 elm_icon_thumb_set(ic, filename, NULL);
294 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
300 _itc_icon_file_get(void *data __UNUSED__,
306 if (strcmp(source, "elm.swallow.icon")) return NULL;
308 ic = elm_icon_add(obj);
309 elm_icon_standard_set(ic, "file");
311 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
317 _itc_state_get(void *data __UNUSED__,
318 Evas_Object *obj __UNUSED__,
319 const char *source __UNUSED__)
326 Evas_Object *obj __UNUSED__)
328 eina_stringshare_del(data);
332 _expand_done(void *data,
333 Evas_Object *obj __UNUSED__,
336 Elm_Genlist_Item *it = event_info;
337 const char *path = elm_genlist_item_data_get(it);
338 _populate(data, path, it);
342 _contract_done(void *data __UNUSED__,
343 Evas_Object *obj __UNUSED__,
346 Elm_Genlist_Item *it = event_info;
347 elm_genlist_item_subitems_clear(it);
351 _expand_req(void *data __UNUSED__,
352 Evas_Object *obj __UNUSED__,
355 Elm_Genlist_Item *it = event_info;
356 elm_genlist_item_expanded_set(it, 1);
360 _contract_req(void *data __UNUSED__,
361 Evas_Object *obj __UNUSED__,
364 Elm_Genlist_Item *it = event_info;
365 elm_genlist_item_expanded_set(it, 0);
378 wd = elm_widget_data_get(sd->fs);
381 if ((!wd->only_folder) && ecore_file_is_dir(path))
383 if (wd->expand && wd->mode == ELM_FILESELECTOR_LIST)
385 _do_anchors(sd->fs, path);
386 elm_entry_entry_set(wd->filename_entry, "");
390 /* keep a ref to path 'couse it will be destroyed by _populate */
391 p = eina_stringshare_add(path);
392 _populate(sd->fs, p, NULL);
393 eina_stringshare_del(p);
397 else /* navigating through folders only or file is not a dir. */
399 if (wd->expand && wd->mode == ELM_FILESELECTOR_LIST)
400 _do_anchors(sd->fs, path);
401 else if (wd->only_folder)
403 /* keep a ref to path 'couse it will be destroyed by _populate */
404 p = eina_stringshare_add(path);
405 _populate(sd->fs, p, NULL);
406 eina_stringshare_del(p);
408 elm_entry_entry_set(wd->filename_entry,
409 ecore_file_file_get(path));
412 evas_object_smart_callback_call(sd->fs, SIG_SELECTED, (void *)path);
415 wd->sel_idler = NULL;
417 return ECORE_CALLBACK_CANCEL;
422 Evas_Object *obj __UNUSED__,
430 wd = elm_widget_data_get(data);
433 sd = malloc(sizeof(*sd));
435 sd->path = wd->mode == ELM_FILESELECTOR_LIST ?
436 elm_genlist_item_data_get(event_info) :
437 elm_gengrid_item_data_get(event_info);
441 eina_stringshare_replace(&wd->path, "");
445 dir = wd->only_folder ? strdup(sd->path) : ecore_file_dir_get(sd->path);
448 eina_stringshare_replace(&wd->path, dir);
453 eina_stringshare_replace(&wd->path, "");
459 old_sd = ecore_idler_del(wd->sel_idler);
462 wd->sel_idler = ecore_idler_add(_sel_do, sd);
467 Evas_Object *obj __UNUSED__,
468 void *event_info __UNUSED__)
470 Evas_Object *fs = data;
473 Widget_Data *wd = elm_widget_data_get(fs);
475 parent = ecore_file_dir_get(wd->path);
476 _populate(fs, parent, NULL);
482 Evas_Object *obj __UNUSED__,
483 void *event_info __UNUSED__)
485 Evas_Object *fs = data;
486 _populate(fs, getenv("HOME"), NULL);
491 Evas_Object *obj __UNUSED__,
492 void *event_info __UNUSED__)
494 Evas_Object *fs = data;
495 evas_object_smart_callback_call(fs, SIG_DONE,
496 (void *)elm_fileselector_selected_get(fs));
501 Evas_Object *obj __UNUSED__,
502 void *event_info __UNUSED__)
504 Evas_Object *fs = data;
505 evas_object_smart_callback_call(fs, SIG_DONE, NULL);
509 _anchor_clicked(void *data,
510 Evas_Object *obj __UNUSED__,
513 Evas_Object *fs = data;
514 Widget_Data *wd = elm_widget_data_get(fs);
515 Elm_Entry_Anchor_Info *info = event_info;
518 // keep a ref to path 'couse it will be destroyed by _populate
519 p = eina_stringshare_add(info->name);
520 _populate(fs, p, NULL);
521 evas_object_smart_callback_call(data, SIG_SELECTED, (void *)p);
522 eina_stringshare_del(p);
526 _do_anchors(Evas_Object *obj,
529 Widget_Data *wd = elm_widget_data_get(obj);
530 char **tok, buf[PATH_MAX * 3];
534 tok = eina_str_split(path, "/", 0);
535 eina_strlcat(buf, "<a href=/>root</a>", sizeof(buf));
536 for (i = 0; tok[i]; i++)
538 if ((!tok[i]) || (!tok[i][0])) continue;
539 eina_strlcat(buf, wd->path_separator, sizeof(buf));
540 eina_strlcat(buf, "<a href=", sizeof(buf));
541 for (j = 0; j <= i; j++)
543 if (strlen(tok[j]) < 1) continue;
544 eina_strlcat(buf, "/", sizeof(buf));
545 eina_strlcat(buf, tok[j], sizeof(buf));
547 eina_strlcat(buf, ">", sizeof(buf));
548 eina_strlcat(buf, tok[i], sizeof(buf));
549 eina_strlcat(buf, "</a>", sizeof(buf));
554 elm_entry_entry_set(wd->path_entry, buf);
559 _filter_cb(void *data __UNUSED__, Eio_File *handler, const Eina_File_Direct_Info *info)
561 const char *filename;
563 if (info->path[info->name_start] == '.')
566 filename = eina_stringshare_add(info->path);
567 eio_file_associate_direct_add(handler, "filename", filename, EINA_FREE_CB(eina_stringshare_del));
569 if (info->type == EINA_FILE_DIR)
571 eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_DIRECTORY], NULL);
572 eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_DIRECTORY], NULL);
576 if (evas_object_image_extension_can_load_get(info->path + info->name_start))
578 eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_FILE_IMAGE], NULL);
579 eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_FILE_IMAGE], NULL);
583 eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_FILE_UNKNOW], NULL);
584 eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_FILE_UNKNOW], NULL);
592 _file_grid_cmp(const void *a, const void *b)
594 const Elm_Gengrid_Item *ga = a;
595 const Elm_Gengrid_Item *gb = b;
596 const Elm_Gengrid_Item_Class *ca = elm_gengrid_item_item_class_get(ga);
597 const Elm_Gengrid_Item_Class *cb = elm_gengrid_item_item_class_get(gb);
599 if (ca == &grid_itc[ELM_DIRECTORY])
601 if (cb != &grid_itc[ELM_DIRECTORY])
605 return strcoll(elm_gengrid_item_data_get(ga), elm_gengrid_item_data_get(gb));
609 _file_list_cmp(const void *a, const void *b)
611 const Elm_Genlist_Item *la = a;
612 const Elm_Genlist_Item *lb = b;
613 const Elm_Genlist_Item_Class *ca = elm_genlist_item_item_class_get(la);
614 const Elm_Genlist_Item_Class *cb = elm_genlist_item_item_class_get(lb);
616 if (ca == &list_itc[ELM_DIRECTORY])
618 if (cb != &list_itc[ELM_DIRECTORY])
622 return strcoll(elm_genlist_item_data_get(la), elm_genlist_item_data_get(lb));
626 _signal_first(Widget_Request *wr)
628 if (!wr->first) return ;
629 evas_object_smart_callback_call(wr->obj, SIG_DIRECTORY_OPEN, (void *)wr->path);
632 elm_genlist_clear(wr->wd->files_list);
633 elm_gengrid_clear(wr->wd->files_grid);
634 eina_stringshare_replace(&wr->wd->path, wr->path);
635 _do_anchors(wr->obj, wr->path);
638 if (wr->wd->filename_entry) elm_entry_entry_set(wr->wd->filename_entry, "");
640 wr->first = EINA_FALSE;
644 _main_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *info __UNUSED__)
646 Widget_Request *wr = data;
648 if (eio_file_check(handler))
650 if (!wr->wd->files_list || !wr->wd->files_grid) return ;
654 if (wr->wd->mode == ELM_FILESELECTOR_LIST)
655 elm_genlist_item_direct_sorted_insert(wr->wd->files_list, eio_file_associate_find(handler, "type/list"),
656 eina_stringshare_ref(eio_file_associate_find(handler, "filename")),
657 wr->parent, ELM_GENLIST_ITEM_NONE, _file_list_cmp, NULL, NULL);
658 else if (wr->wd->mode == ELM_FILESELECTOR_GRID)
659 elm_gengrid_item_direct_sorted_insert(wr->wd->files_grid, eio_file_associate_find(handler, "type/grid"),
660 eina_stringshare_ref(eio_file_associate_find(handler, "filename")),
661 _file_grid_cmp, NULL, NULL);
665 _widget_request_cleanup(Widget_Request *wr)
667 EINA_REFCOUNT_UNREF(wr->wd)
668 _widget_data_free(wr->wd);
670 eina_stringshare_del(wr->path);
675 _done_cb(void *data, Eio_File *handler __UNUSED__)
677 Widget_Request *wr = data;
681 wr->wd->current = NULL;
682 _widget_request_cleanup(wr);
686 _error_cb(void *data, Eio_File *handler, int error __UNUSED__)
688 Widget_Request *wr = data;
690 if (wr->wd->current == handler)
691 wr->wd->current = NULL;
692 _widget_request_cleanup(wr);
698 _populate(Evas_Object *obj,
700 Elm_Genlist_Item *parent)
702 Widget_Data *wd = elm_widget_data_get(obj);
706 Eina_File_Direct_Info *file;
709 Eina_List *files = NULL, *dirs = NULL;
714 if (!ecore_file_is_dir(path)) return ;
715 it = eina_file_stat_ls(path);
717 evas_object_smart_callback_call(obj, SIG_DIRECTORY_OPEN, (void *)path);
720 elm_genlist_clear(wd->files_list);
721 elm_gengrid_clear(wd->files_grid);
722 eina_stringshare_replace(&wd->path, path);
723 _do_anchors(obj, path);
726 if (wd->filename_entry) elm_entry_entry_set(wd->filename_entry, "");
727 EINA_ITERATOR_FOREACH(it, file)
729 const char *filename;
731 if (file->path[file->name_start] == '.')
734 filename = eina_stringshare_add(file->path);
735 if (file->type == EINA_FILE_DIR)
736 dirs = eina_list_append(dirs, filename);
737 else if (!wd->only_folder)
738 files = eina_list_append(files, filename);
740 eina_iterator_free(it);
742 files = eina_list_sort(files, eina_list_count(files),
743 EINA_COMPARE_CB(strcoll));
744 dirs = eina_list_sort(dirs, eina_list_count(dirs), EINA_COMPARE_CB(strcoll));
745 EINA_LIST_FREE(dirs, real)
747 if (wd->mode == ELM_FILESELECTOR_LIST)
748 elm_genlist_item_append(wd->files_list, &list_itc[ELM_DIRECTORY],
749 real, /* item data */
751 wd->expand ? ELM_GENLIST_ITEM_SUBITEMS :
752 ELM_GENLIST_ITEM_NONE,
754 else if (wd->mode == ELM_FILESELECTOR_GRID)
755 elm_gengrid_item_append(wd->files_grid, &grid_itc[ELM_DIRECTORY],
756 real, /* item data */
760 EINA_LIST_FREE(files, real)
762 Elm_Fileselector_Type type = evas_object_image_extension_can_load_fast_get(real) ?
763 ELM_FILE_IMAGE : ELM_FILE_UNKNOW;
765 if (wd->mode == ELM_FILESELECTOR_LIST)
766 elm_genlist_item_append(wd->files_list, &list_itc[type],
767 real, /* item data */
768 parent, ELM_GENLIST_ITEM_NONE,
770 else if (wd->mode == ELM_FILESELECTOR_GRID)
771 elm_gengrid_item_append(wd->files_grid, &grid_itc[type],
772 real, /* item data */
777 eio_file_cancel(wd->current);
778 wr = malloc(sizeof (Widget_Request));
781 EINA_REFCOUNT_REF(wr->wd);
782 wr->parent = parent; /* FIXME: should we refcount the parent ? */
784 wr->path = eina_stringshare_add(path);
785 wr->first = EINA_TRUE;
787 wd->current = eio_file_stat_ls(path,
799 * Add a new Fileselector object
801 * @param parent The parent object
802 * @return The new object or NULL if it cannot be created
804 * @ingroup Fileselector
807 elm_fileselector_add(Evas_Object *parent)
810 Evas_Object *obj, *ic, *bt, *li, *en, *grid;
815 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
817 EINA_REFCOUNT_INIT(wd);
819 ELM_SET_WIDTYPE(widtype, "fileselector");
820 elm_widget_type_set(obj, "fileselector");
821 elm_widget_sub_object_add(parent, obj);
822 elm_widget_data_set(obj, wd);
823 elm_widget_del_hook_set(obj, _del_hook);
824 elm_widget_theme_hook_set(obj, _theme_hook);
825 elm_widget_can_focus_set(obj, EINA_FALSE);
827 wd->expand = !!_elm_config->fileselector_expand_enable;
829 wd->edje = edje_object_add(e);
830 _elm_theme_object_set(obj, wd->edje, "fileselector", "base", "default");
831 elm_widget_resize_object_set(obj, wd->edje);
834 ic = elm_icon_add(parent);
835 elm_icon_standard_set(ic, "arrow_up");
836 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
837 bt = elm_button_add(parent);
838 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
839 elm_button_icon_set(bt, ic);
840 elm_button_label_set(bt, E_("Up"));
841 evas_object_size_hint_align_set(bt, 0.0, 0.0);
843 evas_object_smart_callback_add(bt, "clicked", _up, obj);
845 elm_widget_sub_object_add(obj, bt);
849 ic = elm_icon_add(parent);
850 elm_icon_standard_set(ic, "home");
851 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
852 bt = elm_button_add(parent);
853 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
854 elm_button_icon_set(bt, ic);
855 elm_button_label_set(bt, E_("Home"));
856 evas_object_size_hint_align_set(bt, 0.0, 0.0);
858 evas_object_smart_callback_add(bt, "clicked", _home, obj);
860 elm_widget_sub_object_add(obj, bt);
861 wd->home_button = bt;
863 list_itc[ELM_DIRECTORY].func.icon_get = grid_itc[ELM_DIRECTORY].func.icon_get = _itc_icon_folder_get;
864 list_itc[ELM_FILE_IMAGE].func.icon_get = grid_itc[ELM_FILE_IMAGE].func.icon_get = _itc_icon_image_get;
865 list_itc[ELM_FILE_UNKNOW].func.icon_get = grid_itc[ELM_FILE_UNKNOW].func.icon_get = _itc_icon_file_get;
867 for (i = 0; i < ELM_FILE_LAST; ++i)
869 list_itc[i].func.label_get = grid_itc[i].func.label_get = _itc_label_get;
870 list_itc[i].func.state_get = grid_itc[i].func.state_get = _itc_state_get;
871 list_itc[i].func.del = grid_itc[i].func.del = _itc_del;
874 li = elm_genlist_add(parent);
875 elm_widget_mirrored_automatic_set(li, EINA_FALSE);
876 evas_object_size_hint_align_set(li, EVAS_HINT_FILL, EVAS_HINT_FILL);
877 evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
878 evas_object_size_hint_min_set(li, 100, 100);
880 grid = elm_gengrid_add(parent);
881 elm_widget_mirrored_automatic_set(grid, EINA_FALSE);
882 evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
883 evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
885 s = elm_finger_size_get() * 2;
886 elm_gengrid_item_size_set(grid, s, s);
887 elm_gengrid_align_set(grid, 0.0, 0.0);
889 evas_object_smart_callback_add(li, "selected", _sel, obj);
890 evas_object_smart_callback_add(li, "expand,request", _expand_req, obj);
891 evas_object_smart_callback_add(li, "contract,request", _contract_req, obj);
892 evas_object_smart_callback_add(li, "expanded", _expand_done, obj);
893 evas_object_smart_callback_add(li, "contracted", _contract_done, obj);
895 evas_object_smart_callback_add(grid, "selected", _sel, obj);
897 elm_widget_sub_object_add(obj, li);
898 elm_widget_sub_object_add(obj, grid);
900 wd->files_grid = grid;
903 en = elm_entry_add(parent);
904 elm_entry_scrollable_set(en, EINA_TRUE);
905 elm_widget_mirrored_automatic_set(en, EINA_FALSE);
906 elm_entry_editable_set(en, EINA_FALSE);
907 elm_entry_single_line_set(en, EINA_TRUE);
908 elm_entry_line_wrap_set(en, ELM_WRAP_CHAR);
909 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
910 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
912 evas_object_smart_callback_add(en, "anchor,clicked", _anchor_clicked, obj);
914 elm_widget_sub_object_add(obj, en);
918 en = elm_entry_add(parent);
919 elm_entry_scrollable_set(en, EINA_TRUE);
920 elm_widget_mirrored_automatic_set(en, EINA_FALSE);
921 elm_entry_editable_set(en, EINA_TRUE);
922 elm_entry_single_line_set(en, EINA_TRUE);
923 elm_entry_line_wrap_set(en, ELM_WRAP_CHAR);
924 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
925 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
927 elm_widget_sub_object_add(obj, en);
928 wd->filename_entry = en;
930 elm_fileselector_buttons_ok_cancel_set(obj, EINA_TRUE);
931 elm_fileselector_is_save_set(obj, EINA_FALSE);
935 evas_object_smart_callbacks_descriptions_set(obj, _signals);
940 * This enables/disables the file name entry box where the user can
941 * type in a name for the file to be saved as.
943 * @param obj The fileselector object
944 * @param is_save If true, the fileselector is a save dialog
946 * @ingroup Fileselector
949 elm_fileselector_is_save_set(Evas_Object *obj,
952 ELM_CHECK_WIDTYPE(obj, widtype);
953 Widget_Data *wd = elm_widget_data_get(obj);
956 elm_object_disabled_set(wd->filename_entry, !is_save);
959 edje_object_signal_emit(wd->edje, "elm,state,save,on", "elm");
961 edje_object_signal_emit(wd->edje, "elm,state,save,off", "elm");
965 * This returns whether the fileselector is a "save" type fileselector
967 * @param obj The fileselector object
968 * @return If true, the fileselector is a save type.
970 * @ingroup Fileselector
973 elm_fileselector_is_save_get(const Evas_Object *obj)
975 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
976 Widget_Data *wd = elm_widget_data_get(obj);
977 if (!wd) return EINA_FALSE;
978 return elm_object_disabled_get(wd->filename_entry);
982 * This enables/disables folder-only view in the fileselector.
984 * @param obj The fileselector object
985 * @param only If true, the fileselector will only display directories.
986 * If false, files are displayed also.
988 * @ingroup Fileselector
991 elm_fileselector_folder_only_set(Evas_Object *obj,
994 ELM_CHECK_WIDTYPE(obj, widtype);
995 Widget_Data *wd = elm_widget_data_get(obj);
997 if (wd->only_folder == only) return;
998 wd->only_folder = !!only;
999 if (wd->path) _populate(obj, wd->path, NULL);
1003 * This gets the state of file display in the fileselector.
1005 * @param obj The fileselector object
1006 * @return If true, files are not being shown in the fileselector.
1007 * If false, files are being shown.
1009 * @ingroup Fileselector
1012 elm_fileselector_folder_only_get(const Evas_Object *obj)
1014 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1015 Widget_Data *wd = elm_widget_data_get(obj);
1016 if (!wd) return EINA_FALSE;
1017 return wd->only_folder;
1021 * This enables/disables the ok,cancel buttons.
1023 * @param obj The fileselector object
1024 * @param only If true, a box containing ok and cancel buttons is created.
1025 * If false, the box and the buttons are destroyed.
1027 * @ingroup Fileselector
1030 elm_fileselector_buttons_ok_cancel_set(Evas_Object *obj,
1033 ELM_CHECK_WIDTYPE(obj, widtype);
1034 Widget_Data *wd = elm_widget_data_get(obj);
1041 bt = elm_button_add(obj);
1042 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
1043 elm_button_label_set(bt, E_("Cancel"));
1045 evas_object_smart_callback_add(bt, "clicked", _canc, obj);
1047 elm_widget_sub_object_add(obj, bt);
1048 wd->cancel_button = bt;
1051 bt = elm_button_add(obj);
1052 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
1053 elm_button_label_set(bt, E_("OK"));
1055 evas_object_smart_callback_add(bt, "clicked", _ok, obj);
1057 elm_widget_sub_object_add(obj, bt);
1064 evas_object_del(wd->cancel_button);
1065 wd->cancel_button = NULL;
1066 evas_object_del(wd->ok_button);
1067 wd->ok_button = NULL;
1072 * This gets the state of the box containing ok and cancel buttons.
1074 * @param obj The fileselector object
1075 * @return If true, the box exists.
1076 * If false, the box does not exist.
1078 * @ingroup Fileselector
1081 elm_fileselector_buttons_ok_cancel_get(const Evas_Object *obj)
1083 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1084 Widget_Data *wd = elm_widget_data_get(obj);
1085 if (!wd) return EINA_FALSE;
1086 return wd->ok_button ? EINA_TRUE : EINA_FALSE;
1090 * This enables a tree view in the fileselector, <b>if in @c
1091 * ELM_FILESELECTOR_LIST mode</b>. If it's in other mode, the changes
1092 * made by this function will only be visible when one switches back
1095 * @param obj The fileselector object
1096 * @param expand If true, tree view is enabled.
1097 * If false, tree view is disabled.
1099 * In a tree view, arrows are created on the sides of directories,
1100 * allowing them to expand in place.
1102 * @ingroup Fileselector
1105 elm_fileselector_expandable_set(Evas_Object *obj,
1108 ELM_CHECK_WIDTYPE(obj, widtype);
1111 wd = elm_widget_data_get(obj);
1114 wd->expand = !!expand;
1116 if (wd->path) _populate(obj, wd->path, NULL);
1120 * This gets the state of tree view in the fileselector.
1122 * @param obj The fileselector object
1123 * @return If true, tree view is enabled and folders will be expandable.
1124 * If false, tree view is disabled.
1126 * @ingroup Fileselector
1129 elm_fileselector_expandable_get(const Evas_Object *obj)
1131 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1132 Widget_Data *wd = elm_widget_data_get(obj);
1133 if (!wd) return EINA_FALSE;
1138 * This sets the path that the fileselector will display.
1140 * @param obj The fileselector object
1141 * @param path The path of the fileselector
1143 * @ingroup Fileselector
1146 elm_fileselector_path_set(Evas_Object *obj,
1149 ELM_CHECK_WIDTYPE(obj, widtype);
1150 _populate(obj, path, NULL);
1154 * This gets the path that the fileselector displays.
1156 * @param obj The fileselector object
1157 * @return The path that the fileselector is displaying
1159 * @ingroup Fileselector
1162 elm_fileselector_path_get(const Evas_Object *obj)
1164 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1165 Widget_Data *wd = elm_widget_data_get(obj);
1166 if (!wd) return NULL;
1171 * This sets the mode in which the fileselector will display files.
1173 * @param obj The fileselector object
1175 * @param mode The mode of the fileselector, being it one of @c
1176 * ELM_FILESELECTOR_LIST (default) or @c ELM_FILESELECTOR_GRID. The
1177 * first one, naturally, will display the files in a list. By using
1178 * elm_fileselector_expandable_set(), the user will trigger a tree
1179 * view for that list. The latter will make the widget to display its
1180 * entries in a grid form.
1182 * @see elm_fileselector_expandable_set().
1184 * @ingroup Fileselector
1187 elm_fileselector_mode_set(Evas_Object *obj,
1188 Elm_Fileselector_Mode mode)
1190 ELM_CHECK_WIDTYPE(obj, widtype);
1192 Widget_Data *wd = elm_widget_data_get(obj);
1195 if (mode == wd->mode) return;
1197 if (mode == ELM_FILESELECTOR_LIST)
1199 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
1202 evas_object_show(wd->files_list);
1203 evas_object_hide(wd->files_grid);
1206 evas_object_hide(wd->files_list);
1210 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
1213 evas_object_show(wd->files_grid);
1214 evas_object_hide(wd->files_list);
1217 evas_object_hide(wd->files_grid);
1222 _populate(obj, wd->path, NULL);
1226 * This gets the mode in which the fileselector is displaying files.
1228 * @param obj The fileselector object
1229 * @return The mode in which the fileselector is at
1231 * @ingroup Fileselector
1233 EAPI Elm_Fileselector_Mode
1234 elm_fileselector_mode_get(const Evas_Object *obj)
1236 ELM_CHECK_WIDTYPE(obj, widtype) ELM_FILESELECTOR_LAST;
1238 Widget_Data *wd = elm_widget_data_get(obj);
1239 if (!wd) return ELM_FILESELECTOR_LAST;
1245 * This gets the currently selected path in the file selector.
1247 * @param obj The file selector object
1248 * @return The absolute path of the selected object in the fileselector
1250 * @ingroup Fileselector
1253 elm_fileselector_selected_get(const Evas_Object *obj)
1255 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1256 Widget_Data *wd = elm_widget_data_get(obj);
1257 if (!wd) return NULL;
1259 if (wd->filename_entry)
1264 name = elm_entry_entry_get(wd->filename_entry);
1265 snprintf(buf, sizeof(buf), "%s/%s",
1266 wd->only_folder ? ecore_file_dir_get(wd->path) : wd->path,
1268 eina_stringshare_replace(&wd->selection, buf);
1269 return wd->selection;
1272 if (wd->mode == ELM_FILESELECTOR_LIST)
1274 Elm_Genlist_Item *it;
1275 it = elm_genlist_selected_item_get(wd->files_list);
1276 if (it) return elm_genlist_item_data_get(it);
1280 Elm_Gengrid_Item *it;
1281 it = elm_gengrid_selected_item_get(wd->files_grid);
1282 if (it) return elm_gengrid_item_data_get(it);
1289 * This sets the currently selected path in the file selector.
1291 * @param obj The file selector object
1292 * @param path The path to a file or directory
1293 * @return @c EINA_TRUE on success, @c EINA_FALSE on failure. The
1294 * latter case occurs if the directory or file pointed to do not
1297 * @ingroup Fileselector
1300 elm_fileselector_selected_set(Evas_Object *obj,
1303 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1304 Widget_Data *wd = elm_widget_data_get(obj);
1305 if (!wd) return EINA_FALSE;
1307 if (ecore_file_is_dir(path))
1308 _populate(obj, path, NULL);
1311 if (!ecore_file_exists(path))
1314 _populate(obj, ecore_file_dir_get(path), NULL);
1315 if (wd->filename_entry)
1317 elm_entry_entry_set(wd->filename_entry,
1318 ecore_file_file_get(path));
1319 eina_stringshare_replace(&wd->selection, path);