[nautilus/gnome-3-6] slot: rework query editor visible state synchronization



commit bde82c2791a2fa7bac2f2384b033bebb4d9710a9
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Oct 29 14:54:37 2012 -0400

    slot: rework query editor visible state synchronization
    
    Fix a case where entering a directory from the search results would not
    take the query editor down, and refactor some code around the state
    synchronization between the two objects.

 src/nautilus-window-manage-views.c |   17 ++++++++--
 src/nautilus-window-private.h      |    3 --
 src/nautilus-window-slot.c         |   44 ++++++++++++++++++++------
 src/nautilus-window-slot.h         |    5 ++-
 src/nautilus-window.c              |   60 ++++-------------------------------
 5 files changed, 58 insertions(+), 71 deletions(-)
---
diff --git a/src/nautilus-window-manage-views.c b/src/nautilus-window-manage-views.c
index 80d3677..5cc8191 100644
--- a/src/nautilus-window-manage-views.c
+++ b/src/nautilus-window-manage-views.c
@@ -1050,9 +1050,20 @@ create_content_view (NautilusWindowSlot *slot,
 	}
 
 	if (NAUTILUS_IS_SEARCH_DIRECTORY (old_directory) &&
-	    !NAUTILUS_IS_SEARCH_DIRECTORY (new_directory) &&
-	    slot->pending_selection == NULL) {
-		slot->pending_selection = nautilus_view_get_selection (slot->content_view);
+	    !NAUTILUS_IS_SEARCH_DIRECTORY (new_directory)) {
+		/* Reset the search_visible state when going out of a search directory,
+		 * before nautilus_window_slot_sync_search_widgets() is called
+		 * if we're not being loaded with search visible.
+		 */
+		if (!slot->load_with_search) {
+			slot->search_visible = FALSE;
+		}
+
+		slot->load_with_search = FALSE;
+
+		if (slot->pending_selection == NULL) {
+			slot->pending_selection = nautilus_view_get_selection (slot->content_view);
+		}
 	}
 
 	/* Actually load the pending location and selection: */
diff --git a/src/nautilus-window-private.h b/src/nautilus-window-private.h
index 94d6220..b35db8a 100644
--- a/src/nautilus-window-private.h
+++ b/src/nautilus-window-private.h
@@ -116,9 +116,6 @@ void nautilus_window_sync_zoom_widgets     (NautilusWindow *window);
 void nautilus_window_sync_up_button        (NautilusWindow *window);
 void nautilus_window_sync_view_as_menus    (NautilusWindow *window);
 
-void nautilus_window_set_search_action_active (NautilusWindow *window,
-                                               gboolean        active);
-
 void nautilus_window_set_search_visible   (NautilusWindow *window,
                                            gboolean        visible);
 
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index 44c758d..ec8a4c4 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -97,8 +97,9 @@ sync_search_directory (NautilusWindowSlot *slot)
 	text = nautilus_query_get_text (query);
 
 	if (!strlen (text)) {
-		location = nautilus_query_editor_get_location (slot->query_editor);
+		/* Prevent the location change from hiding the query editor in this case */
 		slot->load_with_search = TRUE;
+		location = nautilus_query_editor_get_location (slot->query_editor);
 		nautilus_window_slot_open_location (slot, location, 0);
 		g_object_unref (location);
 	} else {
@@ -141,7 +142,7 @@ static void
 query_editor_cancel_callback (NautilusQueryEditor *editor,
 			      NautilusWindowSlot *slot)
 {
-	nautilus_window_set_search_action_active (slot->details->window, FALSE);
+	nautilus_window_slot_set_search_visible (slot, FALSE);
 }
 
 static void
@@ -205,16 +206,10 @@ show_query_editor (NautilusWindowSlot *slot)
 	NautilusSearchDirectory *search_directory;
 	GFile *location;
 
-	/* This might be called while we're still loading the location.
-	 * In such a case, just set slot->load_with_search to TRUE, to stop
-	 * nautilus_window_sync_search_widgets() from hiding it again when
-	 * loading has completed.
-	 */
 	if (slot->location) {
 		location = slot->location;
 	} else {
 		location = slot->pending_location;
-		slot->load_with_search = TRUE;
 	}
 
 	directory = nautilus_directory_get (location);
@@ -252,14 +247,43 @@ show_query_editor (NautilusWindowSlot *slot)
 }
 
 void
-nautilus_window_slot_set_query_editor_visible (NautilusWindowSlot *slot,
-					       gboolean            visible)
+nautilus_window_slot_set_search_visible (NautilusWindowSlot *slot,
+					 gboolean            visible)
 {
+	gboolean old_visible;
+	GFile *location;
+	GtkAction *action;
+
+	old_visible = slot->search_visible;
+	slot->search_visible = visible;
+
 	if (visible) {
 		show_query_editor (slot);
 	} else {
 		hide_query_editor (slot);
 	}
+
+	if (slot != nautilus_window_get_active_slot (slot->details->window)) {
+		return;
+	}
+
+	action = gtk_action_group_get_action (nautilus_window_get_main_action_group (slot->details->window),
+					      NAUTILUS_ACTION_SEARCH);
+	gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
+
+	if (!visible && old_visible) {
+		/* Use the location bar as the return location */
+		if (slot->query_editor != NULL) {
+			location = nautilus_query_editor_get_location (slot->query_editor);
+			/* Last try: use the home directory as the return location */
+			if (location == NULL) {
+				location = g_file_new_for_path (g_get_home_dir ());
+			}
+
+			nautilus_window_go_to (slot->details->window, location);
+			g_object_unref (location);
+		}
+	}
 }
 
 static void
