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 _theme_hook(Evas_Object *obj)
118 Widget_Data *wd = elm_widget_data_get(obj);
119 const char *style = elm_widget_style_get(obj);
124 _elm_theme_object_set(obj, wd->edje, "fileselector", "base", style);
126 if (elm_object_disabled_get(obj))
127 edje_object_signal_emit(wd->edje, "elm,state,disabled", "elm");
129 data = edje_object_data_get(wd->edje, "path_separator");
131 wd->path_separator = data;
133 wd->path_separator = "/";
135 if (!style) style = "default";
136 snprintf(buf, sizeof(buf), "fileselector/%s", style);
138 #define SWALLOW(part_name, object_ptn) \
141 elm_widget_style_set(object_ptn, buf); \
142 if (edje_object_part_swallow(wd->edje, part_name, object_ptn)) \
143 evas_object_show(object_ptn); \
145 evas_object_hide(object_ptn); \
147 SWALLOW("elm.swallow.up", wd->up_button);
148 SWALLOW("elm.swallow.home", wd->home_button);
150 if (wd->mode == ELM_FILESELECTOR_LIST)
152 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
155 evas_object_show(wd->files_list);
156 evas_object_hide(wd->files_grid);
159 evas_object_hide(wd->files_list);
163 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
166 evas_object_show(wd->files_grid);
167 evas_object_hide(wd->files_list);
170 evas_object_hide(wd->files_grid);
173 SWALLOW("elm.swallow.filename", wd->filename_entry);
174 SWALLOW("elm.swallow.path", wd->path_entry);
176 snprintf(buf, sizeof(buf), "fileselector/actions/%s", style);
177 SWALLOW("elm.swallow.cancel", wd->cancel_button);
178 SWALLOW("elm.swallow.ok", wd->ok_button);
181 edje_object_message_signal_process(wd->edje);
182 edje_object_scale_set
183 (wd->edje, elm_widget_scale_get(obj) * _elm_config->scale);
187 /*** GENLIST "MODEL" ***/
189 _itc_label_get(void *data,
190 Evas_Object *obj __UNUSED__,
191 const char *source __UNUSED__)
193 return strdup(ecore_file_file_get(data)); /* NOTE this will be
199 _itc_icon_get(void *data,
205 if (!strcmp(source, "elm.swallow.icon"))
207 ic = elm_icon_add(obj);
208 if (ecore_file_is_dir((char *)data))
209 elm_icon_standard_set(ic, "folder");
211 elm_icon_standard_set(ic, "file");
212 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
214 evas_object_show(ic);
221 _itc_state_get(void *data __UNUSED__,
222 Evas_Object *obj __UNUSED__,
223 const char *source __UNUSED__)
230 Evas_Object *obj __UNUSED__)
232 eina_stringshare_del(data);
236 _expand_done(void *data,
237 Evas_Object *obj __UNUSED__,
240 Elm_Genlist_Item *it = event_info;
241 const char *path = elm_genlist_item_data_get(it);
242 _populate(data, path, it);
246 _contract_done(void *data __UNUSED__,
247 Evas_Object *obj __UNUSED__,
250 Elm_Genlist_Item *it = event_info;
251 elm_genlist_item_subitems_clear(it);
255 _expand_req(void *data __UNUSED__,
256 Evas_Object *obj __UNUSED__,
259 Elm_Genlist_Item *it = event_info;
260 elm_genlist_item_expanded_set(it, 1);
264 _contract_req(void *data __UNUSED__,
265 Evas_Object *obj __UNUSED__,
268 Elm_Genlist_Item *it = event_info;
269 elm_genlist_item_expanded_set(it, 0);
282 wd = elm_widget_data_get(sd->fs);
285 if ((!wd->only_folder) && ecore_file_is_dir(path))
287 if (wd->expand && wd->mode == ELM_FILESELECTOR_LIST)
289 _do_anchors(sd->fs, path);
290 elm_scrolled_entry_entry_set(wd->filename_entry, "");
294 /* keep a ref to path 'couse it will be destroyed by _populate */
295 p = eina_stringshare_add(path);
296 _populate(sd->fs, p, NULL);
297 eina_stringshare_del(p);
301 else /* navigating through folders only or file is not a dir. */
303 if (wd->expand && wd->mode == ELM_FILESELECTOR_LIST)
304 _do_anchors(sd->fs, path);
305 else if (wd->only_folder)
307 /* keep a ref to path 'couse it will be destroyed by _populate */
308 p = eina_stringshare_add(path);
309 _populate(sd->fs, p, NULL);
310 eina_stringshare_del(p);
312 elm_scrolled_entry_entry_set(wd->filename_entry,
313 ecore_file_file_get(path));
316 evas_object_smart_callback_call(sd->fs, SIG_SELECTED, (void *)path);
319 wd->sel_idler = NULL;
321 return ECORE_CALLBACK_CANCEL;
326 Evas_Object *obj __UNUSED__,
334 wd = elm_widget_data_get(data);
337 sd = malloc(sizeof(*sd));
339 sd->path = wd->mode == ELM_FILESELECTOR_LIST ?
340 elm_genlist_item_data_get(event_info) :
341 elm_gengrid_item_data_get(event_info);
345 eina_stringshare_replace(&wd->path, "");
349 dir = wd->only_folder ? strdup(sd->path) : ecore_file_dir_get(sd->path);
352 eina_stringshare_replace(&wd->path, dir);
357 eina_stringshare_replace(&wd->path, "");
363 old_sd = ecore_idler_del(wd->sel_idler);
366 wd->sel_idler = ecore_idler_add(_sel_do, sd);
371 Evas_Object *obj __UNUSED__,
372 void *event_info __UNUSED__)
374 Evas_Object *fs = data;
377 Widget_Data *wd = elm_widget_data_get(fs);
379 parent = ecore_file_dir_get(wd->path);
380 _populate(fs, parent, NULL);
386 Evas_Object *obj __UNUSED__,
387 void *event_info __UNUSED__)
389 Evas_Object *fs = data;
390 _populate(fs, getenv("HOME"), NULL);
395 Evas_Object *obj __UNUSED__,
396 void *event_info __UNUSED__)
398 Evas_Object *fs = data;
399 evas_object_smart_callback_call(fs, SIG_DONE,
400 (void *)elm_fileselector_selected_get(fs));
405 Evas_Object *obj __UNUSED__,
406 void *event_info __UNUSED__)
408 Evas_Object *fs = data;
409 evas_object_smart_callback_call(fs, SIG_DONE, NULL);
413 _anchor_clicked(void *data,
414 Evas_Object *obj __UNUSED__,
417 Evas_Object *fs = data;
418 Widget_Data *wd = elm_widget_data_get(fs);
419 Elm_Entry_Anchor_Info *info = event_info;
422 // keep a ref to path 'couse it will be destroyed by _populate
423 p = eina_stringshare_add(info->name);
424 _populate(fs, p, NULL);
425 evas_object_smart_callback_call(data, SIG_SELECTED, (void *)p);
426 eina_stringshare_del(p);
430 _do_anchors(Evas_Object *obj,
433 Widget_Data *wd = elm_widget_data_get(obj);
434 char **tok, buf[PATH_MAX * 3];
438 tok = eina_str_split(path, "/", 0);
439 eina_strlcat(buf, "<a href=/>root</a>", sizeof(buf));
440 for (i = 0; tok[i]; i++)
442 if ((!tok[i]) || (!tok[i][0])) continue;
443 eina_strlcat(buf, wd->path_separator, sizeof(buf));
444 eina_strlcat(buf, "<a href=", sizeof(buf));
445 for (j = 0; j <= i; j++)
447 if (strlen(tok[j]) < 1) continue;
448 eina_strlcat(buf, "/", sizeof(buf));
449 eina_strlcat(buf, tok[j], sizeof(buf));
451 eina_strlcat(buf, ">", sizeof(buf));
452 eina_strlcat(buf, tok[i], sizeof(buf));
453 eina_strlcat(buf, "</a>", sizeof(buf));
458 elm_scrolled_entry_entry_set(wd->path_entry, buf);
462 _populate(Evas_Object *obj,
464 Elm_Genlist_Item *parent)
466 Widget_Data *wd = elm_widget_data_get(obj);
471 Eina_List *files = NULL, *dirs = NULL, *l;
473 if ((!wd) || (!ecore_file_is_dir(path))) return;
476 evas_object_smart_callback_call(obj, SIG_DIRECTORY_OPEN, (void *)path);
479 elm_genlist_clear(wd->files_list);
480 elm_gengrid_clear(wd->files_grid);
481 eina_stringshare_replace(&wd->path, path);
482 _do_anchors(obj, path);
485 if (wd->filename_entry) elm_scrolled_entry_entry_set(wd->filename_entry, "");
486 while ((dp = readdir(dir)))
488 if (dp->d_name[0] == '.') continue; // TODO make this configurable
490 snprintf(buf, sizeof(buf), "%s/%s", path, dp->d_name);
491 real = ecore_file_realpath(buf); /* TODO: this will resolv
492 * symlinks...I dont like
494 if (ecore_file_is_dir(real))
495 dirs = eina_list_append(dirs, real);
496 else if (!wd->only_folder)
497 files = eina_list_append(files, real);
501 files = eina_list_sort(files, eina_list_count(files),
502 EINA_COMPARE_CB(strcoll));
503 dirs = eina_list_sort(dirs, eina_list_count(dirs), EINA_COMPARE_CB(strcoll));
504 EINA_LIST_FOREACH(dirs, l, real)
506 if (wd->mode == ELM_FILESELECTOR_LIST)
507 elm_genlist_item_append(wd->files_list, &list_itc,
508 eina_stringshare_add(real), /* item data */
510 wd->expand ? ELM_GENLIST_ITEM_SUBITEMS :
511 ELM_GENLIST_ITEM_NONE,
513 else if (wd->mode == ELM_FILESELECTOR_GRID)
514 elm_gengrid_item_append(wd->files_grid, &grid_itc,
515 eina_stringshare_add(real), /* item data */
520 eina_list_free(dirs);
522 EINA_LIST_FOREACH(files, l, real)
524 if (wd->mode == ELM_FILESELECTOR_LIST)
525 elm_genlist_item_append(wd->files_list, &list_itc,
526 eina_stringshare_add(real), /* item data */
527 parent, ELM_GENLIST_ITEM_NONE,
529 else if (wd->mode == ELM_FILESELECTOR_GRID)
530 elm_gengrid_item_append(wd->files_grid, &grid_itc,
531 eina_stringshare_add(real), /* item data */
535 eina_list_free(files);
541 * Add a new Fileselector object
543 * @param parent The parent object
544 * @return The new object or NULL if it cannot be created
546 * @ingroup Fileselector
549 elm_fileselector_add(Evas_Object *parent)
551 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
553 Evas *e = evas_object_evas_get(parent);
555 Evas_Object *obj, *ic, *bt, *li, *en, *grid;
560 wd = ELM_NEW(Widget_Data);
561 wd->expand = !!_elm_config->fileselector_expand_enable;
562 obj = elm_widget_add(evas_object_evas_get(parent));
563 ELM_SET_WIDTYPE(widtype, "fileselector");
564 elm_widget_type_set(obj, "fileselector");
565 elm_widget_sub_object_add(parent, obj);
566 elm_widget_data_set(obj, wd);
567 elm_widget_del_hook_set(obj, _del_hook);
568 elm_widget_theme_hook_set(obj, _theme_hook);
569 elm_widget_can_focus_set(obj, EINA_FALSE);
571 wd->edje = edje_object_add(e);
572 _elm_theme_object_set(obj, wd->edje, "fileselector", "base", "default");
573 elm_widget_resize_object_set(obj, wd->edje);
576 ic = elm_icon_add(parent);
577 elm_icon_standard_set(ic, "arrow_up");
578 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
579 bt = elm_button_add(parent);
580 elm_button_icon_set(bt, ic);
581 elm_button_label_set(bt, "Up");
582 evas_object_size_hint_align_set(bt, 0.0, 0.0);
584 evas_object_smart_callback_add(bt, "clicked", _up, obj);
586 elm_widget_sub_object_add(obj, bt);
590 ic = elm_icon_add(parent);
591 elm_icon_standard_set(ic, "home");
592 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
593 bt = elm_button_add(parent);
594 elm_button_icon_set(bt, ic);
595 elm_button_label_set(bt, "Home");
596 evas_object_size_hint_align_set(bt, 0.0, 0.0);
598 evas_object_smart_callback_add(bt, "clicked", _home, obj);
600 elm_widget_sub_object_add(obj, bt);
601 wd->home_button = bt;
603 list_itc.item_style = grid_itc.item_style = "default";
604 list_itc.func.label_get = grid_itc.func.label_get = _itc_label_get;
605 list_itc.func.icon_get = grid_itc.func.icon_get = _itc_icon_get;
606 list_itc.func.state_get = grid_itc.func.state_get = _itc_state_get;
607 list_itc.func.del = grid_itc.func.del = _itc_del;
609 li = elm_genlist_add(parent);
610 evas_object_size_hint_align_set(li, EVAS_HINT_FILL, EVAS_HINT_FILL);
611 evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
612 evas_object_size_hint_min_set(li, 100, 100);
614 grid = elm_gengrid_add(parent);
615 evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
616 evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
618 s = elm_finger_size_get() * 2;
619 elm_gengrid_item_size_set(grid, s, s);
620 elm_gengrid_align_set(grid, 0.0, 0.0);
622 evas_object_smart_callback_add(li, "selected", _sel, obj);
623 evas_object_smart_callback_add(li, "expand,request", _expand_req, obj);
624 evas_object_smart_callback_add(li, "contract,request", _contract_req, obj);
625 evas_object_smart_callback_add(li, "expanded", _expand_done, obj);
626 evas_object_smart_callback_add(li, "contracted", _contract_done, obj);
628 evas_object_smart_callback_add(grid, "selected", _sel, obj);
630 elm_widget_sub_object_add(obj, li);
631 elm_widget_sub_object_add(obj, grid);
633 wd->files_grid = grid;
636 en = elm_scrolled_entry_add(parent);
637 elm_scrolled_entry_editable_set(en, EINA_FALSE);
638 elm_scrolled_entry_single_line_set(en, EINA_TRUE);
639 elm_scrolled_entry_line_char_wrap_set(en, EINA_TRUE);
640 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
641 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
643 evas_object_smart_callback_add(en, "anchor,clicked", _anchor_clicked, obj);
645 elm_widget_sub_object_add(obj, en);
649 en = elm_scrolled_entry_add(parent);
650 elm_scrolled_entry_editable_set(en, EINA_TRUE);
651 elm_scrolled_entry_single_line_set(en, EINA_TRUE);
652 elm_scrolled_entry_line_char_wrap_set(en, EINA_TRUE);
653 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
654 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
656 elm_widget_sub_object_add(obj, en);
657 wd->filename_entry = en;
659 elm_fileselector_buttons_ok_cancel_set(obj, EINA_TRUE);
660 elm_fileselector_is_save_set(obj, EINA_FALSE);
664 evas_object_smart_callbacks_descriptions_set(obj, _signals);
669 * This enables/disables the file name entry box where the user can
670 * type in a name for the file to be saved as.
672 * @param obj The fileselector object
673 * @param is_save If true, the fileselector is a save dialog
675 * @ingroup Fileselector
678 elm_fileselector_is_save_set(Evas_Object *obj,
681 ELM_CHECK_WIDTYPE(obj, widtype);
682 Widget_Data *wd = elm_widget_data_get(obj);
685 elm_object_disabled_set(wd->filename_entry, is_save);
688 edje_object_signal_emit(wd->edje, "elm,state,save,on", "elm");
690 edje_object_signal_emit(wd->edje, "elm,state,save,off", "elm");
694 * This returns whether the fileselector is a "save" type fileselector
696 * @param obj The fileselector object
697 * @return If true, the fileselector is a save type.
699 * @ingroup Fileselector
702 elm_fileselector_is_save_get(const Evas_Object *obj)
704 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
705 Widget_Data *wd = elm_widget_data_get(obj);
706 if (!wd) return EINA_FALSE;
707 return elm_object_disabled_get(wd->filename_entry);
711 * This enables/disables folder-only view in the fileselector.
713 * @param obj The fileselector object
714 * @param only If true, the fileselector will only display directories.
715 * If false, files are displayed also.
717 * @ingroup Fileselector
720 elm_fileselector_folder_only_set(Evas_Object *obj,
723 ELM_CHECK_WIDTYPE(obj, widtype);
724 Widget_Data *wd = elm_widget_data_get(obj);
726 if (wd->only_folder == only) return;
727 wd->only_folder = !!only;
728 if (wd->path) _populate(obj, wd->path, NULL);
732 * This gets the state of file display in the fileselector.
734 * @param obj The fileselector object
735 * @return If true, files are not being shown in the fileselector.
736 * If false, files are being shown.
738 * @ingroup Fileselector
741 elm_fileselector_folder_only_get(const Evas_Object *obj)
743 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
744 Widget_Data *wd = elm_widget_data_get(obj);
745 if (!wd) return EINA_FALSE;
746 return wd->only_folder;
750 * This enables/disables the ok,cancel buttons.
752 * @param obj The fileselector object
753 * @param only If true, a box containing ok and cancel buttons is created.
754 * If false, the box and the buttons are destroyed.
756 * @ingroup Fileselector
759 elm_fileselector_buttons_ok_cancel_set(Evas_Object *obj,
762 ELM_CHECK_WIDTYPE(obj, widtype);
763 Widget_Data *wd = elm_widget_data_get(obj);
770 bt = elm_button_add(obj);
771 elm_button_label_set(bt, "Cancel");
773 evas_object_smart_callback_add(bt, "clicked", _canc, obj);
775 elm_widget_sub_object_add(obj, bt);
776 wd->cancel_button = bt;
779 bt = elm_button_add(obj);
780 elm_button_label_set(bt, "OK");
782 evas_object_smart_callback_add(bt, "clicked", _ok, obj);
784 elm_widget_sub_object_add(obj, bt);
791 evas_object_del(wd->cancel_button);
792 wd->cancel_button = NULL;
793 evas_object_del(wd->ok_button);
794 wd->ok_button = NULL;
799 * This gets the state of the box containing ok and cancel buttons.
801 * @param obj The fileselector object
802 * @return If true, the box exists.
803 * If false, the box does not exist.
805 * @ingroup Fileselector
808 elm_fileselector_buttons_ok_cancel_get(const Evas_Object *obj)
810 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
811 Widget_Data *wd = elm_widget_data_get(obj);
812 if (!wd) return EINA_FALSE;
813 return wd->ok_button ? EINA_TRUE : EINA_FALSE;
817 * This enables a tree view in the fileselector, <b>if in @c
818 * ELM_FILESELECTOR_LIST mode</b>. If it's in other mode, the changes
819 * made by this function will only be visible when one switches back
822 * @param obj The fileselector object
823 * @param expand If true, tree view is enabled.
824 * If false, tree view is disabled.
826 * In a tree view, arrows are created on the sides of directories,
827 * allowing them to expand in place.
829 * @ingroup Fileselector
832 elm_fileselector_expandable_set(Evas_Object *obj,
835 ELM_CHECK_WIDTYPE(obj, widtype);
838 wd = elm_widget_data_get(obj);
841 wd->expand = !!expand;
843 if (wd->path) _populate(obj, wd->path, NULL);
847 * This gets the state of tree view in the fileselector.
849 * @param obj The fileselector object
850 * @return If true, tree view is enabled and folders will be expandable.
851 * If false, tree view is disabled.
853 * @ingroup Fileselector
856 elm_fileselector_expandable_get(const Evas_Object *obj)
858 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
859 Widget_Data *wd = elm_widget_data_get(obj);
860 if (!wd) return EINA_FALSE;
865 * This sets the path that the fileselector will display.
867 * @param obj The fileselector object
868 * @param path The path of the fileselector
870 * @ingroup Fileselector
873 elm_fileselector_path_set(Evas_Object *obj,
876 ELM_CHECK_WIDTYPE(obj, widtype);
877 _populate(obj, path, NULL);
881 * This gets the path that the fileselector displays.
883 * @param obj The fileselector object
884 * @return The path that the fileselector is displaying
886 * @ingroup Fileselector
889 elm_fileselector_path_get(const Evas_Object *obj)
891 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
892 Widget_Data *wd = elm_widget_data_get(obj);
893 if (!wd) return NULL;
898 * This sets the mode in which the fileselector will display files.
900 * @param obj The fileselector object
902 * @param mode The mode of the fileselector, being it one of @c
903 * ELM_FILESELECTOR_LIST (default) or @c ELM_FILESELECTOR_GRID. The
904 * first one, naturally, will display the files in a list. By using
905 * elm_fileselector_expandable_set(), the user will trigger a tree
906 * view for that list. The latter will make the widget to display its
907 * entries in a grid form.
909 * @see elm_fileselector_expandable_set().
911 * @ingroup Fileselector
914 elm_fileselector_mode_set(Evas_Object *obj,
915 Elm_Fileselector_Mode mode)
917 ELM_CHECK_WIDTYPE(obj, widtype);
919 Widget_Data *wd = elm_widget_data_get(obj);
922 if (mode == wd->mode) return;
924 if (mode == ELM_FILESELECTOR_LIST)
926 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
929 evas_object_show(wd->files_list);
930 evas_object_hide(wd->files_grid);
933 evas_object_hide(wd->files_list);
937 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
940 evas_object_show(wd->files_grid);
941 evas_object_hide(wd->files_list);
944 evas_object_hide(wd->files_grid);
949 _populate(obj, wd->path, NULL);
953 * This gets the mode in which the fileselector is displaying files.
955 * @param obj The fileselector object
956 * @return The mode in which the fileselector is at
958 * @ingroup Fileselector
960 EAPI Elm_Fileselector_Mode
961 elm_fileselector_mode_get(const Evas_Object *obj)
963 ELM_CHECK_WIDTYPE(obj, widtype) ELM_FILESELECTOR_LAST;
965 Widget_Data *wd = elm_widget_data_get(obj);
966 if (!wd) return ELM_FILESELECTOR_LAST;
972 * This gets the currently selected path in the file selector.
974 * @param obj The file selector object
975 * @return The absolute path of the selected object in the fileselector
977 * @ingroup Fileselector
980 elm_fileselector_selected_get(const Evas_Object *obj)
982 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
983 Widget_Data *wd = elm_widget_data_get(obj);
984 if (!wd) return NULL;
986 if (wd->filename_entry)
991 name = elm_scrolled_entry_entry_get(wd->filename_entry);
992 snprintf(buf, sizeof(buf), "%s/%s",
993 wd->only_folder ? ecore_file_dir_get(wd->path) : wd->path,
995 eina_stringshare_replace(&wd->selection, buf);
996 return wd->selection;
999 if (wd->mode == ELM_FILESELECTOR_LIST)
1001 Elm_Genlist_Item *it;
1002 it = elm_genlist_selected_item_get(wd->files_list);
1003 if (it) return elm_genlist_item_data_get(it);
1007 Elm_Gengrid_Item *it;
1008 it = elm_gengrid_selected_item_get(wd->files_grid);
1009 if (it) return elm_gengrid_item_data_get(it);
1016 * This sets the currently selected path in the file selector.
1018 * @param obj The file selector object
1019 * @param path The path to a file or directory
1020 * @return @c EINA_TRUE on success, @c EINA_FALSE on failure. The
1021 * latter case occurs if the directory or file pointed to do not
1024 * @ingroup Fileselector
1027 elm_fileselector_selected_set(Evas_Object *obj,
1030 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1031 Widget_Data *wd = elm_widget_data_get(obj);
1032 if (!wd) return EINA_FALSE;
1034 if (ecore_file_is_dir(path))
1035 _populate(obj, path, NULL);
1038 if (!ecore_file_exists(path))
1041 _populate(obj, ecore_file_dir_get(path), NULL);
1042 if (wd->filename_entry)
1044 elm_scrolled_entry_entry_set(wd->filename_entry,
1045 ecore_file_file_get(path));
1046 eina_stringshare_replace(&wd->selection, path);