summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2020-01-03 15:35:17 -0800
committerCedric BAIL <cedric.bail@free.fr>2020-01-09 10:27:43 -0800
commit9ac976b079dae2e0355216af26f671837c9e5dc2 (patch)
treeafa79f1757e5ab34f76bf118fc4748893c172057
parent93c7e7dc8f2ad5efa7617e25b8f51346e67778ce (diff)
elementary: properly propagate "child.selected" change.
Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Differential Revision: https://phab.enlightenment.org/D11013
-rw-r--r--src/lib/elementary/efl_ui_select_model.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/src/lib/elementary/efl_ui_select_model.c b/src/lib/elementary/efl_ui_select_model.c
index 6852b50b40..fde6cca4c7 100644
--- a/src/lib/elementary/efl_ui_select_model.c
+++ b/src/lib/elementary/efl_ui_select_model.c
@@ -24,18 +24,23 @@ struct _Efl_Ui_Select_Model_Data
24 Efl_Ui_Select_Model *last_model; 24 Efl_Ui_Select_Model *last_model;
25 25
26 Efl_Ui_Select_Mode selection; 26 Efl_Ui_Select_Mode selection;
27
28 Eina_Bool none : 1;
29}; 27};
30 28
31static void 29static void
30_efl_ui_select_model_apply_last_model(Eo *obj, Efl_Ui_Select_Model_Data *pd, Eo *last_model)
31{
32 efl_replace(&pd->last_model, last_model);
33 efl_model_properties_changed(obj, "child.selected");
34}
35
36static void
32_efl_ui_select_model_child_removed(void *data, const Efl_Event *event) 37_efl_ui_select_model_child_removed(void *data, const Efl_Event *event)
33{ 38{
34 Efl_Ui_Select_Model_Data *pd = data; 39 Efl_Ui_Select_Model_Data *pd = data;
35 Efl_Model_Children_Event *ev = event->info; 40 Efl_Model_Children_Event *ev = event->info;
36 41
37 if (ev->child == pd->last_model) 42 if (ev->child == pd->last_model)
38 efl_replace(&pd->last_model, NULL); 43 _efl_ui_select_model_apply_last_model(event->object, pd, NULL);
39} 44}
40 45
41static Eo* 46static Eo*
@@ -49,7 +54,6 @@ _efl_ui_select_model_efl_object_constructor(Eo *obj,
49 efl_boolean_model_boolean_add(obj, "selected", EINA_FALSE); 54 efl_boolean_model_boolean_add(obj, "selected", EINA_FALSE);
50 55
51 efl_event_callback_add(obj, EFL_MODEL_EVENT_CHILD_REMOVED, _efl_ui_select_model_child_removed, pd); 56 efl_event_callback_add(obj, EFL_MODEL_EVENT_CHILD_REMOVED, _efl_ui_select_model_child_removed, pd);
52 pd->none = EINA_TRUE;
53 57
54 parent = efl_parent_get(obj); 58 parent = efl_parent_get(obj);
55 if (efl_isa(parent, EFL_UI_SELECT_MODEL_CLASS)) 59 if (efl_isa(parent, EFL_UI_SELECT_MODEL_CLASS))
@@ -64,7 +68,6 @@ _efl_ui_select_model_efl_object_invalidate(Eo *obj,
64{ 68{
65 efl_replace(&pd->fallback_model, NULL); 69 efl_replace(&pd->fallback_model, NULL);
66 efl_replace(&pd->last_model, NULL); 70 efl_replace(&pd->last_model, NULL);
67 pd->none = EINA_TRUE;
68 71
69 efl_invalidate(efl_super(obj, EFL_UI_SELECT_MODEL_CLASS)); 72 efl_invalidate(efl_super(obj, EFL_UI_SELECT_MODEL_CLASS));
70} 73}
@@ -75,7 +78,7 @@ _efl_ui_select_model_fallback(Efl_Ui_Select_Model_Data *pd)
75 Eina_Value selected; 78 Eina_Value selected;
76 79
77 if (!pd->parent) return; 80 if (!pd->parent) return;
78 if (!pd->parent->none) return; 81 if (!pd->parent->last_model) return;
79 if (!pd->parent->fallback_model) return; 82 if (!pd->parent->fallback_model) return;
80 // I think it only make sense to trigger the fallback on single mode 83 // I think it only make sense to trigger the fallback on single mode
81 if (pd->parent->selection != EFL_UI_SELECT_MODE_SINGLE) return; 84 if (pd->parent->selection != EFL_UI_SELECT_MODE_SINGLE) return;
@@ -129,8 +132,7 @@ _commit_change(Eo *child, void *data EINA_UNUSED, const Eina_Value v)
129 if (selflag) 132 if (selflag)
130 { 133 {
131 // select case 134 // select case
132 pd->none = EINA_FALSE; 135 _efl_ui_select_model_apply_last_model(parent, pd, child);
133 efl_replace(&pd->last_model, child);
134 efl_event_callback_call(child, EFL_UI_SELECT_MODEL_EVENT_SELECTED, child); 136 efl_event_callback_call(child, EFL_UI_SELECT_MODEL_EVENT_SELECTED, child);
135 } 137 }
136 else 138 else
@@ -139,8 +141,7 @@ _commit_change(Eo *child, void *data EINA_UNUSED, const Eina_Value v)
139 // There should only be one model which represent the same data at all in memory 141 // There should only be one model which represent the same data at all in memory
140 if (pd->last_model == child) // direct comparison of pointer is ok 142 if (pd->last_model == child) // direct comparison of pointer is ok
141 { 143 {
142 efl_replace(&pd->last_model, NULL); 144 _efl_ui_select_model_apply_last_model(parent, pd, NULL);
143 pd->none = EINA_TRUE;
144 145
145 // Just in case we need to refill the fallback 146 // Just in case we need to refill the fallback
146 _efl_ui_select_model_fallback(pd); 147 _efl_ui_select_model_fallback(pd);
@@ -401,13 +402,12 @@ _efl_ui_select_model_efl_model_property_set(Eo *obj,
401 { 402 {
402 if (pd->parent->last_model == obj && !newflag) 403 if (pd->parent->last_model == obj && !newflag)
403 { 404 {
404 efl_replace(&pd->last_model, NULL); 405 _efl_ui_select_model_apply_last_model(efl_parent_get(obj), pd->parent, NULL);
405 pd->parent->none = EINA_TRUE;
406 406
407 _efl_ui_select_model_fallback(pd); 407 _efl_ui_select_model_fallback(pd);
408 } 408 }
409 } 409 }
410 else 410 else if (pd->parent->last_model)
411 { 411 {
412 Eo *parent; 412 Eo *parent;
413 unsigned long selected = 0; 413 unsigned long selected = 0;
@@ -431,6 +431,10 @@ _efl_ui_select_model_efl_model_property_set(Eo *obj,
431 .error = _untangle_error, 431 .error = _untangle_error,
432 .free = _untangle_free); 432 .free = _untangle_free);
433 } 433 }
434 else
435 {
436 _efl_ui_select_model_apply_last_model(efl_parent_get(obj), pd->parent, obj);
437 }
434 } 438 }
435 439
436 return efl_future_then(efl_ref(obj), chain, 440 return efl_future_then(efl_ref(obj), chain,
@@ -450,10 +454,10 @@ _efl_ui_select_model_efl_model_property_get(const Eo *obj, Efl_Ui_Select_Model_D
450 // Last selected child 454 // Last selected child
451 if (eina_streq("child.selected", property)) 455 if (eina_streq("child.selected", property))
452 { 456 {
453 if (pd->none) 457 if (pd->last_model)
454 return eina_value_error_new(EFL_MODEL_ERROR_INCORRECT_VALUE);
455 else if (pd->last_model)
456 return eina_value_ulong_new(efl_composite_model_index_get(pd->last_model)); 458 return eina_value_ulong_new(efl_composite_model_index_get(pd->last_model));
459 else if (pd->fallback_model)
460 return eina_value_ulong_new(efl_composite_model_index_get(pd->fallback_model));
457 else // Nothing selected yet, try again later 461 else // Nothing selected yet, try again later
458 return eina_value_error_new(EAGAIN); 462 return eina_value_error_new(EAGAIN);
459 } 463 }
@@ -653,7 +657,7 @@ _efl_ui_select_model_efl_ui_single_selectable_fallback_selection_set(Eo *obj,
653 657
654 efl_replace(&pd->fallback_model, fallback); 658 efl_replace(&pd->fallback_model, fallback);
655 659
656 if (!pd->none) return ; 660 if (!pd->last_model) return ;
657 661
658 // When we provide a fallback, we should use it! 662 // When we provide a fallback, we should use it!
659 index = efl_model_property_get(fallback, EFL_COMPOSITE_MODEL_CHILD_INDEX); 663 index = efl_model_property_get(fallback, EFL_COMPOSITE_MODEL_CHILD_INDEX);