diff --git a/src/nautilus-window-slot.h b/src/nautilus-window-slot.h
index e0f7872..9d96437 100644
--- a/src/nautilus-window-slot.h
+++ b/src/nautilus-window-slot.h
@@ -91,7 +91,7 @@ struct NautilusWindowSlot {
 	gulong qe_changed_id;
 	gulong qe_cancel_id;
 	gulong qe_activated_id;
-	gboolean search_active;
+	gboolean search_visible;
 
 	/* New location. */
 	NautilusLocationChangeType location_change_type;
@@ -129,8 +129,9 @@ void             nautilus_window_slot_set_window           (NautilusWindowSlot *
 							    NautilusWindow     *window);
 
 void    nautilus_window_slot_update_title		   (NautilusWindowSlot *slot);
-void    nautilus_window_slot_set_query_editor_visible	   (NautilusWindowSlot *slot,
+void    nautilus_window_slot_set_search_visible            (NautilusWindowSlot *slot,
 							    gboolean            visible);
+
 gboolean nautilus_window_slot_handle_event       	   (NautilusWindowSlot *slot,
 							    GdkEventKey        *event);
 
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 66145c6..7459342 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -278,11 +278,11 @@ nautilus_window_set_search_visible (NautilusWindow *window,
 
 	if (visible) {
 		remember_focus_widget (window);
-		nautilus_window_slot_set_query_editor_visible (slot, TRUE);
 	} else {
 		restore_focus_widget (window);
-		nautilus_window_slot_set_query_editor_visible (slot, FALSE);
 	}
+
+	nautilus_window_slot_set_search_visible (slot, visible);
 }
 
 static void
@@ -656,68 +656,22 @@ nautilus_window_slot_close (NautilusWindow     *window,
 	}
 }
 
-static void
-toggle_toolbar_search_button (NautilusWindow *window,
-			      gboolean        active)
-{
-	GtkAction *action;
-	NautilusWindowSlot *slot;
-	gboolean old_active;
-	GFile *location;
-
-	slot = nautilus_window_get_active_slot (window);
-	action = gtk_action_group_get_action (nautilus_window_get_main_action_group (window),
-					      NAUTILUS_ACTION_SEARCH);
-
-	old_active = slot->search_active;
-	gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), active);
-	slot->search_active = active;
-
-	if (!active && old_active) {
-		/* Use the location bar as the return location */
-		if (slot->query_editor != NULL) {
-			location = nautilus_query_editor_get_location (slot->query_editor);
-			/* Last try: use the home directory as the return location */
-			if (location == NULL) {
-				location = g_file_new_for_path (g_get_home_dir ());
-			}
-
-			nautilus_window_go_to (window, location);
-			g_object_unref (location);
-		}
-	}
-}
-
-void
-nautilus_window_set_search_action_active (NautilusWindow *window,
-					  gboolean        active)
-{
-	toggle_toolbar_search_button (window, active);
-}
-
 void
 nautilus_window_sync_search_widgets (NautilusWindow *window)
 {
 	NautilusDirectory *directory;
-	NautilusSearchDirectory *search_directory;
 	NautilusWindowSlot *slot;
+	gboolean visible;
 
-	search_directory = NULL;
 	slot = window->details->active_slot;
+	visible = slot->search_visible;
 
 	directory = nautilus_directory_get (slot->location);
 	if (NAUTILUS_IS_SEARCH_DIRECTORY (directory)) {
-		search_directory = NAUTILUS_SEARCH_DIRECTORY (directory);
-	}
-
-	if (search_directory != NULL || slot->load_with_search ||
-	    gtk_widget_get_visible (GTK_WIDGET (slot->query_editor))) {
-		slot->load_with_search = FALSE;
-		toggle_toolbar_search_button (window, TRUE);
-	} else {
-		toggle_toolbar_search_button (window, FALSE);
+		visible = TRUE;
 	}
 
+	nautilus_window_slot_set_search_visible (slot, visible);
 	nautilus_directory_unref (directory);
 }
 
@@ -1564,7 +1518,7 @@ nautilus_window_key_press_event (GtkWidget *widget,
 	}
 
 	if (nautilus_window_slot_handle_event (window->details->active_slot, event)) {
-		toggle_toolbar_search_button (window, TRUE);
+		nautilus_window_slot_set_search_visible (window->details->active_slot, TRUE);
 		return TRUE;
 	}
 



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