[nautilus/wip/gbsneto/files-view: 2/4] view: add interface



commit 19a89fee27d3f493e51249540f0cce373a874e9b
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Mon Aug 17 08:33:42 2015 -0300

    view: add interface
    
    Nautilus is in the proccess of receiving a places view,
    based on GtkFileChooser's one.
    
    To be able to handle that, an abstraction layer is needed
    between NautilusFilesView and NautilusWindowSlot, so we factor
    out the common data between views.
    
    Add the NautilusView interface, and make NautilusFilesView a
    NautilusView implementation. Because of the new way we handle
    search on the view side, the search logic is rewritten to match
    the new expected behavior.

 src/Makefile.am                    |    2 +
 src/nautilus-desktop-canvas-view.c |    7 +-
 src/nautilus-files-view.c          |  273 +++++++++++++++++++++++++-------
 src/nautilus-files-view.h          |   10 --
 src/nautilus-trash-bar.c           |    6 +-
 src/nautilus-view.c                |  231 ++++++++++++++++++++++++++
 src/nautilus-view.h                |   84 ++++++++++
 src/nautilus-window-slot.c         |  313 +++++++++++-------------------------
 src/nautilus-window-slot.h         |    7 +-
 9 files changed, 641 insertions(+), 292 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index fddb767..2b01996 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -209,6 +209,8 @@ nautilus_SOURCES = \
        nautilus-toolbar.h                      \
        nautilus-trash-bar.c                    \
        nautilus-trash-bar.h                    \
+       nautilus-view.c                         \
+       nautilus-view.h                         \
        nautilus-window-slot.c                  \
        nautilus-window-slot.h                  \
        nautilus-window-slot-dnd.c              \
diff --git a/src/nautilus-desktop-canvas-view.c b/src/nautilus-desktop-canvas-view.c
index 49910b0..a1d67d2 100644
--- a/src/nautilus-desktop-canvas-view.c
+++ b/src/nautilus-desktop-canvas-view.c
@@ -642,6 +642,7 @@ real_update_context_menus (NautilusFilesView *view)
        NautilusDesktopCanvasView *desktop_view;
        GAction *action;
        GActionGroup *view_action_group;
+        GList *selection;
        int selection_count;
 
        g_assert (NAUTILUS_IS_DESKTOP_CANVAS_VIEW (view));
@@ -664,13 +665,17 @@ real_update_context_menus (NautilusFilesView *view)
        g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
 
        /* Stretch */
