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
28 # include <elementary_config.h>
31 #include <Elementary.h>
38 typedef struct _Widget_Data Widget_Data;
45 Evas_Object *filename_entry;
46 Evas_Object *path_entry;
47 Evas_Object *files_list;
48 Evas_Object *files_grid;
49 Evas_Object *up_button;
50 Evas_Object *home_button;
52 Evas_Object *ok_button;
53 Evas_Object *cancel_button;
56 const char *selection;
57 Ecore_Idler *sel_idler;
59 const char *path_separator;
65 Elm_Fileselector_Mode mode;
67 Eina_Bool only_folder : 1;
77 typedef struct _Widget_Request Widget_Request;
78 struct _Widget_Request
81 Elm_Genlist_Item *parent;
93 } Elm_Fileselector_Type;
95 static Elm_Genlist_Item_Class list_itc[ELM_FILE_LAST] = {
96 { "default", { NULL, NULL, NULL, NULL, NULL }, NULL },
97 { "default", { NULL, NULL, NULL, NULL, NULL }, NULL },
98 { "default", { NULL, NULL, NULL, NULL, NULL }, NULL }
100 static Elm_Gengrid_Item_Class grid_itc[ELM_FILE_LAST] = {
101 { "default", { NULL, NULL, NULL, NULL } },
102 { "default", { NULL, NULL, NULL, NULL } },
103 { "default", { NULL, NULL, NULL, NULL } }
106 static const char *widtype = NULL;
108 static const char SIG_DIRECTORY_OPEN[] = "directory,open";
109 static const char SIG_DONE[] = "done";
110 static const char SIG_SELECTED[] = "selected";
111 static const Evas_Smart_Cb_Description _signals[] = {
112 {SIG_DIRECTORY_OPEN, "s"},
118 static void _populate(Evas_Object *obj,
120 Elm_Genlist_Item *parent);
121 static void _do_anchors(Evas_Object *obj,
124 /*** ELEMENTARY WIDGET ***/
126 _widget_data_free(Widget_Data *wd)
128 if (wd->path) eina_stringshare_del(wd->path);
129 if (wd->selection) eina_stringshare_del(wd->selection);
134 sd = ecore_idler_del(wd->sel_idler);
141 _del_hook(Evas_Object *obj)
145 wd = elm_widget_data_get(obj);
150 eio_file_cancel(wd->current);
153 wd->files_list = NULL;
154 wd->files_grid = NULL;
156 EINA_REFCOUNT_UNREF(wd)
157 _widget_data_free(wd);
161 _sizing_eval(Evas_Object *obj)
163 Widget_Data *wd = elm_widget_data_get(obj);
164 Evas_Coord minw = -1, minh = -1;
166 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
167 edje_object_size_min_restricted_calc(wd->edje, &minw, &minh, minw, minh);
168 evas_object_size_hint_min_set(obj, minw, minh);
172 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
174 Widget_Data *wd = elm_widget_data_get(obj);
176 elm_widget_mirrored_set(wd->cancel_button, rtl);
177 elm_widget_mirrored_set(wd->ok_button, rtl);
178 elm_widget_mirrored_set(wd->files_list, rtl);
179 elm_widget_mirrored_set(wd->up_button, rtl);
180 elm_widget_mirrored_set(wd->home_button, rtl);
181 edje_object_mirrored_set(wd->edje, rtl);
185 _theme_hook(Evas_Object *obj)
187 Widget_Data *wd = elm_widget_data_get(obj);
188 const char *style = elm_widget_style_get(obj);
193 _elm_widget_mirrored_reload(obj);
195 _elm_theme_object_set(obj, wd->edje, "fileselector", "base", style);
197 if (elm_object_disabled_get(obj))
198 edje_object_signal_emit(wd->edje, "elm,state,disabled", "elm");
200 data = edje_object_data_get(wd->edje, "path_separator");
202 wd->path_separator = data;
204 wd->path_separator = "/";
206 if (!style) style = "default";
207 snprintf(buf, sizeof(buf), "fileselector/%s", style);
209 #define SWALLOW(part_name, object_ptn) \
212 elm_widget_style_set(object_ptn, buf); \
213 if (edje_object_part_swallow(wd->edje, part_name, object_ptn)) \
214 evas_object_show(object_ptn); \
216 evas_object_hide(object_ptn); \
218 SWALLOW("elm.swallow.up", wd->up_button);
219 SWALLOW("elm.swallow.home", wd->home_button);
221 if (wd->mode == ELM_FILESELECTOR_LIST)
223 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
226 evas_object_show(wd->files_list);
227 evas_object_hide(wd->files_grid);
230 evas_object_hide(wd->files_list);
234 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
237 evas_object_show(wd->files_grid);
238 evas_object_hide(wd->files_list);
241 evas_object_hide(wd->files_grid);
244 SWALLOW("elm.swallow.filename", wd->filename_entry);
245 SWALLOW("elm.swallow.path", wd->path_entry);
247 snprintf(buf, sizeof(buf), "fileselector/actions/%s", style);
248 SWALLOW("elm.swallow.cancel", wd->cancel_button);
249 SWALLOW("elm.swallow.ok", wd->ok_button);
252 edje_object_message_signal_process(wd->edje);
253 _mirrored_set(obj, elm_widget_mirrored_get(obj));
254 edje_object_scale_set
255 (wd->edje, elm_widget_scale_get(obj) * _elm_config->scale);
259 /*** GENLIST "MODEL" ***/
261 _itc_label_get(void *data,
262 Evas_Object *obj __UNUSED__,
263 const char *source __UNUSED__)
265 return strdup(ecore_file_file_get(data)); /* NOTE this will be
271 _itc_icon_folder_get(void *data __UNUSED__,
277 if (strcmp(source, "elm.swallow.icon")) return NULL;
279 ic = elm_icon_add(obj);
280 elm_icon_standard_set(ic, "folder");
282 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
288 _itc_icon_image_get(void *data,
292 const char *filename = data;
295 if (strcmp(source, "elm.swallow.icon")) return NULL;
297 ic = elm_icon_add(obj);
298 elm_icon_standard_set(ic, "image");
299 elm_icon_thumb_set(ic, filename, NULL);
301 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
307 _itc_icon_file_get(void *data __UNUSED__,
313 if (strcmp(source, "elm.swallow.icon")) return NULL;
315 ic = elm_icon_add(obj);
316 elm_icon_standard_set(ic, "file");
318 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL,
324 _itc_state_get(void *data __UNUSED__,
325 Evas_Object *obj __UNUSED__,
326 const char *source __UNUSED__)
333 Evas_Object *obj __UNUSED__)
335 eina_stringshare_del(data);
339 _expand_done(void *data,
340 Evas_Object *obj __UNUSED__,
343 Elm_Genlist_Item *it = event_info;
344 const char *path = elm_genlist_item_data_get(it);
345 _populate(data, path, it);
349 _contract_done(void *data __UNUSED__,
350 Evas_Object *obj __UNUSED__,
353 Elm_Genlist_Item *it = event_info;
354 elm_genlist_item_subitems_clear(it);
358 _expand_req(void *data __UNUSED__,
359 Evas_Object *obj __UNUSED__,
362 Elm_Genlist_Item *it = event_info;
363 elm_genlist_item_expanded_set(it, 1);
367 _contract_req(void *data __UNUSED__,
368 Evas_Object *obj __UNUSED__,
371 Elm_Genlist_Item *it = event_info;
372 elm_genlist_item_expanded_set(it, 0);
385 wd = elm_widget_data_get(sd->fs);
388 if ((!wd->only_folder) && ecore_file_is_dir(path))
390 if (wd->expand && wd->mode == ELM_FILESELECTOR_LIST)
392 _do_anchors(sd->fs, path);
393 elm_entry_entry_set(wd->filename_entry, "");
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);
404 else /* navigating through folders only or file is not a dir. */
406 if (wd->expand && wd->mode == ELM_FILESELECTOR_LIST)
407 _do_anchors(sd->fs, path);
408 else if (wd->only_folder)
410 /* keep a ref to path 'couse it will be destroyed by _populate */
411 p = eina_stringshare_add(path);
412 _populate(sd->fs, p, NULL);
413 eina_stringshare_del(p);
415 elm_entry_entry_set(wd->filename_entry,
416 ecore_file_file_get(path));
419 evas_object_smart_callback_call(sd->fs, SIG_SELECTED, (void *)path);
422 wd->sel_idler = NULL;
424 return ECORE_CALLBACK_CANCEL;
429 Evas_Object *obj __UNUSED__,
437 wd = elm_widget_data_get(data);
440 sd = malloc(sizeof(*sd));
442 sd->path = wd->mode == ELM_FILESELECTOR_LIST ?
443 elm_genlist_item_data_get(event_info) :
444 elm_gengrid_item_data_get(event_info);
448 eina_stringshare_replace(&wd->path, "");
452 dir = wd->only_folder ? strdup(sd->path) : ecore_file_dir_get(sd->path);
455 eina_stringshare_replace(&wd->path, dir);
460 eina_stringshare_replace(&wd->path, "");
466 old_sd = ecore_idler_del(wd->sel_idler);
469 wd->sel_idler = ecore_idler_add(_sel_do, sd);
474 Evas_Object *obj __UNUSED__,
475 void *event_info __UNUSED__)
477 Evas_Object *fs = data;
480 Widget_Data *wd = elm_widget_data_get(fs);
482 parent = ecore_file_dir_get(wd->path);
483 _populate(fs, parent, NULL);
489 Evas_Object *obj __UNUSED__,
490 void *event_info __UNUSED__)
492 Evas_Object *fs = data;
493 _populate(fs, getenv("HOME"), NULL);
498 Evas_Object *obj __UNUSED__,
499 void *event_info __UNUSED__)
501 Evas_Object *fs = data;
502 evas_object_smart_callback_call(fs, SIG_DONE,
503 (void *)elm_fileselector_selected_get(fs));
508 Evas_Object *obj __UNUSED__,
509 void *event_info __UNUSED__)
511 Evas_Object *fs = data;
512 evas_object_smart_callback_call(fs, SIG_DONE, NULL);
516 _anchor_clicked(void *data,
517 Evas_Object *obj __UNUSED__,
520 Evas_Object *fs = data;
521 Widget_Data *wd = elm_widget_data_get(fs);
522 Elm_Entry_Anchor_Info *info = event_info;
525 // keep a ref to path 'couse it will be destroyed by _populate
526 p = eina_stringshare_add(info->name);
527 _populate(fs, p, NULL);
528 evas_object_smart_callback_call(data, SIG_SELECTED, (void *)p);
529 eina_stringshare_del(p);
533 _do_anchors(Evas_Object *obj,
536 Widget_Data *wd = elm_widget_data_get(obj);
537 char **tok, buf[PATH_MAX * 3];
541 tok = eina_str_split(path, "/", 0);
542 eina_strlcat(buf, "<a href=/>root</a>", sizeof(buf));
543 for (i = 0; tok[i]; i++)
545 if ((!tok[i]) || (!tok[i][0])) continue;
546 eina_strlcat(buf, wd->path_separator, sizeof(buf));
547 eina_strlcat(buf, "<a href=", sizeof(buf));
548 for (j = 0; j <= i; j++)
550 if (strlen(tok[j]) < 1) continue;
551 eina_strlcat(buf, "/", sizeof(buf));
552 eina_strlcat(buf, tok[j], sizeof(buf));
554 eina_strlcat(buf, ">", sizeof(buf));
555 eina_strlcat(buf, tok[i], sizeof(buf));
556 eina_strlcat(buf, "</a>", sizeof(buf));
561 elm_entry_entry_set(wd->path_entry, buf);
566 _filter_cb(void *data __UNUSED__, Eio_File *handler, const Eina_File_Direct_Info *info)
568 const char *filename;
570 if (info->path[info->name_start] == '.')
573 filename = eina_stringshare_add(info->path);
574 eio_file_associate_direct_add(handler, "filename", filename, EINA_FREE_CB(eina_stringshare_del));
576 if (info->type == EINA_FILE_DIR)
578 eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_DIRECTORY], NULL);
579 eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_DIRECTORY], NULL);
583 if (evas_object_image_extension_can_load_get(info->path + info->name_start))
585 eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_FILE_IMAGE], NULL);
586 eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_FILE_IMAGE], NULL);
590 eio_file_associate_direct_add(handler, "type/grid", &grid_itc[ELM_FILE_UNKNOW], NULL);
591 eio_file_associate_direct_add(handler, "type/list", &list_itc[ELM_FILE_UNKNOW], NULL);
599 _file_grid_cmp(const void *a, const void *b)
601 const Elm_Gengrid_Item *ga = a;
602 const Elm_Gengrid_Item *gb = b;
603 const Elm_Gengrid_Item_Class *ca = elm_gengrid_item_item_class_get(ga);
604 const Elm_Gengrid_Item_Class *cb = elm_gengrid_item_item_class_get(gb);
606 if (ca == &grid_itc[ELM_DIRECTORY])
608 if (cb != &grid_itc[ELM_DIRECTORY])
612 return strcoll(elm_gengrid_item_data_get(ga), elm_gengrid_item_data_get(gb));
616 _file_list_cmp(const void *a, const void *b)
618 const Elm_Genlist_Item *la = a;
619 const Elm_Genlist_Item *lb = b;
620 const Elm_Genlist_Item_Class *ca = elm_genlist_item_item_class_get(la);
621 const Elm_Genlist_Item_Class *cb = elm_genlist_item_item_class_get(lb);
623 if (ca == &list_itc[ELM_DIRECTORY])
625 if (cb != &list_itc[ELM_DIRECTORY])
629 return strcoll(elm_genlist_item_data_get(la), elm_genlist_item_data_get(lb));
633 _signal_first(Widget_Request *wr)
635 if (!wr->first) return ;
636 evas_object_smart_callback_call(wr->obj, SIG_DIRECTORY_OPEN, (void *)wr->path);
639 elm_genlist_clear(wr->wd->files_list);
640 elm_gengrid_clear(wr->wd->files_grid);
641 eina_stringshare_replace(&wr->wd->path, wr->path);
642 _do_anchors(wr->obj, wr->path);
645 if (wr->wd->filename_entry) elm_entry_entry_set(wr->wd->filename_entry, "");
647 wr->first = EINA_FALSE;
651 _main_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *info __UNUSED__)
653 Widget_Request *wr = data;
655 if (eio_file_check(handler))
657 if (!wr->wd->files_list || !wr->wd->files_grid || wr->wd->current != handler)
659 eio_file_cancel(handler);
665 if (wr->wd->mode == ELM_FILESELECTOR_LIST)
666 elm_genlist_item_direct_sorted_insert(wr->wd->files_list, eio_file_associate_find(handler, "type/list"),
667 eina_stringshare_ref(eio_file_associate_find(handler, "filename")),
668 wr->parent, ELM_GENLIST_ITEM_NONE, _file_list_cmp, NULL, NULL);
669 else if (wr->wd->mode == ELM_FILESELECTOR_GRID)
670 elm_gengrid_item_direct_sorted_insert(wr->wd->files_grid, eio_file_associate_find(handler, "type/grid"),
671 eina_stringshare_ref(eio_file_associate_find(handler, "filename")),
672 _file_grid_cmp, NULL, NULL);
676 _widget_request_cleanup(Widget_Request *wr)
678 EINA_REFCOUNT_UNREF(wr->wd)
679 _widget_data_free(wr->wd);
681 eina_stringshare_del(wr->path);
686 _done_cb(void *data, Eio_File *handler __UNUSED__)
688 Widget_Request *wr = data;
693 wr->wd->current = NULL;
695 _widget_request_cleanup(wr);
699 _error_cb(void *data, Eio_File *handler, int error __UNUSED__)
701 Widget_Request *wr = data;
704 if (wr->wd->current == handler)
705 wr->wd->current = NULL;
707 _widget_request_cleanup(wr);
713 _populate(Evas_Object *obj,
715 Elm_Genlist_Item *parent)
717 Widget_Data *wd = elm_widget_data_get(obj);
721 Eina_File_Direct_Info *file;
724 Eina_List *files = NULL, *dirs = NULL;
729 if (!ecore_file_is_dir(path)) return ;
730 it = eina_file_stat_ls(path);
732 evas_object_smart_callback_call(obj, SIG_DIRECTORY_OPEN, (void *)path);
735 elm_genlist_clear(wd->files_list);
736 elm_gengrid_clear(wd->files_grid);
737 eina_stringshare_replace(&wd->path, path);
738 _do_anchors(obj, path);
741 if (wd->filename_entry) elm_entry_entry_set(wd->filename_entry, "");
742 EINA_ITERATOR_FOREACH(it, file)
744 const char *filename;
746 if (file->path[file->name_start] == '.')
749 filename = eina_stringshare_add(file->path);
750 if (file->type == EINA_FILE_DIR)
751 dirs = eina_list_append(dirs, filename);
752 else if (!wd->only_folder)
753 files = eina_list_append(files, filename);
755 eina_iterator_free(it);
757 files = eina_list_sort(files, eina_list_count(files),
758 EINA_COMPARE_CB(strcoll));
759 dirs = eina_list_sort(dirs, eina_list_count(dirs), EINA_COMPARE_CB(strcoll));
760 EINA_LIST_FREE(dirs, real)
762 if (wd->mode == ELM_FILESELECTOR_LIST)
763 elm_genlist_item_append(wd->files_list, &list_itc[ELM_DIRECTORY],
764 real, /* item data */
766 wd->expand ? ELM_GENLIST_ITEM_SUBITEMS :
767 ELM_GENLIST_ITEM_NONE,
769 else if (wd->mode == ELM_FILESELECTOR_GRID)
770 elm_gengrid_item_append(wd->files_grid, &grid_itc[ELM_DIRECTORY],
771 real, /* item data */
775 EINA_LIST_FREE(files, real)
777 Elm_Fileselector_Type type = evas_object_image_extension_can_load_fast_get(real) ?
778 ELM_FILE_IMAGE : ELM_FILE_UNKNOW;
780 if (wd->mode == ELM_FILESELECTOR_LIST)
781 elm_genlist_item_append(wd->files_list, &list_itc[type],
782 real, /* item data */
783 parent, ELM_GENLIST_ITEM_NONE,
785 else if (wd->mode == ELM_FILESELECTOR_GRID)
786 elm_gengrid_item_append(wd->files_grid, &grid_itc[type],
787 real, /* item data */
792 eio_file_cancel(wd->current);
793 wr = malloc(sizeof (Widget_Request));
796 EINA_REFCOUNT_REF(wr->wd);
797 wr->parent = parent; /* FIXME: should we refcount the parent ? */
799 wr->path = eina_stringshare_add(path);
800 wr->first = EINA_TRUE;
802 wd->current = eio_file_stat_ls(path,
814 * Add a new Fileselector object
816 * @param parent The parent object
817 * @return The new object or NULL if it cannot be created
819 * @ingroup Fileselector
822 elm_fileselector_add(Evas_Object *parent)
825 Evas_Object *obj, *ic, *bt, *li, *en, *grid;
830 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
832 EINA_REFCOUNT_INIT(wd);
834 ELM_SET_WIDTYPE(widtype, "fileselector");
835 elm_widget_type_set(obj, "fileselector");
836 elm_widget_sub_object_add(parent, obj);
837 elm_widget_data_set(obj, wd);
838 elm_widget_del_hook_set(obj, _del_hook);
839 elm_widget_theme_hook_set(obj, _theme_hook);
840 elm_widget_can_focus_set(obj, EINA_FALSE);
842 wd->expand = !!_elm_config->fileselector_expand_enable;
844 wd->edje = edje_object_add(e);
845 _elm_theme_object_set(obj, wd->edje, "fileselector", "base", "default");
846 elm_widget_resize_object_set(obj, wd->edje);
849 ic = elm_icon_add(parent);
850 elm_icon_standard_set(ic, "arrow_up");
851 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
852 bt = elm_button_add(parent);
853 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
854 elm_button_icon_set(bt, ic);
855 elm_object_text_set(bt, E_("Up"));
856 evas_object_size_hint_align_set(bt, 0.0, 0.0);
858 evas_object_smart_callback_add(bt, "clicked", _up, obj);
860 elm_widget_sub_object_add(obj, bt);
864 ic = elm_icon_add(parent);
865 elm_icon_standard_set(ic, "home");
866 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
867 bt = elm_button_add(parent);
868 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
869 elm_button_icon_set(bt, ic);
870 elm_object_text_set(bt, E_("Home"));
871 evas_object_size_hint_align_set(bt, 0.0, 0.0);
873 evas_object_smart_callback_add(bt, "clicked", _home, obj);
875 elm_widget_sub_object_add(obj, bt);
876 wd->home_button = bt;
878 list_itc[ELM_DIRECTORY].func.icon_get = grid_itc[ELM_DIRECTORY].func.icon_get = _itc_icon_folder_get;
879 list_itc[ELM_FILE_IMAGE].func.icon_get = grid_itc[ELM_FILE_IMAGE].func.icon_get = _itc_icon_image_get;
880 list_itc[ELM_FILE_UNKNOW].func.icon_get = grid_itc[ELM_FILE_UNKNOW].func.icon_get = _itc_icon_file_get;
882 for (i = 0; i < ELM_FILE_LAST; ++i)
884 list_itc[i].func.label_get = grid_itc[i].func.label_get = _itc_label_get;
885 list_itc[i].func.state_get = grid_itc[i].func.state_get = _itc_state_get;
886 list_itc[i].func.del = grid_itc[i].func.del = _itc_del;
889 li = elm_genlist_add(parent);
890 elm_widget_mirrored_automatic_set(li, EINA_FALSE);
891 evas_object_size_hint_align_set(li, EVAS_HINT_FILL, EVAS_HINT_FILL);
892 evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
893 evas_object_size_hint_min_set(li, 100, 100);
895 grid = elm_gengrid_add(parent);
896 elm_widget_mirrored_automatic_set(grid, EINA_FALSE);
897 evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
898 evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
900 s = elm_finger_size_get() * 2;
901 elm_gengrid_item_size_set(grid, s, s);
902 elm_gengrid_align_set(grid, 0.0, 0.0);
904 evas_object_smart_callback_add(li, "selected", _sel, obj);
905 evas_object_smart_callback_add(li, "expand,request", _expand_req, obj);
906 evas_object_smart_callback_add(li, "contract,request", _contract_req, obj);
907 evas_object_smart_callback_add(li, "expanded", _expand_done, obj);
908 evas_object_smart_callback_add(li, "contracted", _contract_done, obj);
910 evas_object_smart_callback_add(grid, "selected", _sel, obj);
912 elm_widget_sub_object_add(obj, li);
913 elm_widget_sub_object_add(obj, grid);
915 wd->files_grid = grid;
918 en = elm_entry_add(parent);
919 elm_entry_scrollable_set(en, EINA_TRUE);
920 elm_widget_mirrored_automatic_set(en, EINA_FALSE);
921 elm_entry_editable_set(en, EINA_FALSE);
922 elm_entry_single_line_set(en, EINA_TRUE);
923 elm_entry_line_wrap_set(en, ELM_WRAP_CHAR);
924 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
925 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
927 evas_object_smart_callback_add(en, "anchor,clicked", _anchor_clicked, obj);
929 elm_widget_sub_object_add(obj, en);
933 en = elm_entry_add(parent);
934 elm_entry_scrollable_set(en, EINA_TRUE);
935 elm_widget_mirrored_automatic_set(en, EINA_FALSE);
936 elm_entry_editable_set(en, EINA_TRUE);
937 elm_entry_single_line_set(en, EINA_TRUE);
938 elm_entry_line_wrap_set(en, ELM_WRAP_CHAR);
939 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
940 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
942 elm_widget_sub_object_add(obj, en);
943 wd->filename_entry = en;
945 elm_fileselector_buttons_ok_cancel_set(obj, EINA_TRUE);
946 elm_fileselector_is_save_set(obj, EINA_FALSE);
950 evas_object_smart_callbacks_descriptions_set(obj, _signals);
955 * This enables/disables the file name entry box where the user can
956 * type in a name for the file to be saved as.
958 * @param obj The fileselector object
959 * @param is_save If true, the fileselector is a save dialog
961 * @ingroup Fileselector
964 elm_fileselector_is_save_set(Evas_Object *obj,
967 ELM_CHECK_WIDTYPE(obj, widtype);
968 Widget_Data *wd = elm_widget_data_get(obj);
971 elm_object_disabled_set(wd->filename_entry, !is_save);
974 edje_object_signal_emit(wd->edje, "elm,state,save,on", "elm");
976 edje_object_signal_emit(wd->edje, "elm,state,save,off", "elm");
980 * This returns whether the fileselector is a "save" type fileselector
982 * @param obj The fileselector object
983 * @return If true, the fileselector is a save type.
985 * @ingroup Fileselector
988 elm_fileselector_is_save_get(const Evas_Object *obj)
990 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
991 Widget_Data *wd = elm_widget_data_get(obj);
992 if (!wd) return EINA_FALSE;
993 return elm_object_disabled_get(wd->filename_entry);
997 * This enables/disables folder-only view in the fileselector.
999 * @param obj The fileselector object
1000 * @param only If true, the fileselector will only display directories.
1001 * If false, files are displayed also.
1003 * @ingroup Fileselector
1006 elm_fileselector_folder_only_set(Evas_Object *obj,
1009 ELM_CHECK_WIDTYPE(obj, widtype);
1010 Widget_Data *wd = elm_widget_data_get(obj);
1012 if (wd->only_folder == only) return;
1013 wd->only_folder = !!only;
1014 if (wd->path) _populate(obj, wd->path, NULL);
1018 * This gets the state of file display in the fileselector.
1020 * @param obj The fileselector object
1021 * @return If true, files are not being shown in the fileselector.
1022 * If false, files are being shown.
1024 * @ingroup Fileselector
1027 elm_fileselector_folder_only_get(const Evas_Object *obj)
1029 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1030 Widget_Data *wd = elm_widget_data_get(obj);
1031 if (!wd) return EINA_FALSE;
1032 return wd->only_folder;
1036 * This enables/disables the ok,cancel buttons.
1038 * @param obj The fileselector object
1039 * @param only If true, a box containing ok and cancel buttons is created.
1040 * If false, the box and the buttons are destroyed.
1042 * @ingroup Fileselector
1045 elm_fileselector_buttons_ok_cancel_set(Evas_Object *obj,
1048 ELM_CHECK_WIDTYPE(obj, widtype);
1049 Widget_Data *wd = elm_widget_data_get(obj);
1056 bt = elm_button_add(obj);
1057 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
1058 elm_object_text_set(bt, E_("Cancel"));
1060 evas_object_smart_callback_add(bt, "clicked", _canc, obj);
1062 elm_widget_sub_object_add(obj, bt);
1063 wd->cancel_button = bt;
1066 bt = elm_button_add(obj);
1067 elm_widget_mirrored_automatic_set(bt, EINA_FALSE);
1068 elm_object_text_set(bt, E_("OK"));
1070 evas_object_smart_callback_add(bt, "clicked", _ok, obj);
1072 elm_widget_sub_object_add(obj, bt);
1079 evas_object_del(wd->cancel_button);
1080 wd->cancel_button = NULL;
1081 evas_object_del(wd->ok_button);
1082 wd->ok_button = NULL;
1087 * This gets the state of the box containing ok and cancel buttons.
1089 * @param obj The fileselector object
1090 * @return If true, the box exists.
1091 * If false, the box does not exist.
1093 * @ingroup Fileselector
1096 elm_fileselector_buttons_ok_cancel_get(const Evas_Object *obj)
1098 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1099 Widget_Data *wd = elm_widget_data_get(obj);
1100 if (!wd) return EINA_FALSE;
1101 return wd->ok_button ? EINA_TRUE : EINA_FALSE;
1105 * This enables a tree view in the fileselector, <b>if in @c
1106 * ELM_FILESELECTOR_LIST mode</b>. If it's in other mode, the changes
1107 * made by this function will only be visible when one switches back
1110 * @param obj The fileselector object
1111 * @param expand If true, tree view is enabled.
1112 * If false, tree view is disabled.
1114 * In a tree view, arrows are created on the sides of directories,
1115 * allowing them to expand in place.
1117 * @ingroup Fileselector
1120 elm_fileselector_expandable_set(Evas_Object *obj,
1123 ELM_CHECK_WIDTYPE(obj, widtype);
1126 wd = elm_widget_data_get(obj);
1129 wd->expand = !!expand;
1131 if (wd->path) _populate(obj, wd->path, NULL);
1135 * This gets the state of tree view in the fileselector.
1137 * @param obj The fileselector object
1138 * @return If true, tree view is enabled and folders will be expandable.
1139 * If false, tree view is disabled.
1141 * @ingroup Fileselector
1144 elm_fileselector_expandable_get(const Evas_Object *obj)
1146 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1147 Widget_Data *wd = elm_widget_data_get(obj);
1148 if (!wd) return EINA_FALSE;
1153 * This sets the path that the fileselector will display.
1155 * @param obj The fileselector object
1156 * @param path The path of the fileselector
1158 * @ingroup Fileselector
1161 elm_fileselector_path_set(Evas_Object *obj,
1164 ELM_CHECK_WIDTYPE(obj, widtype);
1165 _populate(obj, path, NULL);
1169 * This gets the path that the fileselector displays.
1171 * @param obj The fileselector object
1172 * @return The path that the fileselector is displaying
1174 * @ingroup Fileselector
1177 elm_fileselector_path_get(const Evas_Object *obj)
1179 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1180 Widget_Data *wd = elm_widget_data_get(obj);
1181 if (!wd) return NULL;
1186 * This sets the mode in which the fileselector will display files.
1188 * @param obj The fileselector object
1190 * @param mode The mode of the fileselector, being it one of @c
1191 * ELM_FILESELECTOR_LIST (default) or @c ELM_FILESELECTOR_GRID. The
1192 * first one, naturally, will display the files in a list. By using
1193 * elm_fileselector_expandable_set(), the user will trigger a tree
1194 * view for that list. The latter will make the widget to display its
1195 * entries in a grid form.
1197 * @see elm_fileselector_expandable_set().
1199 * @ingroup Fileselector
1202 elm_fileselector_mode_set(Evas_Object *obj,
1203 Elm_Fileselector_Mode mode)
1205 ELM_CHECK_WIDTYPE(obj, widtype);
1207 Widget_Data *wd = elm_widget_data_get(obj);
1210 if (mode == wd->mode) return;
1212 if (mode == ELM_FILESELECTOR_LIST)
1214 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
1217 evas_object_show(wd->files_list);
1218 evas_object_hide(wd->files_grid);
1221 evas_object_hide(wd->files_list);
1225 if (edje_object_part_swallow(wd->edje, "elm.swallow.files",
1228 evas_object_show(wd->files_grid);
1229 evas_object_hide(wd->files_list);
1232 evas_object_hide(wd->files_grid);
1237 _populate(obj, wd->path, NULL);
1241 * This gets the mode in which the fileselector is displaying files.
1243 * @param obj The fileselector object
1244 * @return The mode in which the fileselector is at
1246 * @ingroup Fileselector
1248 EAPI Elm_Fileselector_Mode
1249 elm_fileselector_mode_get(const Evas_Object *obj)
1251 ELM_CHECK_WIDTYPE(obj, widtype) ELM_FILESELECTOR_LAST;
1253 Widget_Data *wd = elm_widget_data_get(obj);
1254 if (!wd) return ELM_FILESELECTOR_LAST;
1260 * This gets the currently selected path in the file selector.
1262 * @param obj The file selector object
1263 * @return The absolute path of the selected object in the fileselector
1265 * @ingroup Fileselector
1268 elm_fileselector_selected_get(const Evas_Object *obj)
1270 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1271 Widget_Data *wd = elm_widget_data_get(obj);
1272 if (!wd) return NULL;
1274 if (wd->filename_entry)
1279 name = elm_entry_entry_get(wd->filename_entry);
1280 snprintf(buf, sizeof(buf), "%s/%s",
1281 wd->only_folder ? ecore_file_dir_get(wd->path) : wd->path,
1283 eina_stringshare_replace(&wd->selection, buf);
1284 return wd->selection;
1287 if (wd->mode == ELM_FILESELECTOR_LIST)
1289 Elm_Genlist_Item *it;
1290 it = elm_genlist_selected_item_get(wd->files_list);
1291 if (it) return elm_genlist_item_data_get(it);
1295 Elm_Gengrid_Item *it;
1296 it = elm_gengrid_selected_item_get(wd->files_grid);
1297 if (it) return elm_gengrid_item_data_get(it);
1304 * This sets the currently selected path in the file selector.
1306 * @param obj The file selector object
1307 * @param path The path to a file or directory
1308 * @return @c EINA_TRUE on success, @c EINA_FALSE on failure. The
1309 * latter case occurs if the directory or file pointed to do not
1312 * @ingroup Fileselector
1315 elm_fileselector_selected_set(Evas_Object *obj,
1318 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1319 Widget_Data *wd = elm_widget_data_get(obj);
1320 if (!wd) return EINA_FALSE;
1322 if (ecore_file_is_dir(path))
1323 _populate(obj, path, NULL);
1326 if (!ecore_file_exists(path))
1329 _populate(obj, ecore_file_dir_get(path), NULL);
1330 if (wd->filename_entry)
1332 elm_entry_entry_set(wd->filename_entry,
1333 ecore_file_file_get(path));
1334 eina_stringshare_replace(&wd->selection, path);