Spread single-click-activate api

This makes sense to have in all the views,
not just GtkListView.
This commit is contained in:
Matthias Clasen 2019-12-23 15:22:35 -05:00
parent 12b1007046
commit f611d55f16
5 changed files with 135 additions and 0 deletions

View File

@ -504,6 +504,8 @@ gtk_column_view_get_sorter
gtk_column_view_get_show_separators gtk_column_view_get_show_separators
gtk_column_view_set_show_separators gtk_column_view_set_show_separators
gtk_column_view_sort_by_column gtk_column_view_sort_by_column
gtk_column_view_set_single_click_activate
gtk_column_view_get_single_click_activate
<SUBSECTION Standard> <SUBSECTION Standard>
GTK_COLUMN_VIEW GTK_COLUMN_VIEW
GTK_COLUMN_VIEW_CLASS GTK_COLUMN_VIEW_CLASS
@ -550,6 +552,8 @@ gtk_grid_view_set_max_columns
gtk_grid_view_get_max_columns gtk_grid_view_get_max_columns
gtk_grid_view_set_min_columns gtk_grid_view_set_min_columns
gtk_grid_view_get_min_columns gtk_grid_view_get_min_columns
gtk_grid_view_set_single_click_activate
gtk_grid_view_get_single_click_activate
<SUBSECTION Standard> <SUBSECTION Standard>
GTK_GRID_VIEW GTK_GRID_VIEW
GTK_GRID_VIEW_CLASS GTK_GRID_VIEW_CLASS

View File

@ -81,6 +81,7 @@ enum
PROP_SORTER, PROP_SORTER,
PROP_VADJUSTMENT, PROP_VADJUSTMENT,
PROP_VSCROLL_POLICY, PROP_VSCROLL_POLICY,
PROP_SINGLE_CLICK_ACTIVATE,
N_PROPS N_PROPS
}; };
@ -317,6 +318,10 @@ gtk_column_view_get_property (GObject *object,
g_value_set_object (value, self->sorter); g_value_set_object (value, self->sorter);
break; break;
case PROP_SINGLE_CLICK_ACTIVATE:
g_value_set_boolean (value, gtk_column_view_get_single_click_activate (self));
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
@ -373,6 +378,10 @@ gtk_column_view_set_property (GObject *object,
} }
break; break;
case PROP_SINGLE_CLICK_ACTIVATE:
gtk_column_view_set_single_click_activate (self, g_value_get_boolean (value));
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
@ -457,6 +466,18 @@ gtk_column_view_class_init (GtkColumnViewClass *klass)
GTK_TYPE_SORTER, GTK_TYPE_SORTER,
G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
/**
* GtkColumnView:single-click-activate:
*
* Activate rows on single click and select them on hover
*/
properties[PROP_SINGLE_CLICK_ACTIVATE] =
g_param_spec_boolean ("single-click-activate",
P_("Single click activate"),
P_("Activate rows on single click"),
FALSE,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (gobject_class, N_PROPS, properties); g_object_class_install_properties (gobject_class, N_PROPS, properties);
/** /**
@ -769,3 +790,42 @@ gtk_column_view_sort_by_column (GtkColumnView *self,
column, column,
direction == GTK_SORT_DESCENDING); direction == GTK_SORT_DESCENDING);
} }
/**
* gtk_column_view_set_single_click_activate:
* @self: a #GtkColumnView
* @single_click_activate: %TRUE to activate items on single click
*
* Sets whether rows should be activated on single click and
* selected on hover.
*/
void
gtk_column_view_set_single_click_activate (GtkColumnView *self,
gboolean single_click_activate)
{
g_return_if_fail (GTK_IS_COLUMN_VIEW (self));
if (single_click_activate == gtk_list_view_get_single_click_activate (self->listview))
return;
gtk_list_view_set_single_click_activate (self->listview, single_click_activate);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SINGLE_CLICK_ACTIVATE]);
}
/**
* gtk_column_view_get_single_click_activate:
* @self: a #GtkColumnView
*
* Returns whether rows will be activated on single click and
* selected on hover.
*
* Returns: %TRUE if rows are activated on single click
*/
gboolean
gtk_column_view_get_single_click_activate (GtkColumnView *self)
{
g_return_val_if_fail (GTK_IS_COLUMN_VIEW (self), FALSE);
return gtk_list_view_get_single_click_activate (self->listview);
}

View File

@ -81,6 +81,12 @@ void gtk_column_view_sort_by_column (GtkColumnView
GtkColumnViewColumn *column, GtkColumnViewColumn *column,
GtkSortType direction); GtkSortType direction);
GDK_AVAILABLE_IN_ALL
void gtk_column_view_set_single_click_activate (GtkColumnView *self,
gboolean single_click_activate);
GDK_AVAILABLE_IN_ALL
gboolean gtk_column_view_get_single_click_activate (GtkColumnView *self);
G_END_DECLS G_END_DECLS
#endif /* __GTK_COLUMN_VIEW_H__ */ #endif /* __GTK_COLUMN_VIEW_H__ */

View File

@ -90,6 +90,7 @@ enum
PROP_MAX_COLUMNS, PROP_MAX_COLUMNS,
PROP_MIN_COLUMNS, PROP_MIN_COLUMNS,
PROP_MODEL, PROP_MODEL,
PROP_SINGLE_CLICK_ACTIVATE,
N_PROPS N_PROPS
}; };
@ -909,6 +910,10 @@ gtk_grid_view_get_property (GObject *object,
g_value_set_object (value, gtk_list_base_get_model (GTK_LIST_BASE (self))); g_value_set_object (value, gtk_list_base_get_model (GTK_LIST_BASE (self)));
break; break;
case PROP_SINGLE_CLICK_ACTIVATE:
g_value_set_boolean (value, gtk_list_item_manager_get_single_click_activate (self->item_manager));
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
@ -941,6 +946,10 @@ gtk_grid_view_set_property (GObject *object,
gtk_grid_view_set_model (self, g_value_get_object (value)); gtk_grid_view_set_model (self, g_value_get_object (value));
break; break;
case PROP_SINGLE_CLICK_ACTIVATE:
gtk_grid_view_set_single_click_activate (self, g_value_get_boolean (value));
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
@ -1041,6 +1050,18 @@ gtk_grid_view_class_init (GtkGridViewClass *klass)
G_TYPE_LIST_MODEL, G_TYPE_LIST_MODEL,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
/**
* GtkGridView:single-click-activate:
*
* Activate rows on single click and select them on hover
*/
properties[PROP_SINGLE_CLICK_ACTIVATE] =
g_param_spec_boolean ("single-click-activate",
P_("Single click activate"),
P_("Activate rows on single click"),
FALSE,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (gobject_class, N_PROPS, properties); g_object_class_install_properties (gobject_class, N_PROPS, properties);
/** /**
@ -1311,3 +1332,41 @@ gtk_grid_view_set_min_columns (GtkGridView *self,
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MIN_COLUMNS]); g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MIN_COLUMNS]);
} }
/**
* gtk_grid_view_set_single_click_activate:
* @self: a #GtkGridView
* @single_click_activate: %TRUE to activate items on single click
*
* Sets whether items should be activated on single click and
* selected on hover.
*/
void
gtk_grid_view_set_single_click_activate (GtkGridView *self,
gboolean single_click_activate)
{
g_return_if_fail (GTK_IS_GRID_VIEW (self));
if (single_click_activate == gtk_list_item_manager_get_single_click_activate (self->item_manager))
return;
gtk_list_item_manager_set_single_click_activate (self->item_manager, single_click_activate);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SINGLE_CLICK_ACTIVATE]);
}
/**
* gtk_grid_view_get_single_click_activate:
* @self: a #GtkListView
*
* Returns whether items will be activated on single click and
* selected on hover.
*
* Returns: %TRUE if items are activated on single click
*/
gboolean
gtk_grid_view_get_single_click_activate (GtkGridView *self)
{
g_return_val_if_fail (GTK_IS_GRID_VIEW (self), FALSE);
return gtk_list_item_manager_get_single_click_activate (self->item_manager);
}

View File

@ -74,6 +74,12 @@ GDK_AVAILABLE_IN_ALL
void gtk_grid_view_set_max_columns (GtkGridView *self, void gtk_grid_view_set_max_columns (GtkGridView *self,
guint max_columns); guint max_columns);
GDK_AVAILABLE_IN_ALL
void gtk_grid_view_set_single_click_activate (GtkGridView *self,
gboolean single_click_activate);
GDK_AVAILABLE_IN_ALL
gboolean gtk_grid_view_get_single_click_activate (GtkGridView *self);
G_END_DECLS G_END_DECLS