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

git pushed a commit to branch fix/eo-api-finalize-master-fixes-2
in repository efl.

View the commit online.

commit 10abd4ab6206b0f91515d3e50905db70813695c9
Author: Cedric BAIL <[email protected]>
AuthorDate: Wed Nov 18 10:24:13 2026 -0600

    elementary: setting a view's own model again changes nothing
    
    Efl.Ui.Widget's model_set always unregistered, re-registered and
    emitted model,changed, even when the model was the one the widget
    already had. A Collection_View answered by dropping all its items and
    rebuilding its model chain, including the Select_Model it wraps a plain
    model in. The selection lives in that wrapper, so it was lost, and
    last_selected stayed NULL: the selection did not change after the
    rebuild, so nothing made the selected row's item again.
    
    Return early when the model is unchanged and was not found through a
    provider (setting it explicitly still cuts that link). Do the same in
    Efl.Model_Provider, whose model,changed every widget it feeds passes
    on, and make Efl.Composite_Model take its own source again silently
    rather than logging an error. A different model resets the view as
    before. Document the contract on Efl.Ui.View.model, and test it over a
    model that provides its own selection, a plain one the view wraps, a
    provider, and a bound plain widget.
    
    Callers had to avoid rebinding a list to its own model for this reason.
    The legacy elm_fileselector overrides are left as they were.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/ecore/efl_composite_model.c                |   1 +
 src/lib/efl/interfaces/efl_model_provider.c        |   4 +
 src/lib/efl/interfaces/efl_ui_view.eo              |  13 +-
 src/lib/elementary/efl_ui_widget.c                 |   7 +
 src/tests/efl/efl_test_composite_model.c           |  45 +++++++
 src/tests/elementary/efl_ui_test_collection_view.c | 149 +++++++++++++++++++++
 src/tests/elementary/efl_ui_test_property_bind.c   | 124 +++++++++++++++++
 7 files changed, 341 insertions(+), 2 deletions(-)

