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>
30 typedef struct _Widget_Data Widget_Data;
35 Evas_Object *filename_entry;
36 Evas_Object *path_entry;
37 Evas_Object *files_list;
38 Evas_Object *files_grid;
39 Evas_Object *up_button;
40 Evas_Object *home_button;
42 Evas_Object *ok_button;
43 Evas_Object *cancel_button;
46 const char *selection;
47 Ecore_Idler *sel_idler;
49 const char *path_separator;
51 Elm_Fileselector_Mode mode;
53 Eina_Bool only_folder : 1;
63 Elm_Genlist_Item_Class list_itc;
64 Elm_Gengrid_Item_Class grid_itc;
66 static const char *widtype = NULL;
68 static const char SIG_DIRECTORY_OPEN[] = "directory,open";
69 static const char SIG_DONE[] = "done";
70 static const char SIG_SELECTED[] = "selected";
71 static const Evas_Smart_Cb_Description _signals[] = {
72 {SIG_DIRECTORY_OPEN, "s"},
78 static void _populate(Evas_Object *obj,
80 Elm_Genlist_Item *parent);
81 static void _do_anchors(Evas_Object *obj,
84 /*** ELEMENTARY WIDGET ***/
86 _del_hook(Evas_Object *obj)
91 wd = elm_widget_data_get(obj);
94 if (wd->path) eina_stringshare_del(wd->path);
95 if (wd->selection) eina_stringshare_del(wd->selection);
98 sd = ecore_idler_del(wd->sel_idler);
105 _sizing_eval(Evas_Object *obj)
107 Widget_Data *wd = elm_widget_data_get(obj);
108 Evas_Coord minw = -1, minh = -1;
110 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
111 edje_object_size_min_restricted_calc(wd->edje, &minw, &minh, minw, minh);
112 evas_object_size_hint_min_set(obj, minw, minh);
116 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
118 Widget_Data *wd = elm_widget_data_get(obj);
120 elm_widget_mirrored_set(wd->cancel_button, rtl);
121 elm_widget_mirrored_set(wd->ok_button, rtl);
122 elm_widget_mirrored_set(wd->files_list, rtl);
123 elm_widget_mirrored_set(wd->up_button, rtl);
124 elm_widget_mirrored_set(wd->home_button, rtl);
125 edje_object_mirrored_set(wd->edje, rtl);
129 _theme_hook(Evas_Object *obj)
131 Widget_Data *wd = elm_widget_data_get(obj);
132 const char *style = elm_widget_style_get(obj);
137 _elm_widget_mirrored_reload(obj);
139 _elm_theme_object_set(obj, wd->edje, "fileselector", "base", style);
141 if (elm_object_disabled_get(obj))
142 edje_object_signal_emit(wd->edje, "elm,state,disabled", "elm");
144 data = edje_object_data_get(wd->edje, "path_separator");
146 wd->path_separator = data;
148 wd->path_separator = "/";
150 if (!style) style = "default";
151 snprintf(buf, sizeof(buf), "fileselector/%s", style);
153 #define SWALLOW(part_name, object_ptn) \
156 elm_widget_style_set(object_ptn, buf); \
157 if (edje_object_part_swallow(wd->edje, part_name, object_ptn)) \
158 evas_object_show(object_ptn); \
160 evas_object_hide(object_ptn); \
162 SWALLOW("elm.swallow.up", wd->up_button);
163 SWALLOW("elm.swallow.home", wd->home_button);
165 if (wd->mode == ELM_FILESELECTOR_LIST)
167 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
170 evas_object_show(wd->files_list);
171 evas_object_hide(wd->files_grid);
174 evas_object_hide(wd->files_list);
178 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
181 evas_object_show(wd->files_grid);
182 evas_object_hide(wd->files_list);
185 evas_object_hide(wd->files_grid);
188 SWALLOW("elm.swallow.filename", wd->filename_entry);
189 SWALLOW("elm.swallow.path", wd->path_entry);
191 snprintf(buf, sizeof(buf), "fileselector/actions/%s", style);
192 SWALLOW("elm.swallow.cancel", wd->cancel_button);
193 SWALLOW("elm.swallow.ok", wd->ok_button);
196 edje_object_message_signal_process(wd->edje);
197 _mirrored_set(obj, elm_widget_mirrored_get(obj));
198 edje_object_scale_set
199 (wd->edje, elm_widget_scale_get(obj) * _elm_config->scale);
203 /*** GENLIST "MODEL" ***/
205 _itc_label_get(void *data,
206 Evas_Object *obj __UNUSED__,
207 const char *source __UNUSED__)
209 return strdup(ecore_file_file_get(data)); /* NOTE this will be
215 _itc_icon_get(void *data,
221 if (!strcmp(source, "elm.swallow.icon"))
223 const char *filename = data;
225 ic = elm_icon_add(obj);
226 if (ecore_file_is_dir((char *)data))
227 elm_icon_standard_set(ic, "folder");
230 if (evas_object_image_extension_can_load_fast_get(filename))
232 elm_icon_standard_set(ic, "image");
233 elm_icon_thumb_set(ic, filename, NULL);
237 elm_icon_standard_set(ic, "file");
241 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
243 evas_object_show(ic);
250 _itc_state_get(void *data __UNUSED__,
251 Evas_Object *obj __UNUSED__,
252 const char *source __UNUSED__)
259 Evas_Object *obj __UNUSED__)
261 eina_stringshare_del(data);
265 _expand_done(void *data,
266 Evas_Object *obj __UNUSED__,
269 Elm_Genlist_Item *it = event_info;
270 const char *path = elm_genlist_item_data_get(it);
271 _populate(data, path, it);
275 _contract_done(void *data __UNUSED__,
276 Evas_Object *obj __UNUSED__,
279 Elm_Genlist_Item *it = event_info;
280 elm_genlist_item_subitems_clear(it);
284 _expand_req(void *data __UNUSED__,
285 Evas_Object *obj __UNUSED__,
288 Elm_Genlist_Item *it = event_info;
289 elm_genlist_item_expanded_set(it, 1);
293 _contract_req(void *data __UNUSED__,
294 Evas_Object *obj __UNUSED__,
297 Elm_Genlist_Item *it = event_info;
298 elm_genlist_item_expanded_set(it, 0);
311 wd = elm_widget_data_get(sd->fs);
314 if ((!wd->only_folder) && ecore_file_is_dir(path))
316 if (wd->expand && wd->mode == ELM_FILESELECTOR_LIST)
318 _do_anchors(sd->fs, path);
319 elm_entry_entry_set(wd->filename_entry, "");
323 /* keep a ref to path 'couse it will be destroyed by _populate */
324 p = eina_stringshare_add(path);
325 _populate(sd->fs, p, NULL);
326 eina_stringshare_del(p);
330 else /* navigating through folders only or file is not a dir. */
332 if (wd->expand && wd->mode == ELM_FILESELECTOR_LIST)
333 _do_anchors(sd->fs, path);
334 else if (wd->only_folder)
336 /* keep a ref to path 'couse it will be destroyed by _populate */
337 p = eina_stringshare_add(path);
338 _populate(sd->fs, p, NULL);
339 eina_stringshare_del(p);
341 elm_entry_entry_set(wd->filename_entry,
342 ecore_file_file_get(path));
345 evas_object_smart_callback_call(sd->fs, SIG_SELECTED, (void *)path);
348 wd->sel_idler = NULL;
350 return ECORE_CALLBACK_CANCEL;
355 Evas_Object *obj __UNUSED__,
363 wd = elm_widget_data_get(data);
366 sd = malloc(sizeof(*sd));
368 sd->path = wd->mode == ELM_FILESELECTOR_LIST ?
369 elm_genlist_item_data_get(event_info) :
370 elm_gengrid_item_data_get(event_info);
374 eina_stringshare_replace(&wd->path, "");
378 dir = wd->only_folder ? strdup(sd->path) : ecore_file_dir_get(sd->path);
381 eina_stringshare_replace(&wd->path, dir);
386 eina_stringshare_replace(&wd->path, "");
392 old_sd = ecore_idler_del(wd->sel_idler);
395 wd->sel_idler = ecore_idler_add(_sel_do, sd);
400 Evas_Object *obj __UNUSED__,
401 void *event_info __UNUSED__)
403 Evas_Object *fs = data;
406 Widget_Data *wd = elm_widget_data_get(fs);
408 parent = ecore_file_dir_get(wd->path);
409 _populate(fs, parent, NULL);
415 Evas_Object *obj __UNUSED__,
416 void *event_info __UNUSED__)
418 Evas_Object *fs = data;
419 _populate(fs, getenv("HOME"), NULL);
424 Evas_Object *obj __UNUSED__,
425 void *event_info __UNUSED__)
427 Evas_Object *fs = data;
428 evas_object_smart_callback_call(fs, SIG_DONE,
429 (void *)elm_fileselector_selected_get(fs));
434 Evas_Object *obj __UNUSED__,
435 void *event_info __UNUSED__)
437 Evas_Object *fs = data;
438 evas_object_smart_callback_call(fs, SIG_DONE, NULL);
442 _anchor_clicked(void *data,
443 Evas_Object *obj __UNUSED__,
446 Evas_Object *fs = data;
447 Widget_Data *wd = elm_widget_data_get(fs);
448 Elm_Entry_Anchor_Info *info = event_info;
451 // keep a ref to path 'couse it will be destroyed by _populate
452 p = eina_stringshare_add(info->name);
453 _populate(fs, p, NULL);
454 evas_object_smart_callback_call(data, SIG_SELECTED, (void *)p);
455 eina_stringshare_del(p);
459 _do_anchors(Evas_Object *obj,
462 Widget_Data *wd = elm_widget_data_get(obj);
463 char **tok, buf[PATH_MAX * 3];
467 tok = eina_str_split(path, "/", 0);
468 eina_strlcat(buf, "<a href=/>root</a>", sizeof(buf));
469 for (i = 0; tok[i]; i++)
471 if ((!tok[i]) || (!tok[i][0])) continue;
472 eina_strlcat(buf, wd->path_separator, sizeof(buf));
473 eina_strlcat(buf, "<a href=", sizeof(buf));
474 for (j = 0; j <= i; j++)
476 if (strlen(tok[j]) < 1) continue;
477 eina_strlcat(buf, "/", sizeof(buf));
478 eina_strlcat(buf, tok[j], sizeof(buf));
480 eina_strlcat(buf, ">", sizeof(buf));
481 eina_strlcat(buf, tok[i], sizeof(buf));
482 eina_strlcat(buf, "</a>", sizeof(buf));
487 elm_entry_entry_set(wd->path_entry, buf);
491 _populate(Evas_Object *obj,
493 Elm_Genlist_Item *parent)
495 Widget_Data *wd = elm_widget_data_get(obj);
500 Eina_List *files = NULL, *dirs = NULL, *l;
502 if ((!wd) || (!ecore_file_is_dir(path))) return;
505 evas_object_smart_callback_call(obj, SIG_DIRECTORY_OPEN, (void *)path);
508 elm_genlist_clear(wd->files_list);
509 elm_gengrid_clear(wd->files_grid);
510 eina_stringshare_replace(&wd->path, path);
511 _do_anchors(obj, path);
514 if (wd->filename_entry) elm_entry_entry_set(wd->filename_entry, "");
515 while ((dp = readdir(dir)))
517 if (dp->d_name[0] == '.') continue; // TODO make this configurable
519 snprintf(buf, sizeof(buf), "%s/%s", path, dp->d_name);
520 real = ecore_file_realpath(buf); /* TODO: this will resolv
521 * symlinks...I dont like
523 if (ecore_file_is_dir(real))
524 dirs = eina_list_append(dirs, real);
525 else if (!wd->only_folder)
526 files = eina_list_append(files, real);
530 files = eina_list_sort(files, eina_list_count(files),
531 EINA_COMPARE_CB(strcoll));
532 dirs = eina_list_sort(dirs, eina_list_count(dirs), EINA_COMPARE_CB(strcoll));
533 EINA_LIST_FOREACH(dirs, l, real)
535 if (wd->mode == ELM_FILESELECTOR_LIST)
536 elm_genlist_item_append(wd->files_list, &list_itc,
537 eina_stringshare_add(real), /* item data */
539 wd->expand ? ELM_GENLIST_ITEM_SUBITEMS :
540 ELM_GENLIST_ITEM_NONE,
542 else if (wd->mode == ELM_FILESELECTOR_GRID)
543 elm_gengrid_item_append(wd->files_grid, &grid_itc,
544 eina_stringshare_add(real), /* item data */
549 eina_list_free(dirs);
551 EINA_LIST_FOREACH(files, l, real)
553 if (wd->mode == ELM_FILESELECTOR_LIST)
554 elm_genlist_item_append(wd->files_list, &list_itc,
555 eina_stringshare_add(real), /* item data */
556 parent, ELM_GENLIST_ITEM_NONE,
558 else if (wd->mode == ELM_FILESELECTOR_GRID)
559 elm_gengrid_item_append(wd->files_grid, &grid_itc,
560 eina_stringshare_add(real), /* item data */
564 eina_list_free(files);
570 * Add a new Fileselector object
572 * @param parent The parent object
573 * @return The new object or NULL if it cannot be created
575 * @ingroup Fileselector
578 elm_fileselector_add(Evas_Object *parent)
581 Evas_Object *obj, *ic, *bt, *li, *en, *grid;
585 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
587 ELM_SET_WIDTYPE(widtype, "fileselector");
588 elm_widget_type_set(obj, "fileselector");
589 elm_widget_sub_object_add(parent, obj);
590 elm_widget_data_set(obj, wd);
591 elm_widget_del_hook_set(obj, _del_hook);
592 elm_widget_theme_hook_set(obj, _theme_hook);
593 elm_widget_can_focus_set(obj, EINA_FALSE);
595 wd->expand = !!_elm_config->fileselector_expand_enable;
597 wd->edje = edje_object_add(e);
598 _elm_theme_object_set(obj, wd->edje, "fileselector", "base", "default");
599 elm_widget_resize_object_set(obj, wd->edje);
602 ic = elm_icon_add(parent);
603 elm_icon_standard_set(ic, "arrow_up");
604 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
605 bt = elm_button_add(parent);
606 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
607 elm_button_icon_set(bt, ic);
608 elm_button_label_set(bt, E_("Up"));
609 evas_object_size_hint_align_set(bt, 0.0, 0.0);
611 evas_object_smart_callback_add(bt, "clicked", _up, obj);
613 elm_widget_sub_object_add(obj, bt);
617 ic = elm_icon_add(parent);
618 elm_icon_standard_set(ic, "home");
619 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
620 bt = elm_button_add(parent);
621 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
622 elm_button_icon_set(bt, ic);
623 elm_button_label_set(bt, E_("Home"));
624 evas_object_size_hint_align_set(bt, 0.0, 0.0);
626 evas_object_smart_callback_add(bt, "clicked", _home, obj);
628 elm_widget_sub_object_add(obj, bt);
629 wd->home_button = bt;
631 list_itc.item_style = grid_itc.item_style = "default";
632 list_itc.func.label_get = grid_itc.func.label_get = _itc_label_get;
633 list_itc.func.icon_get = grid_itc.func.icon_get = _itc_icon_get;
634 list_itc.func.state_get = grid_itc.func.state_get = _itc_state_get;
635 list_itc.func.del = grid_itc.func.del = _itc_del;
637 li = elm_genlist_add(parent);
638 elm_widget_mirrored_automatic_set(li, EINA_FALSE);
639 evas_object_size_hint_align_set(li, EVAS_HINT_FILL, EVAS_HINT_FILL);
640 evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
641 evas_object_size_hint_min_set(li, 100, 100);
643 grid = elm_gengrid_add(parent);
644 elm_widget_mirrored_automatic_set(grid, EINA_FALSE);
645 evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
646 evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
648 s = elm_finger_size_get() * 2;
649 elm_gengrid_item_size_set(grid, s, s);
650 elm_gengrid_align_set(grid, 0.0, 0.0);
652 evas_object_smart_callback_add(li, "selected", _sel, obj);
653 evas_object_smart_callback_add(li, "expand,request", _expand_req, obj);
654 evas_object_smart_callback_add(li, "contract,request", _contract_req, obj);
655 evas_object_smart_callback_add(li, "expanded", _expand_done, obj);
656 evas_object_smart_callback_add(li, "contracted", _contract_done, obj);
658 evas_object_smart_callback_add(grid, "selected", _sel, obj);
660 elm_widget_sub_object_add(obj, li);
661 elm_widget_sub_object_add(obj, grid);
663 wd->files_grid = grid;
666 en = elm_entry_add(parent);
667 elm_entry_scrollable_set(en, EINA_TRUE);
668 elm_widget_mirrored_automatic_set(en, EINA_FALSE);
669 elm_entry_editable_set(en, EINA_FALSE);
670 elm_entry_single_line_set(en, EINA_TRUE);
671 elm_entry_line_wrap_set(en, ELM_WRAP_CHAR);
672 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
673 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
675 evas_object_smart_callback_add(en, "anchor,clicked", _anchor_clicked, obj);
677 elm_widget_sub_object_add(obj, en);
681 en = elm_entry_add(parent);
682 elm_entry_scrollable_set(en, EINA_TRUE);
683 elm_widget_mirrored_automatic_set(en, EINA_FALSE);
684 elm_entry_editable_set(en, EINA_TRUE);
685 elm_entry_single_line_set(en, EINA_TRUE);
686 elm_entry_line_wrap_set(en, ELM_WRAP_CHAR);
687 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
688 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
690 elm_widget_sub_object_add(obj, en);
691 wd->filename_entry = en;
693 elm_fileselector_buttons_ok_cancel_set(obj, EINA_TRUE);
694 elm_fileselector_is_save_set(obj, EINA_FALSE);
698 evas_object_smart_callbacks_descriptions_set(obj, _signals);
703 * This enables/disables the file name entry box where the user can
704 * type in a name for the file to be saved as.
706 * @param obj The fileselector object
707 * @param is_save If true, the fileselector is a save dialog
709 * @ingroup Fileselector
712 elm_fileselector_is_save_set(Evas_Object *obj,
715 ELM_CHECK_WIDTYPE(obj, widtype);
716 Widget_Data *wd = elm_widget_data_get(obj);
719 elm_object_disabled_set(wd->filename_entry, !is_save);
722 edje_object_signal_emit(wd->edje, "elm,state,save,on", "elm");
724 edje_object_signal_emit(wd->edje, "elm,state,save,off", "elm");
728 * This returns whether the fileselector is a "save" type fileselector
730 * @param obj The fileselector object
731 * @return If true, the fileselector is a save type.
733 * @ingroup Fileselector
736 elm_fileselector_is_save_get(const Evas_Object *obj)
738 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
739 Widget_Data *wd = elm_widget_data_get(obj);
740 if (!wd) return EINA_FALSE;
741 return elm_object_disabled_get(wd->filename_entry);
745 * This enables/disables folder-only view in the fileselector.
747 * @param obj The fileselector object
748 * @param only If true, the fileselector will only display directories.
749 * If false, files are displayed also.
751 * @ingroup Fileselector
754 elm_fileselector_folder_only_set(Evas_Object *obj,
757 ELM_CHECK_WIDTYPE(obj, widtype);
758 Widget_Data *wd = elm_widget_data_get(obj);
760 if (wd->only_folder == only) return;
761 wd->only_folder = !!only;
762 if (wd->path) _populate(obj, wd->path, NULL);
766 * This gets the state of file display in the fileselector.
768 * @param obj The fileselector object
769 * @return If true, files are not being shown in the fileselector.
770 * If false, files are being shown.
772 * @ingroup Fileselector
775 elm_fileselector_folder_only_get(const Evas_Object *obj)
777 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
778 Widget_Data *wd = elm_widget_data_get(obj);
779 if (!wd) return EINA_FALSE;
780 return wd->only_folder;
784 * This enables/disables the ok,cancel buttons.
786 * @param obj The fileselector object
787 * @param only If true, a box containing ok and cancel buttons is created.
788 * If false, the box and the buttons are destroyed.
790 * @ingroup Fileselector
793 elm_fileselector_buttons_ok_cancel_set(Evas_Object *obj,
796 ELM_CHECK_WIDTYPE(obj, widtype);
797 Widget_Data *wd = elm_widget_data_get(obj);
804 bt = elm_button_add(obj);
805 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
806 elm_button_label_set(bt, E_("Cancel"));
808 evas_object_smart_callback_add(bt, "clicked", _canc, obj);
810 elm_widget_sub_object_add(obj, bt);
811 wd->cancel_button = bt;
814 bt = elm_button_add(obj);
815 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
816 elm_button_label_set(bt, E_("OK"));
818 evas_object_smart_callback_add(bt, "clicked", _ok, obj);
820 elm_widget_sub_object_add(obj, bt);
827 evas_object_del(wd->cancel_button);
828 wd->cancel_button = NULL;
829 evas_object_del(wd->ok_button);
830 wd->ok_button = NULL;
835 * This gets the state of the box containing ok and cancel buttons.
837 * @param obj The fileselector object
838 * @return If true, the box exists.
839 * If false, the box does not exist.
841 * @ingroup Fileselector
844 elm_fileselector_buttons_ok_cancel_get(const Evas_Object *obj)
846 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
847 Widget_Data *wd = elm_widget_data_get(obj);
848 if (!wd) return EINA_FALSE;
849 return wd->ok_button ? EINA_TRUE : EINA_FALSE;
853 * This enables a tree view in the fileselector, <b>if in @c
854 * ELM_FILESELECTOR_LIST mode</b>. If it's in other mode, the changes
855 * made by this function will only be visible when one switches back
858 * @param obj The fileselector object
859 * @param expand If true, tree view is enabled.
860 * If false, tree view is disabled.
862 * In a tree view, arrows are created on the sides of directories,
863 * allowing them to expand in place.
865 * @ingroup Fileselector
868 elm_fileselector_expandable_set(Evas_Object *obj,
871 ELM_CHECK_WIDTYPE(obj, widtype);
874 wd = elm_widget_data_get(obj);
877 wd->expand = !!expand;
879 if (wd->path) _populate(obj, wd->path, NULL);
883 * This gets the state of tree view in the fileselector.
885 * @param obj The fileselector object
886 * @return If true, tree view is enabled and folders will be expandable.
887 * If false, tree view is disabled.
889 * @ingroup Fileselector
892 elm_fileselector_expandable_get(const Evas_Object *obj)
894 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
895 Widget_Data *wd = elm_widget_data_get(obj);
896 if (!wd) return EINA_FALSE;
901 * This sets the path that the fileselector will display.
903 * @param obj The fileselector object
904 * @param path The path of the fileselector
906 * @ingroup Fileselector
909 elm_fileselector_path_set(Evas_Object *obj,
912 ELM_CHECK_WIDTYPE(obj, widtype);
913 _populate(obj, path, NULL);
917 * This gets the path that the fileselector displays.
919 * @param obj The fileselector object
920 * @return The path that the fileselector is displaying
922 * @ingroup Fileselector
925 elm_fileselector_path_get(const Evas_Object *obj)
927 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
928 Widget_Data *wd = elm_widget_data_get(obj);
929 if (!wd) return NULL;
934 * This sets the mode in which the fileselector will display files.
936 * @param obj The fileselector object
938 * @param mode The mode of the fileselector, being it one of @c
939 * ELM_FILESELECTOR_LIST (default) or @c ELM_FILESELECTOR_GRID. The
940 * first one, naturally, will display the files in a list. By using
941 * elm_fileselector_expandable_set(), the user will trigger a tree
942 * view for that list. The latter will make the widget to display its
943 * entries in a grid form.
945 * @see elm_fileselector_expandable_set().
947 * @ingroup Fileselector
950 elm_fileselector_mode_set(Evas_Object *obj,
951 Elm_Fileselector_Mode mode)
953 ELM_CHECK_WIDTYPE(obj, widtype);
955 Widget_Data *wd = elm_widget_data_get(obj);
958 if (mode == wd->mode) return;
960 if (mode == ELM_FILESELECTOR_LIST)
962 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
965 evas_object_show(wd->files_list);
966 evas_object_hide(wd->files_grid);
969 evas_object_hide(wd->files_list);
973 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
976 evas_object_show(wd->files_grid);
977 evas_object_hide(wd->files_list);
980 evas_object_hide(wd->files_grid);
985 _populate(obj, wd->path, NULL);
989 * This gets the mode in which the fileselector is displaying files.
991 * @param obj The fileselector object
992 * @return The mode in which the fileselector is at
994 * @ingroup Fileselector
996 EAPI Elm_Fileselector_Mode
997 elm_fileselector_mode_get(const Evas_Object *obj)
999 ELM_CHECK_WIDTYPE(obj, widtype) ELM_FILESELECTOR_LAST;
1001 Widget_Data *wd = elm_widget_data_get(obj);
1002 if (!wd) return ELM_FILESELECTOR_LAST;
1008 * This gets the currently selected path in the file selector.
1010 * @param obj The file selector object
1011 * @return The absolute path of the selected object in the fileselector
1013 * @ingroup Fileselector
1016 elm_fileselector_selected_get(const Evas_Object *obj)
1018 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1019 Widget_Data *wd = elm_widget_data_get(obj);
1020 if (!wd) return NULL;
1022 if (wd->filename_entry)
1027 name = elm_entry_entry_get(wd->filename_entry);
1028 snprintf(buf, sizeof(buf), "%s/%s",
1029 wd->only_folder ? ecore_file_dir_get(wd->path) : wd->path,
1031 eina_stringshare_replace(&wd->selection, buf);
1032 return wd->selection;
1035 if (wd->mode == ELM_FILESELECTOR_LIST)
1037 Elm_Genlist_Item *it;
1038 it = elm_genlist_selected_item_get(wd->files_list);
1039 if (it) return elm_genlist_item_data_get(it);
1043 Elm_Gengrid_Item *it;
1044 it = elm_gengrid_selected_item_get(wd->files_grid);
1045 if (it) return elm_gengrid_item_data_get(it);
1052 * This sets the currently selected path in the file selector.
1054 * @param obj The file selector object
1055 * @param path The path to a file or directory
1056 * @return @c EINA_TRUE on success, @c EINA_FALSE on failure. The
1057 * latter case occurs if the directory or file pointed to do not
1060 * @ingroup Fileselector
1063 elm_fileselector_selected_set(Evas_Object *obj,
1066 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1067 Widget_Data *wd = elm_widget_data_get(obj);
1068 if (!wd) return EINA_FALSE;
1070 if (ecore_file_is_dir(path))
1071 _populate(obj, path, NULL);
1074 if (!ecore_file_exists(path))
1077 _populate(obj, ecore_file_dir_get(path), NULL);
1078 if (wd->filename_entry)
1080 elm_entry_entry_set(wd->filename_entry,
1081 ecore_file_file_get(path));
1082 eina_stringshare_replace(&wd->selection, path);