1
0
mirror of https://gitlab.gnome.org/GNOME/nautilus synced 2024-06-30 23:46:35 +00:00

window-slot: Make :selection property reliable

Currently, it caches the view selection through bindings.

Unfortunately, this cache may get out of sync with the view, because
NautilusView:selection is a file list that's generated on-demand, and
NautilusView::notify:selection is unreliable. E.g. when the view
switches to a new location, it empties the model, which effectively
clears selection, but this is not notified as a selection change.

Making NautilusView:selection's notifications reliable is going to
require quite a bit of refactoring, so that's for another time.

Drop the binding and proxy the selection property without caching it.
This commit is contained in:
António Fernandes 2024-06-22 19:32:12 +01:00
parent 1676b73f15
commit 80130fc32a

View File

@ -156,10 +156,9 @@ struct _NautilusWindowSlot
/* View bindings */
GBinding *searching_binding;
GBinding *selection_binding;
gulong selection_notify_id;
GBinding *extensions_background_menu_binding;
GBinding *templates_menu_binding;
GList *selection;
};
G_DEFINE_TYPE (NautilusWindowSlot, nautilus_window_slot, ADW_TYPE_BIN);
@ -666,12 +665,8 @@ nautilus_window_slot_add_extra_location_widget (NautilusWindowSlot *self,
}
static void
nautilus_window_slot_set_selection (NautilusWindowSlot *self,
GList *selection)
on_view_selection_notify (NautilusWindowSlot *self)
{
nautilus_file_list_free (self->selection);
self->selection = selection;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTION]);
}
@ -735,12 +730,6 @@ nautilus_window_slot_set_property (GObject *object,
}
break;
case PROP_SELECTION:
{
nautilus_window_slot_set_selection (self, g_value_get_pointer (value));
}
break;
default:
{
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@ -826,6 +815,12 @@ nautilus_window_slot_get_property (GObject *object,
}
break;
case PROP_SELECTION:
{
g_value_set_pointer (value, nautilus_window_slot_get_selection (self));
}
break;
case PROP_TEMPLATES_MENU:
{
g_value_set_object (value, real_get_templates_menu (self));
@ -885,7 +880,12 @@ nautilus_window_slot_get_property (GObject *object,
GList *
nautilus_window_slot_get_selection (NautilusWindowSlot *self)
{
return self->selection;
if (self->content_view != NULL)
{
return nautilus_view_get_selection (self->content_view);
}
return NULL;
}
static void
@ -2895,7 +2895,7 @@ nautilus_window_slot_switch_new_content_view (NautilusWindowSlot *self)
if (self->content_view != NULL)
{
g_binding_unbind (self->searching_binding);
g_binding_unbind (self->selection_binding);
g_clear_signal_handler (&self->selection_notify_id, self->content_view);
g_binding_unbind (self->extensions_background_menu_binding);
g_binding_unbind (self->templates_menu_binding);
widget = GTK_WIDGET (self->content_view);
@ -2917,9 +2917,8 @@ nautilus_window_slot_switch_new_content_view (NautilusWindowSlot *self)
self->searching_binding = g_object_bind_property (self->content_view, "searching",
self, "search-visible",
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
self->selection_binding = g_object_bind_property (self->content_view, "selection",
self, "selection",
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
self->selection_notify_id = g_signal_connect_swapped (self->content_view, "notify::selection",
G_CALLBACK (on_view_selection_notify), self);
self->extensions_background_menu_binding = g_object_bind_property (self->content_view, "extensions-background-menu",
self, "extensions-background-menu",
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
@ -2978,7 +2977,6 @@ nautilus_window_slot_dispose (GObject *object)
nautilus_window_slot_remove_extra_location_widgets (self);
g_clear_pointer (&self->searching_binding, g_binding_unbind);
g_clear_pointer (&self->selection_binding, g_binding_unbind);
g_clear_pointer (&self->extensions_background_menu_binding, g_binding_unbind);
g_clear_pointer (&self->templates_menu_binding, g_binding_unbind);
@ -2987,6 +2985,7 @@ nautilus_window_slot_dispose (GObject *object)
if (self->content_view)
{
g_clear_signal_handler (&self->selection_notify_id, self->content_view);
gtk_box_remove (GTK_BOX (self->vbox), GTK_WIDGET (self->content_view));
g_clear_object (&self->content_view);
}
@ -3004,7 +3003,6 @@ nautilus_window_slot_dispose (GObject *object)
g_clear_object (&self->location);
g_clear_object (&self->pending_file_to_activate);
g_clear_pointer (&self->pending_selection, nautilus_file_list_free);
g_clear_pointer (&self->selection, nautilus_file_list_free);
g_clear_object (&self->current_location_bookmark);
g_clear_object (&self->last_location_bookmark);
@ -3113,7 +3111,7 @@ nautilus_window_slot_class_init (NautilusWindowSlotClass *klass)
g_param_spec_pointer ("selection",
"Selection of the current view of the slot",
"The selection of the current view of the slot. Proxy property from the view",
G_PARAM_READWRITE);
G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
properties[PROP_ICON_NAME] =
g_param_spec_string ("icon-name",