mirror of
https://gitlab.gnome.org/GNOME/nautilus
synced 2024-10-01 05:23:56 +00:00
list-base: Disable rubberband for single selection
It's only useful for multi-selection and doesn't really work with single selections anyway.
This commit is contained in:
parent
df76ccad24
commit
a01c4f3ce8
|
@ -469,6 +469,19 @@ setup_cell (GtkSignalListItemFactory *factory,
|
|||
gtk_expression_bind (expression, listitem, "accessible-label", listitem);
|
||||
}
|
||||
|
||||
static void
|
||||
on_model_changed (NautilusGridView *self)
|
||||
{
|
||||
NautilusViewModel *model = nautilus_list_base_get_model (NAUTILUS_LIST_BASE (self));
|
||||
|
||||
if (model != NULL)
|
||||
{
|
||||
gtk_grid_view_set_enable_rubberband (GTK_GRID_VIEW (self->view_ui),
|
||||
!nautilus_view_model_get_single_selection (model));
|
||||
}
|
||||
|
||||
gtk_grid_view_set_model (self->view_ui, GTK_SELECTION_MODEL (model));
|
||||
}
|
||||
static GtkGridView *
|
||||
create_view_ui (NautilusGridView *self)
|
||||
{
|
||||
|
@ -481,7 +494,6 @@ create_view_ui (NautilusGridView *self)
|
|||
g_signal_connect (factory, "unbind", G_CALLBACK (unbind_cell), self);
|
||||
|
||||
widget = gtk_grid_view_new (NULL, factory);
|
||||
g_object_bind_property (self, "model", widget, "model", G_BINDING_SYNC_CREATE);
|
||||
|
||||
/* We don't use the built-in child activation feature for clicks because it
|
||||
* doesn't fill all our needs nor does it match our expected behavior.
|
||||
|
@ -491,7 +503,6 @@ create_view_ui (NautilusGridView *self)
|
|||
* hover). Setting it to FALSE gives us the expected behavior. */
|
||||
gtk_grid_view_set_single_click_activate (GTK_GRID_VIEW (widget), FALSE);
|
||||
gtk_grid_view_set_max_columns (GTK_GRID_VIEW (widget), 20);
|
||||
gtk_grid_view_set_enable_rubberband (GTK_GRID_VIEW (widget), TRUE);
|
||||
gtk_grid_view_set_tab_behavior (GTK_GRID_VIEW (widget), GTK_LIST_TAB_ITEM);
|
||||
|
||||
/* While we don't want to use GTK's click activation, we'll let it handle
|
||||
|
@ -541,6 +552,8 @@ nautilus_grid_view_init (NautilusGridView *self)
|
|||
self->view_ui = create_view_ui (self);
|
||||
nautilus_list_base_setup_gestures (NAUTILUS_LIST_BASE (self));
|
||||
|
||||
g_signal_connect_swapped (self, "notify::model", G_CALLBACK (on_model_changed), self);
|
||||
|
||||
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolled_window),
|
||||
GTK_WIDGET (self->view_ui));
|
||||
|
||||
|
|
|
@ -205,9 +205,15 @@ rubberband_set_state (NautilusListBase *self,
|
|||
* rubberband on item release/stop. See:
|
||||
* https://gitlab.gnome.org/GNOME/gtk/-/issues/5670 */
|
||||
|
||||
GtkWidget *view;
|
||||
NautilusListBasePrivate *priv = nautilus_list_base_get_instance_private (self);
|
||||
|
||||
view = nautilus_list_base_get_view_ui (self);
|
||||
if (priv->model != NULL && nautilus_view_model_get_single_selection (priv->model))
|
||||
{
|
||||
/* Rubberband is always disabled in this case. Do nothing. */
|
||||
return;
|
||||
}
|
||||
|
||||
GtkWidget *view = nautilus_list_base_get_view_ui (self);
|
||||
if (GTK_IS_GRID_VIEW (view))
|
||||
{
|
||||
gtk_grid_view_set_enable_rubberband (GTK_GRID_VIEW (view), enabled);
|
||||
|
|
|
@ -383,7 +383,6 @@ create_view_ui (NautilusListView *self)
|
|||
* activation, as it affects the selection behavior as well (e.g. selects on
|
||||
* hover). Setting it to FALSE gives us the expected behavior. */
|
||||
gtk_column_view_set_single_click_activate (GTK_COLUMN_VIEW (widget), FALSE);
|
||||
gtk_column_view_set_enable_rubberband (GTK_COLUMN_VIEW (widget), TRUE);
|
||||
gtk_column_view_set_tab_behavior (GTK_COLUMN_VIEW (widget), GTK_LIST_TAB_ITEM);
|
||||
gtk_column_view_set_row_factory (GTK_COLUMN_VIEW (widget), row_factory);
|
||||
|
||||
|
@ -1078,6 +1077,9 @@ on_model_changed (NautilusListView *self)
|
|||
nautilus_view_model_set_sorter (model, self->view_model_sorter);
|
||||
|
||||
nautilus_view_model_expand_as_a_tree (model, self->expand_as_a_tree);
|
||||
|
||||
gtk_column_view_set_enable_rubberband (GTK_COLUMN_VIEW (self->view_ui),
|
||||
!nautilus_view_model_get_single_selection (model));
|
||||
}
|
||||
|
||||
gtk_column_view_set_model (self->view_ui, GTK_SELECTION_MODEL (model));
|
||||
|
|
|
@ -239,6 +239,12 @@ get_property (GObject *object,
|
|||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_SINGLE_SELECTION:
|
||||
{
|
||||
g_value_set_boolean (value, nautilus_view_model_get_single_selection (self));
|
||||
}
|
||||
break;
|
||||
|
||||
case PROP_SORTER:
|
||||
{
|
||||
g_value_set_object (value, nautilus_view_model_get_sorter (self));
|
||||
|
@ -357,7 +363,7 @@ nautilus_view_model_class_init (NautilusViewModelClass *klass)
|
|||
properties[PROP_SINGLE_SELECTION] =
|
||||
g_param_spec_boolean ("single-selection", NULL, NULL,
|
||||
FALSE,
|
||||
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
|
||||
properties[PROP_SORTER] =
|
||||
g_param_spec_object ("sorter", NULL, NULL,
|
||||
GTK_TYPE_SORTER,
|
||||
|
@ -394,6 +400,12 @@ nautilus_view_model_new (gboolean single_selection)
|
|||
NULL);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nautilus_view_model_get_single_selection (NautilusViewModel *self)
|
||||
{
|
||||
return self->single_selection;
|
||||
}
|
||||
|
||||
GtkSorter *
|
||||
nautilus_view_model_get_sorter (NautilusViewModel *self)
|
||||
{
|
||||
|
|
|
@ -12,6 +12,7 @@ G_DECLARE_FINAL_TYPE (NautilusViewModel, nautilus_view_model, NAUTILUS, VIEW_MOD
|
|||
|
||||
NautilusViewModel * nautilus_view_model_new (gboolean single_selection);
|
||||
|
||||
gboolean nautilus_view_model_get_single_selection (NautilusViewModel *self);
|
||||
GtkSorter *nautilus_view_model_get_sorter (NautilusViewModel *self);
|
||||
void nautilus_view_model_set_sorter (NautilusViewModel *self,
|
||||
GtkSorter *sorter);
|
||||
|
|
Loading…
Reference in a new issue