diff options
author | Jasmine Hassan <[email protected]> | 2012-10-19 00:19:18 +0200 |
---|---|---|
committer | Jasmine Hassan <[email protected]> | 2012-11-16 09:45:50 +0200 |
commit | 11c358d779c6c0913cf9d784a8adbb663c6b8bd9 (patch) | |
tree | e110420b2b5a74abf41a6ec5a2df699d76363150 | |
parent | 662d2326c5ce63c867b3d94fb2bb44d9a244399b (diff) | |
download | caja-11c358d779c6c0913cf9d784a8adbb663c6b8bd9.tar.bz2 caja-11c358d779c6c0913cf9d784a8adbb663c6b8bd9.tar.xz |
[window] rewrite window-opening policies
The code there was very hackish and convoluted. Rewrite it to make
it at least cleaner. This will allow further cleanup later.
http://git.gnome.org/browse/nautilus/commit/?id=54e0a1f21513babc89f980b5b02af2bf7a6ebe85
-rw-r--r-- | src/caja-window-manage-views.c | 144 |
1 files changed, 74 insertions, 70 deletions
diff --git a/src/caja-window-manage-views.c b/src/caja-window-manage-views.c index e34fc232..89722d04 100644 --- a/src/caja-window-manage-views.c +++ b/src/caja-window-manage-views.c @@ -511,23 +511,28 @@ caja_window_slot_open_location_full (CajaWindowSlot *slot, GFile *location, CajaWindowOpenMode mode, CajaWindowOpenFlags flags, - GList *new_selection) + GList *new_selection, + CajaWindowGoToCallback callback, + gpointer user_data) { CajaWindow *window; CajaWindow *target_window; CajaWindowPane *pane; CajaWindowSlot *target_slot; CajaWindowOpenFlags slot_flags; - gboolean do_load_location = TRUE; + gboolean existing = FALSE; GFile *old_location; char *old_uri, *new_uri; int new_slot_position; GList *l; + gboolean target_spatial, target_navigation, target_same; + gboolean is_desktop; window = slot->pane->window; target_window = NULL; target_slot = NULL; + target_spatial = target_navigation = target_same = FALSE; old_uri = caja_window_slot_get_location_uri (slot); if (old_uri == NULL) @@ -546,87 +551,86 @@ caja_window_slot_open_location_full (CajaWindowSlot *slot, g_assert (!((flags & CAJA_WINDOW_OPEN_FLAG_NEW_WINDOW) != 0 && (flags & CAJA_WINDOW_OPEN_FLAG_NEW_TAB) != 0)); + is_desktop = CAJA_IS_DESKTOP_WINDOW (window); + target_same = is_desktop && + !caja_desktop_window_loaded (CAJA_DESKTOP_WINDOW (window)); old_location = caja_window_slot_get_location (slot); + switch (mode) { case CAJA_WINDOW_OPEN_ACCORDING_TO_MODE : - if (g_settings_get_boolean (caja_preferences, CAJA_PREFERENCES_ALWAYS_USE_BROWSER)) - { - target_window = window; - if (CAJA_IS_SPATIAL_WINDOW (window)) - { - if (!CAJA_SPATIAL_WINDOW (window)->affect_spatial_window_on_next_location_change) - { - target_window = caja_application_create_navigation_window - (window->application, - NULL, - gtk_window_get_screen (GTK_WINDOW (window))); - } - else - { - CAJA_SPATIAL_WINDOW (window)->affect_spatial_window_on_next_location_change = FALSE; - } - } - else if ((flags & CAJA_WINDOW_OPEN_FLAG_NEW_WINDOW) != 0) - { - target_window = caja_application_create_navigation_window - (window->application, - NULL, - gtk_window_get_screen (GTK_WINDOW (window))); + if (g_settings_get_boolean (caja_preferences, CAJA_PREFERENCES_ALWAYS_USE_BROWSER)) { + /* always use browser: if we're on the desktop the target is a new navigation window, + * otherwise it's the same window. + */ + if (is_desktop) { + target_navigation = TRUE; + } else { + target_same = TRUE; } } else if (CAJA_IS_SPATIAL_WINDOW (window)) { - if (!CAJA_SPATIAL_WINDOW (window)->affect_spatial_window_on_next_location_change) - { - target_window = caja_application_present_spatial_window_with_selection ( - window->application, - window, - NULL, - location, - new_selection, - gtk_window_get_screen (GTK_WINDOW (window))); - do_load_location = FALSE; - } - else - { - CAJA_SPATIAL_WINDOW (window)->affect_spatial_window_on_next_location_change = FALSE; - target_window = window; - } - } - else if (flags & CAJA_WINDOW_OPEN_FLAG_NEW_WINDOW) - { - target_window = caja_application_create_navigation_window - (window->application, - NULL, - gtk_window_get_screen (GTK_WINDOW (window))); - } - else - { - target_window = window; + /* don't always use browser: if source is spatial, target is spatial */ + target_spatial = TRUE; + } else if (flags & CAJA_WINDOW_OPEN_FLAG_NEW_WINDOW) { + /* if it's specified to open a new window, and we're not using spatial, + * the target is a navigation. + */ + target_navigation = TRUE; } break; case CAJA_WINDOW_OPEN_IN_SPATIAL : - target_window = caja_application_present_spatial_window ( - window->application, - window, - NULL, - location, - gtk_window_get_screen (GTK_WINDOW (window))); + target_spatial = TRUE; break; case CAJA_WINDOW_OPEN_IN_NAVIGATION : - target_window = caja_application_create_navigation_window - (window->application, - NULL, - gtk_window_get_screen (GTK_WINDOW (window))); + target_navigation = TRUE; break; default : - g_warning ("Unknown open location mode"); + g_critical ("Unknown open location mode"); g_object_unref (old_location); return; } + /* now get/create the window according to the mode */ + if (target_same) { + target_window = window; + } else if (target_navigation) { + target_window = caja_application_create_navigation_window + (window->application, + NULL, + gtk_window_get_screen (GTK_WINDOW (window))); + } else { + target_window = caja_application_get_spatial_window + (window->application, + window, + NULL, + location, + gtk_window_get_screen (GTK_WINDOW (window)), + &existing); + } + + /* if the spatial window is already showing, present it and set the + * new selection, if present. + */ + if (existing) { + target_slot = target_window->details->active_pane->active_slot; + + gtk_window_present (GTK_WINDOW (target_window)); + + if (new_selection != NULL && slot->content_view != NULL) { + caja_view_set_selection (target_slot->content_view, new_selection); + } + + /* call the callback successfully */ + if (callback != NULL) { + callback (window, NULL, user_data); + } + + return; + } + g_assert (target_window != NULL); if ((flags & CAJA_WINDOW_OPEN_FLAG_NEW_TAB) != 0 && @@ -676,14 +680,14 @@ caja_window_slot_open_location_full (CajaWindowSlot *slot, } } - if ((!do_load_location) || - (target_window == window && target_slot == slot && - old_location && g_file_equal (old_location, location))) - { - if (old_location) - { - g_object_unref (old_location); + if ((target_window == window && target_slot == slot && + old_location && g_file_equal (old_location, location))) { + + if (callback != NULL) { + callback (window, NULL, user_data); } + + g_object_unref (old_location); return; } |