This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository efl.

View the commit online.

commit 532061fca6e07e4cbd3d5a1b8c49535bbe022b91
Author: Cedric BAIL <[email protected]>
AuthorDate: Fri Aug 21 17:02:36 2026 -0600

    elementary: Select_Model implements allow_manual_deselection
    
    The class claims Efl.Ui.Single_Selectable but left
    allow_manual_deselection unimplemented.
    
    It is implemented rather than dropped, because it means something here.
    The property is documented in terms of clicking, but a model has no
    clicks and can be driven from code with no view attached at all; what it
    decides is whether a single-selection model may end up with nothing
    selected. Refused before the value is stored rather than undone
    afterwards, so the selection is never briefly empty. A fallback
    selection is not this case -- something is still selected once it takes
    over -- so that deselection goes through.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/elementary/efl_ui_select_model.c        | 36 +++++++++++++
 src/lib/elementary/efl_ui_select_model.eo       |  1 +
 src/tests/elementary/efl_ui_test_select_model.c | 71 +++++++++++++++++++++++++
 3 files changed, 108 insertions(+)

diff --git a/src/lib/elementary/efl_ui_select_model.c b/src/lib/elementary/efl_ui_select_model.c
index 278ce05993..76588eace8 100644
--- a/src/lib/elementary/efl_ui_select_model.c
+++ b/src/lib/elementary/efl_ui_select_model.c
@@ -24,6 +24,8 @@ struct _Efl_Ui_Select_Model_Data
    Efl_Ui_Select_Model *last_model;
 
    Efl_Ui_Select_Mode selection;
+
+   Eina_Bool allow_manual_deselection : 1;
 };
 
 static void
@@ -55,6 +57,10 @@ _efl_ui_select_model_efl_object_constructor(Eo *obj,
 
    efl_event_callback_add(obj, EFL_MODEL_EVENT_CHILD_REMOVED, _efl_ui_select_model_child_removed, pd);
 
+   /* Same default as Efl.Ui.Collection: unselecting what is selected is
+      allowed until someone says otherwise. */
+   pd->allow_manual_deselection = EINA_TRUE;
+
    parent = efl_parent_get(obj);
    if (efl_isa(parent, EFL_UI_SELECT_MODEL_CLASS))
      pd->parent = efl_data_scope_get(parent, EFL_UI_SELECT_MODEL_CLASS);
@@ -158,6 +164,21 @@ _commit_change(Eo *child, void *data EINA_UNUSED, const Eina_Value v)
    return v;
 }
 
