[gnome-flashback] desktop: handle Enter key



commit 6cdb04eb051c5a2c21317ffdd326bb65b30aa746
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sat Nov 16 16:14:42 2019 +0200

    desktop: handle Enter key

 gnome-flashback/libdesktop/gf-icon-view.c | 33 +++++++++++++++
 gnome-flashback/libdesktop/gf-icon.c      | 68 +++++++++++++++----------------
 gnome-flashback/libdesktop/gf-icon.h      |  2 +
 3 files changed, 69 insertions(+), 34 deletions(-)
---
diff --git a/gnome-flashback/libdesktop/gf-icon-view.c b/gnome-flashback/libdesktop/gf-icon-view.c
index d49f6e1..a574408 100644
--- a/gnome-flashback/libdesktop/gf-icon-view.c
+++ b/gnome-flashback/libdesktop/gf-icon-view.c
@@ -84,6 +84,8 @@ enum
   SELECT_ALL,
   UNSELECT_ALL,
 
+  ACTIVATE,
+
   LAST_SIGNAL
 };
 
@@ -1913,6 +1915,19 @@ unselect_all_cb (GfIconView *self,
   unselect_icons (self);
 }
 
+static void
+activate_cb (GfIconView *self,
+             gpointer    user_data)
+{
+  GList *l;
+
+  if (self->selected_icons == NULL)
+    return;
+
+  for (l = self->selected_icons; l != NULL; l = l->next)
+    gf_icon_open (GF_ICON (l->data));
+}
+
 static GtkWidget *
 create_dummy_icon (GfIconView *self)
 {
@@ -2058,6 +2073,11 @@ install_signals (void)
     g_signal_new ("unselect-all", GF_TYPE_ICON_VIEW,
                   G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                   0, NULL, NULL, NULL, G_TYPE_NONE, 0);
+
+  view_signals[ACTIVATE] =
+    g_signal_new ("activate", GF_TYPE_ICON_VIEW,
+                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                  0, NULL, NULL, NULL, G_TYPE_NONE, 0);
 }
 
 static void
@@ -2072,6 +2092,18 @@ add_bindings (GtkBindingSet *binding_set)
   modifiers = GDK_CONTROL_MASK | GDK_SHIFT_MASK;
   gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, modifiers,
                                 "unselect-all", 0);
+
+  modifiers = 0;
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, modifiers,
+                                "activate", 0);
+
+  modifiers = 0;
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, modifiers,
+                                "activate", 0);
+
+  modifiers = 0;
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, modifiers,
+                                "activate", 0);
 }
 
 static void
@@ -2106,6 +2138,7 @@ gf_icon_view_init (GfIconView *self)
 
   g_signal_connect (self, "select-all", G_CALLBACK (select_all_cb), NULL);
   g_signal_connect (self, "unselect-all", G_CALLBACK (unselect_all_cb), NULL);
+  g_signal_connect (self, "activate", G_CALLBACK (activate_cb), NULL);
 
   add_event_filter (self);
 
diff --git a/gnome-flashback/libdesktop/gf-icon.c b/gnome-flashback/libdesktop/gf-icon.c
index 24ae67a..b38bce8 100644
--- a/gnome-flashback/libdesktop/gf-icon.c
+++ b/gnome-flashback/libdesktop/gf-icon.c
@@ -99,38 +99,6 @@ update_state (GfIcon *self)
   gtk_widget_set_state_flags (GTK_WIDGET (self), state, TRUE);
 }
 
-static void
-icon_open (GfIcon *self)
-{
-  GfIconPrivate *priv;
-  GError *error;
-  char *uri;
-
-  priv = gf_icon_get_instance_private (self);
-  error = NULL;
-
-  if (priv->app_info != NULL)
-    {
-      if (!gf_launch_app_info (priv->app_info, &error))
-        {
-          g_warning ("%s", error->message);
-          g_error_free (error);
-        }
-
-      return;
-    }
-
-  uri = g_file_get_uri (priv->file);
-
-  if (!gf_launch_uri (uri, &error))
-    {
-      g_warning ("%s", error->message);
-      g_error_free (error);
-    }
-
-  g_free (uri);
-}
-
 static void
 rename_validate_cb (GfRenamePopover *popover,
                     const char      *new_name,
@@ -203,7 +171,7 @@ static void
 open_cb (GtkMenuItem *item,
          GfIcon      *self)
 {
-  icon_open (self);
+  gf_icon_open (self);
 }
 
 static void
@@ -411,7 +379,7 @@ multi_press_pressed_cb (GtkGestureMultiPress *gesture,
         gf_icon_set_selected (self, TRUE);
 
       if (!control_pressed && n_press == 2)
-        icon_open (self);
+        gf_icon_open (self);
     }
   else if (button == GDK_BUTTON_SECONDARY)
     {
@@ -976,6 +944,38 @@ gf_icon_get_selected (GfIcon *self)
   return priv->selected;
 }
 
+void
+gf_icon_open (GfIcon *self)
+{
+  GfIconPrivate *priv;
+  GError *error;
+  char *uri;
+
+  priv = gf_icon_get_instance_private (self);
+  error = NULL;
+
+  if (priv->app_info != NULL)
+    {
+      if (!gf_launch_app_info (priv->app_info, &error))
+        {
+          g_warning ("%s", error->message);
+          g_error_free (error);
+        }
+
+      return;
+    }
+
+  uri = g_file_get_uri (priv->file);
+
+  if (!gf_launch_uri (uri, &error))
+    {
+      g_warning ("%s", error->message);
+      g_error_free (error);
+    }
+
+  g_free (uri);
+}
+
 void
 gf_icon_update (GfIcon *self)
 {
diff --git a/gnome-flashback/libdesktop/gf-icon.h b/gnome-flashback/libdesktop/gf-icon.h
index c416740..677a09a 100644
--- a/gnome-flashback/libdesktop/gf-icon.h
+++ b/gnome-flashback/libdesktop/gf-icon.h
@@ -58,6 +58,8 @@ void        gf_icon_set_selected      (GfIcon     *self,
 
 gboolean    gf_icon_get_selected      (GfIcon     *self);
 
+void        gf_icon_open              (GfIcon     *self);
+
 void        gf_icon_update            (GfIcon     *self);
 
 G_END_DECLS


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