[nautilus/wip/csoriano/slot-cleanup: 2/2] slot: clean up
- From: Carlos Soriano Sánchez <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/csoriano/slot-cleanup: 2/2] slot: clean up
- Date: Tue, 25 Aug 2015 17:55:04 +0000 (UTC)
commit fb7f51f8657ef0ec872539cbe4007ded49478af1
Author: Carlos Soriano <csoriano gnome org>
Date: Tue Aug 25 19:54:11 2015 +0200
slot: clean up
src/nautilus-application.c | 119 ++++++++++++++++--
src/nautilus-window-slot.c | 308 +++++++++++++-------------------------------
src/nautilus-window-slot.h | 15 +--
src/nautilus-window.c | 143 ++++++++++----------
src/nautilus-window.h | 18 ++-
5 files changed, 286 insertions(+), 317 deletions(-)
---
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index 29bc259..5ec4734 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -39,6 +39,7 @@
#include "nautilus-progress-persistence-handler.h"
#include "nautilus-self-check-functions.h"
#include "nautilus-shell-search-provider.h"
+#include "nautilus-desktop-canvas-view.h"
#include "nautilus-window.h"
#include "nautilus-window-slot.h"
@@ -427,9 +428,13 @@ open_window (NautilusApplication *application,
window = nautilus_application_create_window (application, gdk_screen_get_default ());
if (location != NULL) {
- nautilus_window_go_to (window, location);
+ nautilus_window_open_location_full (window, location, 0, NULL, NULL);
} else {
- nautilus_window_slot_go_home (nautilus_window_get_active_slot (window), 0);
+ GFile *home;
+ home = g_file_new_for_path (g_get_home_dir ());
+ nautilus_window_open_location_full (window, home, 0, NULL, NULL);
+
+ g_object_unref (home);
}
nautilus_profile_end (NULL);
@@ -447,22 +452,20 @@ nautilus_application_open_location (NautilusApplication *application,
nautilus_profile_start (NULL);
+ if (selection != NULL) {
+ sel_list = g_list_prepend (sel_list, nautilus_file_get (selection));
+ }
+
slot = get_window_slot_for_location (application, location);
if (!slot) {
window = nautilus_application_create_window (application, gdk_screen_get_default ());
- slot = nautilus_window_get_active_slot (window);
} else {
window = nautilus_window_slot_get_window (slot);
- nautilus_window_set_active_slot (window, slot);
gtk_window_present (GTK_WINDOW (window));
}
- if (selection != NULL) {
- sel_list = g_list_prepend (sel_list, nautilus_file_get (selection));
- }
-
- nautilus_window_slot_open_location_full (slot, location, 0, sel_list, NULL, NULL);
+ nautilus_application_open_location_full (application, location, 0, sel_list, window, slot);
if (sel_list != NULL) {
nautilus_file_list_free (sel_list);
@@ -471,6 +474,104 @@ nautilus_application_open_location (NautilusApplication *application,
nautilus_profile_end (NULL);
}
+static void
+new_window_show_callback (GtkWidget *widget,
+ gpointer user_data){
+ NautilusWindow *window;
+
+ window = NAUTILUS_WINDOW (user_data);
+ nautilus_window_close (window);
+
+ g_signal_handlers_disconnect_by_func (widget,
+ G_CALLBACK (new_window_show_callback),
+ user_data);
+}
+
+void
+nautilus_application_open_location_full (NautilusApplication *application,
+ GFile *location,
+ NautilusWindowOpenFlags flags,
+ GList *selection,
+ NautilusWindow *target_window,
+ NautilusWindowSlot *target_slot)
+{
+ NautilusWindowSlot *active_slot;
+ NautilusWindow *active_window;
+ char *old_uri, *new_uri;
+ gboolean use_same;
+ gboolean is_desktop;
+ NautilusWindowOpenFlags slot_flags;
+
+ use_same = TRUE;
+ active_window = NAUTILUS_WINDOW (gtk_application_get_active_window (GTK_APPLICATION (application)));
+ active_slot = nautilus_window_get_active_slot (active_window);
+
+ /* this happens at startup */
+ old_uri = nautilus_window_slot_get_location_uri (active_slot);
+ if (old_uri == NULL) {
+ old_uri = g_strdup ("(none)");
+ use_same = TRUE;
+ }
+ new_uri = g_file_get_uri (location);
+
+ DEBUG ("Opening location, old: %s, new: %s", old_uri, new_uri);
+ nautilus_profile_start ("Opening location, old: %s, new: %s", old_uri, new_uri);
+
+ g_free (old_uri);
+ g_free (new_uri);
+
+ if ((target_window && NAUTILUS_IS_DESKTOP_CANVAS_VIEW (target_window)) ||
+ (!target_window && NAUTILUS_IS_DESKTOP_CANVAS_VIEW (active_window))) {
+ NautilusWindow *desktop_target_window;
+
+ desktop_target_window = target_window ? target_window : active_window;
+ use_same = !nautilus_desktop_window_loaded (NAUTILUS_DESKTOP_WINDOW (desktop_target_window));
+
+ /* if we're requested to open a new tab on the desktop, open a window
+ * instead.
+ */
+ if (flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) {
+ flags ^= NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB;
+ flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW;
+ }
+ }
+
+ g_assert (!((flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW) != 0 &&
+ (flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) != 0));
+
+ /* and if the flags specify so, this is overridden */
+ if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW) != 0) {
+ use_same = FALSE;
+ }
+
+ /* now get/create the window */
+ if (use_same) {
+ target_window = active_window;
+ } else {
+ target_window = nautilus_application_create_window (application,
+ gtk_window_get_screen (GTK_WINDOW
(active_window)));
+ }
+
+ g_assert (target_window != NULL);
+
+ /* close the current window if the flags say so */
+ if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND) != 0) {
+ if (!is_desktop) {
+ if (gtk_widget_get_visible (GTK_WIDGET (target_window))) {
+ nautilus_window_close (active_window);
+ } else {
+ g_signal_connect_object (target_window,
+ "show",
+ G_CALLBACK (new_window_show_callback),
+ active_window,
+ G_CONNECT_AFTER);
+ }
+ }
+ }
+
+}
+
+
/* Note: when launched from command line we do not reach this method
* since we manually handle the command line parameters in order to
* parse --no-default-window, etc.
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index a47a178..61d08cd 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -62,6 +62,7 @@ enum {
PROP_WINDOW,
PROP_ICON,
PROP_VIEW_WIDGET,
+ PROP_LOADING,
NUM_PROPERTIES
};
@@ -69,6 +70,7 @@ struct NautilusWindowSlotDetails {
NautilusWindow *window;
gboolean active : 1;
+ guint loading : 1;
/* slot contains
* 1) an vbox containing extra_location_widgets
@@ -123,8 +125,6 @@ struct NautilusWindowSlotDetails {
GCancellable *mount_cancellable;
GError *mount_error;
gboolean tried_mount;
- NautilusWindowGoToCallback open_callback;
- gpointer open_callback_user_data;
gchar *view_mode_before_search;
gchar *view_mode_before_places;
};
@@ -142,6 +142,7 @@ static void nautilus_window_slot_emit_location_change (NautilusWindowSlot *slot,
static gboolean nautilus_window_slot_content_view_matches (NautilusWindowSlot *slot, const char *iid);
static NautilusView* nautilus_window_slot_get_view_for_location (NautilusWindowSlot *slot, GFile *location);
static void nautilus_window_slot_set_content_view (NautilusWindowSlot *slot, const char *id);
+static void nautilus_window_slot_set_loading (NautilusWindowSlot *slot, gboolean loading);
static NautilusView*
nautilus_window_slot_get_view_for_location (NautilusWindowSlot *slot,
@@ -315,7 +316,7 @@ query_editor_changed_callback (NautilusQueryEditor *editor,
view = nautilus_window_slot_get_current_view (slot);
nautilus_view_set_search_query (view, query);
- nautilus_window_slot_open_location (slot, nautilus_view_get_location (view), 0);
+ nautilus_window_slot_open_location_full (slot, nautilus_view_get_location (view), 0, NULL);
}
static void
@@ -350,9 +351,7 @@ hide_query_editor (NautilusWindowSlot *slot)
nautilus_window_slot_open_location_full (slot,
nautilus_view_get_location (view),
0,
- selection,
- NULL,
- NULL);
+ selection);
nautilus_file_list_free (selection);
}
@@ -559,6 +558,9 @@ nautilus_window_slot_get_property (GObject *object,
case PROP_VIEW_WIDGET:
g_value_set_object (value, nautilus_window_slot_get_view_widget (slot));
break;
+ case PROP_LOADING:
+ g_value_set_boolean (value, nautilus_window_slot_get_loading (slot));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -692,196 +694,58 @@ nautilus_window_slot_init (NautilusWindowSlot *slot)
#define MAX_URI_IN_DIALOG_LENGTH 60
static void begin_location_change (NautilusWindowSlot *slot,
- GFile *location,
- GFile *previous_location,
- GList *new_selection,
- NautilusLocationChangeType type,
- guint distance,
- const char *scroll_pos,
- NautilusWindowGoToCallback callback,
- gpointer user_data);
+ GFile *location,
+ GFile *previous_location,
+ GList *new_selection,
+ NautilusLocationChangeType type,
+ guint distance,
+ const char *scroll_pos);
static void free_location_change (NautilusWindowSlot *slot);
static void end_location_change (NautilusWindowSlot *slot);
static void cancel_location_change (NautilusWindowSlot *slot);
static void got_file_info_for_view_selection_callback (NautilusFile *file,
gpointer callback_data);
-static gboolean setup_view (NautilusWindowSlot *slot,
- NautilusView *view,
- GError **error);
+static gboolean setup_view (NautilusWindowSlot *slot,
+ NautilusView *view);
static void load_new_location (NautilusWindowSlot *slot,
GFile *location,
GList *selection,
gboolean tell_current_content_view,
gboolean tell_new_content_view);
-static void
-new_window_show_callback (GtkWidget *widget,
- gpointer user_data){
- NautilusWindow *window;
-
- window = NAUTILUS_WINDOW (user_data);
- nautilus_window_close (window);
-
- g_signal_handlers_disconnect_by_func (widget,
- G_CALLBACK (new_window_show_callback),
- user_data);
-}
-
void
-nautilus_window_slot_open_location_full (NautilusWindowSlot *slot,
- GFile *location,
- NautilusWindowOpenFlags flags,
- GList *new_selection,
- NautilusWindowGoToCallback callback,
- gpointer user_data)
+nautilus_window_slot_open_location_full (NautilusWindowSlot *slot,
+ GFile *location,
+ NautilusWindowOpenFlags flags,
+ GList *new_selection)
{
- NautilusWindow *window;
- NautilusWindow *target_window;
- NautilusWindowSlot *target_slot;
- NautilusWindowOpenFlags slot_flags;
GFile *old_location;
GList *old_selection;
- char *old_uri, *new_uri;
- int new_slot_position;
- gboolean use_same;
- gboolean is_desktop;
-
- window = nautilus_window_slot_get_window (slot);
-
- target_window = NULL;
- target_slot = NULL;
- use_same = TRUE;
-
- /* this happens at startup */
- old_uri = nautilus_window_slot_get_location_uri (slot);
- if (old_uri == NULL) {
- old_uri = g_strdup ("(none)");
- use_same = TRUE;
- }
- new_uri = g_file_get_uri (location);
-
- DEBUG ("Opening location, old: %s, new: %s", old_uri, new_uri);
- nautilus_profile_start ("Opening location, old: %s, new: %s", old_uri, new_uri);
-
- g_free (old_uri);
- g_free (new_uri);
-
- is_desktop = NAUTILUS_IS_DESKTOP_WINDOW (window);
-
- if (is_desktop) {
- use_same = !nautilus_desktop_window_loaded (NAUTILUS_DESKTOP_WINDOW (window));
-
- /* if we're requested to open a new tab on the desktop, open a window
- * instead.
- */
- if (flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) {
- flags ^= NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB;
- flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW;
- }
- }
-
- g_assert (!((flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW) != 0 &&
- (flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) != 0));
-
- /* and if the flags specify so, this is overridden */
- if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW) != 0) {
- use_same = FALSE;
- }
-
- old_location = nautilus_window_slot_get_location (slot);
-
- /* now get/create the window */
- if (use_same) {
- target_window = window;
- } else {
- target_window = nautilus_application_create_window
- (NAUTILUS_APPLICATION (g_application_get_default ()),
- gtk_window_get_screen (GTK_WINDOW (window)));
- }
-
- g_assert (target_window != NULL);
-
- /* if the flags say we want a new tab, open a slot in the current window */
- if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) != 0) {
- g_assert (target_window == window);
-
- slot_flags = 0;
-
- new_slot_position = g_settings_get_enum (nautilus_preferences,
NAUTILUS_PREFERENCES_NEW_TAB_POSITION);
- if (new_slot_position == NAUTILUS_NEW_TAB_POSITION_END) {
- slot_flags = NAUTILUS_WINDOW_OPEN_SLOT_APPEND;
- }
-
- target_slot = nautilus_window_open_slot (window,
- slot_flags);
- }
-
- /* close the current window if the flags say so */
- if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND) != 0) {
- if (!is_desktop) {
- if (gtk_widget_get_visible (GTK_WIDGET (target_window))) {
- nautilus_window_close (window);
- } else {
- g_signal_connect_object (target_window,
- "show",
- G_CALLBACK (new_window_show_callback),
- window,
- G_CONNECT_AFTER);
- }
- }
- }
-
- if (target_slot == NULL) {
- if (target_window == window) {
- target_slot = slot;
- } else {
- target_slot = nautilus_window_get_active_slot (target_window);
- }
- }
+ NautilusWindow *window;
+ gboolean is_desktop;
old_selection = NULL;
+ old_location = nautilus_window_slot_get_location (slot);
+ window = nautilus_window_slot_get_window (slot);
+ is_desktop = NAUTILUS_IS_DESKTOP_CANVAS_VIEW (window);
+
if (slot->details->content_view) {
old_selection = nautilus_view_get_selection (slot->details->content_view);
}
-
- if (target_window == window && target_slot == slot && !is_desktop &&
- old_location && g_file_equal (old_location, location) &&
- nautilus_file_selection_equal (old_selection, new_selection)) {
-
- if (callback != NULL) {
- callback (window, location, NULL, user_data);
- }
-
- goto done;
- }
+ if (!is_desktop &&
+ old_location && g_file_equal (old_location, location) &&
+ nautilus_file_selection_equal (old_selection, new_selection))
+ goto done;
slot->details->pending_use_default_location = ((flags &
NAUTILUS_WINDOW_OPEN_FLAG_USE_DEFAULT_LOCATION) != 0);
- begin_location_change (target_slot, location, old_location, new_selection,
- NAUTILUS_LOCATION_CHANGE_STANDARD, 0, NULL, callback, user_data);
+ begin_location_change (slot, location, old_location, new_selection,
+ NAUTILUS_LOCATION_CHANGE_STANDARD, 0, NULL);
done:
nautilus_file_list_free (old_selection);
nautilus_profile_end (NULL);
}
-static gboolean
-report_callback (NautilusWindowSlot *slot,
- GError *error)
-{
- if (slot->details->open_callback != NULL) {
- gboolean res;
- res = slot->details->open_callback (nautilus_window_slot_get_window (slot),
- slot->details->pending_location,
- error, slot->details->open_callback_user_data);
- slot->details->open_callback = NULL;
- slot->details->open_callback_user_data = NULL;
-
- return res;
- }
-
- return FALSE;
-}
-
/*
* begin_location_change
*
@@ -894,22 +758,18 @@ report_callback (NautilusWindowSlot *slot,
* @distance: If type is back or forward, the index into the back or forward chain. If
* type is standard or reload, this is ignored, and must be 0.
* @scroll_pos: The file to scroll to when the location is loaded.
- * @callback: function to be called when the location is changed.
- * @user_data: data for @callback.
*
* This is the core function for changing the location of a window. Every change to the
* location begins here.
*/
static void
-begin_location_change (NautilusWindowSlot *slot,
- GFile *location,
- GFile *previous_location,
- GList *new_selection,
- NautilusLocationChangeType type,
- guint distance,
- const char *scroll_pos,
- NautilusWindowGoToCallback callback,
- gpointer user_data)
+begin_location_change (NautilusWindowSlot *slot,
+ GFile *location,
+ GFile *previous_location,
+ GList *new_selection,
+ NautilusLocationChangeType type,
+ guint distance,
+ const char *scroll_pos)
{
NautilusDirectory *directory;
NautilusFile *file;
@@ -971,9 +831,6 @@ begin_location_change (NautilusWindowSlot *slot,
slot->details->pending_scroll_to = g_strdup (scroll_pos);
- slot->details->open_callback = callback;
- slot->details->open_callback_user_data = user_data;
-
/* The code to force a reload is here because if we do it
* after determining an initial view (in the components), then
* we end up fetching things twice.
@@ -1309,23 +1166,16 @@ got_file_info_for_view_selection_callback (NautilusFile *file,
}
if (view != NULL) {
- GError *err = NULL;
-
- setup_view (slot, view, &err);
-
- report_callback (slot, err);
- g_clear_error (&err);
+ setup_view (slot, view);
} else {
if (error == NULL) {
error = g_error_new (G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
_("Unable to load location"));
}
- if (!report_callback (slot, error)) {
- nautilus_window_slot_display_view_selection_failure (window,
- file,
- location,
- error);
- }
+ nautilus_window_slot_display_view_selection_failure (window,
+ file,
+ location,
+ error);
if (!gtk_widget_get_visible (GTK_WIDGET (window))) {
/* Destroy never-had-a-chance-to-be-seen window. This case
@@ -1348,7 +1198,7 @@ got_file_info_for_view_selection_callback (NautilusFile *file,
root = g_file_new_for_path ("/");
/* the last fallback is to go to a known place that can't be
deleted! */
- nautilus_window_slot_open_location (slot, location, 0);
+ nautilus_window_slot_open_location_full (slot, location, 0,
NULL);
g_object_unref (root);
}
} else {
@@ -1399,12 +1249,10 @@ got_file_info_for_view_selection_callback (NautilusFile *file,
* view, and the current location will be used.
*/
static gboolean
-setup_view (NautilusWindowSlot *slot,
- NautilusView *view,
- GError **error_out)
+setup_view (NautilusWindowSlot *slot,
+ NautilusView *view)
{
gboolean ret = TRUE;
- GError *error = NULL;
GFile *old_location;
nautilus_profile_start (NULL);
@@ -1440,20 +1288,14 @@ setup_view (NautilusWindowSlot *slot,
TRUE);
g_list_free_full (selection, g_object_unref);
} else {
- /* Something is busted, there was no location to load. */
- ret = FALSE;
- error = g_error_new (G_IO_ERROR,
- G_IO_ERROR_NOT_FOUND,
- _("Unable to load location"));
- }
-
- if (error != NULL) {
- g_propagate_error (error_out, error);
- } else {
- change_view (slot);
- gtk_widget_show (GTK_WIDGET (slot->details->window));
+ ret = FALSE;
+ goto out;
}
+ change_view (slot);
+ gtk_widget_show (GTK_WIDGET (slot->details->window));
+
+out:
nautilus_profile_end (NULL);
return ret;
@@ -1685,7 +1527,7 @@ nautilus_window_slot_set_content_view (NautilusWindowSlot *slot,
slot->details->location_change_type = NAUTILUS_LOCATION_CHANGE_RELOAD;
- if (!setup_view (slot, NAUTILUS_VIEW (view), NULL)) {
+ if (!setup_view (slot, NAUTILUS_VIEW (view))) {
/* Just load the homedir. */
nautilus_window_slot_go_home (slot, FALSE);
}
@@ -1722,7 +1564,7 @@ nautilus_window_back_or_forward (NautilusWindow *window,
location = nautilus_bookmark_get_location (bookmark);
if (flags != 0) {
- nautilus_window_slot_open_location (slot, location, flags);
+ nautilus_window_slot_open_location_full (slot, location, flags, NULL);
} else {
char *scroll_pos;
@@ -1733,8 +1575,7 @@ nautilus_window_back_or_forward (NautilusWindow *window,
location, old_location, NULL,
back ? NAUTILUS_LOCATION_CHANGE_BACK : NAUTILUS_LOCATION_CHANGE_FORWARD,
distance,
- scroll_pos,
- NULL, NULL);
+ scroll_pos);
g_free (scroll_pos);
}
@@ -1772,8 +1613,7 @@ nautilus_window_slot_force_reload (NautilusWindowSlot *slot)
}
begin_location_change
(slot, location, location, selection,
- NAUTILUS_LOCATION_CHANGE_RELOAD, 0, current_pos,
- NULL, NULL);
+ NAUTILUS_LOCATION_CHANGE_RELOAD, 0, current_pos);
g_free (current_pos);
g_object_unref (location);
g_list_free_full (selection, g_object_unref);
@@ -2152,6 +1992,8 @@ view_started_loading (NautilusWindowSlot *slot,
gtk_widget_grab_focus (GTK_WIDGET (slot->details->window));
gtk_widget_show (GTK_WIDGET (slot->details->window));
+
+ nautilus_window_slot_set_loading (slot, TRUE);
}
static void
@@ -2172,6 +2014,8 @@ view_ended_loading (NautilusWindowSlot *slot,
}
nautilus_window_slot_set_allow_stop (slot, FALSE);
+
+ nautilus_window_slot_set_loading (slot, FALSE);
}
static void
@@ -2466,6 +2310,7 @@ nautilus_window_slot_class_init (NautilusWindowSlotClass *klass)
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
+
signals[LOCATION_CHANGED] =
g_signal_new ("location-changed",
G_TYPE_FROM_CLASS (klass),
@@ -2483,6 +2328,12 @@ nautilus_window_slot_class_init (NautilusWindowSlotClass *klass)
"Whether the slot is the active slot of the window",
FALSE,
G_PARAM_READWRITE);
+ properties[PROP_LOADING] =
+ g_param_spec_boolean ("loading",
+ "Whether the slot loading",
+ "Whether the slot is loading a new location",
+ FALSE,
+ G_PARAM_READABLE);
properties[PROP_WINDOW] =
g_param_spec_object ("window",
@@ -2659,7 +2510,7 @@ nautilus_window_slot_go_home (NautilusWindowSlot *slot,
g_return_if_fail (NAUTILUS_IS_WINDOW_SLOT (slot));
home = g_file_new_for_path (g_get_home_dir ());
- nautilus_window_slot_open_location (slot, home, flags);
+ nautilus_window_slot_open_location_full (slot, home, flags, NULL);
g_object_unref (home);
}
@@ -2678,7 +2529,7 @@ nautilus_window_slot_go_up (NautilusWindowSlot *slot,
return;
}
- nautilus_window_slot_open_location (slot, parent, flags);
+ nautilus_window_slot_open_location_full (slot, parent, flags, NULL);
g_object_unref (parent);
}
@@ -2764,3 +2615,22 @@ nautilus_window_slot_set_active (NautilusWindowSlot *slot,
g_object_notify_by_pspec (G_OBJECT (slot), properties[PROP_ACTIVE]);
}
}
+
+static void
+nautilus_window_slot_set_loading (NautilusWindowSlot *slot,
+ gboolean loading)
+{
+ g_return_if_fail (NAUTILUS_IS_WINDOW_SLOT (slot));
+
+ slot->details->loading = loading;
+
+ g_object_notify_by_pspec (G_OBJECT (slot), properties[PROP_LOADING]);
+}
+
+gboolean
+nautilus_window_slot_get_loading (NautilusWindowSlot *slot)
+{
+ g_return_val_if_fail (NAUTILUS_IS_WINDOW_SLOT (slot), FALSE);
+
+ return slot->details->loading;
+}
diff --git a/src/nautilus-window-slot.h b/src/nautilus-window-slot.h
index 238d926..f3da7bd 100644
--- a/src/nautilus-window-slot.h
+++ b/src/nautilus-window-slot.h
@@ -72,16 +72,10 @@ NautilusWindow * nautilus_window_slot_get_window (NautilusWindowSlot *
void nautilus_window_slot_set_window (NautilusWindowSlot *slot,
NautilusWindow *window);
-/* convenience wrapper without selection and callback/user_data */
-#define nautilus_window_slot_open_location(slot, location, flags)\
- nautilus_window_slot_open_location_full(slot, location, flags, NULL, NULL, NULL)
-
-void nautilus_window_slot_open_location_full (NautilusWindowSlot *slot,
- GFile *location,
- NautilusWindowOpenFlags flags,
- GList *new_selection,
- NautilusWindowGoToCallback callback,
- gpointer user_data);
+void nautilus_window_slot_open_location_full (NautilusWindowSlot *slot,
+ GFile *location,
+ NautilusWindowOpenFlags flags,
+ GList *new_selection);
GFile * nautilus_window_slot_get_location (NautilusWindowSlot *slot);
char * nautilus_window_slot_get_location_uri (NautilusWindowSlot *slot);
@@ -129,5 +123,6 @@ gboolean nautilus_window_slot_get_active (NautilusWindowSlot *
void nautilus_window_slot_set_active (NautilusWindowSlot *slot,
gboolean active);
+gboolean nautilus_window_slot_get_loading (NautilusWindowSlot *slot);
#endif /* NAUTILUS_WINDOW_SLOT_H */
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 50db396..f9a6716 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -82,6 +82,7 @@ static void mouse_forward_button_changed (gpointer callbac
static void use_extra_mouse_buttons_changed (gpointer callback_data);
static void nautilus_window_initialize_actions (NautilusWindow *window);
static GtkWidget * nautilus_window_ensure_location_entry (NautilusWindow *window);
+static void nautilus_window_report_location_change (NautilusWindow *window);
/* Sanity check: highest mouse button value I could find was 14. 5 is our
* lower threshold (well-documented to be the one of the button events for the
@@ -470,13 +471,51 @@ undo_manager_changed (NautilusWindow *window)
g_free (redo_description);
}
+static void
+on_location_changed (NautilusWindow *window)
+{
+
+ nautilus_window_report_location_change (window);
+ gtk_places_sidebar_set_location (GTK_PLACES_SIDEBAR (window->priv->places_sidebar),
+ nautilus_window_slot_get_location (nautilus_window_get_active_slot
(window)));
+}
+
+static void
+on_slot_loading_changed (NautilusWindowSlot *slot,
+ NautilusWindow *window)
+{
+ if (nautilus_window_get_active_slot (window) == slot)
+ on_location_changed (window);
+}
+
void
-nautilus_window_go_to (NautilusWindow *window, GFile *location)
+nautilus_window_open_location_full (NautilusWindow *window,
+ GFile *location,
+ NautilusWindowOpenFlags flags,
+ GList *selection,
+ NautilusWindowSlot *target_slot)
{
- g_return_if_fail (NAUTILUS_IS_WINDOW (window));
+ NautilusWindowSlot *active_slot;
+ NautilusWindowOpenFlags flags_with_preferences;
+ gboolean new_tab_at_end;
+
+ active_slot = nautilus_window_get_active_slot (window);
+
+ /* if the flags say we want a new tab, open a slot in the current window */
+ if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) != 0) {
+ new_tab_at_end = g_settings_get_enum (nautilus_preferences,
NAUTILUS_PREFERENCES_NEW_TAB_POSITION) == NAUTILUS_NEW_TAB_POSITION_END
+ if (new_tab_at_end)
+ flags = flags & NAUTILUS_WINDOW_OPEN_SLOT_APPEND;
- nautilus_window_slot_open_location (nautilus_window_get_active_slot (window),
- location, 0);
+ target_slot = nautilus_window_open_slot (window, flags);
+ }
+
+ if (target_slot == NULL) {
+ target_slot = active_slot;
+ }
+
+ nautilus_window_set_active_slot (window, target_slot);
+ nautilus_window_slot_open_location_full (target_slot, location, flags, selection);
}
static int
@@ -569,7 +608,7 @@ location_entry_location_changed_callback (GtkWidget *widget,
restore_focus_widget (window);
- nautilus_window_slot_open_location (window->priv->active_slot, location, 0);
+ nautilus_window_open_location_full (window, location, 0, NULL, NULL);
}
static void
@@ -593,6 +632,21 @@ notebook_switch_page_cb (GtkNotebook *notebook,
}
static void
+connect_slot (NautilusWindow *window,
+ NautilusWindowSlot *slot)
+{
+ g_signal_connect (slot, "notify::loading",
+ G_CALLBACK (on_slot_loading_changed), window);
+}
+
+static void
+disconnect_slot (NautilusWindow *window,
+ NautilusWindowSlot *slot)
+{
+ g_signal_handlers_disconnect_by_data (slot, window);
+}
+
+static void
close_slot (NautilusWindow *window,
NautilusWindowSlot *slot,
gboolean remove_from_notebook)
@@ -604,6 +658,8 @@ close_slot (NautilusWindow *window,
DEBUG ("Closing slot %p", slot);
+ disconnect_slot (window, slot);
+
window->priv->slots = g_list_remove (window->priv->slots, slot);
g_signal_emit (window, signals[SLOT_REMOVED], 0, slot);
@@ -621,13 +677,14 @@ close_slot (NautilusWindow *window,
NautilusWindowSlot *
nautilus_window_open_slot (NautilusWindow *window,
- NautilusWindowOpenSlotFlags flags)
+ NautilusWindowOpenFlags flags)
{
NautilusWindowSlot *slot;
g_assert (NAUTILUS_IS_WINDOW (window));
slot = nautilus_window_slot_new (window);
+ connect_slot (window, slot);
g_signal_handlers_block_by_func (window->priv->notebook,
G_CALLBACK (notebook_switch_page_cb),
@@ -655,19 +712,13 @@ nautilus_window_new_tab (NautilusWindow *window)
NautilusWindowSlot *new_slot;
NautilusWindowOpenFlags flags;
GFile *location;
- int new_slot_position;
char *scheme;
current_slot = nautilus_window_get_active_slot (window);
location = nautilus_window_slot_get_location (current_slot);
if (location != NULL) {
- flags = 0;
-
- new_slot_position = g_settings_get_enum (nautilus_preferences,
NAUTILUS_PREFERENCES_NEW_TAB_POSITION);
- if (new_slot_position == NAUTILUS_NEW_TAB_POSITION_END) {
- flags = NAUTILUS_WINDOW_OPEN_SLOT_APPEND;
- }
+ flags = g_settings_get_enum (nautilus_preferences, NAUTILUS_PREFERENCES_NEW_TAB_POSITION);
scheme = g_file_get_uri_scheme (location);
if (strcmp (scheme, "x-nautilus-search") == 0) {
@@ -680,7 +731,7 @@ nautilus_window_new_tab (NautilusWindow *window)
new_slot = nautilus_window_open_slot (window, flags);
nautilus_window_set_active_slot (window, new_slot);
- nautilus_window_slot_open_location (new_slot, location, 0);
+ nautilus_window_open_location_full (window, location, 0, NULL, new_slot);
g_object_unref (location);
}
}
@@ -845,34 +896,6 @@ setup_side_pane_width (NautilusWindow *window)
window->priv->side_pane_width);
}
-static void
-nautilus_window_location_opened (NautilusWindow *window,
- GFile *location,
- GError *error,
- gpointer user_data)
-{
- g_return_if_fail (NAUTILUS_IS_WINDOW (window));
-
- if (error) {
- NautilusFile *old_file;
- GFile *old_location;
-
- old_file = nautilus_window_slot_get_file (window->priv->active_slot);
- old_location = nautilus_file_get_location (old_file);
-
- gtk_places_sidebar_set_location (GTK_PLACES_SIDEBAR (window->priv->places_sidebar),
old_location);
-
- g_warning ("error opening location: %s", error->message);
-
- nautilus_window_slot_display_view_selection_failure (window,
- old_file,
- location,
- error);
-
- g_object_unref (old_location);
- }
-}
-
/* Callback used when the places sidebar changes location; we need to change the displayed folder */
static void
open_location_cb (NautilusWindow *window,
@@ -896,12 +919,7 @@ open_location_cb (NautilusWindow *window,
break;
}
- nautilus_window_slot_open_location_full (window->priv->active_slot,
- location,
- flags,
- NULL,
- (NautilusWindowGoToCallback)
nautilus_window_location_opened,
- NULL);
+ nautilus_window_open_location_full (window, location, flags, NULL, NULL);
}
/* Callback used when the places sidebar needs us to present an error message */
@@ -1023,21 +1041,6 @@ places_sidebar_drag_perform_drop_cb (GtkPlacesSidebar *sidebar,
g_list_free_full (source_uri_list, g_free);
}
-/* Callback for our own loading_uri signal. We update the sidebar's path. */
-static void
-window_loading_uri_cb (NautilusWindow *window,
- char *location,
- gpointer user_data)
-{
- if (window->priv->places_sidebar) {
- GFile *file;
-
- file = g_file_new_for_uri (location);
- gtk_places_sidebar_set_location (GTK_PLACES_SIDEBAR (window->priv->places_sidebar), file);
- g_object_unref (file);
- }
-}
-
/* Callback used in the "empty trash" menu item from the places sidebar */
static void
action_empty_trash (GSimpleAction *action,
@@ -1226,9 +1229,6 @@ nautilus_window_set_up_sidebar (NautilusWindow *window)
G_CALLBACK (places_sidebar_drag_perform_drop_cb), window);
g_signal_connect (window->priv->places_sidebar, "populate-popup",
G_CALLBACK (places_sidebar_populate_popup_cb), window);
-
- g_signal_connect (window, "loading-uri",
- G_CALLBACK (window_loading_uri_cb), window);
}
void
@@ -1502,9 +1502,11 @@ static void
on_notification_operation_open_clicked (GtkWidget *notification,
NautilusWindow *window)
{
- nautilus_window_slot_open_location (window->priv->active_slot,
+ nautilus_window_open_location_full (window,
window->priv->folder_to_open,
- 0);
+ 0,
+ NULL,
+ NULL);
hide_notification_operation (window);
}
@@ -1576,7 +1578,7 @@ path_bar_location_changed_callback (GtkWidget *widget,
if (i >= 0) {
nautilus_window_back_or_forward (window, TRUE, i, 0);
} else {
- nautilus_window_slot_open_location (slot, location, 0);
+ nautilus_window_open_location_full (window, location, 0, NULL, NULL);
}
}
@@ -2204,8 +2206,7 @@ nautilus_window_set_active_slot (NautilusWindow *window, NautilusWindowSlot *new
/* make new slot active, if it exists */
if (new_slot) {
- /* inform sidebar panels */
- nautilus_window_report_location_change (window);
+ on_location_changed (window);
nautilus_toolbar_set_active_slot (NAUTILUS_TOOLBAR (window->priv->toolbar), new_slot);
diff --git a/src/nautilus-window.h b/src/nautilus-window.h
index 2bffe05..aa1c3ab 100644
--- a/src/nautilus-window.h
+++ b/src/nautilus-window.h
@@ -41,14 +41,10 @@ typedef enum {
NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND = 1 << 0,
NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW = 1 << 1,
NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB = 1 << 2,
- NAUTILUS_WINDOW_OPEN_FLAG_USE_DEFAULT_LOCATION = 1 << 3
+ NAUTILUS_WINDOW_OPEN_SLOT_APPEND = 1 << 3,
+ NAUTILUS_WINDOW_OPEN_FLAG_USE_DEFAULT_LOCATION = 1 << 4
} NautilusWindowOpenFlags;
-typedef enum {
- NAUTILUS_WINDOW_OPEN_SLOT_NONE = 0,
- NAUTILUS_WINDOW_OPEN_SLOT_APPEND = 1
-} NautilusWindowOpenSlotFlags;
-
typedef gboolean (* NautilusWindowGoToCallback) (NautilusWindow *window,
GFile *location,
GError *error,
@@ -105,16 +101,22 @@ GType nautilus_window_get_type (void);
NautilusWindow * nautilus_window_new (GdkScreen *screen);
void nautilus_window_close (NautilusWindow *window);
+void nautilus_window_open_location_full (NautilusWindow *window,
+ GFile *location,
+ NautilusWindowOpenFlags flags,
+ GList *selection,
+ NautilusWindowSlot *target_slot);
void nautilus_window_go_to (NautilusWindow *window,
- GFile *location);
+ GFile *location,
+ NautilusWindowOpenFlags flags);
void nautilus_window_new_tab (NautilusWindow *window);
NautilusWindowSlot * nautilus_window_get_active_slot (NautilusWindow *window);
void nautilus_window_set_active_slot (NautilusWindow *window,
NautilusWindowSlot *slot);
GList * nautilus_window_get_slots (NautilusWindow *window);
NautilusWindowSlot * nautilus_window_open_slot (NautilusWindow *window,
- NautilusWindowOpenSlotFlags flags);
+ NautilusWindowOpenFlags flags);
void nautilus_window_slot_close (NautilusWindow *window,
NautilusWindowSlot *slot);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]