[gtk/wip/otte/listview: 103/158] gridview: Implement (un)select all



commit 2f5343b8069ec74f40ddc6fb7a611610f99ea2f0
Author: Benjamin Otte <otte redhat com>
Date:   Sun Oct 20 22:05:48 2019 +0200

    gridview: Implement (un)select all
    
    Adds listitem.select-all and listitem.unselect-all actions and installs
    the same keybindings as the treeview for those actions.

 gtk/gtkgridview.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)
---
diff --git a/gtk/gtkgridview.c b/gtk/gtkgridview.c
index 45711ae2e8..f69d6aafcd 100644
--- a/gtk/gtkgridview.c
+++ b/gtk/gtkgridview.c
@@ -22,6 +22,7 @@
 #include "gtkgridview.h"
 
 #include "gtkadjustment.h"
+#include "gtkbindings.h"
 #include "gtkintl.h"
 #include "gtklistitemfactory.h"
 #include "gtklistitemmanagerprivate.h"
@@ -1278,6 +1279,32 @@ gtk_grid_view_select_item_action (GtkWidget  *widget,
   gtk_grid_view_select_item (self, pos, modify, extend);
 }
 
+static void
+gtk_grid_view_select_all (GtkWidget  *widget,
+                          const char *action_name,
+                          GVariant   *parameter)
+{
+  GtkGridView *self = GTK_GRID_VIEW (widget);
+  GtkSelectionModel *selection_model;
+
+  selection_model = gtk_list_item_manager_get_model (self->item_manager);
+
+  gtk_selection_model_select_all (selection_model);
+}
+
+static void
+gtk_grid_view_unselect_all (GtkWidget  *widget,
+                            const char *action_name,
+                            GVariant   *parameter)
+{
+  GtkGridView *self = GTK_GRID_VIEW (widget);
+  GtkSelectionModel *selection_model;
+
+  selection_model = gtk_list_item_manager_get_model (self->item_manager);
+
+  gtk_selection_model_unselect_all (selection_model);
+}
+
 static void
 gtk_grid_view_compute_scroll_align (GtkGridView   *self,
                                     GtkOrientation orientation,
@@ -1430,6 +1457,7 @@ gtk_grid_view_class_init (GtkGridViewClass *klass)
 {
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+  GtkBindingSet *binding_set;
   gpointer iface;
 
   widget_class->focus = gtk_grid_view_focus;
@@ -1582,6 +1610,28 @@ gtk_grid_view_class_init (GtkGridViewClass *klass)
                                    "(ubb)",
                                    gtk_grid_view_select_item_action);
 
+  /**
+   * GtkGridView|list.select-all:
+   *
+   * If the selection model supports it, select all items in the model.
+   * If not, do nothing.
+   */
+  gtk_widget_class_install_action (widget_class,
+                                   "list.select-all",
+                                   NULL,
+                                   gtk_grid_view_select_all);
+
+  /**
+   * GtkGridView|list.unselect-all:
+   *
+   * If the selection model supports it, unselect all items in the model.
+   * If not, do nothing.
+   */
+  gtk_widget_class_install_action (widget_class,
+                                   "list.unselect-all",
+                                   NULL,
+                                   gtk_grid_view_unselect_all);
+
   /**
    * GtkGridView|list.scroll-to-item:
    * @position: position of item to scroll to
@@ -1594,6 +1644,14 @@ gtk_grid_view_class_init (GtkGridViewClass *klass)
                                    "u",
                                    gtk_grid_view_scroll_to_item);
 
+  binding_set = gtk_binding_set_by_class (klass);
+
+  gtk_binding_entry_add_action (binding_set, GDK_KEY_a, GDK_CONTROL_MASK, "list.select-all", NULL);
+  gtk_binding_entry_add_action (binding_set, GDK_KEY_slash, GDK_CONTROL_MASK, "list.select-all", NULL);
+
+  gtk_binding_entry_add_action (binding_set, GDK_KEY_A, GDK_CONTROL_MASK | GDK_SHIFT_MASK, 
"list.unselect-all", NULL);
+  gtk_binding_entry_add_action (binding_set, GDK_KEY_backslash, GDK_CONTROL_MASK, "list.unselect-all", NULL);
+
   gtk_widget_class_set_css_name (widget_class, I_("flowbox"));
 
 }


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