[gtk/wayland-key-repeat: 65/98] listitem: Add "listitem.select" action and keybindings for it



commit 7bddadf75ff1259f05a9242c517c2de46d9f9028
Author: Benjamin Otte <otte redhat com>
Date:   Wed Oct 16 16:28:47 2019 +0200

    listitem: Add "listitem.select" action and keybindings for it
    
    In fact, grab space with all modifiers to toggle selection of the
    current item.

 gtk/gtklistitem.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
---
diff --git a/gtk/gtklistitem.c b/gtk/gtklistitem.c
index 860e8f269f..ac393674e2 100644
--- a/gtk/gtklistitem.c
+++ b/gtk/gtklistitem.c
@@ -226,6 +226,25 @@ gtk_list_item_set_property (GObject      *object,
     }
 }
 
+static void
+gtk_list_item_select_action (GtkWidget  *widget,
+                             const char *action_name,
+                             GVariant   *parameter)
+{
+  GtkListItem *self = GTK_LIST_ITEM (widget);
+  gboolean modify, extend;
+
+  if (!self->selectable)
+    return;
+
+  g_variant_get (parameter, "(bb)", &modify, &extend);
+
+  gtk_widget_activate_action (GTK_WIDGET (self),
+                              "list.select-item",
+                              "(ubb)",
+                              self->position, modify, extend);
+}
+
 static void
 gtk_list_item_class_init (GtkListItemClass *klass)
 {
@@ -325,6 +344,24 @@ gtk_list_item_class_init (GtkListItemClass *klass)
 
   widget_class->activate_signal = signals[ACTIVATE_SIGNAL];
 
+  /**
+   * GtkListItem|listitem.select:
+   * @modify: %TRUE to toggle the existing selection, %FALSE to select
+   * @extend: %TRUE to extend the selection
+   *
+   * Changes selection if the item is selectable.
+   * If the item is not selectable, nothing happens.
+   *
+   * This function will emit the list.select-item action and the resulting
+   * behavior, in particular the interpretation of @modify and @extend
+   * depends on the view containing this listitem. See for example
+   * GtkListView|list.select-item or GtkGridView|list.select-item.
+   */
+  gtk_widget_class_install_action (widget_class,
+                                   "listitem.select",
+                                   "(bb)",
+                                   gtk_list_item_select_action);
+
   binding_set = gtk_binding_set_by_class (klass);
 
   gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
@@ -334,6 +371,25 @@ gtk_list_item_class_init (GtkListItemClass *klass)
   gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
                                 "activate-keybinding", 0);
 
+  /* note that some of these may get overwritten by child widgets,
+   * such as GtkTreeExpander */
+  gtk_binding_entry_add_action (binding_set, GDK_KEY_space, 0,
+                                "listitem.select", "(bb)", TRUE, FALSE);
+  gtk_binding_entry_add_action (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
+                                "listitem.select", "(bb)", TRUE, FALSE);
+  gtk_binding_entry_add_action (binding_set, GDK_KEY_space, GDK_SHIFT_MASK,
+                                "listitem.select", "(bb)", TRUE, FALSE);
+  gtk_binding_entry_add_action (binding_set, GDK_KEY_space, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
+                                "listitem.select", "(bb)", TRUE, FALSE);
+  gtk_binding_entry_add_action (binding_set, GDK_KEY_KP_Space, 0,
+                                "listitem.select", "(bb)", TRUE, FALSE);
+  gtk_binding_entry_add_action (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
+                                "listitem.select", "(bb)", TRUE, FALSE);
+  gtk_binding_entry_add_action (binding_set, GDK_KEY_KP_Space, GDK_SHIFT_MASK,
+                                "listitem.select", "(bb)", TRUE, FALSE);
+  gtk_binding_entry_add_action (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
+                                "listitem.select", "(bb)", TRUE, FALSE);
+
   /* This gets overwritten by gtk_list_item_new() but better safe than sorry */
   gtk_widget_class_set_css_name (widget_class, I_("row"));
 }


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