[gnome-builder] search: search focus improvements



commit 66119a3a452aa24647dedd8b12e9681ed87a88ac
Author: Christian Hergert <christian hergert me>
Date:   Sat Jun 13 00:20:01 2015 -0700

    search: search focus improvements

 plugins/devhelp/gb-devhelp-view.c    |   10 ++++++++++
 src/search/gb-search-box.c           |    3 +++
 src/search/gb-search-display-group.c |   31 +++++++++++++++++++++++++++++--
 src/search/gb-search-display-group.h |    1 +
 src/search/gb-search-display.c       |   14 +++++++-------
 5 files changed, 50 insertions(+), 9 deletions(-)
---
diff --git a/plugins/devhelp/gb-devhelp-view.c b/plugins/devhelp/gb-devhelp-view.c
index e936f8a..e9d433b 100644
--- a/plugins/devhelp/gb-devhelp-view.c
+++ b/plugins/devhelp/gb-devhelp-view.c
@@ -174,6 +174,14 @@ gb_devhelp_view_set_split_view (GbView   *view,
 }
 
 static void
+gb_devhelp_view_grab_focus (GtkWidget *widget)
+{
+  GbDevhelpView *self = (GbDevhelpView *)widget;
+
+  gtk_widget_grab_focus (GTK_WIDGET (self->web_view1));
+}
+
+static void
 gb_devhelp_view_finalize (GObject *object)
 {
   GbDevhelpView *self = GB_DEVHELP_VIEW (object);
@@ -232,6 +240,8 @@ gb_devhelp_view_class_init (GbDevhelpViewClass *klass)
   object_class->get_property = gb_devhelp_view_get_property;
   object_class->set_property = gb_devhelp_view_set_property;
 
+  widget_class->grab_focus = gb_devhelp_view_grab_focus;
+
   view_class->get_document = gb_devhelp_view_get_document;
   view_class->create_split = gb_devhelp_view_create_split;
   view_class->set_split_view =  gb_devhelp_view_set_split_view;
diff --git a/src/search/gb-search-box.c b/src/search/gb-search-box.c
index 45a3423..0f61bc2 100644
--- a/src/search/gb-search-box.c
+++ b/src/search/gb-search-box.c
@@ -145,6 +145,9 @@ gb_search_box_entry_activate (GbSearchBox    *self,
   g_return_if_fail (GTK_IS_SEARCH_ENTRY (entry));
 
   gb_search_display_activate (self->display);
+
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->button), FALSE);
+  gtk_entry_set_text (GTK_ENTRY (self->entry), "");
 }
 
 static void
diff --git a/src/search/gb-search-display-group.c b/src/search/gb-search-display-group.c
index 974445f..ae5c2e8 100644
--- a/src/search/gb-search-display-group.c
+++ b/src/search/gb-search-display-group.c
@@ -71,6 +71,7 @@ IdeSearchResult *
 gb_search_display_group_get_first (GbSearchDisplayGroup *self)
 {
   GtkListBoxRow *row = NULL;
+  IdeSearchResult *ret = NULL;
 
   g_return_val_if_fail (GB_IS_SEARCH_DISPLAY_GROUP (self), NULL);
 
@@ -79,9 +80,9 @@ gb_search_display_group_get_first (GbSearchDisplayGroup *self)
                          &row);
 
   if (GB_IS_SEARCH_DISPLAY_ROW (row))
-    return gb_search_display_row_get_result (GB_SEARCH_DISPLAY_ROW (row));
+    ret = gb_search_display_row_get_result (GB_SEARCH_DISPLAY_ROW (row));
 
-  return NULL;
+  return ret;
 }
 
 IdeSearchProvider *
@@ -486,3 +487,29 @@ gb_search_display_group_init (GbSearchDisplayGroup *self)
   gtk_list_box_set_sort_func (self->rows, compare_cb, self->more_row, NULL);
   gtk_list_box_set_header_func (self->rows, gb_search_display_group_header_cb, NULL, NULL);
 }
+
+gboolean
+gb_search_display_group_activate (GbSearchDisplayGroup *group)
+{
+  GtkListBoxRow *row = NULL;
+
+  g_return_if_fail (GB_IS_SEARCH_DISPLAY_GROUP (group));
+
+  gtk_container_foreach (GTK_CONTAINER (group->rows),
+                         gb_search_display_group_foreach_cb,
+                         &row);
+
+  if (GB_IS_SEARCH_DISPLAY_ROW (row))
+    {
+      IdeSearchResult *result;
+      IdeSearchProvider *provider;
+
+      result = gb_search_display_row_get_result (GB_SEARCH_DISPLAY_ROW (row));
+      provider = ide_search_result_get_provider (result);
+      ide_search_provider_activate (provider, GTK_WIDGET (row), result);
+
+      return TRUE;
+    }
+
+  return FALSE;
+}
diff --git a/src/search/gb-search-display-group.h b/src/search/gb-search-display-group.h
index a6e4b86..51fa942 100644
--- a/src/search/gb-search-display-group.h
+++ b/src/search/gb-search-display-group.h
@@ -40,6 +40,7 @@ void               gb_search_display_group_unselect      (GbSearchDisplayGroup *
 void               gb_search_display_group_focus_first   (GbSearchDisplayGroup *group);
 void               gb_search_display_group_focus_last    (GbSearchDisplayGroup *group);
 IdeSearchResult   *gb_search_display_group_get_first     (GbSearchDisplayGroup *group);
+gboolean           gb_search_display_group_activate      (GbSearchDisplayGroup *group);
 
 G_END_DECLS
 
diff --git a/src/search/gb-search-display.c b/src/search/gb-search-display.c
index 1b59b36..4304977 100644
--- a/src/search/gb-search-display.c
+++ b/src/search/gb-search-display.c
@@ -191,22 +191,22 @@ gb_search_display_keynav_failed (GbSearchDisplay      *self,
 void
 gb_search_display_activate (GbSearchDisplay *self)
 {
-  IdeSearchResult *result = NULL;
-  guint i;
+  gsize i;
 
   g_return_if_fail (GB_IS_SEARCH_DISPLAY (self));
 
-  for (i = 0; !result && i < self->providers->len; i++)
+  for (i = 0; i < self->providers->len; i++)
     {
       ProviderEntry *ptr;
 
       ptr = g_ptr_array_index (self->providers, i);
+
       if (ptr->group != NULL)
-        result = gb_search_display_group_get_first (ptr->group);
+        {
+          if (gb_search_display_group_activate (ptr->group))
+            break;
+        }
     }
-
-  if (result)
-    g_signal_emit (self, gSignals [RESULT_ACTIVATED], 0, result);
 }
 
 static void


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