-       selection_count = nautilus_files_view_get_selection_count (view);
+        selection = nautilus_files_view_get_selection (view);
+       selection_count = g_list_length (selection);
        canvas_container = get_canvas_container (desktop_view);
 
        action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group), "stretch");
        g_simple_action_set_enabled (G_SIMPLE_ACTION (action), selection_count == 1 &&
                                                               canvas_container != NULL &&
                                                               !nautilus_canvas_container_has_stretch_handles 
(canvas_container));
+
+        nautilus_file_list_free (selection);
+
        /* Unstretch */
        action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group), "unstretch");
        g_simple_action_set_enabled (G_SIMPLE_ACTION (action), canvas_container != NULL &&
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index a6c5c75..910a080 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -39,6 +39,7 @@
 #include "nautilus-properties-window.h"
 #include "nautilus-window.h"
 #include "nautilus-toolbar.h"
+#include "nautilus-view.h"
 
 #if ENABLE_EMPTY_VIEW
 #include "nautilus-empty-view.h"
@@ -147,11 +148,14 @@ enum {
         PROP_SUPPORTS_ZOOMING,
         PROP_ICON,
         PROP_VIEW_WIDGET,
+        PROP_IS_SEARCH,
+        PROP_IS_LOADING,
+        PROP_LOCATION,
+        PROP_SEARCH_QUERY,
         NUM_PROPERTIES
 };
 
 static guint signals[LAST_SIGNAL];
-static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
 
 static GdkAtom copied_files_atom;
 
@@ -163,8 +167,11 @@ struct NautilusFilesViewDetails
         NautilusWindowSlot *slot;
         NautilusDirectory *model;
         NautilusFile *directory_as_file;
+        GFile *location;
         guint dir_merge_id;
 
+        NautilusQuery *search_query;
+
         gint duplicated_label_timeout_id;
         GtkWidget *rename_file_popover;
 
@@ -302,7 +309,14 @@ static void     update_templates_directory                     (NautilusFilesVie
 
 static void     check_empty_states                             (NautilusFilesView *view);
 
-G_DEFINE_TYPE (NautilusFilesView, nautilus_files_view, GTK_TYPE_OVERLAY);
+static gboolean nautilus_files_view_is_searching               (NautilusView      *view);
+
+static void     nautilus_files_view_iface_init                 (NautilusViewInterface *view);
+
+G_DEFINE_TYPE_WITH_CODE (NautilusFilesView,
+                         nautilus_files_view,
+                         GTK_TYPE_OVERLAY,
+                         G_IMPLEMENT_INTERFACE (NAUTILUS_TYPE_VIEW, nautilus_files_view_iface_init));
 
 static const struct {
         unsigned int keyval;
@@ -331,7 +345,7 @@ check_empty_states (NautilusFilesView *view)
                                                             NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES);
                 filtered = nautilus_file_list_filter_hidden (files, show_hidden_files);
                 if (g_list_length (filtered) == 0) {
-                        if (nautilus_files_view_is_search (view)) {
+                        if (nautilus_view_is_searching (NAUTILUS_VIEW (view))) {
                                 gtk_widget_show (view->details->no_search_results_widget);
                         } else {
                                 gtk_widget_show (view->details->folder_is_empty_widget);
@@ -373,7 +387,7 @@ real_setup_loading_floating_bar (NautilusFilesView *view)
 
         nautilus_floating_bar_cleanup_actions (NAUTILUS_FLOATING_BAR (view->details->floating_bar));
         nautilus_floating_bar_set_primary_label (NAUTILUS_FLOATING_BAR (view->details->floating_bar),
-                                                 nautilus_files_view_is_search (view) ? _("Searching…") : 
_("Loading…"));
+                                                 nautilus_view_is_searching (NAUTILUS_VIEW (view)) ? 
_("Searching…") : _("Loading…"));
         nautilus_floating_bar_set_details_label (NAUTILUS_FLOATING_BAR (view->details->floating_bar), NULL);
         nautilus_floating_bar_set_show_spinner (NAUTILUS_FLOATING_BAR (view->details->floating_bar), 
view->details->loading);
         nautilus_floating_bar_add_action (NAUTILUS_FLOATING_BAR (view->details->floating_bar),
@@ -628,18 +642,18 @@ nautilus_files_view_using_manual_layout (NautilusFilesView  *view)
 
 /**
  * nautilus_files_view_get_icon:
- * @view: a #NautilusFilesView
+ * @view: a #NautilusView
  *
  * Retrieves the #GIcon that represents @view.
  *
  * Returns: (transfer none): the #Gicon that represents @view
  */
-GIcon*
-nautilus_files_view_get_icon (NautilusFilesView *view)
+static GIcon*
+nautilus_files_view_get_icon (NautilusView *view)
 {
         g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
 
-        return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->get_icon (view);
+        return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->get_icon (NAUTILUS_FILES_VIEW (view));
 }
 
 /**
@@ -651,12 +665,12 @@ nautilus_files_view_get_icon (NautilusFilesView *view)
  *
  * Returns: (transfer none): a #GtkWidget for the view menu
  */
-GtkWidget*
-nautilus_files_view_get_view_widget (NautilusFilesView *view)
+static GtkWidget*
+nautilus_files_view_get_view_widget (NautilusView *view)
 {
         g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
 
-        return view->details->view_menu_widget;
+        return NAUTILUS_FILES_VIEW (view)->details->view_menu_widget;
 }
 
 /**
@@ -825,12 +839,16 @@ nautilus_files_view_restore_default_zoom_level (NautilusFilesView *view)
 }
 
 gboolean
-nautilus_files_view_is_search (NautilusFilesView *view)
+nautilus_files_view_is_searching (NautilusView *view)
 {
-  if (!view->details->model)
+  NautilusFilesView *files_view;
+
+  files_view = NAUTILUS_FILES_VIEW (view);
+
+  if (!files_view->details->model)
     return FALSE;
 
-  return NAUTILUS_IS_SEARCH_DIRECTORY (view->details->model);
+  return NAUTILUS_IS_SEARCH_DIRECTORY (files_view->details->model);
 }
 
 const char *
@@ -864,7 +882,7 @@ nautilus_files_view_scroll_to_file (NautilusFilesView *view,
  * Return value: GList of NautilusFile pointers representing the selection.
  *
  **/
-GList *
+GList*
 nautilus_files_view_get_selection (NautilusFilesView *view)
 {
         g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
@@ -2718,20 +2736,6 @@ nautilus_files_view_grab_focus (GtkWidget *widget)
         }
 }
 
-int
-nautilus_files_view_get_selection_count (NautilusFilesView *view)
-{
-        /* FIXME: This could be faster if we special cased it in subclasses */
-        GList *files;
-        int len;
-
-        files = nautilus_files_view_get_selection (NAUTILUS_FILES_VIEW (view));
-        len = g_list_length (files);
-        nautilus_file_list_free (files);
-
-        return len;
-}
-
 void
 nautilus_files_view_set_selection (NautilusFilesView *nautilus_files_view,
                                    GList             *selection)
@@ -2830,6 +2834,9 @@ nautilus_files_view_destroy (GtkWidget *object)
                 view->details->directory_as_file = NULL;
         }
 
+        g_clear_object (&view->details->search_query);
+        g_clear_object (&view->details->location);
+
         /* We don't own the slot, so no unref */
         view->details->slot = NULL;
 
@@ -3048,15 +3055,15 @@ nautilus_files_view_send_selection_change (NautilusFilesView *view)
         g_signal_emit (view, signals[SELECTION_CHANGED], 0);
 }
 
-void
-nautilus_files_view_load_location (NautilusFilesView *nautilus_files_view,
-                                   GFile             *location)
+static void
+nautilus_files_view_set_location (NautilusView *view,
+                                  GFile        *location)
 {
         NautilusDirectory *directory;
 
         nautilus_profile_start (NULL);
         directory = nautilus_directory_get (location);
-        load_directory (nautilus_files_view, directory);
+        load_directory (NAUTILUS_FILES_VIEW (view), directory);
         nautilus_directory_unref (directory);
         nautilus_profile_end (NULL);
 }
@@ -3098,7 +3105,7 @@ done_loading (NautilusFilesView *view,
 
                 selection = view->details->pending_selection;
 
-                if (nautilus_files_view_is_search (view) && all_files_seen) {
+                if (nautilus_view_is_searching (NAUTILUS_VIEW (view)) && all_files_seen) {
                         nautilus_files_view_select_first (view);
                         do_reveal = TRUE;
                 } else if (selection != NULL && all_files_seen) {
@@ -3132,6 +3139,7 @@ done_loading (NautilusFilesView *view,
 
         view->details->loading = FALSE;
         g_signal_emit (view, signals[END_LOADING], 0, all_files_seen);
+        g_object_notify (G_OBJECT (view), "is-loading");
 
         check_empty_states (view);
 
@@ -6300,7 +6308,7 @@ real_update_actions_state (NautilusFilesView *view)
         selection_contains_special_link = special_link_in_selection (selection);
         selection_contains_desktop_or_home_dir = desktop_or_home_dir_in_selection (selection);
         selection_contains_recent = showing_recent_directory (view);
-        selection_contains_search = nautilus_files_view_is_search (view);
+        selection_contains_search = nautilus_view_is_searching (NAUTILUS_VIEW (view));
         selection_is_read_only = selection_count == 1 &&
                 (!nautilus_file_can_write (NAUTILUS_FILE (selection->data)) &&
                  !nautilus_file_has_activation_uri (NAUTILUS_FILE (selection->data)));
@@ -7072,6 +7080,7 @@ load_directory (NautilusFilesView *view,
         NautilusDirectory *old_directory;
         NautilusFile *old_file;
         NautilusFileAttributes attributes;
+        GFile *old_location;
 
         g_assert (NAUTILUS_IS_FILES_VIEW (view));
         g_assert (NAUTILUS_IS_DIRECTORY (directory));
@@ -7082,6 +7091,7 @@ load_directory (NautilusFilesView *view,
         g_signal_emit (view, signals[CLEAR], 0);
 
         view->details->loading = TRUE;
+        g_object_notify (G_OBJECT (view), "is-loading");
 
         setup_loading_floating_bar (view);
 
@@ -7107,6 +7117,13 @@ load_directory (NautilusFilesView *view,
                 nautilus_directory_get_corresponding_file (directory);
         nautilus_file_unref (old_file);
 
+        old_location = view->details->location;
+        view->details->location = nautilus_directory_get_location (directory);
+        g_clear_object (&old_location);
+
+        g_object_notify (G_OBJECT (view), "location");
+        g_object_notify (G_OBJECT (view), "is-searching");
+
         /* FIXME bugzilla.gnome.org 45062: In theory, we also need to monitor metadata here (as
          * well as doing a call when ready), in case external forces
          * change the directory's file metadata.
@@ -7572,11 +7589,27 @@ nautilus_files_view_get_property (GObject    *object,
 
         switch (prop_id) {
         case PROP_ICON:
-                g_value_set_object (value, nautilus_files_view_get_icon (view));
+                g_value_set_object (value, nautilus_view_get_icon (NAUTILUS_VIEW (view)));
                 break;
 
         case PROP_VIEW_WIDGET:
-                g_value_set_object (value, nautilus_files_view_get_view_widget (view));
+                g_value_set_object (value, nautilus_view_get_view_widget (NAUTILUS_VIEW (view)));
+                break;
+
+        case PROP_IS_LOADING:
+                g_value_set_boolean (value, nautilus_view_is_loading (NAUTILUS_VIEW (view)));
+                break;
+
+        case PROP_IS_SEARCH:
+                g_value_set_boolean (value, nautilus_view_is_searching (NAUTILUS_VIEW (view)));
+                break;
+
+        case PROP_LOCATION:
+                g_value_set_object (value, nautilus_view_get_location (NAUTILUS_VIEW (view)));
+                break;
+
+        case PROP_SEARCH_QUERY:
+                g_value_set_object (value, view->details->search_query);
                 break;
 
         default:
@@ -7613,6 +7646,15 @@ nautilus_files_view_set_property (GObject      *object,
         case PROP_SUPPORTS_ZOOMING:
                 directory_view->details->supports_zooming = g_value_get_boolean (value);
                 break;
+
+        case PROP_LOCATION:
+                nautilus_view_set_location (NAUTILUS_VIEW (directory_view), g_value_get_object (value));
+                break;
+
+        case PROP_SEARCH_QUERY:
+                nautilus_view_set_search_query (NAUTILUS_VIEW (directory_view), g_value_get_object (value));
+                break;
+
         default:
                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                 break;
@@ -7791,6 +7833,129 @@ nautilus_files_view_key_press_event (GtkWidget   *widget,
         return GDK_EVENT_PROPAGATE;
 }
 
+static NautilusQuery*
+nautilus_files_view_get_search_query (NautilusView *view)
+{
+        return NAUTILUS_FILES_VIEW (view)->details->search_query;
+}
+
+static void
+nautilus_files_view_set_search_query (NautilusView  *view,
+                                      NautilusQuery *query)
+{
+        NautilusFilesView *files_view;
+        GFile *location;
+
+        files_view = NAUTILUS_FILES_VIEW (view);
+        location = NULL;
+
+        g_set_object (&files_view->details->search_query, query);
+        g_object_notify (G_OBJECT (view), "search-query");
+
+        if (query) {
+                if (nautilus_view_is_searching (view)) {
+                        location = nautilus_directory_get_location (files_view->details->model);
+
+                        /*
+                         * Reuse the search directory if we are already searching, and
+                         * only update the current location.
+                         */
+                        nautilus_search_directory_set_query (NAUTILUS_SEARCH_DIRECTORY 
(files_view->details->model), query);
+                        nautilus_view_set_location (view, location);
+                } else {
+                        NautilusDirectory *directory;
+                        GList *selection;
+                        gchar *uri;
+
+                        uri = nautilus_search_directory_generate_new_uri ();
+                        location = g_file_new_for_uri (uri);
+                        selection = nautilus_files_view_get_selection (files_view);
+
+                        directory = nautilus_directory_get (location);
+                        g_assert (NAUTILUS_IS_SEARCH_DIRECTORY (directory));
+
+                        nautilus_search_directory_set_base_model (NAUTILUS_SEARCH_DIRECTORY (directory), 
files_view->details->model);
+                        nautilus_search_directory_set_query (NAUTILUS_SEARCH_DIRECTORY (directory), query);
+
+                        /*
+                         * Delegate the opening of the search directory to window-slot so
+                         * it can check whether it should use list-view or grid-view.
+                         */
+                        nautilus_window_slot_open_location_full (files_view->details->slot,
+                                                                 location,
+                                                                 0,
+                                                                 selection,
+                                                                 NULL,
+                                                                 NULL);
+
+                        g_object_notify (G_OBJECT (view), "is-searching");
+
+                        nautilus_directory_unref (directory);
+                        nautilus_file_list_free (selection);
+                        g_free (uri);
+                }
+        } else if (nautilus_view_is_searching (view)) {
+                NautilusDirectory *base_model;
+                GList *selection;
+
+                base_model = nautilus_search_directory_get_base_model (NAUTILUS_SEARCH_DIRECTORY 
(files_view->details->model));
+                location = nautilus_directory_get_location (base_model);
+                selection = nautilus_files_view_get_selection (files_view);
+
+                /*
+                 * Delegate the opening of the base directory to window-slot when leaving
+                 * search mode too, so it can check the previous view to switch back to.
+                 */
+                nautilus_window_slot_open_location_full (files_view->details->slot,
+                                                         location,
+                                                         0,
+                                                         selection,
+                                                         NULL,
+                                                         NULL);
+
+                g_object_notify (G_OBJECT (view), "is-searching");
+
+                nautilus_directory_unref (base_model);
+                nautilus_file_list_free (selection);
+        }
+
+        g_clear_object (&location);
+}
+
+static GFile*
+nautilus_files_view_get_location (NautilusView *view)
+{
+        NautilusFilesView *files_view;
+
+        files_view = NAUTILUS_FILES_VIEW (view);
+
+        return files_view->details->location;
+}
+
+static gboolean
+nautilus_files_view_is_loading (NautilusView *view)
+{
+        NautilusFilesView *files_view;
+
+        files_view = NAUTILUS_FILES_VIEW (view);
+
+        return files_view->details->loading;
+}
+
+static void
+nautilus_files_view_iface_init (NautilusViewInterface *iface)
+{
+        iface->get_icon = nautilus_files_view_get_icon;
+        iface->get_location = nautilus_files_view_get_location;
+        iface->set_location = nautilus_files_view_set_location;
+        iface->get_search_query = nautilus_files_view_get_search_query;
+        iface->set_search_query = nautilus_files_view_set_search_query;
+        iface->get_view_widget = nautilus_files_view_get_view_widget;
+        iface->is_searching = nautilus_files_view_is_searching;
+        iface->is_loading = nautilus_files_view_is_loading;
+}
+
+
 static void
 nautilus_files_view_class_init (NautilusFilesViewClass *klass)
 {
@@ -7896,35 +8061,31 @@ nautilus_files_view_class_init (NautilusFilesViewClass *klass)
 
         copied_files_atom = gdk_atom_intern ("x-special/gnome-copied-files", FALSE);
 
-        properties[PROP_WINDOW_SLOT] =
+        g_object_class_install_property (
+                oclass,
+                PROP_WINDOW_SLOT,
                 g_param_spec_object ("window-slot",
                                      "Window Slot",
                                      "The parent window slot reference",
                                      NAUTILUS_TYPE_WINDOW_SLOT,
                                      G_PARAM_WRITABLE |
-                                     G_PARAM_CONSTRUCT_ONLY);
-        properties[PROP_SUPPORTS_ZOOMING] =
+                                     G_PARAM_CONSTRUCT_ONLY));
+        g_object_class_install_property (
+                oclass,
+                PROP_SUPPORTS_ZOOMING,
                 g_param_spec_boolean ("supports-zooming",
                                       "Supports zooming",
                                       "Whether the view supports zooming",
                                       TRUE,
                                       G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
-                                      G_PARAM_STATIC_STRINGS);
-        properties[PROP_ICON] =
-                g_param_spec_object ("icon",
-                                     "Icon",
-                                     "The icon that represents the view",
-                                     G_TYPE_ICON,
-                                     G_PARAM_READABLE);
-
-        properties[PROP_VIEW_WIDGET] =
-                g_param_spec_object ("view-widget",
-                                     "View widget",
-                                     "The view's widget that will appear under the view menu button",
-                                     GTK_TYPE_WIDGET,
-                                     G_PARAM_READABLE);
-
-        g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
+                                      G_PARAM_STATIC_STRINGS));
+
+        g_object_class_override_property (oclass, PROP_ICON, "icon");
+        g_object_class_override_property (oclass, PROP_VIEW_WIDGET, "view-widget");
+        g_object_class_override_property (oclass, PROP_IS_LOADING, "is-loading");
+        g_object_class_override_property (oclass, PROP_IS_SEARCH, "is-searching");
+        g_object_class_override_property (oclass, PROP_LOCATION, "location");
+        g_object_class_override_property (oclass, PROP_SEARCH_QUERY, "search-query");
 }
 
 static void
diff --git a/src/nautilus-files-view.h b/src/nautilus-files-view.h
index 606a054..4fdd350 100644
--- a/src/nautilus-files-view.h
+++ b/src/nautilus-files-view.h
@@ -359,14 +359,9 @@ void              nautilus_files_view_new_file_with_initial_contents (NautilusFi
 
 /* selection handling */
 void              nautilus_files_view_activate_selection         (NautilusFilesView      *view);
-int               nautilus_files_view_get_selection_count        (NautilusFilesView      *view);
 GList *           nautilus_files_view_get_selection              (NautilusFilesView      *view);
 void              nautilus_files_view_set_selection              (NautilusFilesView      *view,
                                                                   GList                  *selection);
-
-
-void              nautilus_files_view_load_location              (NautilusFilesView      *view,
-                                                                  GFile                  *location);
 void              nautilus_files_view_stop_loading               (NautilusFilesView      *view);
 
 char *            nautilus_files_view_get_first_visible_file     (NautilusFilesView      *view);
@@ -392,10 +387,5 @@ void              nautilus_files_view_action_show_hidden_files   (NautilusFilesV
 
 GActionGroup *    nautilus_files_view_get_action_group           (NautilusFilesView      *view);
 GtkWidget*        nautilus_files_view_get_content_widget         (NautilusFilesView      *view);
-gboolean          nautilus_files_view_is_search                  (NautilusFilesView      *view);
-
-GIcon*            nautilus_files_view_get_icon                   (NautilusFilesView      *view);
-
-GtkWidget*        nautilus_files_view_get_view_widget            (NautilusFilesView      *view);
 
 #endif /* NAUTILUS_FILES_VIEW_H */
diff --git a/src/nautilus-trash-bar.c b/src/nautilus-trash-bar.c
index 0508198..d0e28f4 100644
--- a/src/nautilus-trash-bar.c
+++ b/src/nautilus-trash-bar.c
@@ -57,13 +57,17 @@ static void
 selection_changed_cb (NautilusFilesView *view,
                      NautilusTrashBar *bar)
 {
+        GList *selection;
        int count;
 
-       count = nautilus_files_view_get_selection_count (view);
+        selection = nautilus_files_view_get_selection (view);
+       count = g_list_length (selection);
 
        gtk_info_bar_set_response_sensitive (GTK_INFO_BAR (bar),
                                             TRASH_BAR_RESPONSE_RESTORE,
                                             (count > 0));
+
+        nautilus_file_list_free (selection);
 }
 
 static void
diff --git a/src/nautilus-view.c b/src/nautilus-view.c
new file mode 100644
index 0000000..9be8a76
--- /dev/null
+++ b/src/nautilus-view.c
@@ -0,0 +1,231 @@
+/* nautilus-view.c
+ *
+ * Copyright (C) 2015 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "nautilus-view.h"
+
+G_DEFINE_INTERFACE (NautilusView, nautilus_view, GTK_TYPE_WIDGET)
+
+static void
+nautilus_view_default_init (NautilusViewInterface *iface)
+{
+        /**
+         * NautilusView::icon:
+         *
+         * The #GIcon that represents the view, or %NULL.
+         */
+        g_object_interface_install_property (iface,
+                                             g_param_spec_object ("icon",
+                                                                  "Icon that represents the view",
+                                                                  "The icon that represents the view",
+                                                                  G_TYPE_ICON,
+                                                                  G_PARAM_READABLE));
+
+        /**
+         * NautilusView::view-widget:
+         *
+         * %TRUE if the view is loading the location, %FALSE otherwise.
+         */
+        g_object_interface_install_property (iface,
+                                             g_param_spec_object ("view-widget",
+                                                                  "View widget for the menu",
+                                                                  "The view widget that appears under the 
view menu",
+                                                                  GTK_TYPE_WIDGET,
+                                                                  G_PARAM_READABLE));
+
+        /**
+         * NautilusView::is-loading:
+         *
+         * %TRUE if the view is loading the location, %FALSE otherwise.
+         */
+        g_object_interface_install_property (iface,
+                                             g_param_spec_boolean ("is-loading",
+                                                                   "Current view is loading",
+                                                                   "Whether the current view is loading the 
location or not",
+                                                                   FALSE,
+                                                                   G_PARAM_READABLE));
+
+        /**
+         * NautilusView::is-searching:
+         *
+         * %TRUE if the view is searching, %FALSE otherwise.
+         */
+        g_object_interface_install_property (iface,
+                                             g_param_spec_boolean ("is-searching",
+                                                                   "Current view is searching",
+                                                                   "Whether the current view is searching or 
not",
+                                                                   FALSE,
+                                                                   G_PARAM_READABLE));
+
+        /**
+         * NautilusView::location:
+         *
+         * The current location of the view.
+         */
+        g_object_interface_install_property (iface,
+                                             g_param_spec_object ("location",
+                                                                  "Location displayed by the view",
+                                                                  "The current location displayed by the 
view",
+                                                                  G_TYPE_FILE,
+                                                                  G_PARAM_READWRITE));
+
+        /**
+         * NautilusView::search-query:
+         *
+         * The search query being performed, or NULL.
+         */
+        g_object_interface_install_property (iface,
+                                             g_param_spec_object ("search-query",
+                                                                  "Search query being performed",
+                                                                  "The search query being performed on the 
view",
+                                                                  NAUTILUS_TYPE_QUERY,
+                                                                  G_PARAM_READWRITE));
+}
+
+/**
+ * nautilus_view_get_icon:
+ * @view: a #NautilusView
+ *
+ * Retrieves the #GIcon that represents @view.
+ *
+ * Returns: (transfer none): a #GIcon
+ */
+GIcon*
+nautilus_view_get_icon (NautilusView *view)
+{
+        g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_icon, NULL);
+
+        return NAUTILUS_VIEW_GET_IFACE (view)->get_icon (view);
+}
+
+/**
+ * nautilus_view_get_view_widget:
+ * @view: a #NautilusView
+ *
+ * Retrieves the view menu widget from @view.
+ *
+ * Returns: (transfer none): the widget displayed under view menu.
+ */
+GtkWidget*
+nautilus_view_get_view_widget (NautilusView *view)
+{
+        g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_view_widget, NULL);
+
+        return NAUTILUS_VIEW_GET_IFACE (view)->get_view_widget (view);
+}
+
+/**
+ * nautilus_view_get_search_query:
+ * @view: a #NautilusView
+ *
+ * Retrieves the current current location of @view.
+ *
+ * Returns: (transfer none): a #GFile
+ */
+GFile*
+nautilus_view_get_location (NautilusView *view)
+{
+        g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_location, NULL);
+
+        return NAUTILUS_VIEW_GET_IFACE (view)->get_location (view);
+}
+
+/**
+ * nautilus_view_set_location:
+ * @view: a #NautilusView
+ * @location: the location displayed by @view
+ *
+ * Sets the location of @view.
+ *
+ * Returns:
+ */
+void
+nautilus_view_set_location (NautilusView *view,
+                            GFile        *location)
+{
+        g_return_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->set_location);
+
+        NAUTILUS_VIEW_GET_IFACE (view)->set_location (view, location);
+}
+
+/**
+ * nautilus_view_get_search_query:
+ * @view: a #NautilusView
+ *
+ * Retrieves the current search query displayed by @view.
+ *
+ * Returns: (transfer none): a #
+ */
+NautilusQuery*
+nautilus_view_get_search_query (NautilusView *view)
+{
+        g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_search_query, NULL);
+
+        return NAUTILUS_VIEW_GET_IFACE (view)->get_search_query (view);
+}
+
+/**
+ * nautilus_view_set_search_query:
+ * @view: a #NautilusView
+ * @query: the search query to be performed, or %NULL
+ *
+ * Sets the current search query performed by @view.
+ *
+ * Returns:
+ */
+void
+nautilus_view_set_search_query (NautilusView  *view,
+                                NautilusQuery *query)
+{
+        g_return_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->set_search_query);
+
+        NAUTILUS_VIEW_GET_IFACE (view)->set_search_query (view, query);
+}
+
+/**
+ * nautilus_view_is_loading:
+ * @view: a #NautilusView
+ *
+ * Whether @view is loading the current location.
+ *
+ * Returns: %TRUE if @view is loading, %FALSE otherwise.
+ */
+gboolean
+nautilus_view_is_loading (NautilusView *view)
+{
+        g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->is_loading, FALSE);
+
+        return NAUTILUS_VIEW_GET_IFACE (view)->is_loading (view);
+}
+
+/**
+ * nautilus_view_is_searching:
+ * @view: a #NautilusView
+ *
+ * Whether @view is searching.
+ *
+ * Returns: %TRUE if @view is searching, %FALSE otherwise.
+ */
+gboolean
+nautilus_view_is_searching (NautilusView *view)
+{
+        g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->is_searching, FALSE);
+
+        return NAUTILUS_VIEW_GET_IFACE (view)->is_searching (view);
+}
diff --git a/src/nautilus-view.h b/src/nautilus-view.h
new file mode 100644
index 0000000..c6e24d5
--- /dev/null
+++ b/src/nautilus-view.h
@@ -0,0 +1,84 @@
+/* nautilus-view.h
+ *
+ * Copyright (C) 2015 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef NAUTILUS_VIEW_H
+#define NAUTILUS_VIEW_H
+
+#include <glib.h>
+#include <gtk/gtk.h>
+
+#include <libnautilus-private/nautilus-query.h>
+
+G_BEGIN_DECLS
+
+#define NAUTILUS_TYPE_VIEW (nautilus_view_get_type ())
+
+G_DECLARE_INTERFACE (NautilusView, nautilus_view, NAUTILUS, VIEW, GtkWidget)
+
+struct _NautilusViewInterface
+{
+        GTypeInterface parent;
+
+        /* The icon that represents the view */
+        GIcon*               (*get_icon)                   (NautilusView         *view);
+
+        /*
+         * The widget that is displayed under the view menu. When set to NULL, the
+         * button gets insensitive.
+         */
+        GtkWidget*           (*get_view_widget)            (NautilusView         *view);
+
+        /* Current location of the view */
+        GFile*               (*get_location)               (NautilusView         *view);
+        void                 (*set_location)               (NautilusView         *view,
+                                                            GFile                *location);
+
+        /* Search */
+        NautilusQuery*       (*get_search_query)           (NautilusView         *view);
+        void                 (*set_search_query)           (NautilusView         *view,
+                                                            NautilusQuery        *query);
+
+        /* Whether the current view is loading the location */
+        gboolean             (*is_loading)                 (NautilusView         *view);
+
+        /* Whether the current view is searching or not */
+        gboolean             (*is_searching)               (NautilusView         *view);
+};
+
+GIcon*             nautilus_view_get_icon                  (NautilusView         *view);
+
+GtkWidget*         nautilus_view_get_view_widget           (NautilusView         *view);
+
+GFile*             nautilus_view_get_location              (NautilusView         *view);
+
+void               nautilus_view_set_location              (NautilusView         *view,
+                                                            GFile                *location);
+
+NautilusQuery*     nautilus_view_get_search_query          (NautilusView         *view);
+
+void               nautilus_view_set_search_query          (NautilusView         *view,
+                                                            NautilusQuery        *query);
+
+gboolean           nautilus_view_is_loading                (NautilusView         *view);
+
+gboolean           nautilus_view_is_searching              (NautilusView         *view);
+
+G_END_DECLS
+
+#endif /* NAUTILUS_VIEW_H */
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index 9791cfc..d7d7cdc 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -30,6 +30,7 @@
 #include "nautilus-list-view.h"
 #include "nautilus-special-location-bar.h"
 #include "nautilus-trash-bar.h"
+#include "nautilus-view.h"
 #include "nautilus-window.h"
 #include "nautilus-x-content-bar.h"
 
@@ -74,8 +75,8 @@ struct NautilusWindowSlotDetails {
        gchar *title;
 
        /* Viewed file */
-       NautilusFilesView *content_view;
-       NautilusFilesView *new_content_view;
+       NautilusView *content_view;
+       NautilusView *new_content_view;
        NautilusFile *viewed_file;
        gboolean viewed_file_seen;
        gboolean viewed_file_in_trash;
@@ -127,19 +128,6 @@ static void nautilus_window_slot_connect_new_content_view (NautilusWindowSlot *s
 static void nautilus_window_slot_disconnect_content_view (NautilusWindowSlot *slot);
 static void nautilus_window_slot_emit_location_change (NautilusWindowSlot *slot, GFile *from, GFile *to);
 
-static void
-nautilus_window_slot_sync_search_widgets (NautilusWindowSlot *slot)
-{
-       if (slot != nautilus_window_get_active_slot (slot->details->window)) {
-               return;
-       }
-
-        nautilus_window_slot_set_search_visible (slot,
-                                                 slot->details->search_visible ||
-                                                 (slot->details->content_view &&
-                                                  nautilus_files_view_is_search 
(slot->details->content_view)));
-}
-
 static gboolean
 nautilus_window_slot_content_view_matches_iid (NautilusWindowSlot *slot,
                                               const char *iid)
@@ -147,7 +135,7 @@ nautilus_window_slot_content_view_matches_iid (NautilusWindowSlot *slot,
        if (slot->details->content_view == NULL) {
                return FALSE;
        }
-       return g_strcmp0 (nautilus_files_view_get_view_id (slot->details->content_view), iid) == 0;
+       return g_strcmp0 (nautilus_files_view_get_view_id (NAUTILUS_FILES_VIEW 
(slot->details->content_view)), iid) == 0;
 }
 
 void
@@ -175,64 +163,6 @@ nautilus_window_slot_sync_view_mode (NautilusWindowSlot *slot)
 }
 
 static void
-sync_search_directory (NautilusWindowSlot *slot)
-{
-       NautilusDirectory *directory;
-       NautilusQuery *query;
-       gchar *text;
-       GFile *location;
-
-       g_assert (NAUTILUS_IS_FILE (slot->details->viewed_file));
-
-       directory = nautilus_directory_get_for_file (slot->details->viewed_file);
-       g_assert (NAUTILUS_IS_SEARCH_DIRECTORY (directory));
-
-       query = nautilus_query_editor_get_query (slot->details->query_editor);
-       text = nautilus_query_get_text (query);
-
-       if (!strlen (text)) {
-               /* Prevent the location change from hiding the query editor in this case */
-               slot->details->load_with_search = TRUE;
-               location = nautilus_query_editor_get_location (slot->details->query_editor);
-               nautilus_window_slot_open_location (slot, location, 0);
-               g_object_unref (location);
-       } else {
-               nautilus_search_directory_set_query (NAUTILUS_SEARCH_DIRECTORY (directory),
-                                                    query);
-               nautilus_window_slot_force_reload (slot);
-       }
-
-       g_free (text);
-       g_object_unref (query);
-       nautilus_directory_unref (directory);
-}
-
-static void
-create_new_search (NautilusWindowSlot *slot)
-{
-       char *uri;
-       NautilusDirectory *directory;
-       GFile *location;
-       NautilusQuery *query;
-
-       uri = nautilus_search_directory_generate_new_uri ();
-       location = g_file_new_for_uri (uri);
-
-       directory = nautilus_directory_get (location);
-       g_assert (NAUTILUS_IS_SEARCH_DIRECTORY (directory));
-
-       query = nautilus_query_editor_get_query (slot->details->query_editor);
-       nautilus_search_directory_set_query (NAUTILUS_SEARCH_DIRECTORY (directory), query);
-
-       nautilus_window_slot_open_location (slot, location, 0);
-
-       nautilus_directory_unref (directory);
-       g_object_unref (query);
-       g_object_unref (location);
-       g_free (uri);
-}
-
-static void
 query_editor_cancel_callback (NautilusQueryEditor *editor,
                              NautilusWindowSlot *slot)
 {
@@ -244,7 +174,8 @@ query_editor_activated_callback (NautilusQueryEditor *editor,
                                 NautilusWindowSlot *slot)
 {
        if (slot->details->content_view != NULL) {
-               nautilus_files_view_activate_selection (slot->details->content_view);
+               nautilus_files_view_activate_selection (NAUTILUS_FILES_VIEW (slot->details->content_view));
+                nautilus_window_slot_set_search_visible (slot, FALSE);
        }
 }
 
@@ -254,27 +185,23 @@ query_editor_changed_callback (NautilusQueryEditor *editor,
                               gboolean reload,
                               NautilusWindowSlot *slot)
 {
-       NautilusDirectory *directory;
+        NautilusView *view;
 
-       g_assert (NAUTILUS_IS_FILE (slot->details->viewed_file));
+       view = nautilus_window_slot_get_current_view (slot);
+       query = nautilus_query_editor_get_query (slot->details->query_editor);
 
-       directory = nautilus_directory_get_for_file (slot->details->viewed_file);
-       if (!NAUTILUS_IS_SEARCH_DIRECTORY (directory)) {
-               /* this is the first change from the query editor. we
-                  ask for a location change to the search directory,
-                  indicate the directory needs to be sync'd with the
-                  current query. */
-               create_new_search (slot);
-       } else {
-               sync_search_directory (slot);
-       }
+       nautilus_view_set_search_query (view, query);
 
-       nautilus_directory_unref (directory);
+       g_object_unref (query);
 }
 
 static void
 hide_query_editor (NautilusWindowSlot *slot)
 {
+        NautilusView *view;
+
+        view = nautilus_window_slot_get_current_view (slot);
+
        gtk_revealer_set_reveal_child (GTK_REVEALER (slot->details->query_editor_revealer),
                                       FALSE);
 
@@ -291,6 +218,7 @@ hide_query_editor (NautilusWindowSlot *slot)
                slot->details->qe_activated_id = 0;
        }
 
+        nautilus_view_set_search_query (view, NULL);
        nautilus_query_editor_set_query (slot->details->query_editor, NULL);
 }
 
@@ -311,27 +239,21 @@ nautilus_window_slot_get_current_location (NautilusWindowSlot *slot)
 static void
 show_query_editor (NautilusWindowSlot *slot)
 {
-       NautilusDirectory *directory;
-       NautilusSearchDirectory *search_directory;
-       GFile *location;
+        NautilusView *view;
 
-       location = nautilus_window_slot_get_current_location (slot);
-       directory = nautilus_directory_get (location);
+        view = nautilus_window_slot_get_current_view (slot);
 
-       if (NAUTILUS_IS_SEARCH_DIRECTORY (directory)) {
-               NautilusQuery *query;
-               search_directory = NAUTILUS_SEARCH_DIRECTORY (directory);
-               query = nautilus_search_directory_get_query (search_directory);
-               if (query != NULL) {
-                       nautilus_query_editor_set_query (slot->details->query_editor,
-                                                        query);
-                       g_object_unref (query);
-               }
-       } else {
-               nautilus_query_editor_set_location (slot->details->query_editor, location);
-       }
+        if (nautilus_view_is_searching (view)) {
+                NautilusQuery *query;
 
-       nautilus_directory_unref (directory);
+                query = nautilus_view_get_search_query (view);
+
+                if (query != NULL) {
+                        nautilus_query_editor_set_query (slot->details->query_editor, query);
+                }
+        } else {
+                nautilus_query_editor_set_location (slot->details->query_editor, nautilus_view_get_location 
(view));
+        }
 
        gtk_revealer_set_reveal_child (GTK_REVEALER (slot->details->query_editor_revealer),
                                       TRUE);
@@ -358,63 +280,25 @@ void
 nautilus_window_slot_set_search_visible (NautilusWindowSlot *slot,
                                         gboolean            visible)
 {
-       GAction *action;
-       gboolean old_visible;
-       GFile *return_location;
-       gboolean active_slot;
-
-       /* set search active state for the slot */
-       old_visible = slot->details->search_visible;
-       slot->details->search_visible = visible;
-
-       return_location = NULL;
-       active_slot = (slot == nautilus_window_get_active_slot (slot->details->window));
-
-       if (visible) {
-               show_query_editor (slot);
-       } else {
-               /* If search was active on this slot and became inactive, change
-                * the slot location to the real directory.
-                */
-               if (old_visible && active_slot) {
-                       /* Use the query editor search root if possible */
-                       return_location = nautilus_window_slot_get_query_editor_location (slot);
-
-                       /* Use the home directory as a fallback */
-                       if (return_location == NULL) {
-                               return_location = g_file_new_for_path (g_get_home_dir ());
-                       }
-               }
-
-               if (active_slot) {
-                       gtk_widget_grab_focus (GTK_WIDGET (slot->details->window));
-               }
-
-               /* Now hide the editor and clear its state */
-               hide_query_editor (slot);
-       }
+        if (slot->details->search_visible != visible) {
+                gboolean active_slot;
 
-       if (!active_slot) {
-               return;
-       }
+                /* set search active state for the slot */
+                slot->details->search_visible = visible;
 
-       /* also synchronize the window action state */
-       action =  g_action_map_lookup_action (G_ACTION_MAP (slot->details->window), "toggle-search");
-       g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_boolean (visible));
+                active_slot = (slot == nautilus_window_get_active_slot (slot->details->window));
 
-       /* If search was active on this slot and became inactive, change
-        * the slot location to the real directory.
-        */
-       if (return_location != NULL) {
-               nautilus_window_slot_open_location (slot, return_location, 0);
-               g_object_unref (return_location);
-       }
-}
+                if (visible) {
+                        show_query_editor (slot);
+                } else {
+                        /* Now hide the editor and clear its state */
+                        hide_query_editor (slot);
 
-GFile *
-nautilus_window_slot_get_query_editor_location (NautilusWindowSlot *slot)
-{
-       return nautilus_query_editor_get_location (slot->details->query_editor);
+                        if (active_slot) {
+                                gtk_widget_grab_focus (GTK_WIDGET (slot->details->window));
+                        }
+                }
+        }
 }
 
 gboolean
@@ -454,7 +338,6 @@ real_active (NautilusWindowSlot *slot)
        nautilus_window_sync_allow_stop (window, slot);
        nautilus_window_sync_title (window, slot);
        nautilus_window_sync_location_widgets (window);
-       nautilus_window_slot_sync_search_widgets (slot);
        nautilus_window_slot_sync_view_mode (slot);
 }
 
