[libgd] main-view: Support CTRL/SHIFT-space/enter to select items



commit f5388cbcb86d50bad7bdc77eb61c8e5e2249876f
Author: Alexander Larsson <alexl redhat com>
Date:   Fri Apr 12 12:31:33 2013 +0200

    main-view: Support CTRL/SHIFT-space/enter to select items
    
    CTRL is ignored in selection mode, but means switch to selection mode
    and select in non-selection mode.
    
    SHIFT means range-select, like shift+click.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=697645

 libgd/gd-main-icon-view.c | 20 ++++++++++++++++++++
 libgd/gd-main-list-view.c | 25 +++++++++++++++++++++++++
 libgd/gd-main-view.c      | 28 ++++++++++++++++++++--------
 3 files changed, 65 insertions(+), 8 deletions(-)
---
diff --git a/libgd/gd-main-icon-view.c b/libgd/gd-main-icon-view.c
index d96be6c..91466c3 100644
--- a/libgd/gd-main-icon-view.c
+++ b/libgd/gd-main-icon-view.c
@@ -293,6 +293,11 @@ gd_main_icon_view_class_init (GdMainIconViewClass *klass)
 {
   GObjectClass *oclass = G_OBJECT_CLASS (klass);
   GtkWidgetClass *wclass = GTK_WIDGET_CLASS (klass);
+  GtkBindingSet *binding_set;
+  GdkModifierType activate_modifiers[] = { GDK_SHIFT_MASK, GDK_CONTROL_MASK, GDK_SHIFT_MASK | 
GDK_CONTROL_MASK };
+  int i;
+
+  binding_set = gtk_binding_set_by_class (klass);
 
   oclass->constructed = gd_main_icon_view_constructed;
   wclass->drag_data_get = gd_main_icon_view_drag_data_get;
@@ -306,6 +311,21 @@ gd_main_icon_view_class_init (GdMainIconViewClass *klass)
                                                              G_PARAM_READWRITE));
 
   g_type_class_add_private (klass, sizeof (GdMainIconViewPrivate));
+
+
+  for (i = 0; i < G_N_ELEMENTS (activate_modifiers); i++)
+    {
+      gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, activate_modifiers[i],
+                                   "activate-cursor-item", 0);
+      gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, activate_modifiers[i],
+                                   "activate-cursor-item", 0);
+      gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, activate_modifiers[i],
+                                   "activate-cursor-item", 0);
+      gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, activate_modifiers[i],
+                                   "activate-cursor-item", 0);
+      gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, activate_modifiers[i],
+                                   "activate-cursor-item", 0);
+    }
 }
 
 static void
diff --git a/libgd/gd-main-list-view.c b/libgd/gd-main-list-view.c
index a1be3e6..000a803 100644
--- a/libgd/gd-main-list-view.c
+++ b/libgd/gd-main-list-view.c
@@ -144,12 +144,37 @@ gd_main_list_view_class_init (GdMainListViewClass *klass)
 {
   GObjectClass *oclass = G_OBJECT_CLASS (klass);
   GtkWidgetClass *wclass = GTK_WIDGET_CLASS (klass);
+  GtkBindingSet *binding_set;
+  GdkModifierType activate_modifiers[] = { GDK_SHIFT_MASK, GDK_CONTROL_MASK, GDK_SHIFT_MASK | 
GDK_CONTROL_MASK };
+  int i;
+
+  binding_set = gtk_binding_set_by_class (klass);
 
   oclass->constructed = gd_main_list_view_constructed;
   wclass->drag_data_get = gd_main_list_view_drag_data_get;
   wclass->draw = gd_main_list_view_draw;
 
   g_type_class_add_private (klass, sizeof (GdMainListViewPrivate));
+
+  for (i = 0; i < G_N_ELEMENTS (activate_modifiers); i++)
+    {
+      gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, activate_modifiers[i],
+                                   "select-cursor-row", 1,
+                                   G_TYPE_BOOLEAN, TRUE);
+      gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, activate_modifiers[i],
+                                   "select-cursor-row", 1,
+                                   G_TYPE_BOOLEAN, TRUE);
+      gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, activate_modifiers[i],
+                                   "select-cursor-row", 1,
+                                   G_TYPE_BOOLEAN, TRUE);
+      gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, activate_modifiers[i],
+                                   "select-cursor-row", 1,
+                                   G_TYPE_BOOLEAN, TRUE);
+      gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, activate_modifiers[i],
+                                   "select-cursor-row", 1,
+                                   G_TYPE_BOOLEAN, TRUE);
+    }
+
 }
 
 static void
diff --git a/libgd/gd-main-view.c b/libgd/gd-main-view.c
index 6a9036b..e492326 100644
--- a/libgd/gd-main-view.c
+++ b/libgd/gd-main-view.c
@@ -536,6 +536,14 @@ on_button_release_view_mode (GdMainView *self,
 }
 
 static gboolean
+event_triggers_selection_mode (GdkEventButton *event)
+{
+  return
+    (event->button == 3) ||
+    ((event->button == 1) && (event->state & GDK_CONTROL_MASK));
+}
+
+static gboolean
 on_button_release_event (GtkWidget *view,
                          GdkEventButton *event,
                          gpointer user_data)
@@ -624,8 +632,7 @@ on_button_release_event (GtkWidget *view,
 
   if (!selection_mode)
     {
-      if ((event->button == 3) ||
-          ((event->button == 1) && (event->state & GDK_CONTROL_MASK)))
+      if (event_triggers_selection_mode (event))
         {
           g_signal_emit (self, signals[SELECTION_MODE_REQUEST], 0);
           selection_mode = TRUE;
@@ -660,10 +667,7 @@ on_button_press_event (GtkWidget *view,
   if (path != NULL)
     self->priv->button_press_item_path = gtk_tree_path_to_string (path);
 
-  force_selection =
-    (event->button == 3) ||
-    ((event->button == 1) && (event->state & GDK_CONTROL_MASK));
-
+  force_selection = event_triggers_selection_mode (event);
   if (!self->priv->selection_mode && !force_selection)
     {
       gtk_tree_path_free (path);
@@ -812,8 +816,16 @@ static void
 on_view_path_activated (GdMainView *self,
                         GtkTreePath *path)
 {
-  if (self->priv->selection_mode)
-    toggle_selection_for_path (self, path, FALSE);
+  GdkModifierType state;
+
+  gtk_get_current_event_state (&state);
+
+  if (self->priv->selection_mode || (state & GDK_CONTROL_MASK) != 0)
+    {
+      if (!self->priv->selection_mode)
+       g_signal_emit (self, signals[SELECTION_MODE_REQUEST], 0);
+      toggle_selection_for_path (self, path, ((state & GDK_SHIFT_MASK) != 0));
+    }
   else
     activate_item_for_path (self, path);
 }


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