[gnome-photos/wip/rishi/collection: 6/9] Simplify Searchbar handling and don't show it on key presses in PREVIEW
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/collection: 6/9] Simplify Searchbar handling and don't show it on key presses in PREVIEW
- Date: Mon, 28 Aug 2017 19:05:56 +0000 (UTC)
commit a58afe4ac3b871ff466e36b9e52027effcb46e59
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 | 33 +++++++--------------------------
src/photos-searchbar.c | 3 ---
3 files changed, 8 insertions(+), 29 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..7475a86 100644
--- a/src/photos-main-toolbar.c
+++ b/src/photos-main-toolbar.c
@@ -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);
}
@@ -675,6 +649,8 @@ 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 ());
+ gtk_container_add (GTK_CONTAINER (self), self->searchbar);
+
photos_main_toolbar_reset_toolbar_mode (self);
}
@@ -841,7 +817,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-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]