@@ -741,7 +624,7 @@ nautilus_window_slot_open_location_full (NautilusWindowSlot *slot,
 
        old_selection = NULL;
        if (slot->details->content_view != NULL) {
-               old_selection = nautilus_files_view_get_selection (slot->details->content_view);
+                old_selection = nautilus_files_view_get_selection (NAUTILUS_FILES_VIEW 
(slot->details->content_view));
        }
 
        if (target_window == window && target_slot == slot && !is_desktop &&
@@ -828,13 +711,12 @@ begin_location_change (NautilusWindowSlot *slot,
 
         directory = nautilus_directory_get (location);
 
-
         /* Avoid to update status from the current view in our async calls */
         nautilus_window_slot_disconnect_content_view (slot);
         /* We are going to change the location, so make sure we stop any loading
          * or searching of the previous view, so we avoid to be slow */
         if (slot->details->content_view) {
-                nautilus_files_view_stop_loading (slot->details->content_view);
+                nautilus_files_view_stop_loading (NAUTILUS_FILES_VIEW (slot->details->content_view));
         }
 
        /* If there is no new selection and the new location is
@@ -905,7 +787,7 @@ begin_location_change (NautilusWindowSlot *slot,
         /* Set current_bookmark scroll pos */
         if (slot->details->current_location_bookmark != NULL &&
             slot->details->content_view != NULL) {
-                current_pos = nautilus_files_view_get_first_visible_file (slot->details->content_view);
+                current_pos = nautilus_files_view_get_first_visible_file (NAUTILUS_FILES_VIEW 
(slot->details->content_view));
                 nautilus_bookmark_set_scroll_pos (slot->details->current_location_bookmark, current_pos);
                 g_free (current_pos);
         }
@@ -1213,7 +1095,7 @@ got_file_info_for_view_selection_callback (NautilusFile *file,
                                  * so the view mode of the current view will be the one search is using,
                                  * which is not the one we are interested in */
                                 if (slot->details->view_mode_before_search == NULL) {
-                                        slot->details->view_mode_before_search = g_strdup 
(nautilus_files_view_get_view_id (slot->details->content_view));
+                                        slot->details->view_mode_before_search = g_strdup 
(nautilus_files_view_get_view_id (NAUTILUS_FILES_VIEW (slot->details->content_view)));
                                 }
                                 view_id = g_strdup (NAUTILUS_LIST_VIEW_IID);
                         } else {
@@ -1231,7 +1113,7 @@ got_file_info_for_view_selection_callback (NautilusFile *file,
                                 g_free (slot->details->view_mode_before_search);
                                 slot->details->view_mode_before_search = NULL;
                         } else {
-                               view_id = g_strdup (nautilus_files_view_get_view_id 
(slot->details->content_view));
+                               view_id = g_strdup (nautilus_files_view_get_view_id (NAUTILUS_FILES_VIEW 
(slot->details->content_view)));
                         }
                }
 
@@ -1340,11 +1222,10 @@ create_content_view (NautilusWindowSlot *slot,
                     GError **error_out)
 {
        NautilusWindow *window;
-        NautilusFilesView *view;
+        NautilusView *view;
        GList *selection;
        gboolean ret = TRUE;
        GError *error = NULL;
-       NautilusDirectory *old_directory, *new_directory;
        GFile *old_location;
 
        window = nautilus_window_slot_get_window (slot);
@@ -1371,38 +1252,14 @@ create_content_view (NautilusWindowSlot *slot,
                g_object_ref (view);
         } else {
                 /* create a new content view */
-               view = nautilus_files_view_new (view_id, slot);
+               view = NAUTILUS_VIEW (nautilus_files_view_new (view_id, slot));
 
                 slot->details->new_content_view = view;
         }
         nautilus_window_slot_connect_new_content_view (slot);
 
        /* Forward search selection and state before loading the new model */
-       old_location = nautilus_window_slot_get_location (slot);
-       old_directory = nautilus_directory_get (old_location);
-       new_directory = nautilus_directory_get (slot->details->pending_location);
-
-       if (NAUTILUS_IS_SEARCH_DIRECTORY (new_directory) &&
-           !NAUTILUS_IS_SEARCH_DIRECTORY (old_directory)) {
-               nautilus_search_directory_set_base_model (NAUTILUS_SEARCH_DIRECTORY (new_directory), 
old_directory);
-       }
-
-       if (NAUTILUS_IS_SEARCH_DIRECTORY (old_directory) &&
-           !NAUTILUS_IS_SEARCH_DIRECTORY (new_directory)) {
-               /* Reset the search_active 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->details->load_with_search) {
-                       slot->details->search_visible = FALSE;
-               }
-
-               slot->details->load_with_search = FALSE;
-
-               if (slot->details->pending_selection == NULL) {
-                       slot->details->pending_selection = nautilus_files_view_get_selection 
(slot->details->content_view);
-               }
-       }
+        old_location = slot->details->content_view ? nautilus_view_get_location 
(slot->details->content_view) : NULL;
 
        /* Actually load the pending location and selection: */
 
@@ -1416,7 +1273,7 @@ create_content_view (NautilusWindowSlot *slot,
                g_list_free_full (slot->details->pending_selection, g_object_unref);
                slot->details->pending_selection = NULL;
        } else if (old_location != NULL) {
-               selection = nautilus_files_view_get_selection (slot->details->content_view);
+               selection = nautilus_files_view_get_selection (NAUTILUS_FILES_VIEW 
(slot->details->content_view));
                load_new_location (slot,
                                   old_location,
                                   selection,
@@ -1448,7 +1305,7 @@ load_new_location (NautilusWindowSlot *slot,
                   gboolean tell_new_content_view)
 {
        GList *selection_copy;
-       NautilusFilesView *view;
+       NautilusView *view;
 
        g_assert (slot != NULL);
        g_assert (location != NULL);
@@ -1460,19 +1317,19 @@ load_new_location (NautilusWindowSlot *slot,
        /* Note, these may recurse into report_load_underway */
         if (slot->details->content_view != NULL && tell_current_content_view) {
                view = slot->details->content_view;
-               nautilus_files_view_load_location (slot->details->content_view, location);
+               nautilus_view_set_location (slot->details->content_view, location);
         }
 
         if (slot->details->new_content_view != NULL && tell_new_content_view &&
            (!tell_current_content_view ||
             slot->details->new_content_view != slot->details->content_view) ) {
                view = slot->details->new_content_view;
-               nautilus_files_view_load_location (slot->details->new_content_view, location);
+               nautilus_view_set_location (slot->details->new_content_view, location);
         }
        if (view != NULL) {
                /* new_content_view might have changed here if
                   report_load_underway was called from load_location */
-               nautilus_files_view_set_selection (view, selection_copy);
+               nautilus_files_view_set_selection (NAUTILUS_FILES_VIEW (view), selection_copy);
        }
 
        g_list_free_full (selection_copy, g_object_unref);
@@ -1542,7 +1399,7 @@ cancel_location_change (NautilusWindowSlot *slot)
 
        directory = nautilus_directory_get (slot->details->location);
         /* Stops current loading or search if any, so we are not slow */
-       nautilus_files_view_stop_loading (slot->details->content_view);
+       nautilus_files_view_stop_loading (NAUTILUS_FILES_VIEW (slot->details->content_view));
         nautilus_directory_unref (directory);
 
         if (slot->details->pending_location != NULL
@@ -1554,7 +1411,7 @@ cancel_location_change (NautilusWindowSlot *slot)
                  * be told, or it is the very pending change we wish
                  * to cancel.
                  */
-               selection = nautilus_files_view_get_selection (slot->details->content_view);
+               selection = nautilus_files_view_get_selection (NAUTILUS_FILES_VIEW 
(slot->details->content_view));
                 load_new_location (slot,
                                   location,
                                   selection,
@@ -1637,6 +1494,7 @@ void
 nautilus_window_slot_set_content_view (NautilusWindowSlot *slot,
                                       const char *id)
 {
+        GList *selection;
        char *uri;
 
        g_assert (slot != NULL);
@@ -1654,10 +1512,12 @@ nautilus_window_slot_set_content_view (NautilusWindowSlot *slot,
 
         nautilus_window_slot_set_allow_stop (slot, TRUE);
 
-        if (nautilus_files_view_get_selection_count (slot->details->content_view) == 0) {
+        selection = nautilus_files_view_get_selection (NAUTILUS_FILES_VIEW (slot->details->content_view));
+
+        if (g_list_length (selection) == 0) {
                 /* If there is no selection, queue a scroll to the same icon that
                  * is currently visible */
-                slot->details->pending_scroll_to = nautilus_files_view_get_first_visible_file 
(slot->details->content_view);
+                slot->details->pending_scroll_to = nautilus_files_view_get_first_visible_file 
(NAUTILUS_FILES_VIEW (slot->details->content_view));
         }
        slot->details->location_change_type = NAUTILUS_LOCATION_CHANGE_RELOAD;
 
@@ -1665,6 +1525,8 @@ nautilus_window_slot_set_content_view (NautilusWindowSlot *slot,
                /* Just load the homedir. */
                nautilus_window_slot_go_home (slot, FALSE);
        }
+
+        nautilus_file_list_free (selection);
 }
 
 void
@@ -1740,8 +1602,8 @@ nautilus_window_slot_force_reload (NautilusWindowSlot *slot)
        current_pos = NULL;
        selection = NULL;
        if (slot->details->content_view != NULL) {
-               current_pos = nautilus_files_view_get_first_visible_file (slot->details->content_view);
-               selection = nautilus_files_view_get_selection (slot->details->content_view);
+               current_pos = nautilus_files_view_get_first_visible_file (NAUTILUS_FILES_VIEW 
(slot->details->content_view));
+               selection = nautilus_files_view_get_selection (NAUTILUS_FILES_VIEW 
(slot->details->content_view));
        }
        begin_location_change
                (slot, location, location, selection,
@@ -1763,7 +1625,7 @@ nautilus_window_slot_queue_reload (NautilusWindowSlot *slot)
 
        if (slot->details->pending_location != NULL
            || slot->details->content_view == NULL
-           || nautilus_files_view_get_loading (slot->details->content_view)) {
+           || nautilus_view_is_loading (slot->details->content_view)) {
                /* there is a reload in flight */
                slot->details->needs_reload = TRUE;
                return;
@@ -2038,10 +1900,10 @@ static void
 nautilus_window_slot_show_trash_bar (NautilusWindowSlot *slot)
 {
        GtkWidget *bar;
-       NautilusFilesView *view;
+        NautilusView *view;
 
        view = nautilus_window_slot_get_current_view (slot);
-       bar = nautilus_trash_bar_new (view);
+       bar = nautilus_trash_bar_new (NAUTILUS_FILES_VIEW (view));
        gtk_widget_show (bar);
 
        nautilus_window_slot_add_extra_location_widget (slot, bar);
@@ -2122,9 +1984,20 @@ nautilus_window_slot_update_for_new_location (NautilusWindowSlot *slot)
                nautilus_window_slot_sync_view_mode (slot);
        }
 
-       if (slot == nautilus_window_get_active_slot (window) &&
-           location_really_changed) {
-               nautilus_window_slot_sync_search_widgets (slot);
+        if (slot == nautilus_window_get_active_slot (window) && location_really_changed) {
+                GAction *action;
+                NautilusView *view;
+                gboolean show_search;
+
+                view = nautilus_window_slot_get_current_view (slot);
+                show_search = (slot->details->search_visible || (view && nautilus_view_is_searching (view)));
+                action =  g_action_map_lookup_action (G_ACTION_MAP (slot->details->window), "toggle-search");
+
+                /*
+                 * Instead of calling nautilus_window_slot_set_search_visible(), set the action state,
+                 * which will call nautilus_window_slot_set_search_visible() by itself.
+                 */
+                g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_boolean (show_search));
        }
 }
 
@@ -2135,9 +2008,9 @@ view_end_loading_cb (NautilusFilesView       *view,
 {
        /* Only handle this if we're expecting it.
         * Don't handle it if its from an old view we've switched from */
-       if (view == slot->details->content_view && all_files_seen) {
+       if (view == NAUTILUS_FILES_VIEW (slot->details->content_view) && all_files_seen) {
                if (slot->details->pending_scroll_to != NULL) {
-                       nautilus_files_view_scroll_to_file (slot->details->content_view,
+                       nautilus_files_view_scroll_to_file (NAUTILUS_FILES_VIEW (slot->details->content_view),
                                                      slot->details->pending_scroll_to);
                }
                end_location_change (slot);
@@ -2157,7 +2030,7 @@ view_begin_loading_cb (NautilusFilesView       *view,
 {
        nautilus_profile_start (NULL);
 
-       if (view == slot->details->new_content_view) {
+       if (view == NAUTILUS_FILES_VIEW (slot->details->new_content_view)) {
                location_has_really_changed (slot);
        } else {
                nautilus_window_slot_set_allow_stop (slot, TRUE);
@@ -2522,7 +2395,7 @@ nautilus_window_slot_set_window (NautilusWindowSlot *slot,
        }
 }
 
-NautilusFilesView *
+NautilusView *
 nautilus_window_slot_get_view (NautilusWindowSlot *slot)
 {
        return slot->details->content_view;
@@ -2606,7 +2479,7 @@ nautilus_window_slot_get_current_uri (NautilusWindowSlot *slot)
        return NULL;
 }
 
-NautilusFilesView *
+NautilusView*
 nautilus_window_slot_get_current_view (NautilusWindowSlot *slot)
 {
        if (slot->details->content_view != NULL) {
@@ -2685,23 +2558,23 @@ nautilus_window_slot_new (NautilusWindow *window)
 GIcon*
 nautilus_window_slot_get_icon (NautilusWindowSlot *slot)
 {
-        NautilusFilesView *view;
+        NautilusView *view;
 
         g_return_val_if_fail (NAUTILUS_IS_WINDOW_SLOT (slot), NULL);
 
         view = nautilus_window_slot_get_current_view (slot);
 
-        return view ? nautilus_files_view_get_icon (view) : NULL;
+        return view ? nautilus_view_get_icon (view) : NULL;
 }
 
 GtkWidget*
 nautilus_window_slot_get_view_widget (NautilusWindowSlot *slot)
 {
-        NautilusFilesView *view;
+        NautilusView *view;
 
         g_return_val_if_fail (NAUTILUS_IS_WINDOW_SLOT (slot), NULL);
 
         view = nautilus_window_slot_get_current_view (slot);
 
-        return view ? nautilus_files_view_get_view_widget (view) : NULL;
+        return view ? nautilus_view_get_view_widget (view) : NULL;
 }
diff --git a/src/nautilus-window-slot.h b/src/nautilus-window-slot.h
index fc433ff..bb0bfe7 100644
--- a/src/nautilus-window-slot.h
+++ b/src/nautilus-window-slot.h
@@ -30,6 +30,7 @@ typedef struct NautilusWindowSlotClass NautilusWindowSlotClass;
 typedef struct NautilusWindowSlotDetails NautilusWindowSlotDetails;
 
 #include "nautilus-files-view.h"
+#include "nautilus-view.h"
 #include "nautilus-window.h"
 
 #define NAUTILUS_TYPE_WINDOW_SLOT       (nautilus_window_slot_get_type())
@@ -87,15 +88,13 @@ char *  nautilus_window_slot_get_location_uri                  (NautilusWindowSlot *slot);
 
 NautilusFile *    nautilus_window_slot_get_file            (NautilusWindowSlot *slot);
 NautilusBookmark *nautilus_window_slot_get_bookmark        (NautilusWindowSlot *slot);
-NautilusFilesView *    nautilus_window_slot_get_view            (NautilusWindowSlot *slot);
+NautilusView*  nautilus_window_slot_get_view               (NautilusWindowSlot *slot);
 
-NautilusFilesView * nautilus_window_slot_get_current_view       (NautilusWindowSlot *slot);
+NautilusView*  nautilus_window_slot_get_current_view       (NautilusWindowSlot *slot);
 char *         nautilus_window_slot_get_current_uri        (NautilusWindowSlot *slot);
 
 GList * nautilus_window_slot_get_back_history              (NautilusWindowSlot *slot);
 GList * nautilus_window_slot_get_forward_history           (NautilusWindowSlot *slot);
-
-GFile * nautilus_window_slot_get_query_editor_location     (NautilusWindowSlot *slot);
 void    nautilus_window_slot_set_search_visible            (NautilusWindowSlot *slot,
                                                            gboolean            visible);
 


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