3 * - child elements focusing support
4 * - user defined icon/label cb
5 * - show/hide/add buttons ???
6 * - show/hide hidden files
7 * - double click to choose a file
9 * - make variable/function names that are sensible
14 # include "elementary_config.h"
21 #include <Elementary.h>
24 typedef struct _Widget_Data Widget_Data;
31 Evas_Object *filename_entry;
32 Evas_Object *path_entry;
33 Evas_Object *files_list;
34 Evas_Object *files_grid;
35 Evas_Object *up_button;
36 Evas_Object *home_button;
38 Evas_Object *ok_button;
39 Evas_Object *cancel_button;
42 const char *selection;
43 Ecore_Idler *sel_idler;
45 const char *path_separator;
51 Elm_Fileselector_Mode mode;
53 Eina_Bool only_folder : 1;
63 typedef struct _Widget_Request Widget_Request;
64 struct _Widget_Request
67 Elm_Object_Item *parent;
79 } Elm_Fileselector_Type;
81 static Elm_Genlist_Item_Class *list_itc[ELM_FILE_LAST];
82 static Elm_Gengrid_Item_Class *grid_itc[ELM_FILE_LAST];
84 static const char *widtype = NULL;
86 static const char SIG_DIRECTORY_OPEN[] = "directory,open";
87 static const char SIG_DONE[] = "done";
88 static const char SIG_SELECTED[] = "selected";
89 static const Evas_Smart_Cb_Description _signals[] = {
90 {SIG_DIRECTORY_OPEN, "s"},
96 static void _populate(Evas_Object *obj,
98 Elm_Object_Item *parent);
99 static void _do_anchors(Evas_Object *obj,
102 /*** ELEMENTARY WIDGET ***/
104 _widget_data_free(Widget_Data *wd)
106 if (wd->path) eina_stringshare_del(wd->path);
107 if (wd->selection) eina_stringshare_del(wd->selection);
112 sd = ecore_idler_del(wd->sel_idler);
119 _del_hook(Evas_Object *obj)
124 wd = elm_widget_data_get(obj);
127 for (i = 0; i < ELM_FILE_LAST; ++i)
129 elm_genlist_item_class_free(list_itc[i]);
130 elm_gengrid_item_class_free(grid_itc[i]);
135 eio_file_cancel(wd->current);
138 wd->files_list = NULL;
139 wd->files_grid = NULL;
141 EINA_REFCOUNT_UNREF(wd)
142 _widget_data_free(wd);
146 _sizing_eval(Evas_Object *obj)
148 Widget_Data *wd = elm_widget_data_get(obj);
149 Evas_Coord minw = -1, minh = -1;
151 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
152 edje_object_size_min_restricted_calc(wd->edje, &minw, &minh, minw, minh);
153 evas_object_size_hint_min_set(obj, minw, minh);
157 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
159 Widget_Data *wd = elm_widget_data_get(obj);
161 elm_widget_mirrored_set(wd->cancel_button, rtl);
162 elm_widget_mirrored_set(wd->ok_button, rtl);
163 elm_widget_mirrored_set(wd->files_list, rtl);
164 elm_widget_mirrored_set(wd->up_button, rtl);
165 elm_widget_mirrored_set(wd->home_button, rtl);
166 edje_object_mirrored_set(wd->edje, rtl);
170 _theme_hook(Evas_Object *obj)
172 Widget_Data *wd = elm_widget_data_get(obj);
173 const char *style = elm_widget_style_get(obj);
178 _elm_widget_mirrored_reload(obj);
180 _elm_theme_object_set(obj, wd->edje, "fileselector", "base", style);
182 if (elm_object_disabled_get(obj))
183 edje_object_signal_emit(wd->edje, "elm,state,disabled", "elm");
185 data = edje_object_data_get(wd->edje, "path_separator");
187 wd->path_separator = data;
189 wd->path_separator = "/";
191 if (!style) style = "default";
192 snprintf(buf, sizeof(buf), "fileselector/%s", style);
194 #define SWALLOW(part_name, object_ptn) \
197 elm_widget_style_set(object_ptn, buf); \
198 if (edje_object_part_swallow(wd->edje, part_name, object_ptn)) \
199 evas_object_show(object_ptn); \
201 evas_object_hide(object_ptn); \
203 SWALLOW("elm.swallow.up", wd->up_button);
204 SWALLOW("elm.swallow.home", wd->home_button);
206 if (wd->mode == ELM_FILESELECTOR_LIST)
208 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
211 evas_object_show(wd->files_list);
212 evas_object_hide(wd->files_grid);
215 evas_object_hide(wd->files_list);
219 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
222 evas_object_show(wd->files_grid);
223 evas_object_hide(wd->files_list);
226 evas_object_hide(wd->files_grid);
229 SWALLOW("elm.swallow.filename", wd->filename_entry);
230 SWALLOW("elm.swallow.path", wd->path_entry);
232 snprintf(buf, sizeof(buf), "fileselector/actions/%s", style);
233 SWALLOW("elm.swallow.cancel", wd->cancel_button);
234 SWALLOW("elm.swallow.ok", wd->ok_button);
237 edje_object_message_signal_process(wd->edje);
238 _mirrored_set(obj, elm_widget_mirrored_get(obj));
239 edje_object_scale_set
240 (wd->edje, elm_widget_scale_get(obj) * _elm_config->scale);
244 /*** GENLIST "MODEL" ***/
246 _itc_text_get(void *data,
247 Evas_Object *obj __UNUSED__,
248 const char *source __UNUSED__)
250 return elm_entry_utf8_to_markup(ecore_file_file_get(data)); /* NOTE this will be
256 _itc_icon_folder_get(void *data __UNUSED__,
262 if (strcmp(source, "elm.swallow.icon")) return NULL;
264 ic = elm_icon_add(obj);
265 elm_icon_standard_set(ic, "folder");
267 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
273 _itc_icon_image_get(void *data,
277 const char *filename = data;
280 if (strcmp(source, "elm.swallow.icon")) return NULL;
282 ic = elm_icon_add(obj);
283 elm_icon_standard_set(ic, "image");
284 elm_icon_thumb_set(ic, filename, NULL);
286 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
292 _itc_icon_file_get(void *data __UNUSED__,
298 if (strcmp(source, "elm.swallow.icon")) return NULL;
300 ic = elm_icon_add(obj);
301 elm_icon_standard_set(ic, "file");
303 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
309 _itc_state_get(void *data __UNUSED__,
310 Evas_Object *obj __UNUSED__,
311 const char *source __UNUSED__)
318 Evas_Object *obj __UNUSED__)
320 eina_stringshare_del(data);
324 _expand_done(void *data,
325 Evas_Object *obj __UNUSED__,
328 Elm_Object_Item *it = event_info;
329 const char *path = elm_object_item_data_get(it);
330 _populate(data, path, it);
334 _contract_done(void *data __UNUSED__,
335 Evas_Object *obj __UNUSED__,
338 Elm_Object_Item *it = event_info;
339 elm_genlist_item_subitems_clear(it);
343 _expand_req(void *data __UNUSED__,
344 Evas_Object *obj __UNUSED__,
347 Elm_Object_Item *it = event_info;
348 elm_genlist_item_expanded_set(it, EINA_TRUE);
352 _contract_req(void *data __UNUSED__,
353 Evas_Object *obj __UNUSED__,
356 Elm_Object_Item *it = event_info;
357 elm_genlist_item_expanded_set(it, EINA_FALSE);
370 wd = elm_widget_data_get(sd->fs);
373 if ((!wd->only_folder) && ecore_file_is_dir(path))
375 if (wd->expand && wd->mode == ELM_FILESELECTOR_LIST)
377 _do_anchors(sd->fs, path);
378 elm_object_text_set(wd->filename_entry, "");
382 /* keep a ref to path 'couse it will be destroyed by _populate */
383 p = eina_stringshare_add(path);
384 _populate(sd->fs, p, NULL);
385 eina_stringshare_del(p);
389 else /* navigating through folders only or file is not a dir. */
393 if (wd->expand && wd->mode == ELM_FILESELECTOR_LIST)
394 _do_anchors(sd->fs, path);
395 else if (wd->only_folder)
397 /* keep a ref to path 'couse it will be destroyed by _populate */
398 p = eina_stringshare_add(path);
399 _populate(sd->fs, p, NULL);
400 eina_stringshare_del(p);
402 s = elm_entry_utf8_to_markup(ecore_file_file_get(path));
405 elm_object_text_set(wd->filename_entry, s);
409 elm_object_text_set(wd->filename_entry, "");
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__,
429 //This event_info could be a list or gengrid item
430 Elm_Object_Item *it = event_info;
432 wd = elm_widget_data_get(data);
435 sd = malloc(sizeof(*sd));
437 sd->path = elm_object_item_data_get(it);
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], *s;
534 s = elm_entry_utf8_to_markup(path);
537 tok = eina_str_split(s, "/", 0);
539 eina_strlcat(buf, "<a href=/>root</a>", sizeof(buf));
540 for (i = 0; tok[i]; i++)
542 if ((!tok[i]) || (!tok[i][0])) continue;
543 eina_strlcat(buf, wd->path_separator, sizeof(buf));
544 eina_strlcat(buf, "<a href=", sizeof(buf));
545 for (j = 0; j <= i; j++)
547 if (strlen(tok[j]) < 1) continue;
548 eina_strlcat(buf, "/", sizeof(buf));
549 eina_strlcat(buf, tok[j], sizeof(buf));
551 eina_strlcat(buf, ">", sizeof(buf));
552 eina_strlcat(buf, tok[i], sizeof(buf));
553 eina_strlcat(buf, "</a>", sizeof(buf));
558 elm_object_text_set(wd->path_entry, buf);
563 _filter_cb(void *data __UNUSED__, Eio_File *handler, const Eina_File_Direct_Info *info)
565 const char *filename;
567 if (info->path[info->name_start] == '.')
570 filename = eina_stringshare_add(info->path);
571 eio_file_associate_direct_add(handler, "filename", filename, EINA_FREE_CB(eina_stringshare_del));
573 if (info->type == EINA_FILE_DIR)
575 eio_file_associate_direct_add(handler, "type/grid", grid_itc[ELM_DIRECTORY], NULL);
576 eio_file_associate_direct_add(handler, "type/list", list_itc[ELM_DIRECTORY], NULL);
580 if (evas_object_image_extension_can_load_get(info->path + info->name_start))
582 eio_file_associate_direct_add(handler, "type/grid", grid_itc[ELM_FILE_IMAGE], NULL);
583 eio_file_associate_direct_add(handler, "type/list", list_itc[ELM_FILE_IMAGE], NULL);
587 eio_file_associate_direct_add(handler, "type/grid", grid_itc[ELM_FILE_UNKNOW], NULL);
588 eio_file_associate_direct_add(handler, "type/list", list_itc[ELM_FILE_UNKNOW], NULL);
596 _file_grid_cmp(const void *a, const void *b)
598 const Elm_Object_Item *ga = a;
599 const Elm_Object_Item *gb = b;
600 const Elm_Gengrid_Item_Class *ca = elm_gengrid_item_item_class_get(ga);
601 const Elm_Gengrid_Item_Class *cb = elm_gengrid_item_item_class_get(gb);
603 if (ca == grid_itc[ELM_DIRECTORY])
605 if (cb != grid_itc[ELM_DIRECTORY])
608 else if (cb == grid_itc[ELM_DIRECTORY])
613 return strcoll(elm_object_item_data_get(ga), elm_object_item_data_get(gb));
617 _file_list_cmp(const void *a, const void *b)
619 const Elm_Object_Item *la = a;
620 const Elm_Object_Item *lb = b;
621 const Elm_Genlist_Item_Class *ca = elm_genlist_item_item_class_get(la);
622 const Elm_Genlist_Item_Class *cb = elm_genlist_item_item_class_get(lb);
624 if (ca == list_itc[ELM_DIRECTORY])
626 if (cb != list_itc[ELM_DIRECTORY])
629 else if (cb == list_itc[ELM_DIRECTORY])
634 return strcoll(elm_object_item_data_get(la), elm_object_item_data_get(lb));
638 _signal_first(Widget_Request *wr)
640 if (!wr->first) return ;
641 evas_object_smart_callback_call(wr->obj, SIG_DIRECTORY_OPEN, (void *)wr->path);
644 elm_genlist_clear(wr->wd->files_list);
645 elm_gengrid_clear(wr->wd->files_grid);
646 eina_stringshare_replace(&wr->wd->path, wr->path);
647 _do_anchors(wr->obj, wr->path);
650 if (wr->wd->filename_entry) elm_object_text_set(wr->wd->filename_entry, "");
652 wr->first = EINA_FALSE;
656 _main_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *info __UNUSED__)
658 Widget_Request *wr = data;
660 if (eio_file_check(handler))
662 if (!wr->wd->files_list || !wr->wd->files_grid || wr->wd->current != handler)
664 eio_file_cancel(handler);
670 if (wr->wd->mode == ELM_FILESELECTOR_LIST)
672 Eina_Bool is_dir = (eio_file_associate_find(handler, "type/list") == list_itc[ELM_DIRECTORY]);
674 elm_genlist_item_sorted_insert(wr->wd->files_list, eio_file_associate_find(handler, "type/list"),
675 eina_stringshare_ref(eio_file_associate_find(handler, "filename")),
676 wr->parent, wr->wd->expand && is_dir ? ELM_GENLIST_ITEM_TREE : ELM_GENLIST_ITEM_NONE,
677 _file_list_cmp, NULL, NULL);
679 else if (wr->wd->mode == ELM_FILESELECTOR_GRID)
680 elm_gengrid_item_sorted_insert(wr->wd->files_grid, eio_file_associate_find(handler, "type/grid"),
681 eina_stringshare_ref(eio_file_associate_find(handler, "filename")),
682 _file_grid_cmp, NULL, NULL);
686 _widget_request_cleanup(Widget_Request *wr)
688 EINA_REFCOUNT_UNREF(wr->wd)
689 _widget_data_free(wr->wd);
691 eina_stringshare_del(wr->path);
696 _done_cb(void *data, Eio_File *handler __UNUSED__)
698 Widget_Request *wr = data;
702 wr->wd->current = NULL;
703 _widget_request_cleanup(wr);
707 _error_cb(void *data, Eio_File *handler, int error __UNUSED__)
709 Widget_Request *wr = data;
711 if (wr->wd->current == handler)
712 wr->wd->current = NULL;
713 _widget_request_cleanup(wr);
719 _populate(Evas_Object *obj,
721 Elm_Object_Item *parent)
723 Widget_Data *wd = elm_widget_data_get(obj);
727 Eina_File_Direct_Info *file;
730 Eina_List *files = NULL, *dirs = NULL;
735 if (!ecore_file_is_dir(path)) return ;
736 it = eina_file_stat_ls(path);
738 evas_object_smart_callback_call(obj, SIG_DIRECTORY_OPEN, (void *)path);
741 elm_genlist_clear(wd->files_list);
742 elm_gengrid_clear(wd->files_grid);
743 eina_stringshare_replace(&wd->path, path);
744 _do_anchors(obj, path);
747 if (wd->filename_entry) elm_object_text_set(wd->filename_entry, "");
748 EINA_ITERATOR_FOREACH(it, file)
750 const char *filename;
752 if (file->path[file->name_start] == '.')
755 filename = eina_stringshare_add(file->path);
756 if (file->type == EINA_FILE_DIR)
757 dirs = eina_list_append(dirs, filename);
758 else if (!wd->only_folder)
759 files = eina_list_append(files, filename);
761 eina_iterator_free(it);
763 files = eina_list_sort(files, eina_list_count(files),
764 EINA_COMPARE_CB(strcoll));
765 dirs = eina_list_sort(dirs, eina_list_count(dirs), EINA_COMPARE_CB(strcoll));
766 EINA_LIST_FREE(dirs, real)
768 if (wd->mode == ELM_FILESELECTOR_LIST)
769 elm_genlist_item_append(wd->files_list, list_itc[ELM_DIRECTORY],
770 real, /* item data */
772 wd->expand ? ELM_GENLIST_ITEM_TREE :
773 ELM_GENLIST_ITEM_NONE,
775 else if (wd->mode == ELM_FILESELECTOR_GRID)
776 elm_gengrid_item_append(wd->files_grid, grid_itc[ELM_DIRECTORY],
777 real, /* item data */
781 EINA_LIST_FREE(files, real)
783 Elm_Fileselector_Type type = evas_object_image_extension_can_load_fast_get(real) ?
784 ELM_FILE_IMAGE : ELM_FILE_UNKNOW;
786 if (wd->mode == ELM_FILESELECTOR_LIST)
787 elm_genlist_item_append(wd->files_list, list_itc[type],
788 real, /* item data */
789 parent, ELM_GENLIST_ITEM_NONE,
791 else if (wd->mode == ELM_FILESELECTOR_GRID)
792 elm_gengrid_item_append(wd->files_grid, grid_itc[type],
793 real, /* item data */
797 if (wd->expand && wd->current) return ;
799 eio_file_cancel(wd->current);
800 wr = malloc(sizeof (Widget_Request));
803 EINA_REFCOUNT_REF(wr->wd);
804 wr->parent = parent; /* FIXME: should we refcount the parent ? */
806 wr->path = eina_stringshare_add(path);
807 wr->first = EINA_TRUE;
809 wd->current = eio_file_stat_ls(path,
821 elm_fileselector_add(Evas_Object *parent)
824 Evas_Object *obj, *ic, *bt, *li, *en, *grid;
829 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
831 EINA_REFCOUNT_INIT(wd);
833 ELM_SET_WIDTYPE(widtype, "fileselector");
834 elm_widget_type_set(obj, "fileselector");
835 elm_widget_sub_object_add(parent, obj);
836 elm_widget_data_set(obj, wd);
837 elm_widget_del_hook_set(obj, _del_hook);
838 elm_widget_theme_hook_set(obj, _theme_hook);
839 elm_widget_can_focus_set(obj, EINA_FALSE);
841 wd->expand = !!_elm_config->fileselector_expand_enable;
843 wd->edje = edje_object_add(e);
844 _elm_theme_object_set(obj, wd->edje, "fileselector", "base", "default");
845 elm_widget_resize_object_set(obj, wd->edje);
848 ic = elm_icon_add(parent);
849 elm_icon_standard_set(ic, "arrow_up");
850 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
851 bt = elm_button_add(parent);
852 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
853 elm_object_part_content_set(bt, "icon", ic);
854 elm_object_domain_translatable_text_set(bt, PACKAGE, N_("Up"));
855 evas_object_size_hint_align_set(bt, 0.0, 0.0);
857 evas_object_smart_callback_add(bt, "clicked", _up, obj);
859 elm_widget_sub_object_add(obj, bt);
863 ic = elm_icon_add(parent);
864 elm_icon_standard_set(ic, "home");
865 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
866 bt = elm_button_add(parent);
867 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
868 elm_object_part_content_set(bt, "icon", ic);
869 elm_object_domain_translatable_text_set(bt, PACKAGE, N_("Home"));
870 evas_object_size_hint_align_set(bt, 0.0, 0.0);
872 evas_object_smart_callback_add(bt, "clicked", _home, obj);
874 elm_widget_sub_object_add(obj, bt);
875 wd->home_button = bt;
877 for (i = 0; i < ELM_FILE_LAST; ++i)
879 list_itc[i] = elm_genlist_item_class_new();
880 grid_itc[i] = elm_gengrid_item_class_new();
882 list_itc[i]->item_style = "default";
883 list_itc[i]->func.text_get = grid_itc[i]->func.text_get = _itc_text_get;
884 list_itc[i]->func.state_get = grid_itc[i]->func.state_get = _itc_state_get;
885 list_itc[i]->func.del = grid_itc[i]->func.del = _itc_del;
888 list_itc[ELM_DIRECTORY]->func.content_get =
889 grid_itc[ELM_DIRECTORY]->func.content_get = _itc_icon_folder_get;
890 list_itc[ELM_FILE_IMAGE]->func.content_get =
891 grid_itc[ELM_FILE_IMAGE]->func.content_get = _itc_icon_image_get;
892 list_itc[ELM_FILE_UNKNOW]->func.content_get =
893 grid_itc[ELM_FILE_UNKNOW]->func.content_get = _itc_icon_file_get;
895 li = elm_genlist_add(parent);
896 elm_widget_mirrored_automatic_set(li, EINA_FALSE);
897 evas_object_size_hint_align_set(li, EVAS_HINT_FILL, EVAS_HINT_FILL);
898 evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
899 evas_object_size_hint_min_set(li, 100, 100);
901 grid = elm_gengrid_add(parent);
902 elm_widget_mirrored_automatic_set(grid, EINA_FALSE);
903 evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
904 evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
906 // XXX: will fail for dynamic finger size changing
907 s = _elm_config->finger_size * 2;
908 elm_gengrid_item_size_set(grid, s, s);
909 elm_gengrid_align_set(grid, 0.0, 0.0);
911 evas_object_smart_callback_add(li, "selected", _sel, obj);
912 evas_object_smart_callback_add(li, "expand,request", _expand_req, obj);
913 evas_object_smart_callback_add(li, "contract,request", _contract_req, obj);
914 evas_object_smart_callback_add(li, "expanded", _expand_done, obj);
915 evas_object_smart_callback_add(li, "contracted", _contract_done, obj);
917 evas_object_smart_callback_add(grid, "selected", _sel, obj);
919 elm_widget_sub_object_add(obj, li);
920 elm_widget_sub_object_add(obj, grid);
922 wd->files_grid = grid;
925 en = elm_entry_add(parent);
926 elm_entry_scrollable_set(en, EINA_TRUE);
927 elm_widget_mirrored_automatic_set(en, EINA_FALSE);
928 elm_entry_editable_set(en, EINA_FALSE);
929 elm_entry_single_line_set(en, EINA_TRUE);
930 elm_entry_line_wrap_set(en, ELM_WRAP_CHAR);
931 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
932 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
934 evas_object_smart_callback_add(en, "anchor,clicked", _anchor_clicked, obj);
936 elm_widget_sub_object_add(obj, en);
940 en = elm_entry_add(parent);
941 elm_entry_scrollable_set(en, EINA_TRUE);
942 elm_widget_mirrored_automatic_set(en, EINA_FALSE);
943 elm_entry_editable_set(en, EINA_TRUE);
944 elm_entry_single_line_set(en, EINA_TRUE);
945 elm_entry_line_wrap_set(en, ELM_WRAP_CHAR);
946 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
947 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
949 elm_widget_sub_object_add(obj, en);
950 wd->filename_entry = en;
952 elm_fileselector_buttons_ok_cancel_set(obj, EINA_TRUE);
953 elm_fileselector_is_save_set(obj, EINA_FALSE);
957 evas_object_smart_callbacks_descriptions_set(obj, _signals);
962 elm_fileselector_is_save_set(Evas_Object *obj,
965 ELM_CHECK_WIDTYPE(obj, widtype);
966 Widget_Data *wd = elm_widget_data_get(obj);
969 elm_object_disabled_set(wd->filename_entry, !is_save);
972 edje_object_signal_emit(wd->edje, "elm,state,save,on", "elm");
974 edje_object_signal_emit(wd->edje, "elm,state,save,off", "elm");
978 elm_fileselector_is_save_get(const Evas_Object *obj)
980 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
981 Widget_Data *wd = elm_widget_data_get(obj);
982 if (!wd) return EINA_FALSE;
983 return !elm_object_disabled_get(wd->filename_entry);
987 elm_fileselector_folder_only_set(Evas_Object *obj,
990 ELM_CHECK_WIDTYPE(obj, widtype);
991 Widget_Data *wd = elm_widget_data_get(obj);
993 if (wd->only_folder == only) return;
994 wd->only_folder = !!only;
995 if (wd->path) _populate(obj, wd->path, NULL);
999 elm_fileselector_folder_only_get(const Evas_Object *obj)
1001 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1002 Widget_Data *wd = elm_widget_data_get(obj);
1003 if (!wd) return EINA_FALSE;
1004 return wd->only_folder;
1008 elm_fileselector_buttons_ok_cancel_set(Evas_Object *obj,
1011 ELM_CHECK_WIDTYPE(obj, widtype);
1012 Widget_Data *wd = elm_widget_data_get(obj);
1019 bt = elm_button_add(obj);
1020 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
1021 elm_object_domain_translatable_text_set(bt, PACKAGE, N_("Cancel"));
1023 evas_object_smart_callback_add(bt, "clicked", _canc, obj);
1025 elm_widget_sub_object_add(obj, bt);
1026 wd->cancel_button = bt;
1029 bt = elm_button_add(obj);
1030 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
1031 elm_object_domain_translatable_text_set(bt, PACKAGE, N_("OK"));
1033 evas_object_smart_callback_add(bt, "clicked", _ok, obj);
1035 elm_widget_sub_object_add(obj, bt);
1042 evas_object_del(wd->cancel_button);
1043 wd->cancel_button = NULL;
1044 evas_object_del(wd->ok_button);
1045 wd->ok_button = NULL;
1050 elm_fileselector_buttons_ok_cancel_get(const Evas_Object *obj)
1052 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1053 Widget_Data *wd = elm_widget_data_get(obj);
1054 if (!wd) return EINA_FALSE;
1055 return wd->ok_button ? EINA_TRUE : EINA_FALSE;
1059 elm_fileselector_expandable_set(Evas_Object *obj,
1062 ELM_CHECK_WIDTYPE(obj, widtype);
1065 wd = elm_widget_data_get(obj);
1068 wd->expand = !!expand;
1070 if (wd->path) _populate(obj, wd->path, NULL);
1074 elm_fileselector_expandable_get(const Evas_Object *obj)
1076 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1077 Widget_Data *wd = elm_widget_data_get(obj);
1078 if (!wd) return EINA_FALSE;
1083 elm_fileselector_path_set(Evas_Object *obj,
1086 ELM_CHECK_WIDTYPE(obj, widtype);
1088 path = ecore_file_realpath(_path);
1089 _populate(obj, path, NULL);
1094 elm_fileselector_path_get(const Evas_Object *obj)
1096 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1097 Widget_Data *wd = elm_widget_data_get(obj);
1098 if (!wd) return NULL;
1103 elm_fileselector_mode_set(Evas_Object *obj,
1104 Elm_Fileselector_Mode mode)
1106 ELM_CHECK_WIDTYPE(obj, widtype);
1108 Widget_Data *wd = elm_widget_data_get(obj);
1111 if (mode == wd->mode) return;
1113 if (mode == ELM_FILESELECTOR_LIST)
1115 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
1118 evas_object_show(wd->files_list);
1119 evas_object_hide(wd->files_grid);
1122 evas_object_hide(wd->files_list);
1126 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
1129 evas_object_show(wd->files_grid);
1130 evas_object_hide(wd->files_list);
1133 evas_object_hide(wd->files_grid);
1138 _populate(obj, wd->path, NULL);
1141 EAPI Elm_Fileselector_Mode
1142 elm_fileselector_mode_get(const Evas_Object *obj)
1144 ELM_CHECK_WIDTYPE(obj, widtype) ELM_FILESELECTOR_LAST;
1146 Widget_Data *wd = elm_widget_data_get(obj);
1147 if (!wd) return ELM_FILESELECTOR_LAST;
1153 elm_fileselector_selected_get(const Evas_Object *obj)
1155 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1156 Widget_Data *wd = elm_widget_data_get(obj);
1157 if (!wd) return NULL;
1159 if (!wd->path) return NULL;
1161 if (wd->filename_entry)
1167 dir = wd->only_folder ? ecore_file_dir_get(wd->path) : strdup(wd->path);
1168 name = elm_object_text_get(wd->filename_entry);
1171 s = elm_entry_markup_to_utf8(name);
1174 snprintf(buf, sizeof(buf), "%s/%s", dir, s);
1178 snprintf(buf, sizeof(buf), "%s", dir);
1182 snprintf(buf, sizeof(buf), "%s", dir);
1184 if (wd->only_folder && !ecore_file_is_dir(buf))
1185 eina_stringshare_replace(&wd->selection, ecore_file_dir_get(buf));
1187 eina_stringshare_replace(&wd->selection, buf);
1189 return wd->selection;
1192 if (wd->mode == ELM_FILESELECTOR_LIST)
1194 Elm_Object_Item *gl_it = elm_genlist_selected_item_get(wd->files_list);
1195 if (gl_it) return elm_object_item_data_get(gl_it);
1199 Elm_Object_Item *gg_it = elm_gengrid_selected_item_get(wd->files_grid);
1200 if (gg_it) return elm_object_item_data_get(gg_it);
1207 elm_fileselector_selected_set(Evas_Object *obj,
1210 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1211 Widget_Data *wd = elm_widget_data_get(obj);
1212 if (!wd) return EINA_FALSE;
1214 Eina_Bool ret = EINA_TRUE;
1216 path = ecore_file_realpath(_path);
1218 if (ecore_file_is_dir(path))
1219 _populate(obj, path, NULL);
1222 if (!ecore_file_exists(path))
1228 _populate(obj, ecore_file_dir_get(path), NULL);
1229 if (wd->filename_entry)
1233 s = elm_entry_utf8_to_markup(ecore_file_file_get(path));
1236 elm_object_text_set(wd->filename_entry, s);
1240 elm_object_text_set(wd->filename_entry, "");
1241 eina_stringshare_replace(&wd->selection, path);