}
static void
+_sort_selected_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ Evas_Object *fs = evas_object_data_get(obj, "fileselector");
+ const char *selected = elm_object_item_text_get(event_info);
+
+ printf("selected sort method : %s\n", selected);
+ elm_object_text_set(obj, selected);
+ elm_fileselector_sort_method_set(fs, (Elm_Fileselector_Sort)data);
+}
+
+static Evas_Object *
+_sort_option_create(Evas_Object *parent, Evas_Object *fs)
+{
+ Evas_Object *frame = NULL, *hbox = NULL, *hoversel;
+
+ frame = elm_frame_add(parent);
+ evas_object_size_hint_weight_set(frame, EVAS_HINT_EXPAND, 0);
+ evas_object_size_hint_align_set(frame, EVAS_HINT_FILL, 0);
+ elm_object_text_set(frame, "Sort Option");
+ evas_object_show(frame);
+
+ hbox = elm_box_add(frame);
+ elm_box_horizontal_set(hbox, EINA_TRUE);
+ elm_object_content_set(frame, hbox);
+ evas_object_show(hbox);
+
+ hoversel = elm_hoversel_add(parent);
+ evas_object_data_set(hoversel, "fileselector", fs);
+ elm_object_text_set(hoversel, "Choose sort method");
+
+ elm_hoversel_item_add(hoversel, "File Name(asc)", NULL, ELM_ICON_NONE,
+ _sort_selected_cb,
+ (const void *)ELM_FILESELECTOR_SORT_BY_FILENAME_ASC);
+ elm_hoversel_item_add(hoversel, "File Name(desc)", NULL, ELM_ICON_NONE,
+ _sort_selected_cb,
+ (const void *) ELM_FILESELECTOR_SORT_BY_FILENAME_DESC);
+ elm_hoversel_item_add(hoversel, "Type(asc)", NULL, ELM_ICON_NONE,
+ _sort_selected_cb,
+ (const void *) ELM_FILESELECTOR_SORT_BY_TYPE_ASC);
+ elm_hoversel_item_add(hoversel, "Type(desc)", NULL, ELM_ICON_NONE,
+ _sort_selected_cb,
+ (const void *) ELM_FILESELECTOR_SORT_BY_TYPE_DESC);
+ elm_hoversel_item_add(hoversel, "Size(asc)", NULL, ELM_ICON_NONE,
+ _sort_selected_cb,
+ (const void *) ELM_FILESELECTOR_SORT_BY_SIZE_ASC);
+ elm_hoversel_item_add(hoversel, "Size(desc)", NULL, ELM_ICON_NONE,
+ _sort_selected_cb,
+ (const void *) ELM_FILESELECTOR_SORT_BY_SIZE_DESC);
+ elm_hoversel_item_add(hoversel, "Modified time(asc)", NULL, ELM_ICON_NONE,
+ _sort_selected_cb,
+ (const void *) ELM_FILESELECTOR_SORT_BY_MODIFIED_ASC);
+ elm_hoversel_item_add(hoversel, "Modified time(desc)", NULL, ELM_ICON_NONE,
+ _sort_selected_cb,
+ (const void *) ELM_FILESELECTOR_SORT_BY_MODIFIED_DESC);
+
+ elm_box_pack_end(hbox, hoversel);
+ evas_object_show(hoversel);
+
+ return frame;
+}
+
+static void
_small_icon_clicked(void *data,
Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
elm_box_pack_end(vbox, _option_create(vbox, fs));
elm_box_pack_end(vbox, _getter_option_create(vbox, fs));
elm_box_pack_end(vbox, _mode_option_create(vbox, fs));
+ elm_box_pack_end(vbox, _sort_option_create(vbox, fs));
elm_box_pack_end(vbox, _thumbnail_size_option_create(vbox, fs));
evas_object_resize(win, 320, 700);
return EINA_TRUE;
}
+static const char *
+_file_type(const char *a)
+{
+ char *p = strrchr(a, '.');
+ if (!p) return "";
+
+ return p;
+}
+
+static int
+_strcoll_rev(const char *a, const char *b)
+{
+ return strcoll(b, a);
+}
+
+static int
+_strcoll_type(const char *a, const char *b)
+{
+ return strcoll(_file_type(a), _file_type(b));
+}
+
+static int
+_strcoll_type_rev(const char *a, const char *b)
+{
+ return _strcoll_type(b, a);
+}
+
+static int
+_size_cmp(const char *a, const char *b)
+{
+ return ecore_file_size(a) - ecore_file_size(b);
+}
+
+static int
+_size_cmp_rev(const char *a, const char *b)
+{
+ return _size_cmp(b, a);
+}
+
+static int
+_modified_cmp(const char *a, const char *b)
+{
+ if (ecore_file_mod_time(a) > ecore_file_mod_time(b))
+ return 1;
+
+ return -1;
+}
+
+static int
+_modified_cmp_rev(const char *a, const char *b)
+{
+ return _modified_cmp(b, a);
+}
+
static int
-_file_grid_cmp(const void *a,
- const void *b)
+_file_grid_cmp(const void *a, const void *b)
{
+ Evas_Object *f;
+
const Elm_Object_Item *ga = a;
const Elm_Object_Item *gb = b;
const Elm_Gengrid_Item_Class *ca = elm_gengrid_item_item_class_get(ga);
return 1;
}
- return strcoll(elm_object_item_data_get(ga), elm_object_item_data_get(gb));
+ f = evas_object_data_get(elm_object_item_widget_get(ga), "parent");
+ ELM_FILESELECTOR_DATA_GET(f, sd);
+ return sd->sort_method(elm_object_item_data_get(ga),
+ elm_object_item_data_get(gb));
}
static int
-_file_list_cmp(const void *a,
- const void *b)
+_file_list_cmp(const void *a, const void *b)
{
+ Evas_Object *f;
+
const Elm_Object_Item *la = a;
const Elm_Object_Item *lb = b;
const Elm_Genlist_Item_Class *ca = elm_genlist_item_item_class_get(la);
return 1;
}
- return strcoll(elm_object_item_data_get(la), elm_object_item_data_get(lb));
+ f = evas_object_data_get(elm_object_item_widget_get(la), "parent");
+ ELM_FILESELECTOR_DATA_GET(f, sd);
+ return sd->sort_method(elm_object_item_data_get(la),
+ elm_object_item_data_get(lb));
}
static void
priv->thumbnail_size.w = elm_config_finger_size_get() * 2 - GENGRID_PADDING;
priv->thumbnail_size.h = priv->thumbnail_size.w;
+ priv->sort_type = ELM_FILESELECTOR_SORT_BY_FILENAME_ASC;
+ priv->sort_method = strcoll;
+
// files_view
priv->files_view = _files_list_add(obj);
if (h) *h = sd->thumbnail_size.h;
}
+EAPI void
+elm_fileselector_sort_method_set(Evas_Object *obj, Elm_Fileselector_Sort sort)
+{
+ ELM_FILESELECTOR_CHECK(obj);
+ eo_do(obj, elm_obj_fileselector_sort_method_set(sort));
+}
+
+static void
+_sort_method_set(Eo *obj __UNUSED__, void *_pd, va_list *list EINA_UNUSED)
+{
+ Elm_Fileselector_Sort sort = va_arg(*list, Elm_Fileselector_Sort);
+ Elm_Fileselector_Smart_Data *sd = _pd;
+
+ if (sd->sort_type == sort) return;
+ sd->sort_type = sort;
+
+ switch (sd->sort_type)
+ {
+ case ELM_FILESELECTOR_SORT_BY_FILENAME_ASC:
+ sd->sort_method = strcoll;
+ break;
+ case ELM_FILESELECTOR_SORT_BY_FILENAME_DESC:
+ sd->sort_method = _strcoll_rev;
+ break;
+ case ELM_FILESELECTOR_SORT_BY_TYPE_ASC:
+ sd->sort_method = _strcoll_type;
+ break;
+ case ELM_FILESELECTOR_SORT_BY_TYPE_DESC:
+ sd->sort_method = _strcoll_type_rev;
+ break;
+ case ELM_FILESELECTOR_SORT_BY_SIZE_ASC:
+ sd->sort_method = _size_cmp;
+ break;
+ case ELM_FILESELECTOR_SORT_BY_SIZE_DESC:
+ sd->sort_method = _size_cmp_rev;
+ break;
+ case ELM_FILESELECTOR_SORT_BY_MODIFIED_ASC:
+ sd->sort_method = _modified_cmp;
+ break;
+ case ELM_FILESELECTOR_SORT_BY_MODIFIED_DESC:
+ sd->sort_method = _modified_cmp_rev;
+ break;
+ case ELM_FILESELECTOR_SORT_LAST:
+ default:
+ sd->sort_method = strcoll;
+ }
+
+ _populate(obj, sd->path, NULL, NULL);
+}
+
+EAPI Elm_Fileselector_Sort
+elm_fileselector_sort_method_get(const Evas_Object *obj)
+{
+ ELM_FILESELECTOR_CHECK(obj) ELM_FILESELECTOR_SORT_LAST;
+ Elm_Fileselector_Sort ret = ELM_FILESELECTOR_SORT_LAST;
+ eo_do((Eo *) obj, elm_obj_fileselector_sort_method_get(&ret));
+
+ return ret;
+}
+
+static void
+_sort_method_get(Eo *obj EINA_UNUSED, void *_pd, va_list *list EINA_UNUSED)
+{
+ Elm_Fileselector_Sort *ret = va_arg(*list, Elm_Fileselector_Sort *);
+ Elm_Fileselector_Smart_Data *sd = _pd;
+
+ if (ret) *ret = sd->sort_type;
+}
+
static void
_elm_fileselector_smart_focus_next_manager_is(Eo *obj EINA_UNUSED, void *_pd EINA_UNUSED, va_list *list)
{
EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_HIDDEN_VISIBLE_GET), _hidden_visible_get),
EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_THUMBNAIL_SIZE_SET), _thumbnail_size_set),
EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_THUMBNAIL_SIZE_GET), _thumbnail_size_get),
+ EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_SORT_METHOD_SET), _sort_method_set),
+ EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_SORT_METHOD_GET), _sort_method_get),
EO_OP_FUNC_SENTINEL
};
eo_class_funcs_set(klass, func_desc);
EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_HIDDEN_VISIBLE_GET, "Get if visibility of hidden files/directories in the file selector widget is enabled or disabled."),
EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_THUMBNAIL_SIZE_SET, "Set the size for the thumbnail of the file selector widget's view, if it's in #ELM_FILESELECTOR_GRID mode"),
EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_THUMBNAIL_SIZE_GET, "Get the size for the thumbnails of a given file selector widget."),
+ EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_SORT_METHOD_SET, "Set the sort method of the file selector widget."),
+ EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_SORT_METHOD_GET, "Get the sort method of the file selector widget."),
EO_OP_DESCRIPTION_SENTINEL
};
static const Eo_Class_Description class_desc = {
ELM_FILESELECTOR_LAST /**< sentinel (helper) value, not used */
} Elm_Fileselector_Mode;
+typedef enum
+{
+ ELM_FILESELECTOR_SORT_BY_FILENAME_ASC = 0,
+ ELM_FILESELECTOR_SORT_BY_FILENAME_DESC,
+ ELM_FILESELECTOR_SORT_BY_TYPE_ASC,
+ ELM_FILESELECTOR_SORT_BY_TYPE_DESC,
+ ELM_FILESELECTOR_SORT_BY_SIZE_ASC,
+ ELM_FILESELECTOR_SORT_BY_SIZE_DESC,
+ ELM_FILESELECTOR_SORT_BY_MODIFIED_ASC,
+ ELM_FILESELECTOR_SORT_BY_MODIFIED_DESC,
+ ELM_FILESELECTOR_SORT_LAST /**< sentinel (helper) value, not used */
+} Elm_Fileselector_Sort;
ELM_OBJ_FILESELECTOR_SUB_ID_HIDDEN_VISIBLE_GET,
ELM_OBJ_FILESELECTOR_SUB_ID_THUMBNAIL_SIZE_SET,
ELM_OBJ_FILESELECTOR_SUB_ID_THUMBNAIL_SIZE_GET,
+ ELM_OBJ_FILESELECTOR_SUB_ID_SORT_METHOD_SET,
+ ELM_OBJ_FILESELECTOR_SUB_ID_SORT_METHOD_GET,
ELM_OBJ_FILESELECTOR_SUB_ID_LAST
};
#define elm_obj_fileselector_thumbnail_size_set(w, h) ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_THUMBNAIL_SIZE_SET), EO_TYPECHECK(Evas_Coord, w), EO_TYPECHECK(Evas_Coord, h)
/**
+ * @def elm_obj_fileselector_sort_method_get
+ * @since 1.9
+ *
+ * Get the sort method of the file selector widget.
+ *
+ * @param[out] ret
+ *
+ * @see elm_fileselector_sort_method_get
+ */
+#define elm_obj_fileselector_sort_method_get(ret) ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_SORT_METHOD_GET), EO_TYPECHECK(Elm_Fileselector_Sort *, ret)
+
+/**
+ * @def elm_obj_fileselector_sort_method_set
+ * @since 1.9
+ *
+ * Set the sort method of the file selector widget.
+ *
+ * @param[in] sort
+ *
+ * @see elm_fileselector_sort_method_set
+ */
+#define elm_obj_fileselector_sort_method_set(sort) ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_SORT_METHOD_SET), EO_TYPECHECK(Elm_Fileselector_Sort, sort)
+
+/**
* @}
*/
* @ingroup Fileselector
*/
EAPI void elm_fileselector_thumbnail_size_get(const Evas_Object *obj, Evas_Coord *w, Evas_Coord *h);
+
+/**
+ * Get the sort method of the file selector widget.
+ *
+ * @param obj The file selector object
+ * @return The sort method
+ *
+ * @see elm_fileselector_sort_method_set()
+ *
+ * @since 1.9
+ * @ingroup Fileselector
+ */
+EAPI Elm_Fileselector_Sort elm_fileselector_sort_method_get(const Evas_Object *obj);
+
+/**
+ * Set the sort method of the file selector widget.
+ *
+ * @param obj The file selector object
+ * @param sort The sort method
+ *
+ * @see elm_fileselector_sort_method_get()
+ *
+ * @since 1.9
+ * @ingroup Fileselector
+ */
+EAPI void elm_fileselector_sort_method_set(Evas_Object *obj, Elm_Fileselector_Sort method);
Evas_Coord_Size thumbnail_size;
+ /* a sort method to decide orders of files/directories */
+ int (*sort_method)(const char *, const char *);
+
Elm_Fileselector_Mode mode;
+ Elm_Fileselector_Sort sort_type;
Eina_Bool only_folder : 1;
Eina_Bool expand : 1;