forked from enlightenment/efl
elementary: migrate filesector to use the new Efl.Model API.
This commit is contained in:
parent
a408c145e9
commit
8093eca7f3
File diff suppressed because it is too large
Load Diff
|
@ -3,8 +3,10 @@
|
|||
#endif
|
||||
|
||||
#define EFL_ACCESS_OBJECT_PROTECTED
|
||||
#define ELM_INTERFACE_FILESELECTOR_BETA
|
||||
|
||||
#include <Elementary.h>
|
||||
#include "Eio_Eo.h"
|
||||
#include "elm_priv.h"
|
||||
#include "elm_fileselector_button.eo.h"
|
||||
#include "elm_fileselector_entry.eo.h"
|
||||
|
@ -37,12 +39,6 @@ static const Evas_Smart_Cb_Description _smart_callbacks[] = {
|
|||
};
|
||||
#undef ELM_PRIV_FILESELECTOR_BUTTON_SIGNALS
|
||||
|
||||
static void
|
||||
_model_free_eo_cb(void *eo)
|
||||
{
|
||||
efl_unref(eo);
|
||||
}
|
||||
|
||||
EOLIAN static Efl_Ui_Theme_Apply
|
||||
_elm_fileselector_button_efl_ui_widget_theme_apply(Eo *obj, Elm_Fileselector_Button_Data *sd EINA_UNUSED)
|
||||
{
|
||||
|
@ -70,30 +66,6 @@ _elm_fileselector_button_efl_ui_widget_theme_apply(Eo *obj, Elm_Fileselector_But
|
|||
return int_ret;
|
||||
}
|
||||
|
||||
static void
|
||||
_replace_path_then(void *data, Efl_Event const *event)
|
||||
{
|
||||
Elm_Fileselector_Button_Data *sd = data;
|
||||
Efl_Future_Event_Success *ev = event->info;
|
||||
Eina_Value *v = ev->value;
|
||||
const char *path = NULL;
|
||||
|
||||
eina_value_get(v, &path);
|
||||
eina_stringshare_replace(&sd->fsd.path, path);
|
||||
_event_to_legacy_call
|
||||
(sd->obj, ELM_FILESELECTOR_BUTTON_EVENT_FILE_CHOSEN, (void *)path);
|
||||
}
|
||||
|
||||
static void
|
||||
_replace_path_then_error(void *data, Efl_Event const* event EINA_UNUSED)
|
||||
{
|
||||
Elm_Fileselector_Button_Data *sd = data;
|
||||
ERR("could not get information from Efl.Model");
|
||||
eina_stringshare_replace(&sd->fsd.path, NULL);
|
||||
_event_to_legacy_call
|
||||
(sd->obj, ELM_FILESELECTOR_BUTTON_EVENT_FILE_CHOSEN, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
_selection_done(void *data, const Efl_Event *event)
|
||||
{
|
||||
|
@ -103,15 +75,22 @@ _selection_done(void *data, const Efl_Event *event)
|
|||
|
||||
if (model)
|
||||
{
|
||||
Efl_Future *future = NULL;
|
||||
if (sd->fsd.model)
|
||||
efl_unref(sd->fsd.model);
|
||||
// XXX: the efl_ref here smells wrong. fsd.model is only unreffed ONCE so this obj leaks...
|
||||
sd->fsd.model = efl_ref(model);
|
||||
future = efl_model_property_get(model, "path");
|
||||
efl_future_then(future, _replace_path_then, _replace_path_then_error, NULL, sd);
|
||||
Eina_Value *path;
|
||||
char *file;
|
||||
|
||||
efl_replace(&sd->fsd.model, model);
|
||||
|
||||
path = efl_model_property_get(model, "path");
|
||||
file = eina_value_to_string(path);
|
||||
eina_stringshare_replace(&sd->fsd.path, file);
|
||||
|
||||
efl_event_callback_call
|
||||
(sd->obj, ELM_FILESELECTOR_BUTTON_EVENT_FILE_CHOSEN, model);
|
||||
_event_to_legacy_call
|
||||
(sd->obj, ELM_FILESELECTOR_BUTTON_EVENT_FILE_CHOSEN, file);
|
||||
|
||||
eina_value_free(path);
|
||||
free(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -322,17 +301,15 @@ _elm_fileselector_button_path_set_internal(Evas_Object *obj, const char *path)
|
|||
{
|
||||
ELM_FILESELECTOR_BUTTON_DATA_GET_OR_RETURN(obj, sd);
|
||||
|
||||
Efl_Model *model = efl_add(EIO_MODEL_CLASS, efl_provider_find(obj, EFL_LOOP_CLASS), eio_model_path_set(efl_added, path));
|
||||
Efl_Model *model = efl_add(EIO_MODEL_CLASS, obj, eio_model_path_set(efl_added, path));
|
||||
if (!model)
|
||||
{
|
||||
ERR("Efl.Model allocation error");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sd->fsd.model)
|
||||
efl_unref(sd->fsd.model);
|
||||
// XXX: the efl_ref here smells wrong. fsd.model is only unreffed ONCE so this obj leaks...
|
||||
sd->fsd.model = efl_ref(model);
|
||||
efl_replace(&sd->fsd.model, model);
|
||||
|
||||
eina_stringshare_replace(&sd->fsd.path, path);
|
||||
|
||||
|
@ -349,21 +326,26 @@ elm_fileselector_button_path_set(Evas_Object *obj, const char *path)
|
|||
EOLIAN static void
|
||||
_elm_fileselector_button_efl_ui_view_model_set(Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd, Efl_Model *model)
|
||||
{
|
||||
if (sd->fsd.model)
|
||||
efl_unref(sd->fsd.model);
|
||||
char *file = NULL;
|
||||
|
||||
efl_replace(&sd->fsd.model, model);
|
||||
|
||||
if (model)
|
||||
{
|
||||
sd->fsd.model = efl_ref(model);
|
||||
efl_future_then(efl_model_property_get(model, "path"),
|
||||
_replace_path_then, _replace_path_then_error, NULL, sd);
|
||||
}
|
||||
else
|
||||
{
|
||||
sd->fsd.model = NULL;
|
||||
eina_stringshare_replace(&sd->fsd.path, NULL);
|
||||
Eina_Value *path;
|
||||
|
||||
path = efl_model_property_get(model, "path");
|
||||
file = eina_value_to_string(path);
|
||||
eina_value_free(path);
|
||||
}
|
||||
|
||||
eina_stringshare_replace(&sd->fsd.path, file);
|
||||
|
||||
_event_to_legacy_call
|
||||
(sd->obj, ELM_FILESELECTOR_BUTTON_EVENT_FILE_CHOSEN, file);
|
||||
|
||||
free(file);
|
||||
|
||||
if (sd->fs) elm_interface_fileselector_selected_model_set(sd->fs, model);
|
||||
}
|
||||
|
||||
|
@ -551,7 +533,7 @@ _elm_fileselector_button_selected_get_internal(const Evas_Object *obj)
|
|||
}
|
||||
|
||||
EOLIAN static Efl_Model *
|
||||
_elm_fileselector_button_elm_interface_fileselector_selected_model_get(Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd)
|
||||
_elm_fileselector_button_elm_interface_fileselector_selected_model_get(const Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd)
|
||||
{
|
||||
if (sd->fs) return elm_interface_fileselector_selected_model_get(sd->fs);
|
||||
|
||||
|
@ -581,37 +563,15 @@ _elm_fileselector_button_selected_set_internal(Evas_Object *obj, const char *_pa
|
|||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
_selected_model_then(void *data, Efl_Event const *event)
|
||||
{
|
||||
Eo* v = (Eo*)((Efl_Future_Event_Success*)event->info)->value;
|
||||
Efl_Promise *owner = data;
|
||||
efl_promise_value_set(owner, efl_ref(v), _model_free_eo_cb);
|
||||
}
|
||||
|
||||
static void
|
||||
_selected_model_then_error(void *data, Efl_Event const* event)
|
||||
{
|
||||
Efl_Promise *owner = data;
|
||||
efl_promise_failed_set(owner, ((Efl_Future_Event_Failure*)event->info)->error);
|
||||
}
|
||||
|
||||
EOLIAN static Efl_Future*
|
||||
EOLIAN static Eina_Bool
|
||||
_elm_fileselector_button_elm_interface_fileselector_selected_model_set(Eo *obj EINA_UNUSED, Elm_Fileselector_Button_Data *sd, Efl_Model *model)
|
||||
{
|
||||
Efl_Promise* promise = efl_add(EFL_PROMISE_CLASS, obj);
|
||||
if (sd->fs)
|
||||
{
|
||||
efl_future_then(elm_interface_fileselector_selected_model_set(sd->fs, model),
|
||||
_selected_model_then, _selected_model_then_error, NULL, promise);
|
||||
}
|
||||
else
|
||||
efl_promise_failed_set(promise, EINA_ERROR_FUTURE_CANCEL);
|
||||
elm_interface_fileselector_selected_model_set(sd->fs, model);
|
||||
|
||||
if (sd->fsd.selection)
|
||||
efl_unref(sd->fsd.selection);
|
||||
sd->fsd.selection = model ? efl_ref(model) : NULL;
|
||||
return efl_promise_future_get(promise);
|
||||
efl_replace(&sd->fsd.selection, model);
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
EOLIAN static void
|
||||
|
|
|
@ -4,8 +4,10 @@
|
|||
#endif
|
||||
|
||||
#define EFL_ACCESS_OBJECT_PROTECTED
|
||||
#define ELM_INTERFACE_FILESELECTOR_BETA
|
||||
|
||||
#include <Elementary.h>
|
||||
#include "Eio_Eo.h"
|
||||
#include "elm_priv.h"
|
||||
#include "elm_fileselector_button.eo.h"
|
||||
#include "elm_fileselector_entry.eo.h"
|
||||
|
@ -65,54 +67,26 @@ SIG_FWD(SELECTION_CUT, EFL_UI_EVENT_SELECTION_CUT)
|
|||
SIG_FWD(UNPRESSED, EFL_UI_EVENT_UNPRESSED)
|
||||
#undef SIG_FWD
|
||||
|
||||
static void
|
||||
_file_chosen_path_then(void *data, Efl_Event const* event)
|
||||
{
|
||||
Eina_Array *args = data;
|
||||
const char *file = NULL;
|
||||
char *s;
|
||||
Eo *fs = eina_array_data_get(args, 0);
|
||||
Efl_Model *model = eina_array_data_get(args, 1);
|
||||
|
||||
eina_array_free(args);
|
||||
|
||||
eina_value_get((Eina_Value*)((Efl_Future_Event_Success*)event->info)->value, &file);
|
||||
|
||||
if (!file) return;
|
||||
ELM_FILESELECTOR_ENTRY_DATA_GET(fs, sd);
|
||||
|
||||
s = elm_entry_utf8_to_markup(file);
|
||||
elm_object_text_set(sd->entry, s);
|
||||
free(s);
|
||||
|
||||
_model_event_call
|
||||
(fs, ELM_FILESELECTOR_ENTRY_EVENT_FILE_CHOSEN, model, file);
|
||||
}
|
||||
|
||||
static void
|
||||
_file_chosen_path_then_error(void *data, Efl_Event const* event)
|
||||
{
|
||||
Eina_Error err = ((Efl_Future_Event_Failure*)event->info)->error;
|
||||
ERR("Efl.Model property \"path\" error: %s", eina_error_msg_get(err));
|
||||
eina_array_free(data);
|
||||
}
|
||||
|
||||
static void
|
||||
_FILE_CHOSEN_fwd(void *data, const Efl_Event *event)
|
||||
{
|
||||
Efl_Model *model = event->info;
|
||||
Efl_Future *future = NULL;
|
||||
Eina_Array *args = NULL;
|
||||
Eo *fs = data;
|
||||
Eina_Value *path;
|
||||
char *file = NULL;
|
||||
ELM_FILESELECTOR_ENTRY_DATA_GET(fs, sd);
|
||||
|
||||
if (!model) return;
|
||||
efl_ui_view_model_set(sd->entry, model);
|
||||
efl_ui_model_connect(sd->entry, "default", "path");
|
||||
|
||||
args = eina_array_new(2);
|
||||
eina_array_push(args, data);
|
||||
eina_array_push(args, model);
|
||||
path = efl_model_property_get(model, "path");
|
||||
file = eina_value_to_string(path);
|
||||
|
||||
future = efl_model_property_get(model, "path");
|
||||
efl_future_then
|
||||
(future, _file_chosen_path_then, _file_chosen_path_then_error, NULL, args);
|
||||
_model_event_call
|
||||
(fs, ELM_FILESELECTOR_ENTRY_EVENT_FILE_CHOSEN, model, file);
|
||||
|
||||
eina_value_free(path);
|
||||
free(file);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -141,12 +115,6 @@ _ACTIVATED_fwd(void *data, const Efl_Event *event)
|
|||
(data, ELM_FILESELECTOR_ENTRY_EVENT_ACTIVATED, event->info);
|
||||
}
|
||||
|
||||
static void
|
||||
_model_free_eo_cb(void *eo)
|
||||
{
|
||||
efl_unref(eo);
|
||||
}
|
||||
|
||||
EOLIAN static void
|
||||
_elm_fileselector_entry_elm_layout_sizing_eval(Eo *obj, Elm_Fileselector_Entry_Data *sd EINA_UNUSED)
|
||||
{
|
||||
|
@ -358,16 +326,14 @@ _elm_fileselector_entry_selected_set_internal(Evas_Object *obj, const char *path
|
|||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
EOLIAN static Efl_Future*
|
||||
EOLIAN static Eina_Bool
|
||||
_elm_fileselector_entry_elm_interface_fileselector_selected_model_set(Eo *obj EINA_UNUSED,
|
||||
Elm_Fileselector_Entry_Data *sd,
|
||||
Efl_Model *model)
|
||||
{
|
||||
Efl_Promise* promise = efl_add(EFL_PROMISE_CLASS, obj);
|
||||
Efl_Future* future = efl_promise_future_get(promise);
|
||||
efl_ui_view_model_set(sd->button, model);
|
||||
efl_promise_value_set(promise, efl_ref(model), _model_free_eo_cb);
|
||||
return future;
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
EINA_DEPRECATED EAPI const char *
|
||||
|
@ -385,7 +351,7 @@ _elm_fileselector_entry_selected_get_internal(const Evas_Object *obj)
|
|||
}
|
||||
|
||||
EOLIAN static Efl_Model *
|
||||
_elm_fileselector_entry_elm_interface_fileselector_selected_model_get(Eo *obj EINA_UNUSED, Elm_Fileselector_Entry_Data *sd)
|
||||
_elm_fileselector_entry_elm_interface_fileselector_selected_model_get(const Eo *obj EINA_UNUSED, Elm_Fileselector_Entry_Data *sd)
|
||||
{
|
||||
return efl_ui_view_model_get(sd->button);
|
||||
}
|
||||
|
@ -448,34 +414,12 @@ _elm_fileselector_entry_path_set_internal(Evas_Object *obj, const char *path)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_fs_entry_model_path_get_then(void *data, Efl_Event const *event)
|
||||
{
|
||||
Elm_Fileselector_Entry_Data *sd = data;
|
||||
char *path = NULL;
|
||||
char *s;
|
||||
Eina_Value* v = (Eina_Value*)((Efl_Future_Event_Success*)event->info)->value;
|
||||
|
||||
if (!v)
|
||||
return;
|
||||
|
||||
eina_value_get(v, &path);
|
||||
s = elm_entry_utf8_to_markup(path);
|
||||
if (s)
|
||||
{
|
||||
elm_object_text_set(sd->entry, s);
|
||||
free(s);
|
||||
}
|
||||
}
|
||||
|
||||
EOLIAN static void
|
||||
_elm_fileselector_entry_efl_ui_view_model_set(Eo *obj EINA_UNUSED, Elm_Fileselector_Entry_Data *sd, Efl_Model *model)
|
||||
{
|
||||
Efl_Future *p = NULL;
|
||||
efl_ui_view_model_set(sd->button, model);
|
||||
|
||||
p = efl_model_property_get(model, "path");
|
||||
efl_future_then(p, _fs_entry_model_path_get_then, NULL, NULL, sd);
|
||||
efl_ui_view_model_set(sd->entry, model);
|
||||
efl_ui_model_connect(sd->entry, "default", "path");
|
||||
}
|
||||
|
||||
EINA_DEPRECATED EAPI const char *
|
||||
|
|
|
@ -39,8 +39,7 @@ class Elm.Fileselector (Efl.Ui.Layout.Object, Elm.Interface.Fileselector,
|
|||
Efl.Ui.Widget.theme_apply;
|
||||
Efl.Ui.Widget.focus_state_apply;
|
||||
Elm.Interface.Fileselector.selected_models { get; }
|
||||
Elm.Interface.Fileselector.selected_model_get;
|
||||
Elm.Interface.Fileselector.selected_model_set;
|
||||
Elm.Interface.Fileselector.selected_model { get; set; }
|
||||
Elm.Interface.Fileselector.custom_filter_append;
|
||||
Elm.Interface.Fileselector.expandable { get; set; }
|
||||
Elm.Interface.Fileselector.thumbnail_size { get; set; }
|
||||
|
|
|
@ -10,8 +10,7 @@ class Elm.Fileselector_Button (Efl.Ui.Button, Elm.Interface.Fileselector,
|
|||
Elm.Interface.Fileselector.selected_models { get; }
|
||||
Elm.Interface.Fileselector.expandable { get; set; }
|
||||
Elm.Interface.Fileselector.thumbnail_size { get; set; }
|
||||
Elm.Interface.Fileselector.selected_model_get;
|
||||
Elm.Interface.Fileselector.selected_model_set;
|
||||
Elm.Interface.Fileselector.selected_model { get; set; }
|
||||
Elm.Interface.Fileselector.hidden_visible { get; set; }
|
||||
Elm.Interface.Fileselector.is_save { get; set; }
|
||||
Efl.Ui.View.model { get; set; }
|
||||
|
|
|
@ -8,8 +8,7 @@ class Elm.Fileselector_Entry (Efl.Ui.Layout.Object, Elm.Interface.Fileselector,
|
|||
Efl.Object.constructor;
|
||||
Efl.Ui.Widget.theme_apply;
|
||||
Efl.Ui.Widget.on_disabled_update;
|
||||
Elm.Interface.Fileselector.selected_model_get;
|
||||
Elm.Interface.Fileselector.selected_model_set;
|
||||
Elm.Interface.Fileselector.selected_model { get; set; }
|
||||
Elm.Interface.Fileselector.folder_only { get; set; }
|
||||
Elm.Interface.Fileselector.is_save { get; set; }
|
||||
Efl.Ui.View.model { get; set; }
|
||||
|
|
|
@ -2,7 +2,11 @@
|
|||
# include "elementary_config.h"
|
||||
#endif
|
||||
|
||||
#define ELM_INTERFACE_FILESELECTOR_BETA
|
||||
|
||||
#include <Elementary.h>
|
||||
#include "Eio_Eo.h"
|
||||
|
||||
#include "elm_interface_fileselector.h"
|
||||
|
||||
#include "elm_interface_fileselector.eo.c"
|
||||
|
|
|
@ -137,16 +137,17 @@ interface Elm.Interface.Fileselector (Efl.Ui.View)
|
|||
name: string; [[Name]]
|
||||
}
|
||||
}
|
||||
selected_model_set {
|
||||
[[Set, programmatically, the currently selected file/directory in the given file selector widget]]
|
||||
params {
|
||||
@in model: Efl.Model; [[Model to be set]]
|
||||
@property selected_model @beta {
|
||||
set {
|
||||
[[Set, programmatically, the currently selected file/directory in the given file selector widget]]
|
||||
return: bool; [[$true on success, $false otherwise]]
|
||||
}
|
||||
get {
|
||||
[[Get the currently selected item's model, in the given file the given file selector widget]]
|
||||
}
|
||||
values {
|
||||
model: Eio.Model; [[Model to be set, NULL reset it.]]
|
||||
}
|
||||
return: future<Efl.Model>; [[Promise returning the recorded selected model or error]]
|
||||
}
|
||||
selected_model_get {
|
||||
[[Get the currently selected item's model, in the given file the given file selector widget]]
|
||||
return: Efl.Model; [[Selected model]]
|
||||
}
|
||||
custom_filter_append {
|
||||
[[Append custom filter into filter list]]
|
||||
|
|
|
@ -57,6 +57,8 @@ struct _Elm_Fileselector_Data
|
|||
Ecore_Idler *populate_idler;
|
||||
Ecore_Idler *path_entry_idler;
|
||||
|
||||
Efl_Model *target;
|
||||
|
||||
const char *path_separator;
|
||||
const char *search_string;
|
||||
|
||||
|
@ -104,6 +106,7 @@ struct _Listing_Request
|
|||
Eina_Stringshare *selected_path;
|
||||
int item_total;
|
||||
int item_processed_count;
|
||||
|
||||
Eina_Bool first : 1;
|
||||
Eina_Bool valid : 1;
|
||||
};
|
||||
|
@ -114,11 +117,13 @@ struct _Elm_Fileselector_Item_Data
|
|||
Efl_Model *model;
|
||||
Eina_Stringshare *path;
|
||||
Eina_Stringshare *filename;
|
||||
int64_t size;
|
||||
double mtime;
|
||||
Eina_Stringshare *mime_type;
|
||||
Efl_Model *parent_model;
|
||||
const char *parent_path;
|
||||
|
||||
int64_t size;
|
||||
double mtime;
|
||||
|
||||
Eina_Bool is_dir : 1;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue