[nautilus/wip/gbsneto/files-view: 12/14] view: add interface
- From: Carlos Soriano Sánchez <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/gbsneto/files-view: 12/14] view: add interface
- Date: Thu, 20 Aug 2015 13:17:47 +0000 (UTC)
commit c4c9a741758a2719cd3928974f1c466caeaa015a
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.
https://bugzilla.gnome.org/show_bug.cgi?id=753871
src/Makefile.am | 2 +
src/nautilus-desktop-canvas-view.c | 7 +-
src/nautilus-files-view.c | 296 +++++++++++++++++-----
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 | 471 +++++++++++++++---------------------
src/nautilus-window-slot.h | 14 +-
src/nautilus-window.c | 4 +-
10 files changed, 759 insertions(+), 366 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..9b734ba 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);
@@ -2674,7 +2692,6 @@ slot_active (NautilusWindowSlot *slot,
* zoom slider has the correct adjustment that changes when the
* view mode changes
*/
- nautilus_window_slot_sync_view_mode (slot);
nautilus_files_view_update_context_menus(view);
nautilus_files_view_update_toolbar_menus (view);
@@ -2718,20 +2735,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 +2833,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 +3054,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 +3104,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 +3138,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 +6307,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)));
@@ -7069,8 +7076,6 @@ static void
load_directory (NautilusFilesView *view,
NautilusDirectory *directory)
{
- NautilusDirectory *old_directory;
- NautilusFile *old_file;
NautilusFileAttributes attributes;
g_assert (NAUTILUS_IS_FILES_VIEW (view));
@@ -7096,16 +7101,16 @@ load_directory (NautilusFilesView *view,
view->details->subdirectory_list->data);
}
- old_directory = view->details->model;
+ g_set_object (&view->details->model, directory);
- nautilus_directory_ref (directory);
- view->details->model = directory;
- nautilus_directory_unref (old_directory);
+ g_clear_object (&view->details->directory_as_file);
+ view->details->directory_as_file = nautilus_directory_get_corresponding_file (directory);
- old_file = view->details->directory_as_file;
- view->details->directory_as_file =
- nautilus_directory_get_corresponding_file (directory);
- nautilus_file_unref (old_file);
+ g_clear_object (&view->details->location);
+ view->details->location = nautilus_directory_get_location (directory);
+
+ 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
@@ -7156,6 +7161,7 @@ finish_loading (NautilusFilesView *view)
*/
nautilus_profile_start ("BEGIN_LOADING");
g_signal_emit (view, signals[BEGIN_LOADING], 0);
+ g_object_notify (G_OBJECT (view), "is-loading");
nautilus_profile_end ("BEGIN_LOADING");
check_empty_states (view);
@@ -7572,11 +7578,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 +7635,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 +7822,141 @@ 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;
+
+ files_view = NAUTILUS_FILES_VIEW (view);
+
+ g_set_object (&files_view->details->search_query, query);
+ g_object_notify (G_OBJECT (view), "search-query");
+
+ if (query) {
+ GFile *location;
+
+ location = NULL;
+
+ 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;
+ NautilusFile *file;
+ GList *selection;
+ gchar *path;
+ gchar *uri;
+
+ uri = nautilus_search_directory_generate_new_uri ();
+ location = g_file_new_for_uri (uri);
+ selection = nautilus_files_view_get_selection (files_view);
+ file = nautilus_file_get (location);
+ path = get_view_directory (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_mime_activate_file (nautilus_files_view_get_containing_window (files_view),
+ files_view->details->slot,
+ file,
+ path,
+ 0);
+
+ g_object_notify (G_OBJECT (view), "is-searching");
+
+ nautilus_directory_unref (directory);
+ nautilus_file_list_free (selection);
+ nautilus_file_unref (file);
+ g_free (uri);
+ g_free (path);
+ }
+
+ g_clear_object (&location);
+
+ } else if (nautilus_view_is_searching (view)) {
+ NautilusDirectory *base_model;
+ NautilusFile *file;
+ GList *selection;
+ gchar *path;
+
+ base_model = nautilus_search_directory_get_base_model (NAUTILUS_SEARCH_DIRECTORY
(files_view->details->model));
+ file = nautilus_directory_get_corresponding_file (base_model);
+ selection = nautilus_files_view_get_selection (files_view);
+ path = get_view_directory (files_view);
+
+ /*
+ * Delegate the opening of the base directory to mime-action when leaving
+ * search mode too, so it can check the previous view to switch back to.
+ */
+ nautilus_mime_activate_file (nautilus_files_view_get_containing_window (files_view),
+ files_view->details->slot,
+ file,
+ path,
+ 0);
+
+ g_object_notify (G_OBJECT (view), "is-searching");
+
+ nautilus_directory_unref (base_model);
+ nautilus_file_list_free (selection);
+ nautilus_file_unref (file);
+ g_free (path);
+ }
+}
+
+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 +8062,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..c68dfcd 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"
@@ -54,7 +55,8 @@ enum {
};
enum {
- PROP_WINDOW = 1,
+ PROP_ACTIVE = 1,
+ PROP_WINDOW,
PROP_ICON,
PROP_VIEW_WIDGET,
NUM_PROPERTIES
@@ -63,6 +65,8 @@ enum {
struct NautilusWindowSlotDetails {
NautilusWindow *window;
+ gboolean active : 1;
+
/* slot contains
* 1) an vbox containing extra_location_widgets
* 2) the view
@@ -74,8 +78,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;
@@ -122,24 +126,12 @@ static guint signals[LAST_SIGNAL] = { 0 };
static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
static void nautilus_window_slot_force_reload (NautilusWindowSlot *slot);
-static void location_has_really_changed (NautilusWindowSlot *slot);
+static void change_view (NautilusWindowSlot *slot);
+static void nautilus_window_slot_sync_actions (NautilusWindowSlot *slot);
static void nautilus_window_slot_connect_new_content_view (NautilusWindowSlot *slot);
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,15 +139,20 @@ 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
-nautilus_window_slot_sync_view_mode (NautilusWindowSlot *slot)
+static void
+nautilus_window_slot_sync_actions (NautilusWindowSlot *slot)
{
- GAction *action;
+ NautilusView *view;
+ GAction *action;
+ gboolean show_search;
- if (slot != nautilus_window_get_active_slot (slot->details->window)) {
+ view = nautilus_window_slot_get_current_view (slot);
+ show_search = (slot->details->search_visible || (view && nautilus_view_is_searching (view)));
+
+ if (!nautilus_window_slot_get_active (slot)) {
return;
}
@@ -163,6 +160,13 @@ nautilus_window_slot_sync_view_mode (NautilusWindowSlot *slot)
return;
}
+ /* Search */
+ action = g_action_map_lookup_action (G_ACTION_MAP (slot->details->window), "toggle-search");
+
+ /* By setting the toggle-search action state, NautilusWindow will call
nautilus_window_slot_set_search_visible() */
+ g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_boolean (show_search));
+
+ /* View mode */
action = g_action_map_lookup_action (G_ACTION_MAP (slot->details->window), "view-mode");
if (nautilus_window_slot_content_view_matches_iid (slot, NAUTILUS_LIST_VIEW_ID)) {
@@ -175,64 +179,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 +190,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 +201,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 +234,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 +255,19 @@ 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);
+ }
+ }
gtk_revealer_set_reveal_child (GTK_REVEALER (slot->details->query_editor_revealer),
TRUE);
@@ -358,63 +294,21 @@ 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 (!active_slot) {
- return;
- }
+ if (slot->details->search_visible != visible) {
+ /* 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));
+ if (visible) {
+ show_query_editor (slot);
+ } else {
+ /* Now hide the editor and clear its state */
+ hide_query_editor (slot);
- /* 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);
- }
-}
-
-GFile *
-nautilus_window_slot_get_query_editor_location (NautilusWindowSlot *slot)
-{
- return nautilus_query_editor_get_location (slot->details->query_editor);
+ if (nautilus_window_slot_get_active (slot)) {
+ gtk_widget_grab_focus (GTK_WIDGET (slot->details->window));
+ }
+ }
+ }
}
gboolean
@@ -454,8 +348,7 @@ 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);
+ nautilus_window_slot_sync_actions (slot);
}
static void
@@ -508,6 +401,9 @@ nautilus_window_slot_set_property (GObject *object,
NautilusWindowSlot *slot = NAUTILUS_WINDOW_SLOT (object);
switch (property_id) {
+ case PROP_ACTIVE:
+ nautilus_window_slot_set_active (slot, g_value_get_boolean (value));
+ break;
case PROP_WINDOW:
nautilus_window_slot_set_window (slot, g_value_get_object (value));
break;
@@ -526,6 +422,9 @@ nautilus_window_slot_get_property (GObject *object,
NautilusWindowSlot *slot = NAUTILUS_WINDOW_SLOT (object);
switch (property_id) {
+ case PROP_ACTIVE:
+ g_value_set_boolean (value, nautilus_window_slot_get_active (slot));
+ break;
case PROP_WINDOW:
g_value_set_object (value, slot->details->window);
break;
@@ -741,7 +640,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 +727,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 +803,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);
}
@@ -941,7 +839,7 @@ nautilus_window_slot_set_location (NautilusWindowSlot *slot,
old_location = slot->details->location;
slot->details->location = g_object_ref (location);
- if (slot == nautilus_window_get_active_slot (slot->details->window)) {
+ if (nautilus_window_slot_get_active (slot)) {
nautilus_window_sync_location_widgets (slot->details->window);
}
@@ -1213,7 +1111,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 +1129,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 +1238,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 +1268,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 +1289,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,
@@ -1433,7 +1306,10 @@ create_content_view (NautilusWindowSlot *slot,
if (error != NULL) {
g_propagate_error (error_out, error);
- }
+ } else {
+ change_view (slot);
+ gtk_widget_show (GTK_WIDGET (slot->details->window));
+ }
nautilus_profile_end (NULL);
@@ -1448,7 +1324,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 +1336,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 +1418,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 +1430,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 +1513,7 @@ void
nautilus_window_slot_set_content_view (NautilusWindowSlot *slot,
const char *id)
{
+ GList *selection;
char *uri;
g_assert (slot != NULL);
@@ -1654,10 +1531,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 +1544,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 +1621,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 +1644,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 +1919,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);
@@ -2088,12 +1969,9 @@ slot_add_extension_extra_widgets (NautilusWindowSlot *slot)
static void
nautilus_window_slot_update_for_new_location (NautilusWindowSlot *slot)
{
- NautilusWindow *window;
- GFile *new_location, *old_location;
+ GFile *new_location;
NautilusFile *file;
- gboolean location_really_changed;
- window = nautilus_window_slot_get_window (slot);
new_location = slot->details->pending_location;
slot->details->pending_location = NULL;
@@ -2101,11 +1979,6 @@ nautilus_window_slot_update_for_new_location (NautilusWindowSlot *slot)
nautilus_window_slot_update_bookmark (slot, file);
update_history (slot, slot->details->location_change_type, new_location);
- old_location = nautilus_window_slot_get_location (slot);
-
- location_really_changed =
- old_location == NULL ||
- !g_file_equal (old_location, new_location);
/* Create a NautilusFile for this location, so we can catch it
* if it goes away.
@@ -2117,55 +1990,60 @@ nautilus_window_slot_update_for_new_location (NautilusWindowSlot *slot)
nautilus_window_slot_set_location (slot, new_location);
- if (slot == nautilus_window_get_active_slot (window)) {
- /* Sync the content view menu for this new location. */
- nautilus_window_slot_sync_view_mode (slot);
- }
+ /* Sync the actions for this new location. */
+ nautilus_window_slot_sync_actions (slot);
+}
- if (slot == nautilus_window_get_active_slot (window) &&
- location_really_changed) {
- nautilus_window_slot_sync_search_widgets (slot);
- }
+static void
+view_started_loading (NautilusWindowSlot *slot,
+ NautilusView *view)
+{
+ if (view == slot->details->content_view) {
+ nautilus_window_slot_set_allow_stop (slot, TRUE);
+ }
+
+ nautilus_query_editor_set_location (slot->details->query_editor, nautilus_view_get_location
(NAUTILUS_VIEW (view)));
+ gtk_widget_grab_focus (GTK_WIDGET (slot->details->window));
+
+ gtk_widget_show (GTK_WIDGET (slot->details->window));
}
static void
-view_end_loading_cb (NautilusFilesView *view,
- gboolean all_files_seen,
- NautilusWindowSlot *slot)
-{
- /* 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 (slot->details->pending_scroll_to != NULL) {
- nautilus_files_view_scroll_to_file (slot->details->content_view,
- slot->details->pending_scroll_to);
- }
- end_location_change (slot);
- }
+view_ended_loading (NautilusWindowSlot *slot,
+ NautilusView *view)
+{
+ if (view == slot->details->content_view) {
+ if (NAUTILUS_IS_FILES_VIEW (view) && slot->details->pending_scroll_to != NULL) {
+ nautilus_files_view_scroll_to_file (NAUTILUS_FILES_VIEW
(slot->details->content_view), slot->details->pending_scroll_to);
+ }
- if (slot->details->needs_reload) {
- nautilus_window_slot_queue_reload (slot);
- slot->details->needs_reload = FALSE;
- }
+ end_location_change (slot);
+ }
+
+ if (slot->details->needs_reload) {
+ nautilus_window_slot_queue_reload (slot);
+ slot->details->needs_reload = FALSE;
+ }
nautilus_window_slot_set_allow_stop (slot, FALSE);
}
static void
-view_begin_loading_cb (NautilusFilesView *view,
- NautilusWindowSlot *slot)
+view_is_loading_changed_cb (GObject *object,
+ GParamSpec *pspec,
+ NautilusWindowSlot *slot)
{
- nautilus_profile_start (NULL);
+ NautilusView *view;
- if (view == slot->details->new_content_view) {
- location_has_really_changed (slot);
- } else {
- nautilus_window_slot_set_allow_stop (slot, TRUE);
- }
+ view = NAUTILUS_VIEW (object);
- gtk_widget_grab_focus (GTK_WIDGET (slot->details->window));
+ nautilus_profile_start (NULL);
- gtk_widget_show (GTK_WIDGET (slot->details->window));
+ if (nautilus_view_is_loading (view)) {
+ view_started_loading (slot, view);
+ } else {
+ view_ended_loading (slot, view);
+ }
nautilus_profile_end (NULL);
}
@@ -2234,10 +2112,12 @@ nautilus_window_slot_setup_extra_location_widgets (NautilusWindowSlot *slot)
static void
nautilus_window_slot_connect_new_content_view (NautilusWindowSlot *slot)
{
- if (slot->details->new_content_view != NULL) {
- g_signal_connect (slot->details->new_content_view, "begin-loading", G_CALLBACK
(view_begin_loading_cb), slot);
- g_signal_connect (slot->details->new_content_view, "end-loading", G_CALLBACK
(view_end_loading_cb), slot);
- }
+ if (slot->details->new_content_view) {
+ g_signal_connect (slot->details->new_content_view,
+ "notify::is-loading",
+ G_CALLBACK (view_is_loading_changed_cb),
+ slot);
+ }
}
static void
@@ -2245,8 +2125,9 @@ nautilus_window_slot_disconnect_content_view (NautilusWindowSlot *slot)
{
if (slot->details->content_view != NULL) {
/* disconnect old view */
- g_signal_handlers_disconnect_by_func (slot->details->content_view, G_CALLBACK
(view_end_loading_cb), slot);
- g_signal_handlers_disconnect_by_func (slot->details->content_view, G_CALLBACK
(view_begin_loading_cb), slot);
+ g_signal_handlers_disconnect_by_func (slot->details->content_view,
+ G_CALLBACK (view_is_loading_changed_cb),
+ slot);
}
}
@@ -2283,7 +2164,7 @@ nautilus_window_slot_switch_new_content_view (NautilusWindowSlot *slot)
/* This is called when we have decided we can actually change to the new view/location situation. */
static void
-location_has_really_changed (NautilusWindowSlot *slot)
+change_view (NautilusWindowSlot *slot)
{
NautilusWindow *window;
GFile *location;
@@ -2311,10 +2192,8 @@ location_has_really_changed (NautilusWindowSlot *slot)
location = nautilus_window_slot_get_location (slot);
if (location != NULL) {
g_object_ref (location);
- }
- if (location != NULL) {
- if (slot == nautilus_window_get_active_slot (window)) {
+ if (nautilus_window_slot_get_active (slot)) {
char *uri;
uri = g_file_get_uri (location);
@@ -2452,6 +2331,13 @@ nautilus_window_slot_class_init (NautilusWindowSlotClass *klass)
G_TYPE_STRING,
G_TYPE_STRING);
+ properties[PROP_ACTIVE] =
+ g_param_spec_boolean ("active",
+ "Whether the slot is active",
+ "Whether the slot is the active slot of the window",
+ FALSE,
+ G_PARAM_READWRITE);
+
properties[PROP_WINDOW] =
g_param_spec_object ("window",
"The NautilusWindow",
@@ -2522,7 +2408,7 @@ nautilus_window_slot_set_window (NautilusWindowSlot *slot,
}
}
-NautilusFilesView *
+NautilusView *
nautilus_window_slot_get_view (NautilusWindowSlot *slot)
{
return slot->details->content_view;
@@ -2606,7 +2492,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 +2571,50 @@ 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;
+}
+
+gboolean
+nautilus_window_slot_get_active (NautilusWindowSlot *slot)
+{
+ g_return_val_if_fail (NAUTILUS_IS_WINDOW_SLOT (slot), FALSE);
+
+ return slot->details->active;
+}
+
+void
+nautilus_window_slot_set_active (NautilusWindowSlot *slot,
+ gboolean active)
+{
+ g_return_if_fail (NAUTILUS_IS_WINDOW_SLOT (slot));
+
+ if (slot->details->active != active) {
+ slot->details->active = active;
+
+ if (active) {
+ g_signal_emit (slot, signals[ACTIVE], 0);
+ } else {
+ g_signal_emit (slot, signals[INACTIVE], 0);
+ }
+
+ g_object_notify_by_pspec (G_OBJECT (slot), properties[PROP_ACTIVE]);
+ }
}
diff --git a/src/nautilus-window-slot.h b/src/nautilus-window-slot.h
index fc433ff..44ee0c5 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);
@@ -120,8 +119,6 @@ void nautilus_window_slot_go_home (NautilusWindowSlot *slot,
void nautilus_window_slot_go_up (NautilusWindowSlot *slot,
NautilusWindowOpenFlags flags);
-void nautilus_window_slot_sync_view_mode (NautilusWindowSlot *slot);
-
void nautilus_window_slot_display_view_selection_failure (NautilusWindow *window,
NautilusFile *file,
GFile *location,
@@ -131,4 +128,9 @@ GIcon* nautilus_window_slot_get_icon (NautilusWindowSlot *
GtkWidget* nautilus_window_slot_get_view_widget (NautilusWindowSlot *slot);
+gboolean nautilus_window_slot_get_active (NautilusWindowSlot *slot);
+
+void nautilus_window_slot_set_active (NautilusWindowSlot *slot,
+ gboolean active);
+
#endif /* NAUTILUS_WINDOW_SLOT_H */
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 4ccc96d..296ba53 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -2263,7 +2263,7 @@ nautilus_window_set_active_slot (NautilusWindow *window, NautilusWindowSlot *new
/* make old slot inactive if it exists (may be NULL after init, for example) */
if (old_slot != NULL) {
/* inform slot & view */
- g_signal_emit_by_name (old_slot, "inactive");
+ nautilus_window_slot_set_active (old_slot, FALSE);
}
window->priv->active_slot = new_slot;
@@ -2276,7 +2276,7 @@ nautilus_window_set_active_slot (NautilusWindow *window, NautilusWindowSlot *new
nautilus_toolbar_set_active_slot (NAUTILUS_TOOLBAR (window->priv->toolbar), new_slot);
/* inform slot & view */
- g_signal_emit_by_name (new_slot, "active");
+ nautilus_window_slot_set_active (new_slot, TRUE);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]