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_Genlist_Item *parent;
79 } Elm_Fileselector_Type;
81 static Elm_Genlist_Item_Class list_itc[ELM_FILE_LAST] = {
82 { "default", { NULL, NULL, NULL, NULL } },
83 { "default", { NULL, NULL, NULL, NULL } },
84 { "default", { NULL, NULL, NULL, NULL } }
86 static Elm_Gengrid_Item_Class grid_itc[ELM_FILE_LAST] = {
87 { "default", { NULL, NULL, NULL, NULL } },
88 { "default", { NULL, NULL, NULL, NULL } },
89 { "default", { NULL, NULL, NULL, NULL } }
92 static const char *widtype = NULL;
94 static const char SIG_DIRECTORY_OPEN[] = "directory,open";
95 static const char SIG_DONE[] = "done";
96 static const char SIG_SELECTED[] = "selected";
97 static const Evas_Smart_Cb_Description _signals[] = {
98 {SIG_DIRECTORY_OPEN, "s"},
104 static void _populate(Evas_Object *obj,
106 Elm_Genlist_Item *parent);
107 static void _do_anchors(Evas_Object *obj,
110 /*** ELEMENTARY WIDGET ***/
112 _widget_data_free(Widget_Data *wd)
114 if (wd->path) eina_stringshare_del(wd->path);
115 if (wd->selection) eina_stringshare_del(wd->selection);
120 sd = ecore_idler_del(wd->sel_idler);
127 _del_hook(Evas_Object *obj)
131 wd = elm_widget_data_get(obj);
136 eio_file_cancel(wd->current);
139 wd->files_list = NULL;
140 wd->files_grid = NULL;
142 EINA_REFCOUNT_UNREF(wd)
143 _widget_data_free(wd);
147 _sizing_eval(Evas_Object *obj)
149 Widget_Data *wd = elm_widget_data_get(obj);
150 Evas_Coord minw = -1, minh = -1;
152 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
153 edje_object_size_min_restricted_calc(wd->edje, &minw, &minh, minw, minh);
154 evas_object_size_hint_min_set(obj, minw, minh);
158 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
160 Widget_Data *wd = elm_widget_data_get(obj);
162 elm_widget_mirrored_set(wd->cancel_button, rtl);
163 elm_widget_mirrored_set(wd->ok_button, rtl);
164 elm_widget_mirrored_set(wd->files_list, rtl);
165 elm_widget_mirrored_set(wd->up_button, rtl);
166 elm_widget_mirrored_set(wd->home_button, rtl);
167 edje_object_mirrored_set(wd->edje, rtl);
171 _theme_hook(Evas_Object *obj)
173 Widget_Data *wd = elm_widget_data_get(obj);
174 const char *style = elm_widget_style_get(obj);
179 _elm_widget_mirrored_reload(obj);
181 _elm_theme_object_set(obj, wd->edje, "fileselector", "base", style);
183 if (elm_object_disabled_get(obj))
184 edje_object_signal_emit(wd->edje, "elm,state,disabled", "elm");
186 data = edje_object_data_get(wd->edje, "path_separator");
188 wd->path_separator = data;
190 wd->path_separator = "/";
192 if (!style) style = "default";
193 snprintf(buf, sizeof(buf), "fileselector/%s", style);
195 #define SWALLOW(part_name, object_ptn) \
198 elm_widget_style_set(object_ptn, buf); \
199 if (edje_object_part_swallow(wd->edje, part_name, object_ptn)) \
200 evas_object_show(object_ptn); \
202 evas_object_hide(object_ptn); \
204 SWALLOW("elm.swallow.up", wd->up_button);
205 SWALLOW("elm.swallow.home", wd->home_button);
207 if (wd->mode == ELM_FILESELECTOR_LIST)
209 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
212 evas_object_show(wd->files_list);
213 evas_object_hide(wd->files_grid);
216 evas_object_hide(wd->files_list);
220 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
223 evas_object_show(wd->files_grid);
224 evas_object_hide(wd->files_list);
227 evas_object_hide(wd->files_grid);
230 SWALLOW("elm.swallow.filename", wd->filename_entry);
231 SWALLOW("elm.swallow.path", wd->path_entry);
233 snprintf(buf, sizeof(buf), "fileselector/actions/%s", style);
234 SWALLOW("elm.swallow.cancel", wd->cancel_button);
235 SWALLOW("elm.swallow.ok", wd->ok_button);
238 edje_object_message_signal_process(wd->edje);
239 _mirrored_set(obj, elm_widget_mirrored_get(obj));
240 edje_object_scale_set
241 (wd->edje, elm_widget_scale_get(obj) * _elm_config->scale);
245 /*** GENLIST "MODEL" ***/
247 _itc_text_get(void *data,
248 Evas_Object *obj __UNUSED__,
249 const char *source __UNUSED__)
251 return strdup(ecore_file_file_get(data)); /* NOTE this will be
257 _itc_icon_folder_get(void *data __UNUSED__,
263 if (strcmp(source, "elm.swallow.icon")) return NULL;
265 ic = elm_icon_add(obj);
266 elm_icon_standard_set(ic, "folder");
268 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
274 _itc_icon_image_get(void *data,
278 const char *filename = data;
281 if (strcmp(source, "elm.swallow.icon")) return NULL;
283 ic = elm_icon_add(obj);
284 elm_icon_standard_set(ic, "image");
285 elm_icon_thumb_set(ic, filename, NULL);
287 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
293 _itc_icon_file_get(void *data __UNUSED__,
299 if (strcmp(source, "elm.swallow.icon")) return NULL;
301 ic = elm_icon_add(obj);
302 elm_icon_standard_set(ic, "file");
304 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
310 _itc_state_get(void *data __UNUSED__,
311 Evas_Object *obj __UNUSED__,
312 const char *source __UNUSED__)
319 Evas_Object *obj __UNUSED__)
321 eina_stringshare_del(data);
325 _expand_done(void *data,
326 Evas_Object *obj __UNUSED__,
329 Elm_Genlist_Item *it = event_info;
330 const char *path = elm_genlist_item_data_get(it);
331 _populate(data, path, it);
335 _contract_done(void *data __UNUSED__,
336 Evas_Object *obj __UNUSED__,
339 Elm_Genlist_Item *it = event_info;
340 elm_genlist_item_subitems_clear(it);
344 _expand_req(void *data __UNUSED__,
345 Evas_Object *obj __UNUSED__,
348 Elm_Genlist_Item *it = event_info;
349 elm_genlist_item_expanded_set(it, 1);
353 _contract_req(void *data __UNUSED__,
354 Evas_Object *obj __UNUSED__,
357 Elm_Genlist_Item *it = event_info;
358 elm_genlist_item_expanded_set(it, 0);
371 wd = elm_widget_data_get(sd->fs);
374 if ((!wd->only_folder) && ecore_file_is_dir(path))
376 if (wd->expand && wd->mode == ELM_FILESELECTOR_LIST)
378 _do_anchors(sd->fs, path);
379 elm_entry_entry_set(wd->filename_entry, "");
383 /* keep a ref to path 'couse it will be destroyed by _populate */
384 p = eina_stringshare_add(path);
385 _populate(sd->fs, p, NULL);
386 eina_stringshare_del(p);
390 else /* navigating through folders only or file is not a dir. */
392 if (wd->expand && wd->mode == ELM_FILESELECTOR_LIST)
393 _do_anchors(sd->fs, path);
394 else if (wd->only_folder)
396 /* keep a ref to path 'couse it will be destroyed by _populate */
397 p = eina_stringshare_add(path);
398 _populate(sd->fs, p, NULL);
399 eina_stringshare_del(p);
401 elm_entry_entry_set(wd->filename_entry,
402 ecore_file_file_get(path));
405 evas_object_smart_callback_call(sd->fs, SIG_SELECTED, (void *)path);
408 wd->sel_idler = NULL;
410 return ECORE_CALLBACK_CANCEL;
415 Evas_Object *obj __UNUSED__,
423 wd = elm_widget_data_get(data);
426 sd = malloc(sizeof(*sd));
428 sd->path = wd->mode == ELM_FILESELECTOR_LIST ?
429 elm_genlist_item_data_get(event_info) :
430 elm_gengrid_item_data_get(event_info);
434 eina_stringshare_replace(&wd->path, "");
438 dir = wd->only_folder ? strdup(sd->path) : ecore_file_dir_get(sd->path);
441 eina_stringshare_replace(&wd->path, dir);
446 eina_stringshare_replace(&wd->path, "");
452 old_sd = ecore_idler_del(wd->sel_idler);
455 wd->sel_idler = ecore_idler_add(_sel_do, sd);
460 Evas_Object *obj __UNUSED__,
461 void *event_info __UNUSED__)
463 Evas_Object *fs = data;
466 Widget_Data *wd = elm_widget_data_get(fs);
468 parent = ecore_file_dir_get(wd->path);
469 _populate(fs, parent, NULL);
475 Evas_Object *obj __UNUSED__,
476 void *event_info __UNUSED__)
478 Evas_Object *fs = data;
479 _populate(fs, getenv("HOME"), NULL);
484 Evas_Object *obj __UNUSED__,
485 void *event_info __UNUSED__)
487 Evas_Object *fs = data;
488 evas_object_smart_callback_call(fs, SIG_DONE,
489 (void *)elm_fileselector_selected_get(fs));
494 Evas_Object *obj __UNUSED__,
495 void *event_info __UNUSED__)
497 Evas_Object *fs = data;
498 evas_object_smart_callback_call(fs, SIG_DONE, NULL);
502 _anchor_clicked(void *data,
503 Evas_Object *obj __UNUSED__,
506 Evas_Object *fs = data;
507 Widget_Data *wd = elm_widget_data_get(fs);
508 Elm_Entry_Anchor_Info *info = event_info;
511 // keep a ref to path 'couse it will be destroyed by _populate
512 p = eina_stringshare_add(info->name);
513 _populate(fs, p, NULL);
514 evas_object_smart_callback_call(data, SIG_SELECTED, (void *)p);
515 eina_stringshare_del(p);
519 _do_anchors(Evas_Object *obj,
522 Widget_Data *wd = elm_widget_data_get(obj);
523 char **tok, buf[PATH_MAX * 3];
527 tok = eina_str_split(path, "/", 0);
528 eina_strlcat(buf, "<a href=/>root</a>", sizeof(buf));
529 for (i = 0; tok[i]; i++)
531 if ((!tok[i]) || (!tok[i][0])) continue;
532 eina_strlcat(buf, wd->path_separator, sizeof(buf));
533 eina_strlcat(buf, "<a href=", sizeof(buf));
534 for (j = 0; j <= i; j++)
536 if (strlen(tok[j]) < 1) continue;
537 eina_strlcat(buf, "/", sizeof(buf));
538 eina_strlcat(buf, tok[j], sizeof(buf));
540 eina_strlcat(buf, ">", sizeof(buf));
541 eina_strlcat(buf, tok[i], sizeof(buf));
542 eina_strlcat(buf, "</a>", sizeof(buf));
547 elm_entry_entry_set(wd->path_entry, buf);
552 _filter_cb(void *data __UNUSED__, Eio_File *handler, const Eina_File_Direct_Info *info)
554 const char *filename;
556 if (info->path[info->name_start] == '.')
559 filename = eina_stringshare_add(info->path);
560 eio_file_associate_direct_add(handler, "filename", filename, EINA_FREE_CB(eina_stringshare_del));
562 if (info->type == EINA_FILE_DIR)
564 eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_DIRECTORY], NULL);
565 eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_DIRECTORY], NULL);
569 if (evas_object_image_extension_can_load_get(info->path + info->name_start))
571 eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_FILE_IMAGE], NULL);
572 eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_FILE_IMAGE], NULL);
576 eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_FILE_UNKNOW], NULL);
577 eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_FILE_UNKNOW], NULL);
585 _file_grid_cmp(const void *a, const void *b)
587 const Elm_Gengrid_Item *ga = a;
588 const Elm_Gengrid_Item *gb = b;
589 const Elm_Gengrid_Item_Class *ca = elm_gengrid_item_item_class_get(ga);
590 const Elm_Gengrid_Item_Class *cb = elm_gengrid_item_item_class_get(gb);
592 if (ca == &grid_itc[ELM_DIRECTORY])
594 if (cb != &grid_itc[ELM_DIRECTORY])
597 else if (cb == &grid_itc[ELM_DIRECTORY])
602 return strcoll(elm_gengrid_item_data_get(ga), elm_gengrid_item_data_get(gb));
606 _file_list_cmp(const void *a, const void *b)
608 const Elm_Genlist_Item *la = a;
609 const Elm_Genlist_Item *lb = b;
610 const Elm_Genlist_Item_Class *ca = elm_genlist_item_item_class_get(la);
611 const Elm_Genlist_Item_Class *cb = elm_genlist_item_item_class_get(lb);
613 if (ca == &list_itc[ELM_DIRECTORY])
615 if (cb != &list_itc[ELM_DIRECTORY])
618 else if (cb == &list_itc[ELM_DIRECTORY])
623 return strcoll(elm_genlist_item_data_get(la), elm_genlist_item_data_get(lb));
627 _signal_first(Widget_Request *wr)
629 if (!wr->first) return ;
630 evas_object_smart_callback_call(wr->obj, SIG_DIRECTORY_OPEN, (void *)wr->path);
633 elm_genlist_clear(wr->wd->files_list);
634 elm_gengrid_clear(wr->wd->files_grid);
635 eina_stringshare_replace(&wr->wd->path, wr->path);
636 _do_anchors(wr->obj, wr->path);
639 if (wr->wd->filename_entry) elm_entry_entry_set(wr->wd->filename_entry, "");
641 wr->first = EINA_FALSE;
645 _main_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *info __UNUSED__)
647 Widget_Request *wr = data;
649 if (eio_file_check(handler))
651 if (!wr->wd->files_list || !wr->wd->files_grid || wr->wd->current != handler)
653 eio_file_cancel(handler);
659 if (wr->wd->mode == ELM_FILESELECTOR_LIST)
661 Eina_Bool is_dir = (eio_file_associate_find(handler, "type/list") == &list_itc[ELM_DIRECTORY]);
663 elm_genlist_item_direct_sorted_insert(wr->wd->files_list, eio_file_associate_find(handler, "type/list"),
664 eina_stringshare_ref(eio_file_associate_find(handler, "filename")),
665 wr->parent, wr->wd->expand && is_dir ? ELM_GENLIST_ITEM_SUBITEMS : ELM_GENLIST_ITEM_NONE,
666 _file_list_cmp, NULL, NULL);
668 else if (wr->wd->mode == ELM_FILESELECTOR_GRID)
669 elm_gengrid_item_direct_sorted_insert(wr->wd->files_grid, eio_file_associate_find(handler, "type/grid"),
670 eina_stringshare_ref(eio_file_associate_find(handler, "filename")),
671 _file_grid_cmp, NULL, NULL);
675 _widget_request_cleanup(Widget_Request *wr)
677 EINA_REFCOUNT_UNREF(wr->wd)
678 _widget_data_free(wr->wd);
680 eina_stringshare_del(wr->path);
685 _done_cb(void *data, Eio_File *handler __UNUSED__)
687 Widget_Request *wr = data;
691 wr->wd->current = NULL;
692 _widget_request_cleanup(wr);
696 _error_cb(void *data, Eio_File *handler, int error __UNUSED__)
698 Widget_Request *wr = data;
700 if (wr->wd->current == handler)
701 wr->wd->current = NULL;
702 _widget_request_cleanup(wr);
708 _populate(Evas_Object *obj,
710 Elm_Genlist_Item *parent)
712 Widget_Data *wd = elm_widget_data_get(obj);
716 Eina_File_Direct_Info *file;
719 Eina_List *files = NULL, *dirs = NULL;
724 if (!ecore_file_is_dir(path)) return ;
725 it = eina_file_stat_ls(path);
727 evas_object_smart_callback_call(obj, SIG_DIRECTORY_OPEN, (void *)path);
730 elm_genlist_clear(wd->files_list);
731 elm_gengrid_clear(wd->files_grid);
732 eina_stringshare_replace(&wd->path, path);
733 _do_anchors(obj, path);
736 if (wd->filename_entry) elm_entry_entry_set(wd->filename_entry, "");
737 EINA_ITERATOR_FOREACH(it, file)
739 const char *filename;
741 if (file->path[file->name_start] == '.')
744 filename = eina_stringshare_add(file->path);
745 if (file->type == EINA_FILE_DIR)
746 dirs = eina_list_append(dirs, filename);
747 else if (!wd->only_folder)
748 files = eina_list_append(files, filename);
750 eina_iterator_free(it);
752 files = eina_list_sort(files, eina_list_count(files),
753 EINA_COMPARE_CB(strcoll));
754 dirs = eina_list_sort(dirs, eina_list_count(dirs), EINA_COMPARE_CB(strcoll));
755 EINA_LIST_FREE(dirs, real)
757 if (wd->mode == ELM_FILESELECTOR_LIST)
758 elm_genlist_item_append(wd->files_list, &list_itc[ELM_DIRECTORY],
759 real, /* item data */
761 wd->expand ? ELM_GENLIST_ITEM_SUBITEMS :
762 ELM_GENLIST_ITEM_NONE,
764 else if (wd->mode == ELM_FILESELECTOR_GRID)
765 elm_gengrid_item_append(wd->files_grid, &grid_itc[ELM_DIRECTORY],
766 real, /* item data */
770 EINA_LIST_FREE(files, real)
772 Elm_Fileselector_Type type = evas_object_image_extension_can_load_fast_get(real) ?
773 ELM_FILE_IMAGE : ELM_FILE_UNKNOW;
775 if (wd->mode == ELM_FILESELECTOR_LIST)
776 elm_genlist_item_append(wd->files_list, &list_itc[type],
777 real, /* item data */
778 parent, ELM_GENLIST_ITEM_NONE,
780 else if (wd->mode == ELM_FILESELECTOR_GRID)
781 elm_gengrid_item_append(wd->files_grid, &grid_itc[type],
782 real, /* item data */
786 if (wd->expand && wd->current) return ;
788 eio_file_cancel(wd->current);
789 wr = malloc(sizeof (Widget_Request));
792 EINA_REFCOUNT_REF(wr->wd);
793 wr->parent = parent; /* FIXME: should we refcount the parent ? */
795 wr->path = eina_stringshare_add(path);
796 wr->first = EINA_TRUE;
798 wd->current = eio_file_stat_ls(path,
810 elm_fileselector_add(Evas_Object *parent)
813 Evas_Object *obj, *ic, *bt, *li, *en, *grid;
818 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
820 EINA_REFCOUNT_INIT(wd);
822 ELM_SET_WIDTYPE(widtype, "fileselector");
823 elm_widget_type_set(obj, "fileselector");
824 elm_widget_sub_object_add(parent, obj);
825 elm_widget_data_set(obj, wd);
826 elm_widget_del_hook_set(obj, _del_hook);
827 elm_widget_theme_hook_set(obj, _theme_hook);
828 elm_widget_can_focus_set(obj, EINA_FALSE);
830 wd->expand = !!_elm_config->fileselector_expand_enable;
832 wd->edje = edje_object_add(e);
833 _elm_theme_object_set(obj, wd->edje, "fileselector", "base", "default");
834 elm_widget_resize_object_set(obj, wd->edje);
837 ic = elm_icon_add(parent);
838 elm_icon_standard_set(ic, "arrow_up");
839 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
840 bt = elm_button_add(parent);
841 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
842 elm_object_part_content_set(bt, "icon", ic);
843 elm_object_domain_translatable_text_set(bt, PACKAGE, N_("Up"));
844 evas_object_size_hint_align_set(bt, 0.0, 0.0);
846 evas_object_smart_callback_add(bt, "clicked", _up, obj);
848 elm_widget_sub_object_add(obj, bt);
852 ic = elm_icon_add(parent);
853 elm_icon_standard_set(ic, "home");
854 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
855 bt = elm_button_add(parent);
856 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
857 elm_object_part_content_set(bt, "icon", ic);
858 elm_object_domain_translatable_text_set(bt, PACKAGE, N_("Home"));
859 evas_object_size_hint_align_set(bt, 0.0, 0.0);
861 evas_object_smart_callback_add(bt, "clicked", _home, obj);
863 elm_widget_sub_object_add(obj, bt);
864 wd->home_button = bt;
866 list_itc[ELM_DIRECTORY].func.content_get = grid_itc[ELM_DIRECTORY].func.content_get = _itc_icon_folder_get;
867 list_itc[ELM_FILE_IMAGE].func.content_get = grid_itc[ELM_FILE_IMAGE].func.content_get = _itc_icon_image_get;
868 list_itc[ELM_FILE_UNKNOW].func.content_get = grid_itc[ELM_FILE_UNKNOW].func.content_get = _itc_icon_file_get;
870 for (i = 0; i < ELM_FILE_LAST; ++i)
872 list_itc[i].func.text_get = grid_itc[i].func.text_get = _itc_text_get;
873 list_itc[i].func.state_get = grid_itc[i].func.state_get = _itc_state_get;
874 list_itc[i].func.del = grid_itc[i].func.del = _itc_del;
877 li = elm_genlist_add(parent);
878 elm_widget_mirrored_automatic_set(li, EINA_FALSE);
879 evas_object_size_hint_align_set(li, EVAS_HINT_FILL, EVAS_HINT_FILL);
880 evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
881 evas_object_size_hint_min_set(li, 100, 100);
883 grid = elm_gengrid_add(parent);
884 elm_widget_mirrored_automatic_set(grid, EINA_FALSE);
885 evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
886 evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
888 s = elm_finger_size_get() * 2;
889 elm_gengrid_item_size_set(grid, s, s);
890 elm_gengrid_align_set(grid, 0.0, 0.0);
892 evas_object_smart_callback_add(li, "selected", _sel, obj);
893 evas_object_smart_callback_add(li, "expand,request", _expand_req, obj);
894 evas_object_smart_callback_add(li, "contract,request", _contract_req, obj);
895 evas_object_smart_callback_add(li, "expanded", _expand_done, obj);
896 evas_object_smart_callback_add(li, "contracted", _contract_done, obj);
898 evas_object_smart_callback_add(grid, "selected", _sel, obj);
900 elm_widget_sub_object_add(obj, li);
901 elm_widget_sub_object_add(obj, grid);
903 wd->files_grid = grid;
906 en = elm_entry_add(parent);
907 elm_entry_scrollable_set(en, EINA_TRUE);
908 elm_widget_mirrored_automatic_set(en, EINA_FALSE);
909 elm_entry_editable_set(en, EINA_FALSE);
910 elm_entry_single_line_set(en, EINA_TRUE);
911 elm_entry_line_wrap_set(en, ELM_WRAP_CHAR);
912 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
913 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
915 evas_object_smart_callback_add(en, "anchor,clicked", _anchor_clicked, obj);
917 elm_widget_sub_object_add(obj, en);
921 en = elm_entry_add(parent);
922 elm_entry_scrollable_set(en, EINA_TRUE);
923 elm_widget_mirrored_automatic_set(en, EINA_FALSE);
924 elm_entry_editable_set(en, EINA_TRUE);
925 elm_entry_single_line_set(en, EINA_TRUE);
926 elm_entry_line_wrap_set(en, ELM_WRAP_CHAR);
927 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
928 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
930 elm_widget_sub_object_add(obj, en);
931 wd->filename_entry = en;
933 elm_fileselector_buttons_ok_cancel_set(obj, EINA_TRUE);
934 elm_fileselector_is_save_set(obj, EINA_FALSE);
938 evas_object_smart_callbacks_descriptions_set(obj, _signals);
943 elm_fileselector_is_save_set(Evas_Object *obj,
946 ELM_CHECK_WIDTYPE(obj, widtype);
947 Widget_Data *wd = elm_widget_data_get(obj);
950 elm_object_disabled_set(wd->filename_entry, !is_save);
953 edje_object_signal_emit(wd->edje, "elm,state,save,on", "elm");
955 edje_object_signal_emit(wd->edje, "elm,state,save,off", "elm");
959 elm_fileselector_is_save_get(const Evas_Object *obj)
961 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
962 Widget_Data *wd = elm_widget_data_get(obj);
963 if (!wd) return EINA_FALSE;
964 return elm_object_disabled_get(wd->filename_entry);
968 elm_fileselector_folder_only_set(Evas_Object *obj,
971 ELM_CHECK_WIDTYPE(obj, widtype);
972 Widget_Data *wd = elm_widget_data_get(obj);
974 if (wd->only_folder == only) return;
975 wd->only_folder = !!only;
976 if (wd->path) _populate(obj, wd->path, NULL);
980 elm_fileselector_folder_only_get(const Evas_Object *obj)
982 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
983 Widget_Data *wd = elm_widget_data_get(obj);
984 if (!wd) return EINA_FALSE;
985 return wd->only_folder;
989 elm_fileselector_buttons_ok_cancel_set(Evas_Object *obj,
992 ELM_CHECK_WIDTYPE(obj, widtype);
993 Widget_Data *wd = elm_widget_data_get(obj);
1000 bt = elm_button_add(obj);
1001 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
1002 elm_object_domain_translatable_text_set(bt, PACKAGE, N_("Cancel"));
1004 evas_object_smart_callback_add(bt, "clicked", _canc, obj);
1006 elm_widget_sub_object_add(obj, bt);
1007 wd->cancel_button = bt;
1010 bt = elm_button_add(obj);
1011 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
1012 elm_object_domain_translatable_text_set(bt, PACKAGE, N_("OK"));
1014 evas_object_smart_callback_add(bt, "clicked", _ok, obj);
1016 elm_widget_sub_object_add(obj, bt);
1023 evas_object_del(wd->cancel_button);
1024 wd->cancel_button = NULL;
1025 evas_object_del(wd->ok_button);
1026 wd->ok_button = NULL;
1031 elm_fileselector_buttons_ok_cancel_get(const Evas_Object *obj)
1033 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1034 Widget_Data *wd = elm_widget_data_get(obj);
1035 if (!wd) return EINA_FALSE;
1036 return wd->ok_button ? EINA_TRUE : EINA_FALSE;
1040 elm_fileselector_expandable_set(Evas_Object *obj,
1043 ELM_CHECK_WIDTYPE(obj, widtype);
1046 wd = elm_widget_data_get(obj);
1049 wd->expand = !!expand;
1051 if (wd->path) _populate(obj, wd->path, NULL);
1055 elm_fileselector_expandable_get(const Evas_Object *obj)
1057 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1058 Widget_Data *wd = elm_widget_data_get(obj);
1059 if (!wd) return EINA_FALSE;
1064 elm_fileselector_path_set(Evas_Object *obj,
1067 ELM_CHECK_WIDTYPE(obj, widtype);
1068 _populate(obj, path, NULL);
1072 elm_fileselector_path_get(const Evas_Object *obj)
1074 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1075 Widget_Data *wd = elm_widget_data_get(obj);
1076 if (!wd) return NULL;
1081 elm_fileselector_mode_set(Evas_Object *obj,
1082 Elm_Fileselector_Mode mode)
1084 ELM_CHECK_WIDTYPE(obj, widtype);
1086 Widget_Data *wd = elm_widget_data_get(obj);
1089 if (mode == wd->mode) return;
1091 if (mode == ELM_FILESELECTOR_LIST)
1093 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
1096 evas_object_show(wd->files_list);
1097 evas_object_hide(wd->files_grid);
1100 evas_object_hide(wd->files_list);
1104 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
1107 evas_object_show(wd->files_grid);
1108 evas_object_hide(wd->files_list);
1111 evas_object_hide(wd->files_grid);
1116 _populate(obj, wd->path, NULL);
1119 EAPI Elm_Fileselector_Mode
1120 elm_fileselector_mode_get(const Evas_Object *obj)
1122 ELM_CHECK_WIDTYPE(obj, widtype) ELM_FILESELECTOR_LAST;
1124 Widget_Data *wd = elm_widget_data_get(obj);
1125 if (!wd) return ELM_FILESELECTOR_LAST;
1131 elm_fileselector_selected_get(const Evas_Object *obj)
1133 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1134 Widget_Data *wd = elm_widget_data_get(obj);
1135 if (!wd) return NULL;
1137 if (wd->filename_entry)
1143 dir = wd->only_folder ? ecore_file_dir_get(wd->path) : strdup(wd->path);
1144 name = elm_entry_entry_get(wd->filename_entry);
1145 snprintf(buf, sizeof(buf), "%s/%s",
1147 eina_stringshare_replace(&wd->selection, buf);
1149 return wd->selection;
1152 if (wd->mode == ELM_FILESELECTOR_LIST)
1154 Elm_Genlist_Item *it;
1155 it = elm_genlist_selected_item_get(wd->files_list);
1156 if (it) return elm_genlist_item_data_get(it);
1160 Elm_Gengrid_Item *it;
1161 it = elm_gengrid_selected_item_get(wd->files_grid);
1162 if (it) return elm_gengrid_item_data_get(it);
1169 elm_fileselector_selected_set(Evas_Object *obj,
1172 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1173 Widget_Data *wd = elm_widget_data_get(obj);
1174 if (!wd) return EINA_FALSE;
1176 if (ecore_file_is_dir(path))
1177 _populate(obj, path, NULL);
1180 if (!ecore_file_exists(path))
1183 _populate(obj, ecore_file_dir_get(path), NULL);
1184 if (wd->filename_entry)
1186 elm_entry_entry_set(wd->filename_entry,
1187 ecore_file_file_get(path));
1188 eina_stringshare_replace(&wd->selection, path);