[gnome-photos] searchbar: Allow enter to activate first search item



commit f4cb778eb1763d17d9790d8c962de6e11f088932
Author: Pranav Kant <pranav913 gmail com>
Date:   Wed Feb 26 20:12:23 2014 +0530

    searchbar: Allow enter to activate first search item
    
    https://bugzilla.gnome.org/show_bug.cgi?id=725095

 src/photos-embed.c        |   93 +++++++++++++++++++++++++++++++++------------
 src/photos-main-toolbar.c |    7 +++
 src/photos-main-toolbar.h |    4 ++
 src/photos-searchbar.c    |   24 ++++++++++++
 src/photos-searchbar.h    |    3 +
 5 files changed, 106 insertions(+), 25 deletions(-)
---
diff --git a/src/photos-embed.c b/src/photos-embed.c
index 44c33f0..991893c 100644
--- a/src/photos-embed.c
+++ b/src/photos-embed.c
@@ -1,5 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2014 Pranav Kant
  * Copyright © 2012, 2013, 2014 Red Hat, Inc.
  *
  * This program is free software; you can redistribute it and/or
@@ -48,6 +49,7 @@
 #include "photos-source-manager.h"
 #include "photos-tracker-overview-controller.h"
 #include "photos-view-container.h"
+#include "photos-view-model.h"
 
 
 typedef struct _PhotosEmbedSearchState PhotosEmbedSearchState;
@@ -142,6 +144,68 @@ photos_embed_clear_search (PhotosEmbed *self)
 }
 
 
+static GtkWidget*
+photos_embed_get_view_container_from_mode (PhotosEmbed *self, PhotosWindowMode mode)
+{
+  PhotosEmbedPrivate *priv = self->priv;
+  GtkWidget *view_container;
+
+  switch (mode)
+    {
+    case PHOTOS_WINDOW_MODE_COLLECTIONS:
+      view_container = priv->collections;
+      break;
+
+    case PHOTOS_WINDOW_MODE_FAVORITES:
+      view_container = priv->favorites;
+      break;
+
+    case PHOTOS_WINDOW_MODE_OVERVIEW:
+      view_container = priv->overview;
+      break;
+
+    case PHOTOS_WINDOW_MODE_PREVIEW:
+      view_container = NULL;
+      break;
+
+    case PHOTOS_WINDOW_MODE_SEARCH:
+      view_container = priv->search;
+      break;
+
+    default:
+      g_assert_not_reached ();
+    }
+
+  return view_container;
+}
+
+
+static void
+photos_embed_activate_result (PhotosEmbed *self)
+{
+  PhotosEmbedPrivate *priv = self->priv;
+  GtkTreeIter iter;
+  GtkListStore *store;
+  GtkWidget *view_container;
+  PhotosWindowMode mode;
+
+  mode = photos_mode_controller_get_window_mode (priv->mode_cntrlr);
+  view_container = photos_embed_get_view_container_from_mode (self, mode);
+  store = photos_view_container_get_model (PHOTOS_VIEW_CONTAINER (view_container));
+
+  if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter))
+    {
+      GObject *item;
+      gchar *id;
+
+      gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, PHOTOS_VIEW_MODEL_URN, &id, -1);
+      item = photos_base_manager_get_object_by_id (priv->item_mngr, id);
+      photos_base_manager_set_active_object (priv->item_mngr, item);
+      g_free (id);
+    }
+}
+
+
 static void
 photos_embed_prepare_for_preview (PhotosEmbed *self)
 {
@@ -176,31 +240,7 @@ photos_embed_item_load (GObject *source_object, GAsyncResult *res, gpointer user
     goto out;
 
   mode = photos_mode_controller_get_window_mode (priv->mode_cntrlr);
-  switch (mode)
-    {
-    case PHOTOS_WINDOW_MODE_COLLECTIONS:
-      view_container = priv->collections;
-      break;
-
-    case PHOTOS_WINDOW_MODE_FAVORITES:
-      view_container = priv->favorites;
-      break;
-
-    case PHOTOS_WINDOW_MODE_OVERVIEW:
-      view_container = priv->overview;
-      break;
-
-    case PHOTOS_WINDOW_MODE_PREVIEW:
-      view_container = NULL;
-      break;
-
-    case PHOTOS_WINDOW_MODE_SEARCH:
-      view_container = priv->search;
-      break;
-
-    default:
-      g_assert_not_reached ();
-    }
+  view_container = photos_embed_get_view_container_from_mode (self, mode);
 
   /* If we are already in the preview and navigating using the
    * buttons, then we don't need this.
@@ -612,6 +652,7 @@ photos_embed_init (PhotosEmbed *self)
 {
   PhotosEmbedPrivate *priv;
   GApplication *app;
+  PhotosSearchbar *searchbar;
   PhotosSearchContextState *state;
   gboolean querying;
 
@@ -642,6 +683,8 @@ photos_embed_init (PhotosEmbed *self)
 
   priv->toolbar = photos_main_toolbar_new (GTK_OVERLAY (priv->stack_overlay));
   photos_main_toolbar_set_stack (PHOTOS_MAIN_TOOLBAR (priv->toolbar), GTK_STACK (priv->stack));
+  searchbar = photos_main_toolbar_get_searchbar (PHOTOS_MAIN_TOOLBAR (priv->toolbar));
+  g_signal_connect_swapped (searchbar, "activate-result", G_CALLBACK (photos_embed_activate_result), self);
 
   priv->ntfctn_mngr = g_object_ref_sink (photos_notification_manager_dup_singleton ());
   gtk_overlay_add_overlay (GTK_OVERLAY (priv->stack_overlay), priv->ntfctn_mngr);
diff --git a/src/photos-main-toolbar.c b/src/photos-main-toolbar.c
index 35dd13b..e7cd50a 100644
--- a/src/photos-main-toolbar.c
+++ b/src/photos-main-toolbar.c
@@ -804,6 +804,13 @@ photos_main_toolbar_new (GtkOverlay *overlay)
 }
 
 
+PhotosSearchbar *
+photos_main_toolbar_get_searchbar (PhotosMainToolbar *self)
+{
+  return PHOTOS_SEARCHBAR (self->priv->searchbar);
+}
+
+
 gboolean
 photos_main_toolbar_handle_event (PhotosMainToolbar *self, GdkEventKey *event)
 {
diff --git a/src/photos-main-toolbar.h b/src/photos-main-toolbar.h
index 0d217bd..f836b4d 100644
--- a/src/photos-main-toolbar.h
+++ b/src/photos-main-toolbar.h
@@ -27,6 +27,8 @@
 
 #include <gtk/gtk.h>
 
+#include "photos-searchbar.h"
+
 G_BEGIN_DECLS
 
 #define PHOTOS_TYPE_MAIN_TOOLBAR (photos_main_toolbar_get_type ())
@@ -70,6 +72,8 @@ GType                  photos_main_toolbar_get_type               (void) G_GNUC_
 
 GtkWidget             *photos_main_toolbar_new                    (GtkOverlay *overlay);
 
+PhotosSearchbar *      photos_main_toolbar_get_searchbar          (PhotosMainToolbar *self);
+
 gboolean               photos_main_toolbar_handle_event           (PhotosMainToolbar *self, GdkEventKey 
*event);
 
 gboolean               photos_main_toolbar_is_focus               (PhotosMainToolbar *self);
diff --git a/src/photos-searchbar.c b/src/photos-searchbar.c
index de765ea..04b5891 100644
--- a/src/photos-searchbar.c
+++ b/src/photos-searchbar.c
@@ -1,5 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2014 Pranav Kant
  * Copyright © 2014 Red Hat, Inc.
  *
  * This program is free software; you can redistribute it and/or
@@ -43,6 +44,14 @@ struct _PhotosSearchbarPrivate
   gulong search_state_id;
 };
 
+enum
+{
+  ACTIVATE_RESULT,
+  LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
 
 G_DEFINE_TYPE_WITH_PRIVATE (PhotosSearchbar, photos_searchbar, GTK_TYPE_REVEALER);
 
@@ -137,6 +146,11 @@ photos_searchbar_key_press_event (PhotosSearchbar *self, GdkEventKey *event)
       photos_searchbar_enable_search (self, FALSE);
       ret_val = GDK_EVENT_STOP;
     }
+  else if (event->keyval == GDK_KEY_Return)
+    {
+      g_signal_emit (self, signals[ACTIVATE_RESULT], 0);
+      ret_val = GDK_EVENT_STOP;
+    }
 
   return ret_val;
 }
@@ -250,6 +264,16 @@ photos_searchbar_class_init (PhotosSearchbarClass *class)
   object_class->dispose = photos_searchbar_dispose;
   class->hide = photos_searchbar_default_hide;
   class->show = photos_searchbar_default_show;
+
+  signals[ACTIVATE_RESULT] = g_signal_new ("activate-result",
+                                           G_TYPE_FROM_CLASS (class),
+                                           G_SIGNAL_RUN_LAST,
+                                           G_STRUCT_OFFSET (PhotosSearchbarClass, activate_result),
+                                           NULL, /* accumulator */
+                                           NULL, /* accu_data */
+                                           g_cclosure_marshal_VOID__VOID,
+                                           G_TYPE_NONE,
+                                           0);
 }
 
 
diff --git a/src/photos-searchbar.h b/src/photos-searchbar.h
index 885814a..ac30968 100644
--- a/src/photos-searchbar.h
+++ b/src/photos-searchbar.h
@@ -70,6 +70,9 @@ struct _PhotosSearchbarClass
   void (*entry_changed) (PhotosSearchbar *self);
   void (*hide) (PhotosSearchbar *self);
   void (*show) (PhotosSearchbar *self);
+
+  /* signals */
+  void (*activate_result) (PhotosSearchbar *self);
 };
 
 GType                photos_searchbar_get_type                      (void) G_GNUC_CONST;


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