listview: Add single-click-activate

Add a single-click-activate property to GtkListView.
This commit is contained in:
Matthias Clasen 2019-12-13 20:57:57 -05:00
parent 69c86ae385
commit 2c4c07c96d
3 changed files with 68 additions and 0 deletions

View File

@ -477,6 +477,8 @@ gtk_list_view_set_model
gtk_list_view_get_model
gtk_list_view_set_show_separators
gtk_list_view_get_show_separators
gtk_list_view_set_single_click_activate
gtk_list_view_get_single_click_activate
<SUBSECTION Standard>
GTK_LIST_VIEW
GTK_LIST_VIEW_CLASS

View File

@ -84,6 +84,7 @@ enum
PROP_FACTORY,
PROP_MODEL,
PROP_SHOW_SEPARATORS,
PROP_SINGLE_CLICK_ACTIVATE,
N_PROPS
};
@ -638,6 +639,10 @@ gtk_list_view_get_property (GObject *object,
g_value_set_boolean (value, self->show_separators);
break;
case PROP_SINGLE_CLICK_ACTIVATE:
g_value_set_boolean (value, gtk_list_item_manager_get_single_click_activate (self->item_manager));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@ -666,6 +671,10 @@ gtk_list_view_set_property (GObject *object,
gtk_list_view_set_show_separators (self, g_value_get_boolean (value));
break;
case PROP_SINGLE_CLICK_ACTIVATE:
gtk_list_view_set_single_click_activate (self, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@ -750,6 +759,18 @@ gtk_list_view_class_init (GtkListViewClass *klass)
FALSE,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkListView: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);
/**
@ -973,3 +994,42 @@ gtk_list_view_get_show_separators (GtkListView *self)
return self->show_separators;
}
/**
* gtk_list_view_set_single_click_activate:
* @self: a #GtkListView
* @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_list_view_set_single_click_activate (GtkListView *self,
gboolean single_click_activate)
{
g_return_if_fail (GTK_IS_LIST_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_list_view_get_single_click_activate:
* @self: a #GtkListView
*
* Returns whether rows will be activated on single click and
* selected on hover.
*
* Returns: %TRUE if rows are activated on single click
*/
gboolean
gtk_list_view_get_single_click_activate (GtkListView *self)
{
g_return_val_if_fail (GTK_IS_LIST_VIEW (self), FALSE);
return gtk_list_item_manager_get_single_click_activate (self->item_manager);
}

View File

@ -69,6 +69,12 @@ void gtk_list_view_set_show_separators (GtkListView
GDK_AVAILABLE_IN_ALL
gboolean gtk_list_view_get_show_separators (GtkListView *self);
GDK_AVAILABLE_IN_ALL
void gtk_list_view_set_single_click_activate (GtkListView *self,
gboolean single_click_activate);
GDK_AVAILABLE_IN_ALL
gboolean gtk_list_view_get_single_click_activate (GtkListView *self);
G_END_DECLS
#endif /* __GTK_LIST_VIEW_H__ */