[nautilus/wip/gbsneto/search-popover: 2/8] window-slot: fix search state when going back/forward



commit 028d9df7d5163f26a9a5d6638bbb5f0cde82f170
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Mon Oct 5 11:24:27 2015 -0300

    window-slot: fix search state when going back/forward
    
    When a search is performed, Nautilus adds it to the history
    stack, and we can return to it through the back or forward
    buttons.
    
    While we can indeed go back to the search, the UI components
    such as the search bar doesn't update accordingly, leaving us
    with a search directory without a search bar.
    
    Fix that by properly checking the search-visible action state.

 src/nautilus-files-view.c  |   15 +++++++++++++++
 src/nautilus-window-slot.c |   27 +++++++++++++++++++++++----
 2 files changed, 38 insertions(+), 4 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 572c9de..305748e 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -3088,9 +3088,24 @@ nautilus_files_view_set_location (NautilusView *view,
                                   GFile        *location)
 {
         NautilusDirectory *directory;
+        NautilusFilesView *files_view;
 
         nautilus_profile_start (NULL);
+        files_view = NAUTILUS_FILES_VIEW (view);
         directory = nautilus_directory_get (location);
+
+        /* If we're entering a search directory, the search query
+         * must be updated to match the current search.
+         */
+        if (NAUTILUS_IS_SEARCH_DIRECTORY (directory)) {
+                NautilusQuery *query;
+
+                query = nautilus_search_directory_get_query (NAUTILUS_SEARCH_DIRECTORY (directory));
+
+                g_set_object (&files_view->details->search_query, query);
+                g_clear_object (&query);
+        }
+
         load_directory (NAUTILUS_FILES_VIEW (view), directory);
         nautilus_directory_unref (directory);
         nautilus_profile_end (NULL);
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index b10de00..ab6eaf1 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -249,14 +249,13 @@ nautilus_window_slot_content_view_matches (NautilusWindowSlot *slot,
 }
 
 static void
-check_search_visible (NautilusWindowSlot *slot)
+update_search_visible_action (NautilusWindowSlot *slot)
 {
         NautilusQuery *query;
         NautilusView *view;
         gchar *text;
         GAction *action;
 
-        query = nautilus_query_editor_get_query (slot->details->query_editor);
         action =  g_action_map_lookup_action (G_ACTION_MAP (slot->details->slot_action_group),
                                               "search-visible");
         /* Don't allow search on desktop */
@@ -266,8 +265,28 @@ check_search_visible (NautilusWindowSlot *slot)
         view = nautilus_window_slot_get_current_view (slot);
         /* If we changed location just to another search location, for example,
          * when changing the query, just keep the search visible */
-        if (nautilus_view_is_searching (view))
+        if (nautilus_view_is_searching (view)) {
+                GVariant *variant;
+                gboolean search_visible;
+
+                variant = g_action_get_state (action);
+                search_visible = g_variant_get_boolean (variant);
+
+                g_variant_unref (variant);
+
+                /* When we go back or forward to a search location, the search
+                 * state must be restored.
+                 */
+                if (!search_visible) {
+                        nautilus_query_editor_set_query (slot->details->query_editor,
+                                                         nautilus_view_get_search_query (view));
+                        nautilus_window_slot_set_search_visible (slot, TRUE);
+                }
+
                 return;
+        }
+
+        query = nautilus_query_editor_get_query (slot->details->query_editor);
 
         if (query) {
                 text = nautilus_query_get_text (query);
@@ -298,7 +317,7 @@ nautilus_window_slot_sync_actions (NautilusWindowSlot *slot)
         /* Check if we need to close the search or not after changing the location.
          * Needs to be done after the change has been done, if not, a loop happens,
          * because setting the search enabled or not actually opens a location */
-        check_search_visible (slot);
+        update_search_visible_action (slot);
 
         /* Files view mode */
         action =  g_action_map_lookup_action (G_ACTION_MAP (slot->details->slot_action_group), 
"files-view-mode");


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