[gtk/wip/otte/listview: 5/11] listview: Add single-click-activate



commit 63bb726fd03c0d1b96f09b37d424c50e3defd60c
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Dec 13 20:57:57 2019 -0500

    listview: Add single-click-activate
    
    Add a single-click-activate property to GtkListView.

 docs/reference/gtk/gtk4-sections.txt |  2 ++
 gtk/gtklistview.c                    | 60 ++++++++++++++++++++++++++++++++++++
 gtk/gtklistview.h                    |  6 ++++
 3 files changed, 68 insertions(+)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index f0ab21bc50..53a2fe75a1 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -575,6 +575,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
diff --git a/gtk/gtklistview.c b/gtk/gtklistview.c
index fa104d9961..272be9d46f 100644
--- a/gtk/gtklistview.c
+++ b/gtk/gtklistview.c
@@ -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);
+}
diff --git a/gtk/gtklistview.h b/gtk/gtklistview.h
index 3d5f6a8a56..f00bcf7e3f 100644
--- a/gtk/gtklistview.h
+++ b/gtk/gtklistview.h
@@ -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__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]