diff --git a/src/lib/ecore/efl_composite_model.c b/src/lib/ecore/efl_composite_model.c
index 90f62bff79..9a44038025 100644
--- a/src/lib/ecore/efl_composite_model.c
+++ b/src/lib/ecore/efl_composite_model.c
@@ -319,6 +319,7 @@ _efl_composite_model_efl_ui_view_model_set(Eo *obj EINA_UNUSED, Efl_Composite_Mo
    Eina_Iterator *properties;
    const char *property;
 
+   if (pd->source == model) return;
    if (pd->source != NULL)
      {
         ERR("Source already set for composite model. It can only be set once.");
diff --git a/src/lib/efl/interfaces/efl_model_provider.c b/src/lib/efl/interfaces/efl_model_provider.c
index d60bb4469c..50b8682ac6 100644
--- a/src/lib/efl/interfaces/efl_model_provider.c
+++ b/src/lib/efl/interfaces/efl_model_provider.c
@@ -16,6 +16,10 @@ _efl_model_provider_efl_ui_view_model_set(Eo *obj, Efl_Model_Provider_Data *pd,
 {
    Efl_Model_Changed_Event ev;
 
+   /* The views under it have this model already: telling them again would
+      make each one start over. */
+   if (model == pd->model) return;
+
    ev.previous = efl_ref(pd->model);
    ev.current = efl_ref(model);
    efl_replace(&pd->model, model);
diff --git a/src/lib/efl/interfaces/efl_ui_view.eo b/src/lib/efl/interfaces/efl_ui_view.eo
index b95bf49a3f..b236fcde26 100644
--- a/src/lib/efl/interfaces/efl_ui_view.eo
+++ b/src/lib/efl/interfaces/efl_ui_view.eo
@@ -12,8 +12,17 @@ interface Efl.Ui.View
    ]]
    methods {
       @property model {
-         [[Model that is/will be ]]
-         get {} set {}
+         [[The model the object shows, and that its bound properties read.]]
+         set {
+            [[Setting the non-$null model the object already has changes
+              nothing: no $model,changed event, and whatever the object keeps
+              for that model, such as a selection, stays. On a widget, a
+              different model replaces it and is announced with
+              $model,changed, setting $null looks again for a model provided
+              by a parent, and a model found that way and then set explicitly
+              is announced, as the widget stops following the provider.]]
+         }
+         get {}
          values {
             model: Efl.Model; [[Efl model]]
          }
diff --git a/src/lib/elementary/efl_ui_widget.c b/src/lib/elementary/efl_ui_widget.c
index 8db447f20c..6408ecc9a9 100644
--- a/src/lib/elementary/efl_ui_widget.c
+++ b/src/lib/elementary/efl_ui_widget.c
@@ -6207,6 +6207,13 @@ _efl_ui_widget_efl_ui_view_model_set(Eo *obj,
 {
    Efl_Model_Changed_Event ev;
 
+   /* The model this widget was given is already its model: nothing changes,
+      and the widgets built on it must not be told to start over. A model
+      found through a provider is not the same, setting it explicitly cuts
+      that link. */
+   if (model && model == pd->properties.model && !pd->properties.provider)
+     return;
+
    ev.current = efl_ref(model);
    ev.previous = efl_ref(pd->properties.model);
 
diff --git a/src/tests/efl/efl_test_composite_model.c b/src/tests/efl/efl_test_composite_model.c
index afd7a52033..75f318ef03 100644
--- a/src/tests/efl/efl_test_composite_model.c
+++ b/src/tests/efl/efl_test_composite_model.c
@@ -1457,6 +1457,50 @@ EFL_START_TEST(efl_test_filter_model_removed_row_gone)
 }
 EFL_END_TEST
 
+static unsigned int errors_logged;
+
+static void
+_count_errors(const Eina_Log_Domain *d EINA_UNUSED, Eina_Log_Level level,
+              const char *file EINA_UNUSED, const char *fnc EINA_UNUSED,
+              int line EINA_UNUSED, const char *fmt EINA_UNUSED,
+              void *data EINA_UNUSED, va_list args EINA_UNUSED)
+{
+   if (level <= EINA_LOG_LEVEL_ERR) errors_logged++;
+}
+
+// A composite model takes its source once. The source it has is no error to
+// be given again, and another one is refused and leaves the model alone.
+EFL_START_TEST(efl_test_composite_model_same_source_again)
+{
+   Efl_Generic_Model *source, *other;
+   Efl_Boolean_Model *model;
+
+   source = efl_add_ref(EFL_GENERIC_MODEL_CLASS, efl_main_loop_get());
+   other = efl_add_ref(EFL_GENERIC_MODEL_CLASS, efl_main_loop_get());
+   efl_model_child_add(source);
+   efl_model_child_add(source);
+   model = efl_add_ref(EFL_BOOLEAN_MODEL_CLASS, efl_main_loop_get(),
+                       efl_ui_view_model_set(efl_added, source));
+
+   eina_log_print_cb_set(_count_errors, NULL);
+   errors_logged = 0;
+   efl_ui_view_model_set(model, source);
+   ck_assert_uint_eq(errors_logged, 0);
+   ck_assert_ptr_eq(efl_ui_view_model_get(model), source);
+   ck_assert_uint_eq(efl_model_children_count_get(model), 2);
+
+   efl_ui_view_model_set(model, other);
+   ck_assert_uint_eq(errors_logged, 1);
+   eina_log_print_cb_set(eina_log_print_cb_stderr, NULL);
+   ck_assert_ptr_eq(efl_ui_view_model_get(model), source);
+   ck_assert_uint_eq(efl_model_children_count_get(model), 2);
+
+   efl_unref(model);
+   efl_unref(other);
+   efl_unref(source);
+}
+EFL_END_TEST
+
 void
 efl_test_case_boolean_model(TCase *tc)
 {
@@ -1468,6 +1512,7 @@ efl_test_case_boolean_model(TCase *tc)
    tcase_add_test(tc, efl_test_filter_model);
    tcase_add_test(tc, efl_test_generic_model_child_added);
    tcase_add_test(tc, efl_test_composite_model_source_properties_first);
+   tcase_add_test(tc, efl_test_composite_model_same_source_again);
    tcase_add_test(tc, efl_test_generic_model_properties_changed_event);
    tcase_add_test(tc, efl_test_generic_model_property_replaced);
    tcase_add_test(tc, efl_test_composite_model_pending_slice_insert);
diff --git a/src/tests/elementary/efl_ui_test_collection_view.c b/src/tests/elementary/efl_ui_test_collection_view.c
index a71b37b0ce..fd264ccbdd 100644
--- a/src/tests/elementary/efl_ui_test_collection_view.c
+++ b/src/tests/elementary/efl_ui_test_collection_view.c
@@ -330,6 +330,152 @@ _realized_row(Eina_List *realized, int index)
    return NULL;
 }
 
+static void
+_count_model_changed(void *data, const Efl_Event *ev EINA_UNUSED)
+{
+   unsigned int *count = data;
+
+   (*count)++;
+}
+
+/* Setting the model a view already has changes nothing: the selection
+   stays, and so do the items, whether the view wraps the model in a
+   selection model of its own or the model brings one. */
+static void
+_same_model_keeps_selection(Eina_Bool view_wraps)
+{
+   Efl_Ui_Win *win;
+   Efl_Model *model, *shown;
+   Efl_Ui_List_View *lv;
+   Efl_Ui_Factory *fl;
+   Eo *item, *after;
+   Eina_List *realized = NULL;
+   unsigned int changed = 0;
+   int i;
+
+   win = win_add(NULL, "win", EFL_UI_WIN_TYPE_BASIC);
+   efl_gfx_entity_size_set(win, EINA_SIZE2D(100, 100));
+
+   model = shown = _make_model(win);
+   if (!view_wraps)
+     model = shown = efl_add(EFL_UI_SELECT_MODEL_CLASS, win,
+                             efl_ui_view_model_set(efl_added, model));
+   fl = efl_add(EFL_UI_LAYOUT_FACTORY_CLASS, win,
+                efl_ui_property_bind(efl_added, "text", "title"),
+                efl_ui_widget_factory_item_class_set(efl_added, EFL_UI_LIST_DEFAULT_ITEM_CLASS));
+   lv = efl_add(EFL_UI_LIST_VIEW_CLASS, win,
+                efl_ui_collection_view_factory_set(efl_added, fl),
+                efl_ui_view_model_set(efl_added, model));
+   efl_content_set(win, lv);
+   efl_event_callback_add(lv, EFL_UI_COLLECTION_VIEW_EVENT_ITEM_REALIZED,
+                          _realized_track, &realized);
+   efl_event_callback_add(lv, EFL_UI_COLLECTION_VIEW_EVENT_ITEM_UNREALIZED,
+                          _unrealized_track, &realized);
+   efl_gfx_entity_visible_set(win, EINA_TRUE);
+   get_me_to_those_events(lv);
+
+   click_object_at(lv, 50, 5);
+   item = _wait_last_selected(lv, 0);
+   ck_assert_ptr_nonnull(item);
+   ck_assert(efl_ui_selectable_selected_get(item));
+   ck_assert_ptr_nonnull(realized);
+
+   efl_event_callback_add(lv, EFL_UI_VIEW_EVENT_MODEL_CHANGED,
+                          _count_model_changed, &changed);
+   efl_ui_view_model_set(lv, model);
+   get_me_to_those_events(lv);
+   for (i = 0; i < 50; i++) ecore_main_loop_iterate();
+
+   ck_assert_uint_eq(changed, 0);
+   ck_assert_ptr_eq(efl_ui_view_model_get(lv), shown);
+   ck_assert_ptr_nonnull(realized);
+   ck_assert_ptr_nonnull(_realized_row(realized, 0));
+   after = efl_ui_selectable_last_selected_get(lv);
+   ck_assert_ptr_nonnull(after);
+   ck_assert_int_eq(_item_row(after), 0);
+   ck_assert(efl_ui_selectable_selected_get(after));
+
+   /* a different model still resets the view */
+   efl_ui_view_model_set(lv, _make_model(win));
+   get_me_to_those_events(lv);
+   for (i = 0; i < 50; i++) ecore_main_loop_iterate();
+   ck_assert_uint_eq(changed, 1);
+   ck_assert_ptr_ne(efl_ui_view_model_get(lv), shown);
+   ck_assert_ptr_null(efl_ui_selectable_last_selected_get(lv));
+   ck_assert_ptr_nonnull(realized);
+
+   efl_event_callback_del(lv, EFL_UI_VIEW_EVENT_MODEL_CHANGED,
+                          _count_model_changed, &changed);
+   efl_event_callback_del(lv, EFL_UI_COLLECTION_VIEW_EVENT_ITEM_REALIZED,
+                         _realized_track, &realized);
+   efl_event_callback_del(lv, EFL_UI_COLLECTION_VIEW_EVENT_ITEM_UNREALIZED,
+                         _unrealized_track, &realized);
+   eina_list_free(realized);
+}
+
+/* A collection view fed by a provider keeps its selection when the provider
+   is set to the model it already has, and hears nothing. */
+EFL_START_TEST(test_efl_ui_collection_view_provider_same_model_keeps_selection)
+{
+   Efl_Ui_Win *win;
+   Efl_Model *model;
+   Efl_Model_Provider *provider;
+   Efl_Ui_List_View *lv;
+   Efl_Ui_Factory *fl;
+   Eo *item, *after;
+   unsigned int changed = 0;
+   int i;
+
+   win = win_add(NULL, "win", EFL_UI_WIN_TYPE_BASIC);
+   efl_gfx_entity_size_set(win, EINA_SIZE2D(100, 100));
+
+   model = _make_model(win);
+   provider = efl_add(EFL_MODEL_PROVIDER_CLASS, win);
+   efl_provider_register(win, EFL_MODEL_PROVIDER_CLASS, provider);
+   fl = efl_add(EFL_UI_LAYOUT_FACTORY_CLASS, win,
+                efl_ui_property_bind(efl_added, "text", "title"),
+                efl_ui_widget_factory_item_class_set(efl_added, EFL_UI_LIST_DEFAULT_ITEM_CLASS));
+   lv = efl_add(EFL_UI_LIST_VIEW_CLASS, win,
+                efl_ui_collection_view_factory_set(efl_added, fl));
+   /* A widget starts listening to its provider when something is bound. */
+   ck_assert_int_eq(efl_ui_property_bind(lv, "visible", "shown"), 0);
+   efl_content_set(win, lv);
+   efl_ui_view_model_set(provider, model);
+   efl_gfx_entity_visible_set(win, EINA_TRUE);
+   get_me_to_those_events(lv);
+
+   click_object_at(lv, 50, 5);
+   item = _wait_last_selected(lv, 0);
+   ck_assert_ptr_nonnull(item);
+
+   efl_event_callback_add(lv, EFL_UI_VIEW_EVENT_MODEL_CHANGED,
+                          _count_model_changed, &changed);
+   efl_ui_view_model_set(provider, model);
+   get_me_to_those_events(lv);
+   for (i = 0; i < 50; i++) ecore_main_loop_iterate();
+
+   ck_assert_uint_eq(changed, 0);
+   after = efl_ui_selectable_last_selected_get(lv);
+   ck_assert_ptr_nonnull(after);
+   ck_assert_int_eq(_item_row(after), 0);
+   ck_assert(efl_ui_selectable_selected_get(after));
+   efl_event_callback_del(lv, EFL_UI_VIEW_EVENT_MODEL_CHANGED,
+                          _count_model_changed, &changed);
+}
+EFL_END_TEST
+
+EFL_START_TEST(test_efl_ui_collection_view_same_model_keeps_selection)
+{
+   _same_model_keeps_selection(EINA_FALSE);
+}
+EFL_END_TEST
+
+EFL_START_TEST(test_efl_ui_collection_view_same_plain_model_keeps_selection)
+{
+   _same_model_keeps_selection(EINA_TRUE);
+}
+EFL_END_TEST
+
 /* Focus coming into a view from below lands on its last row, so the view
    keeps an item for that row, out of sight while the top is shown -- and
    for the new last row once rows are added. */
@@ -2569,6 +2715,9 @@ void efl_ui_test_collection_view(TCase *tc)
    tcase_add_test(tc, efl_ui_collection_view_manager_ownership);
    tcase_add_test(tc, test_efl_ui_collection_view_select);
    tcase_add_test(tc, test_efl_ui_collection_view_last_selected_is_an_item);
+   tcase_add_test(tc, test_efl_ui_collection_view_same_model_keeps_selection);
+   tcase_add_test(tc, test_efl_ui_collection_view_provider_same_model_keeps_selection);
+   tcase_add_test(tc, test_efl_ui_collection_view_same_plain_model_keeps_selection);
    tcase_add_test(tc, test_efl_ui_collection_view_select_mode_before_model);
    tcase_add_test(tc, test_efl_ui_collection_view_last_row_kept);
    tcase_add_test(tc, test_efl_ui_collection_view_last_row_removed_offscreen);
diff --git a/src/tests/elementary/efl_ui_test_property_bind.c b/src/tests/elementary/efl_ui_test_property_bind.c
index a07a6bd8ef..295cd40dbc 100644
--- a/src/tests/elementary/efl_ui_test_property_bind.c
+++ b/src/tests/elementary/efl_ui_test_property_bind.c
@@ -766,6 +766,127 @@ EFL_START_TEST(efl_ui_model_provider_live_edit)
 }
 EFL_END_TEST
 
+static unsigned int view_model_changes;
+
+static void
+_view_model_changed(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
+{
+   view_model_changes++;
+}
+
+// Setting the model a widget already has changes nothing: no model,changed,
+// and the binding keeps showing what the model holds. Another model is told.
+EFL_START_TEST(same_model_set_again_emits_nothing)
+{
+   Eo *win = _window();
+   Eo *model = _model_new("t", eina_value_string_new("kept"));
+   Eo *other = _model_new("t", eina_value_string_new("other"));
+   Eo *label;
+
+   label = efl_add(EFL_UI_TEXTBOX_CLASS, win,
+                   efl_ui_view_model_set(efl_added, model),
+                   efl_ui_property_bind(efl_added, "text", "t"));
+   ck_assert_str_eq(efl_text_get(label), "kept");
+
+   view_model_changes = 0;
+   efl_event_callback_add(label, EFL_UI_VIEW_EVENT_MODEL_CHANGED,
+                          _view_model_changed, NULL);
+   efl_ui_view_model_set(label, model);
+   ck_assert_uint_eq(view_model_changes, 0);
+   ck_assert_ptr_eq(efl_ui_view_model_get(label), model);
+   ck_assert_str_eq(efl_text_get(label), "kept");
+
+   _model_set(model, "t", eina_value_string_new("still bound"));
+   ck_assert_str_eq(efl_text_get(label), "still bound");
+
+   efl_ui_view_model_set(label, other);
+   ck_assert_uint_eq(view_model_changes, 1);
+   ck_assert_str_eq(efl_text_get(label), "other");
+
+   efl_event_callback_del(label, EFL_UI_VIEW_EVENT_MODEL_CHANGED,
+                          _view_model_changed, NULL);
+   efl_unref(model);
+   efl_unref(other);
+}
+EFL_END_TEST
+
+// A provider set to the model it already has tells nobody, so the widgets it
+// feeds are not made to start over; a model found through a provider and then
+// set explicitly is still announced, as the widget stops following it.
+EFL_START_TEST(provider_set_to_same_model_emits_nothing)
+{
+   Eo *win = _window();
+   Eo *model = _model_new("t", eina_value_string_new("one"));
+   Eo *other = _model_new("t", eina_value_string_new("other"));
+   Eo *box, *provider, *label;
+
+   box = efl_add(EFL_UI_BOX_CLASS, win);
+   provider = efl_add(EFL_MODEL_PROVIDER_CLASS, box);
+   efl_provider_register(box, EFL_MODEL_PROVIDER_CLASS, provider);
+   label = efl_add(EFL_UI_TEXTBOX_CLASS, box,
+                   efl_ui_property_bind(efl_added, "text", "t"));
+   efl_pack_end(box, label);
+   efl_content_set(win, box);
+
+   efl_ui_view_model_set(provider, model);
+   ck_assert_str_eq(efl_text_get(label), "one");
+
+   view_model_changes = 0;
+   efl_event_callback_add(provider, EFL_UI_VIEW_EVENT_MODEL_CHANGED,
+                          _view_model_changed, NULL);
+   efl_event_callback_add(label, EFL_UI_VIEW_EVENT_MODEL_CHANGED,
+                          _view_model_changed, NULL);
+   efl_ui_view_model_set(provider, model);
+   ck_assert_uint_eq(view_model_changes, 0);
+   ck_assert_str_eq(efl_text_get(label), "one");
+
+   efl_ui_view_model_set(label, model);
+   ck_assert_uint_eq(view_model_changes, 1);
+
+   // It no longer follows the provider
+   efl_ui_view_model_set(provider, other);
+   ck_assert_ptr_eq(efl_ui_view_model_get(label), model);
+   ck_assert_str_eq(efl_text_get(label), "one");
+
+   efl_event_callback_del(provider, EFL_UI_VIEW_EVENT_MODEL_CHANGED,
+                          _view_model_changed, NULL);
+   efl_event_callback_del(label, EFL_UI_VIEW_EVENT_MODEL_CHANGED,
+                          _view_model_changed, NULL);
+   efl_unref(model);
+   efl_unref(other);
+}
+EFL_END_TEST
+
+// A widget whose model was set explicitly, and then set to NULL, looks for the
+// model of its provider again and shows it.
+EFL_START_TEST(model_set_null_finds_the_provider_model)
+{
+   Eo *win = _window();
+   Eo *own = _model_new("t", eina_value_string_new("own"));
+   Eo *provided = _model_new("t", eina_value_string_new("provided"));
+   Eo *box, *provider, *label;
+
+   box = efl_add(EFL_UI_BOX_CLASS, win);
+   provider = efl_add(EFL_MODEL_PROVIDER_CLASS, box);
+   efl_provider_register(box, EFL_MODEL_PROVIDER_CLASS, provider);
+   efl_ui_view_model_set(provider, provided);
+   label = efl_add(EFL_UI_TEXTBOX_CLASS, box,
+                   efl_ui_view_model_set(efl_added, own),
+                   efl_ui_property_bind(efl_added, "text", "t"));
+   efl_pack_end(box, label);
+   efl_content_set(win, box);
+   ck_assert_ptr_eq(efl_ui_view_model_get(label), own);
+   ck_assert_str_eq(efl_text_get(label), "own");
+
+   efl_ui_view_model_set(label, NULL);
+   ck_assert_ptr_eq(efl_ui_view_model_get(label), provided);
+   ck_assert_str_eq(efl_text_get(label), "provided");
+
+   efl_unref(own);
+   efl_unref(provided);
+}
+EFL_END_TEST
+
 /* A factory binds every item again each time it hands one out, reused or
  * not. Binding the same key again replaces the binding: nothing piles up. */
 EFL_START_TEST(rebinding_a_key_replaces_the_binding)
@@ -970,6 +1091,9 @@ efl_ui_test_property_bind(TCase *tc)
    tcase_add_test(tc, radio_box_shows_the_model_value);
    tcase_add_test(tc, radio_box_follows_the_model);
    tcase_add_test(tc, radio_box_press_reaches_the_model);
+tcase_add_test(tc, same_model_set_again_emits_nothing);
+tcase_add_test(tc, provider_set_to_same_model_emits_nothing);
+tcase_add_test(tc, model_set_null_finds_the_provider_model);
    tcase_add_test(tc, radio_box_programmatic_value_does_not_reach_the_model);
    tcase_add_test(tc, radio_box_model_change_does_not_loop);
    tcase_add_test(tc, radio_box_pressing_the_selected_radio_writes_nothing);

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

Reply via email to