+EOLIAN static void
+_efl_ui_select_model_efl_ui_single_selectable_allow_manual_deselection_set(Eo *obj EINA_UNUSED,
+                                                                           Efl_Ui_Select_Model_Data *pd,
+                                                                           Eina_Bool allow_manual_deselection)
+{
+   pd->allow_manual_deselection = !!allow_manual_deselection;
+}
+
+EOLIAN static Eina_Bool
+_efl_ui_select_model_efl_ui_single_selectable_allow_manual_deselection_get(const Eo *obj EINA_UNUSED,
+                                                                           Efl_Ui_Select_Model_Data *pd)
+{
+   return pd->allow_manual_deselection;
+}
+
 static void
 _clear_child(Eo *child,
              void *data EINA_UNUSED,
@@ -401,6 +422,21 @@ _efl_ui_select_model_efl_model_property_set(Eo *obj,
         if (newflag == prevflag)
           return efl_loop_future_resolved(obj, eina_value_bool_init(newflag));
 
+        /* Refusing to be the change that leaves nothing selected, which is
+           what allow_manual_deselection is for. Refused before the value is
+           stored rather than undone afterwards, so the selection is never
+           briefly empty and nothing downstream sees a state that was not
+           meant to exist.
+
+           A fallback is not this case: something is still selected once it
+           takes over, so the deselection is allowed to go through. */
+        if (!newflag &&
+            (pd->parent->selection == EFL_UI_SELECT_MODE_SINGLE) &&
+            (!pd->parent->allow_manual_deselection) &&
+            (!pd->parent->fallback_model) &&
+            (pd->parent->last_model == obj))
+          return efl_loop_future_resolved(obj, eina_value_bool_init(EINA_TRUE));
+
         single_selection = !!(pd->parent->selection == EFL_UI_SELECT_MODE_SINGLE);
 
         // First store the new value in the boolean model we inherit from
diff --git a/src/lib/elementary/efl_ui_select_model.eo b/src/lib/elementary/efl_ui_select_model.eo
index abe5137a18..340f8421b0 100644
--- a/src/lib/elementary/efl_ui_select_model.eo
+++ b/src/lib/elementary/efl_ui_select_model.eo
@@ -17,6 +17,7 @@ class @beta Efl.Ui.Select_Model extends Efl.Boolean_Model
       Efl.Ui.Multi_Selectable_Index_Range.ndx_range_select;
       Efl.Ui.Multi_Selectable_Index_Range.ndx_range_unselect;
       Efl.Ui.Single_Selectable.fallback_selection {get; set;}
+      Efl.Ui.Single_Selectable.allow_manual_deselection {get; set;}
       Efl.Ui.Selectable.selected {get; set;}
    }
    events {
diff --git a/src/tests/elementary/efl_ui_test_select_model.c b/src/tests/elementary/efl_ui_test_select_model.c
index 122b4fa963..b1d9688fe5 100644
--- a/src/tests/elementary/efl_ui_test_select_model.c
+++ b/src/tests/elementary/efl_ui_test_select_model.c
@@ -608,6 +608,76 @@ EFL_START_TEST(efl_test_select_model_gone_row_is_not_selected)
 }
 EFL_END_TEST
 
+/* In single mode, allow_manual_deselection decides whether the model may end
+ * up with nothing selected. It defaults to allowing it, the same as
+ * Efl.Ui.Collection does; turning it off makes the last selection stick.
+ *
+ * This is checked on the model directly rather than through a view: the
+ * property is documented in terms of clicking, but a model has no clicks, and
+ * a model driven from code has to behave the same way. */
+EFL_START_TEST(efl_test_select_model_manual_deselection)
+{
+   Efl_Model *base_model, *model, *child;
+   Eina_Value v = EINA_VALUE_EMPTY;
+   Eina_Value *readback;
+   Eina_Bool selected = EINA_FALSE;
+   int i;
+
+   eina_value_setup(&v, EINA_VALUE_TYPE_INT);
+
+   base_model = efl_add_ref(EFL_GENERIC_MODEL_CLASS, efl_main_loop_get());
+   ck_assert(!!base_model);
+
+   for (i = 0; i < 3; ++i)
+     {
+        child = efl_model_child_add(base_model);
+        ck_assert(!!child);
+        ck_assert(eina_value_set(&v, i));
+        efl_model_property_set(child, "test_p_int", &v);
+     }
+
+   model = efl_add_ref(EFL_UI_SELECT_MODEL_CLASS, efl_main_loop_get(),
+                       efl_ui_view_model_set(efl_added, base_model));
+   ck_assert(!!model);
+   efl_ui_multi_selectable_select_mode_set(model, EFL_UI_SELECT_MODE_SINGLE);
+
+   /* Allowed by default, as Efl.Ui.Collection has it. */
+   ck_assert_int_eq(efl_ui_selectable_allow_manual_deselection_get(model), EINA_TRUE);
+
+   efl_ui_selectable_allow_manual_deselection_set(model, EINA_FALSE);
+   ck_assert_int_eq(efl_ui_selectable_allow_manual_deselection_get(model), EINA_FALSE);
+
+   /* Select one, then try to give it back. */
+   v = eina_value_int_init(1);
+   efl_model_property_set(model, "child.selected", &v);
+   ecore_main_loop_iterate();
+
+   {
+      Eina_Value keep = eina_value_bool_init(EINA_FALSE);
+      Efl_Model *sel = efl_ui_selectable_last_selected_get(model);
+
+      ck_assert_ptr_ne(sel, NULL);
+      efl_model_property_set(sel, "self.selected", &keep);
+      eina_value_flush(&keep);
+      ecore_main_loop_iterate();
+      ecore_main_loop_iterate();
+
+      readback = efl_model_property_get(sel, "selected");
+      ck_assert_ptr_ne(readback, NULL);
+      eina_value_bool_get(readback, &selected);
+      eina_value_free(readback);
+
+      /* Refused: something is still selected. */
+      ck_assert_int_eq(selected, EINA_TRUE);
+      ck_assert_ptr_eq(efl_ui_selectable_last_selected_get(model), sel);
+   }
+
+   eina_value_flush(&v);
+   efl_unref(model);
+   efl_unref(base_model);
+}
+EFL_END_TEST
+
 void
 efl_ui_test_select_model(TCase *tc)
 {
@@ -621,4 +691,5 @@ efl_ui_test_select_model(TCase *tc)
    tcase_add_test(tc, efl_test_select_model_gone_row_is_not_selected);
    tcase_add_test(tc, efl_test_select_model_single_selects_in_one_turn);
    tcase_add_test(tc, efl_test_select_model_single_to_none_unselects_all);
+   tcase_add_test(tc, efl_test_select_model_manual_deselection);
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to