2 * Simple Elementary's <b>file selector entry widget</b> example,
3 * illustrating its usage and API.
5 * See stdout/stderr for output. Compile with:
8 * gcc -g file selector_entry_example.c -o file selector_entry_example `pkg-config --cflags --libs elementary`
12 #include <Elementary.h>
22 /* hook on the file,chosen smart callback */
24 _file_chosen(void *data,
28 const char *file = event_info;
31 printf("File chosen: %s\n", file);
33 printf("File selection canceled.\n");
36 /* toggle inwin mode */
38 _inwin_mode_toggle(void *data,
42 Evas_Object *fs_entry = data;
43 Eina_Bool old_val = elm_fileselector_entry_inwin_mode_get(fs_entry);
45 elm_fileselector_entry_inwin_mode_set(fs_entry, !old_val);
46 printf("Inwin mode set to: %s\n", old_val ? "false" : "true");
50 _current_sel_toggle(void *data,
54 Evas_Object *fs_entry = data;
55 Eina_Bool old_val = elm_fileselector_entry_is_save_get(fs_entry);
56 elm_fileselector_entry_is_save_set(fs_entry, !old_val);
58 printf("%s text entry with selected item's name\n",
59 old_val ? "Disabling" : "Enabling");
63 _folder_only_toggle(void *data,
67 Evas_Object *fs_entry = data;
68 Eina_Bool old_val = elm_fileselector_entry_folder_only_get(fs_entry);
69 elm_fileselector_entry_folder_only_set(fs_entry, !old_val);
71 printf("Folder only mode set to: %s\n", old_val ? "false" : "true");
75 _expandable_toggle(void *data,
79 Evas_Object *fs_entry = data;
80 Eina_Bool old_val = elm_fileselector_entry_expandable_get(fs_entry);
81 elm_fileselector_entry_expandable_set(fs_entry, !old_val);
83 printf("Expandable folders mode set to: %s\n", old_val ? "false" : "true");
90 Evas_Object *win, *bg, *vbox, *hbox, *ic, *ck, *fs_entry, *sep;
92 win = elm_win_add(NULL, "fileselector-entry", ELM_WIN_BASIC);
93 elm_win_title_set(win, "File Selector Entry Example");
94 evas_object_smart_callback_add(win, "delete,request", _on_done, NULL);
97 elm_win_resize_object_add(win, bg);
98 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
101 vbox = elm_box_add(win);
102 elm_win_resize_object_add(win, vbox);
103 evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
104 evas_object_show(vbox);
106 ic = elm_icon_add(win);
107 elm_icon_standard_set(ic, "file");
108 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
110 /* file selector entry */
111 fs_entry = elm_fileselector_entry_add(win);
112 evas_object_size_hint_align_set(fs_entry, EVAS_HINT_FILL, 0);
113 elm_fileselector_entry_path_set(fs_entry, "/tmp");
114 elm_object_text_set(fs_entry, "Select a file");
115 elm_object_part_content_set(fs_entry, "button icon", ic);
117 elm_box_pack_end(vbox, fs_entry);
118 evas_object_show(fs_entry);
119 evas_object_show(ic);
121 /* attribute setting knobs */
122 sep = elm_separator_add(win);
123 elm_separator_horizontal_set(sep, EINA_TRUE);
124 elm_box_pack_end(vbox, sep);
125 evas_object_show(sep);
127 hbox = elm_box_add(win);
128 elm_box_horizontal_set(hbox, EINA_TRUE);
129 elm_box_pack_end(vbox, hbox);
130 evas_object_show(hbox);
132 ck = elm_check_add(win);
133 elm_object_text_set(ck, "editable selection");
134 elm_check_state_set(ck, elm_fileselector_entry_is_save_get(fs_entry));
135 evas_object_smart_callback_add(ck, "changed", _current_sel_toggle, fs_entry);
136 elm_box_pack_end(hbox, ck);
137 evas_object_show(ck);
139 ck = elm_check_add(win);
140 elm_object_text_set(ck, "\"inwin\" mode");
141 elm_check_state_set(ck, elm_fileselector_entry_inwin_mode_get(fs_entry));
142 evas_object_smart_callback_add(ck, "changed", _inwin_mode_toggle, fs_entry);
143 elm_box_pack_end(hbox, ck);
144 evas_object_show(ck);
146 ck = elm_check_add(win);
147 elm_object_text_set(ck, "folders only");
148 elm_check_state_set(ck, elm_fileselector_entry_folder_only_get(fs_entry));
149 evas_object_smart_callback_add(ck, "changed", _folder_only_toggle, fs_entry);
150 elm_box_pack_end(hbox, ck);
151 evas_object_show(ck);
153 ck = elm_check_add(win);
154 elm_object_text_set(ck, "expandable");
155 elm_check_state_set(ck, elm_fileselector_entry_expandable_get(fs_entry));
156 evas_object_smart_callback_add(ck, "changed", _expandable_toggle, fs_entry);
157 elm_box_pack_end(hbox, ck);
158 evas_object_show(ck);
160 evas_object_smart_callback_add(fs_entry, "file,chosen", _file_chosen, NULL);
162 evas_object_resize(win, 400, 400);
163 evas_object_show(win);