ecore: improve usability of Efl.Select_Model to provide helpers in manipulating selection information.
Reviewed-by: Marcel Hollerbach <mail@marcel-hollerbach.de> Differential Revision: https://phab.enlightenment.org/D8570
This commit is contained in:
parent
be37c47fff
commit
4e4210b0f3
|
@ -18,7 +18,7 @@ struct _Efl_Select_Model_Data
|
||||||
Efl_Select_Model_Data *parent;
|
Efl_Select_Model_Data *parent;
|
||||||
unsigned long last;
|
unsigned long last;
|
||||||
|
|
||||||
Eina_Bool exclusive : 1;
|
Eina_Bool single_selection : 1;
|
||||||
Eina_Bool none : 1;
|
Eina_Bool none : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -247,7 +247,7 @@ _efl_select_model_efl_model_properties_get(const Eo *obj,
|
||||||
EFL_COMPOSITE_MODEL_PROPERTIES_SUPER(props,
|
EFL_COMPOSITE_MODEL_PROPERTIES_SUPER(props,
|
||||||
obj, EFL_SELECT_MODEL_CLASS,
|
obj, EFL_SELECT_MODEL_CLASS,
|
||||||
NULL,
|
NULL,
|
||||||
"self.selected", "child.selected", "exclusive");
|
"self.selected", "child.selected", "single_selection");
|
||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,19 +258,19 @@ _efl_select_model_efl_model_property_set(Eo *obj,
|
||||||
{
|
{
|
||||||
Eina_Value vf = EINA_VALUE_EMPTY;
|
Eina_Value vf = EINA_VALUE_EMPTY;
|
||||||
|
|
||||||
if (!strcmp("exclusive", property))
|
if (!strcmp("single_selection", property))
|
||||||
{
|
{
|
||||||
Eina_Bool exclusive = pd->exclusive;
|
Eina_Bool single_selection = pd->single_selection;
|
||||||
Eina_Bool changed;
|
Eina_Bool changed;
|
||||||
|
|
||||||
vf = eina_value_bool_init(exclusive);
|
vf = eina_value_bool_init(single_selection);
|
||||||
eina_value_convert(value, &vf);
|
eina_value_convert(value, &vf);
|
||||||
eina_value_bool_get(&vf, &exclusive);
|
eina_value_bool_get(&vf, &single_selection);
|
||||||
|
|
||||||
changed = (!pd->exclusive != !exclusive);
|
changed = (!pd->single_selection != !single_selection);
|
||||||
pd->exclusive = !!exclusive;
|
pd->single_selection = !!single_selection;
|
||||||
|
|
||||||
if (changed) efl_model_properties_changed(obj, "exclusive");
|
if (changed) efl_model_properties_changed(obj, "single_selection");
|
||||||
|
|
||||||
return efl_loop_future_resolved(obj, vf);
|
return efl_loop_future_resolved(obj, vf);
|
||||||
}
|
}
|
||||||
|
@ -291,7 +291,7 @@ _efl_select_model_efl_model_property_set(Eo *obj,
|
||||||
if (pd->parent && !strcmp("self.selected", property))
|
if (pd->parent && !strcmp("self.selected", property))
|
||||||
{
|
{
|
||||||
Eina_Bool prevflag = EINA_FALSE, newflag = EINA_FALSE;
|
Eina_Bool prevflag = EINA_FALSE, newflag = EINA_FALSE;
|
||||||
Eina_Bool exclusive = EINA_FALSE;
|
Eina_Bool single_selection = EINA_FALSE;
|
||||||
Eina_Bool success;
|
Eina_Bool success;
|
||||||
Eina_Value *prev;
|
Eina_Value *prev;
|
||||||
Eina_Future *chain;
|
Eina_Future *chain;
|
||||||
|
@ -306,14 +306,14 @@ _efl_select_model_efl_model_property_set(Eo *obj,
|
||||||
if (newflag == prevflag)
|
if (newflag == prevflag)
|
||||||
return efl_loop_future_resolved(obj, eina_value_bool_init(newflag));
|
return efl_loop_future_resolved(obj, eina_value_bool_init(newflag));
|
||||||
|
|
||||||
exclusive = pd->parent->exclusive;
|
single_selection = pd->parent->single_selection;
|
||||||
|
|
||||||
// First store the new value in the boolean model we inherit from
|
// First store the new value in the boolean model we inherit from
|
||||||
chain = efl_model_property_set(efl_super(obj, EFL_SELECT_MODEL_CLASS),
|
chain = efl_model_property_set(efl_super(obj, EFL_SELECT_MODEL_CLASS),
|
||||||
"selected", value);
|
"selected", value);
|
||||||
|
|
||||||
// Now act !
|
// Now act !
|
||||||
if (exclusive)
|
if (single_selection)
|
||||||
{
|
{
|
||||||
// We are here either, because we weren't and are after this call
|
// We are here either, because we weren't and are after this call
|
||||||
// or because we were selected and are not anymore. In the later case,
|
// or because we were selected and are not anymore. In the later case,
|
||||||
|
@ -364,8 +364,8 @@ _efl_select_model_efl_model_property_set(Eo *obj,
|
||||||
static Eina_Value *
|
static Eina_Value *
|
||||||
_efl_select_model_efl_model_property_get(const Eo *obj, Efl_Select_Model_Data *pd, const char *property)
|
_efl_select_model_efl_model_property_get(const Eo *obj, Efl_Select_Model_Data *pd, const char *property)
|
||||||
{
|
{
|
||||||
if (!strcmp("exclusive", property))
|
if (!strcmp("single_selection", property))
|
||||||
return eina_value_bool_new(pd->exclusive);
|
return eina_value_bool_new(pd->single_selection);
|
||||||
// Last selected child
|
// Last selected child
|
||||||
if (!strcmp("child.selected", property))
|
if (!strcmp("child.selected", property))
|
||||||
{
|
{
|
||||||
|
@ -383,4 +383,28 @@ _efl_select_model_efl_model_property_get(const Eo *obj, Efl_Select_Model_Data *p
|
||||||
return efl_model_property_get(efl_super(obj, EFL_SELECT_MODEL_CLASS), property);
|
return efl_model_property_get(efl_super(obj, EFL_SELECT_MODEL_CLASS), property);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_efl_select_model_single_selection_set(Eo *obj EINA_UNUSED, Efl_Select_Model_Data *pd, Eina_Bool enable)
|
||||||
|
{
|
||||||
|
pd->single_selection = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Eina_Bool
|
||||||
|
_efl_select_model_single_selection_get(const Eo *obj EINA_UNUSED, Efl_Select_Model_Data *pd)
|
||||||
|
{
|
||||||
|
return pd->single_selection;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Eina_Iterator *
|
||||||
|
_efl_select_model_selected_get(Eo *obj, Efl_Select_Model_Data *pd EINA_UNUSED)
|
||||||
|
{
|
||||||
|
return efl_boolean_model_boolean_iterator_get(obj, "selected", EINA_TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Eina_Iterator *
|
||||||
|
_efl_select_model_unselected_get(Eo *obj, Efl_Select_Model_Data *pd EINA_UNUSED)
|
||||||
|
{
|
||||||
|
return efl_boolean_model_boolean_iterator_get(obj, "selected", EINA_FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
#include "efl_select_model.eo.c"
|
#include "efl_select_model.eo.c"
|
||||||
|
|
|
@ -1,6 +1,29 @@
|
||||||
class @beta Efl.Select_Model extends Efl.Boolean_Model
|
class @beta Efl.Select_Model extends Efl.Boolean_Model
|
||||||
{
|
{
|
||||||
[[Efl select model class]]
|
[[Efl select model class]]
|
||||||
|
methods {
|
||||||
|
selected_get {
|
||||||
|
[[Get an iterator of all the selected child of this model.
|
||||||
|
]]
|
||||||
|
return: iterator<uint64>; [[The iterator give indexes of selected child. It is valid until any change is made on the model.]]
|
||||||
|
}
|
||||||
|
unselected_get {
|
||||||
|
[[Get an iterator of all the child of this model that are not selected.
|
||||||
|
]]
|
||||||
|
return: iterator<uint64>; [[The iterator give indexes of unselected child. It is valid until any change is made on the model.]]
|
||||||
|
}
|
||||||
|
@property single_selection {
|
||||||
|
[[Define if we support only one exclusive selection at a time when set to $true.
|
||||||
|
|
||||||
|
If disable with $false, it will have the behavior of a multi select mode.
|
||||||
|
]]
|
||||||
|
set { }
|
||||||
|
get { }
|
||||||
|
values {
|
||||||
|
enable: bool; [[$true will enable the exclusive mode.]]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
implements {
|
implements {
|
||||||
Efl.Object.constructor;
|
Efl.Object.constructor;
|
||||||
Efl.Model.property { get; set; }
|
Efl.Model.property { get; set; }
|
||||||
|
|
|
@ -161,6 +161,8 @@ EFL_START_TEST(efl_test_select_model)
|
||||||
Eina_Value v = { 0 };
|
Eina_Value v = { 0 };
|
||||||
Efl_Select_Model *model;
|
Efl_Select_Model *model;
|
||||||
Eina_Future *future;
|
Eina_Future *future;
|
||||||
|
Eina_Iterator *it;
|
||||||
|
uint64_t *index;
|
||||||
|
|
||||||
eina_value_setup(&v, EINA_VALUE_TYPE_INT);
|
eina_value_setup(&v, EINA_VALUE_TYPE_INT);
|
||||||
|
|
||||||
|
@ -186,6 +188,16 @@ EFL_START_TEST(efl_test_select_model)
|
||||||
eina_future_then(future, _selection_children_slice_get_then, NULL, NULL);
|
eina_future_then(future, _selection_children_slice_get_then, NULL, NULL);
|
||||||
|
|
||||||
ecore_main_loop_begin();
|
ecore_main_loop_begin();
|
||||||
|
|
||||||
|
it = efl_select_model_selected_get(model);
|
||||||
|
EINA_ITERATOR_FOREACH(it, index)
|
||||||
|
fail_if(*index != 2);
|
||||||
|
eina_iterator_free(it);
|
||||||
|
|
||||||
|
it = efl_select_model_unselected_get(model);
|
||||||
|
EINA_ITERATOR_FOREACH(it, index)
|
||||||
|
fail_if(*index == 2);
|
||||||
|
eina_iterator_free(it);
|
||||||
}
|
}
|
||||||
EFL_END_TEST
|
EFL_END_TEST
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue