[gnome-photos/wip/rishi/collection: 1/9] Simplify Searchbar handling and don't show it on key presses in PREVIEW



commit 91b08b6e8c14994dc83be99bf48c1af8cc399c17
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Aug 25 18:30:02 2017 +0200

    Simplify Searchbar handling and don't show it on key presses in PREVIEW
    
    Whenever the selection or window modes changed, if the app.search
    GAction's state was FALSE, the Searchbar used to be removed from the
    MainToolbar. It would be added back if the new mode supported search.
    The photos_searchbar_handle_event method used the presence of a parent
    container to decide whether it's supposed to handle keyboard events
    for a given mode.
    
    This hinges on the app.search GAction having the right state before the
    MainToolbar handles the mode change. However, that's not the case when
    going from SEARCH (without an active collection) to PREVIEW. The
    GAction is toggled in photos_embed_prepare_for_preview when the search
    state is saved. That's after the application has entered PREVIEW.
    Therefore, pressing a key when previewing a search result will show the
    Searchbar, which it is not supposed to.
    
    The second problem arises if the Searchbar is removed and added while
    it was animating away. It shows a grey bar, without any entry, once it
    is added back to the MainToolbar. Supposedly the remove/add cycle in
    the middle of the animation confuses GTK+.
    
    This isn't observed in practice because commit 770366286115c2c8
    prevents the Searchbar from being hidden during mode changes. It's
    only hidden when viewing a collection, which doesn't use the same code
    path as selection or window mode changes. However, that's going to be
    a problem once the faulty behaviour introduced by commit
    770366286115c2c8 is fixed in a subsequent patch.
    
    All that can be addressed, and the code simplified, if the Searchbar is
    never removed from MainToolbar. Instead of relying on the presence of a
    parent, it can use the GAction's enabled property to decide whether to
    handle keyboard events or not.
    
    As a result, this reverts commit fa26cf4885dbbc69 and keeps the code in
    sync with gnome-documents.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=786936

 src/photos-application.c   |    1 +
 src/photos-main-toolbar.c  |   36 +++++++-----------------------------
 src/photos-main-toolbar.ui |    4 ++++
 src/photos-searchbar.c     |    3 ---
 4 files changed, 12 insertions(+), 32 deletions(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index 7670479..7464a66 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -360,6 +360,7 @@ photos_application_actions_update (PhotosApplication *self)
             || mode == PHOTOS_WINDOW_MODE_FAVORITES
             || mode == PHOTOS_WINDOW_MODE_OVERVIEW
             || mode == PHOTOS_WINDOW_MODE_SEARCH);
+  g_simple_action_set_enabled (self->search_action, enable);
   g_simple_action_set_enabled (self->search_match_action, enable);
   g_simple_action_set_enabled (self->search_source_action, enable);
   g_simple_action_set_enabled (self->search_type_action, enable);
diff --git a/src/photos-main-toolbar.c b/src/photos-main-toolbar.c
index b868c97..3d92408 100644
--- a/src/photos-main-toolbar.c
+++ b/src/photos-main-toolbar.c
@@ -36,9 +36,9 @@
 #include "photos-icons.h"
 #include "photos-item-manager.h"
 #include "photos-main-toolbar.h"
-#include "photos-overview-searchbar.h"
 #include "photos-remote-display-manager.h"
 #include "photos-search-context.h"
+#include "photos-searchbar.h"
 #include "photos-selection-controller.h"
 #include "photos-utils.h"
 
@@ -381,17 +381,6 @@ photos_main_toolbar_clear_state_data (PhotosMainToolbar *self)
   g_clear_pointer (&self->remote_display_button, (GDestroyNotify) gtk_widget_destroy);
   g_clear_pointer (&self->selection_button, (GDestroyNotify) gtk_widget_destroy);
 
-  if (self->searchbar != NULL && gtk_widget_get_parent (self->searchbar) == GTK_WIDGET (self))
-    {
-      GVariant *state;
-
-      state = g_action_get_state (self->search);
-      if (!g_variant_get_boolean (state))
-        gtk_container_remove (GTK_CONTAINER (self), self->searchbar);
-
-      g_variant_unref (state);
-    }
-
   if (self->item_mngr != NULL)
     {
       g_signal_handlers_disconnect_by_func (self->item_mngr, photos_main_toolbar_col_active_changed, self);
@@ -495,9 +484,6 @@ photos_main_toolbar_populate_for_collections (PhotosMainToolbar *self)
   self->selection_button = photos_main_toolbar_add_selection_button (self);
   photos_main_toolbar_add_search_button (self);
 
-  if (gtk_widget_get_parent (self->searchbar) == NULL)
-    gtk_container_add (GTK_CONTAINER (self), self->searchbar);
-
   collection = photos_item_manager_get_active_collection (PHOTOS_ITEM_MANAGER (self->item_mngr));
   photos_main_toolbar_col_active_changed (self, collection);
 }
@@ -534,9 +520,6 @@ photos_main_toolbar_populate_for_favorites (PhotosMainToolbar *self)
   self->selection_button = photos_main_toolbar_add_selection_button (self);
   photos_main_toolbar_add_search_button (self);
 
-  if (gtk_widget_get_parent (self->searchbar) == NULL)
-    gtk_container_add (GTK_CONTAINER (self), self->searchbar);
-
   collection = photos_item_manager_get_active_collection (PHOTOS_ITEM_MANAGER (self->item_mngr));
   photos_main_toolbar_col_active_changed (self, collection);
 }
@@ -552,9 +535,6 @@ photos_main_toolbar_populate_for_overview (PhotosMainToolbar *self)
   self->selection_button = photos_main_toolbar_add_selection_button (self);
   photos_main_toolbar_add_search_button (self);
 
-  if (gtk_widget_get_parent (self->searchbar) == NULL)
-    gtk_container_add (GTK_CONTAINER (self), self->searchbar);
-
   collection = photos_item_manager_get_active_collection (PHOTOS_ITEM_MANAGER (self->item_mngr));
   photos_main_toolbar_col_active_changed (self, collection);
 }
@@ -635,9 +615,6 @@ photos_main_toolbar_populate_for_search (PhotosMainToolbar *self)
   self->selection_button = photos_main_toolbar_add_selection_button (self);
   photos_main_toolbar_add_search_button (self);
 
-  if (gtk_widget_get_parent (self->searchbar) == NULL)
-    gtk_container_add (GTK_CONTAINER (self), self->searchbar);
-
   collection = photos_item_manager_get_active_collection (PHOTOS_ITEM_MANAGER (self->item_mngr));
   photos_main_toolbar_col_active_changed (self, collection);
 }
@@ -661,9 +638,6 @@ photos_main_toolbar_populate_for_selection_mode (PhotosMainToolbar *self)
                            G_CONNECT_SWAPPED);
 
   photos_main_toolbar_add_search_button (self);
-
-  if (gtk_widget_get_parent (self->searchbar) == NULL)
-    gtk_container_add (GTK_CONTAINER (self), self->searchbar);
 }
 
 
@@ -674,7 +648,6 @@ photos_main_toolbar_constructed (GObject *object)
 
   G_OBJECT_CLASS (photos_main_toolbar_parent_class)->constructed (object);
 
-  self->searchbar = g_object_ref_sink (photos_overview_searchbar_new ());
   photos_main_toolbar_reset_toolbar_mode (self);
 }
 
@@ -686,7 +659,6 @@ photos_main_toolbar_dispose (GObject *object)
 
   photos_main_toolbar_clear_state_data (self);
 
-  g_clear_object (&self->searchbar);
   g_clear_object (&self->item_mngr);
   g_clear_object (&self->mode_cntrlr);
   g_clear_object (&self->remote_mngr);
@@ -819,6 +791,7 @@ photos_main_toolbar_class_init (PhotosMainToolbarClass *class)
 
   gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Photos/main-toolbar.ui");
   gtk_widget_class_bind_template_child (widget_class, PhotosMainToolbar, header_bar);
+  gtk_widget_class_bind_template_child (widget_class, PhotosMainToolbar, searchbar);
 }
 
 
@@ -841,7 +814,12 @@ photos_main_toolbar_handle_event (PhotosMainToolbar *self, GdkEventKey *event)
 {
   gboolean ret_val = FALSE;
 
+  if (!g_action_get_enabled (self->search))
+      goto out;
+
   ret_val = photos_searchbar_handle_event (PHOTOS_SEARCHBAR (self->searchbar), event);
+
+ out:
   return ret_val;
 }
 
diff --git a/src/photos-main-toolbar.ui b/src/photos-main-toolbar.ui
index 0650159..72c55ef 100644
--- a/src/photos-main-toolbar.ui
+++ b/src/photos-main-toolbar.ui
@@ -2,6 +2,7 @@
 <!--
  Photos - access, organize and share your photos on GNOME
  Copyright © 2017 Alessandro Bono
+ Copyright © 2017 Red Hat, Inc.
 
  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
@@ -27,5 +28,8 @@
         <property name="visible">1</property>
       </object>
     </child>
+    <child>
+      <object class="PhotosOverviewSearchbar" id="searchbar"/>
+    </child>
   </template>
 </interface>
diff --git a/src/photos-searchbar.c b/src/photos-searchbar.c
index 7b9c434..51f0daf 100644
--- a/src/photos-searchbar.c
+++ b/src/photos-searchbar.c
@@ -244,9 +244,6 @@ photos_searchbar_handle_event (PhotosSearchbar *self, GdkEventKey *event)
 
   priv = photos_searchbar_get_instance_private (self);
 
-  if (gtk_widget_get_parent (GTK_WIDGET (self)) == NULL)
-    goto out;
-
   search_mode_enabled = gtk_search_bar_get_search_mode (GTK_SEARCH_BAR (self));
 
   /* Skip if the search bar is shown and the focus is elsewhere */


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