[gtk/wip/otte/listview: 30/38] gridview: Add activation
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/listview: 30/38] gridview: Add activation
- Date: Tue, 22 Oct 2019 14:49:58 +0000 (UTC)
commit fa87714dbb5f2480726f79f97f3ce8723018fd1a
Author: Benjamin Otte <otte redhat com>
Date: Sun Oct 20 08:13:36 2019 +0200
gridview: Add activation
gtk/gtkgridview.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
---
diff --git a/gtk/gtkgridview.c b/gtk/gtkgridview.c
index 1e035be473..1d07323b6c 100644
--- a/gtk/gtkgridview.c
+++ b/gtk/gtkgridview.c
@@ -108,11 +108,17 @@ enum
N_PROPS
};
+enum {
+ ACTIVATE,
+ LAST_SIGNAL
+};
+
G_DEFINE_TYPE_WITH_CODE (GtkGridView, gtk_grid_view, GTK_TYPE_WIDGET,
G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL)
G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
static GParamSpec *properties[N_PROPS] = { NULL, };
+static guint signals[LAST_SIGNAL] = { 0 };
static void G_GNUC_UNUSED
dump (GtkGridView *self)
@@ -1205,6 +1211,24 @@ gtk_grid_view_select_item_action (GtkWidget *widget,
gtk_grid_view_select_item (self, pos, modify, extend);
}
+static void
+gtk_grid_view_activate_item (GtkWidget *widget,
+ const char *action_name,
+ GVariant *parameter)
+{
+ GtkGridView *self = GTK_GRID_VIEW (widget);
+ guint pos;
+
+ if (!g_variant_check_format_string (parameter, "u", FALSE))
+ return;
+
+ g_variant_get (parameter, "u", &pos);
+ if (self->model == NULL || pos >= g_list_model_get_n_items (self->model))
+ return;
+
+ g_signal_emit (widget, signals[ACTIVATE], 0, pos);
+}
+
static void
gtk_grid_view_class_init (GtkGridViewClass *klass)
{
@@ -1302,6 +1326,42 @@ gtk_grid_view_class_init (GtkGridViewClass *klass)
g_object_class_install_properties (gobject_class, N_PROPS, properties);
+ /**
+ * GtkGridView::activate:
+ * @self: The #GtkGridView
+ * @position: position of item to activate
+ *
+ * The ::activate signal is emitted when a cell has been activated by the user,
+ * usually via activating the GtkGridView|list.activate-item action.
+ *
+ * This allows for a convenient way to handle activation in a gridview.
+ * See GtkListItem:activatable for details on how to use this signal.
+ */
+ signals[ACTIVATE] =
+ g_signal_new (I_("activate"),
+ G_TYPE_FROM_CLASS (gobject_class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__UINT,
+ G_TYPE_NONE, 1,
+ G_TYPE_UINT);
+ g_signal_set_va_marshaller (signals[ACTIVATE],
+ G_TYPE_FROM_CLASS (gobject_class),
+ g_cclosure_marshal_VOID__UINTv);
+
+ /**
+ * GtkGridView|list.activate-item:
+ * @position: position of item to activate
+ *
+ * Activates the item given in @position by emitting the GtkGridView::activate
+ * signal.
+ */
+ gtk_widget_class_install_action (widget_class,
+ "list.activate-item",
+ "u",
+ gtk_grid_view_activate_item);
+
/**
* GtkGridView|list.select-item:
* @position: position of item to select
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]