[nautilus/wip/antoniof/make-window-slot-final: 196/200] window-slot: Drop other-locations subclass




commit ad41d6f635f46e795ee7842b4f7957d935cd3862
Author: António Fernandes <antoniof gnome org>
Date:   Wed Jan 13 10:43:40 2021 +0000

    window-slot: Drop other-locations subclass
    
    The NautilusOtherLocationsWindowSlot subclass has been introduced along
    with its sibling NautilusDesktopWindowSlot.[0]
    
    However, the desktop one is now gone, and this is the only subclass.
    It does only 2 things differently from its parent class:
    
      * Creates a NautilusPlacesView instead of a NautilusFilesView
      * Disables the slot.files-view-mode-toggle and files-view-mode actions
    
    There is little reason not to handle both things in the parent class.
    Also, changing slots when going in and out of the Other Locations place
    throws away the navigation data; while this can be worked around by
    saving and restoring this data, this outweights any potential benefits
    of subclassing.
    
    This commit is equivalent to reverting [0], but due to code style and
    other changes, a clean revert was not possible.
    
    Effectively fixes https://gitlab.gnome.org/GNOME/nautilus/-/issues/32
    
    [0] commit 5f295bd92cb4dabc44e76dd76e83df8190373bd8

 src/meson.build                            |  2 -
 src/nautilus-other-locations-window-slot.c | 83 ------------------------------
 src/nautilus-other-locations-window-slot.h | 33 ------------
 src/nautilus-window-slot.c                 | 66 ++++++++++++------------
 src/nautilus-window-slot.h                 |  8 ---
 src/nautilus-window.c                      | 71 ++-----------------------
 6 files changed, 37 insertions(+), 226 deletions(-)
---
diff --git a/src/meson.build b/src/meson.build
index 0672359a5..39e0b0370 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -102,8 +102,6 @@ libnautilus_sources = [
   'nautilus-mime-actions.h',
   'nautilus-notebook.c',
   'nautilus-notebook.h',
-  'nautilus-other-locations-window-slot.c',
-  'nautilus-other-locations-window-slot.h',
   'nautilus-pathbar.c',
   'nautilus-pathbar.h',
   'nautilus-places-view.c',
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index 17ed6e164..502de6ede 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -27,6 +27,7 @@
 #include "nautilus-bookmark.h"
 #include "nautilus-bookmark-list.h"
 #include "nautilus-mime-actions.h"
+#include "nautilus-places-view.h"
 #include "nautilus-query-editor.h"
 #include "nautilus-special-location-bar.h"
 #include "nautilus-toolbar.h"
@@ -127,6 +128,7 @@ typedef struct
     GError *mount_error;
     gboolean tried_mount;
     gint view_mode_before_search;
+    gint view_mode_before_places;
 
     /* Menus */
     GMenuModel *extensions_background_menu;
@@ -246,30 +248,6 @@ nautilus_window_slot_get_navigation_state (NautilusWindowSlot *self)
     return data;
 }
 
-gboolean
-nautilus_window_slot_handles_location (NautilusWindowSlot *self,
-                                       GFile              *location)
-{
-    return NAUTILUS_WINDOW_SLOT_CLASS (G_OBJECT_GET_CLASS (self))->handles_location (self, location);
-}
-
-static gboolean
-real_handles_location (NautilusWindowSlot *self,
-                       GFile              *location)
-{
-    NautilusFile *file;
-    gboolean handles_location;
-    g_autofree char *uri = NULL;
-
-    uri = g_file_get_uri (location);
-
-    file = nautilus_file_get (location);
-    handles_location = !nautilus_file_is_other_locations (file);
-    nautilus_file_unref (file);
-
-    return handles_location;
-}
-
 static NautilusView *
 nautilus_window_slot_get_view_for_location (NautilusWindowSlot *self,
                                             GFile              *location)
@@ -282,7 +260,7 @@ real_get_view_for_location (NautilusWindowSlot *self,
                             GFile              *location)
 {
     NautilusWindowSlotPrivate *priv;
-    NautilusFile *file;
+    g_autoptr (NautilusFile) file = NULL;
     NautilusView *view;
     guint view_id;
 
@@ -291,13 +269,27 @@ real_get_view_for_location (NautilusWindowSlot *self,
     view = NULL;
     view_id = NAUTILUS_VIEW_INVALID_ID;
 
+    if (nautilus_file_is_other_locations (file))
+    {
+        view = NAUTILUS_VIEW (nautilus_places_view_new ());
+
+        /* Save the current view, so we can go back after places view */
+        if (NAUTILUS_IS_FILES_VIEW (priv->content_view))
+        {
+            priv->view_mode_before_places = nautilus_files_view_get_view_id (priv->content_view);
+        }
+
+        return view;
+    }
+
     /* If we are in search, try to use by default list view. */
     if (nautilus_file_is_in_search (file))
     {
         /* If it's already set, is because we already made the change to search mode,
          * 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 (priv->view_mode_before_search == NAUTILUS_VIEW_INVALID_ID && priv->content_view)
+        if (priv->view_mode_before_search == NAUTILUS_VIEW_INVALID_ID &&
+            NAUTILUS_IS_FILES_VIEW (priv->content_view))
         {
             priv->view_mode_before_search = nautilus_files_view_get_view_id (priv->content_view);
         }
@@ -313,6 +305,11 @@ real_get_view_for_location (NautilusWindowSlot *self,
             view_id = priv->view_mode_before_search;
             priv->view_mode_before_search = NAUTILUS_VIEW_INVALID_ID;
         }
+        else if (NAUTILUS_IS_PLACES_VIEW (priv->content_view))
+        {
+            view_id = priv->view_mode_before_places;
+            priv->view_mode_before_places = NAUTILUS_VIEW_INVALID_ID;
+        }
         else
         {
             view_id = nautilus_files_view_get_view_id (priv->content_view);
@@ -336,8 +333,6 @@ real_get_view_for_location (NautilusWindowSlot *self,
         view = NAUTILUS_VIEW (nautilus_files_view_new (view_id, self));
     }
 
-    nautilus_file_unref (file);
-
     return view;
 }
 
@@ -353,9 +348,9 @@ nautilus_window_slot_content_view_matches (NautilusWindowSlot *self,
         return FALSE;
     }
 
-    if (id != NAUTILUS_VIEW_INVALID_ID && NAUTILUS_IS_FILES_VIEW (priv->content_view))
+    if (id != NAUTILUS_VIEW_INVALID_ID)
     {
-        return nautilus_files_view_get_view_id (priv->content_view) == id;
+        return nautilus_view_get_view_id (priv->content_view) == id;
     }
     else
     {
@@ -406,6 +401,7 @@ nautilus_window_slot_sync_actions (NautilusWindowSlot *self)
 {
     NautilusWindowSlotPrivate *priv;
 
+    NautilusView *view;
     GAction *action;
     GVariant *variant;
 
@@ -426,12 +422,16 @@ nautilus_window_slot_sync_actions (NautilusWindowSlot *self)
     update_search_visible (self);
 
     /* Files view mode */
+    view = nautilus_window_slot_get_current_view (self);
     action = g_action_map_lookup_action (G_ACTION_MAP (priv->slot_action_group), "files-view-mode");
+    g_simple_action_set_enabled (G_SIMPLE_ACTION (action), NAUTILUS_IS_FILES_VIEW (view));
     if (g_action_get_enabled (action))
     {
-        variant = g_variant_new_uint32 (nautilus_files_view_get_view_id 
(nautilus_window_slot_get_current_view (self)));
+        variant = g_variant_new_uint32 (nautilus_files_view_get_view_id (view));
         g_action_change_state (action, variant);
     }
+    action = g_action_map_lookup_action (G_ACTION_MAP (priv->slot_action_group), "files-view-mode-toggle");
+    g_simple_action_set_enabled (G_SIMPLE_ACTION (action), NAUTILUS_IS_FILES_VIEW (view));
 }
 
 static void
@@ -1088,7 +1088,7 @@ action_files_view_mode_toggle (GSimpleAction *action,
 
     self = NAUTILUS_WINDOW_SLOT (user_data);
     priv = nautilus_window_slot_get_instance_private (self);
-    if (priv->content_view == NULL)
+    if (!NAUTILUS_IS_FILES_VIEW (priv->content_view))
     {
         return;
     }
@@ -2735,6 +2735,7 @@ nautilus_window_slot_show_trash_bar (NautilusWindowSlot *self)
     NautilusView *view;
 
     view = nautilus_window_slot_get_current_view (self);
+    g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
     bar = nautilus_trash_bar_new (NAUTILUS_FILES_VIEW (view));
     gtk_widget_show (bar);
 
@@ -3188,7 +3189,6 @@ nautilus_window_slot_class_init (NautilusWindowSlotClass *klass)
     GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
     klass->get_view_for_location = real_get_view_for_location;
-    klass->handles_location = real_handles_location;
 
     oclass->dispose = nautilus_window_slot_dispose;
     oclass->finalize = nautilus_window_slot_finalize;
diff --git a/src/nautilus-window-slot.h b/src/nautilus-window-slot.h
index bdb9dccfa..d2f83175c 100644
--- a/src/nautilus-window-slot.h
+++ b/src/nautilus-window-slot.h
@@ -59,11 +59,6 @@ struct _NautilusWindowSlotClass {
          */
         NautilusView*  (* get_view_for_location) (NautilusWindowSlot *slot,
                                                   GFile              *location);
-        /* Whether this type of slot handles the location or not. This can be used
-         * for the special slots which handle special locations like the desktop
-         * or the other locations. */
-        gboolean (* handles_location) (NautilusWindowSlot *slot,
-                                       GFile              *location);
 };
 
 NautilusWindowSlot * nautilus_window_slot_new              (NautilusWindow     *window);
@@ -121,9 +116,6 @@ GList* nautilus_window_slot_get_selection                  (NautilusWindowSlot *
 void     nautilus_window_slot_search                       (NautilusWindowSlot *slot,
                                                             NautilusQuery      *query);
 
-gboolean nautilus_window_slot_handles_location (NautilusWindowSlot *self,
-                                                GFile              *location);
-
 void nautilus_window_slot_restore_navigation_state (NautilusWindowSlot      *self,
                                                     NautilusNavigationState *data);
 
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 9b6df9767..62dc480d2 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -61,7 +61,6 @@
 #include "nautilus-metadata.h"
 #include "nautilus-mime-actions.h"
 #include "nautilus-notebook.h"
-#include "nautilus-other-locations-window-slot.h"
 #include "nautilus-pathbar.h"
 #include "nautilus-profile.h"
 #include "nautilus-properties-window.h"
@@ -81,9 +80,6 @@ static void mouse_forward_button_changed (gpointer callback_data);
 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 close_slot (NautilusWindow     *window,
-                        NautilusWindowSlot *slot,
-                        gboolean            remove_from_notebook);
 
 /* 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
@@ -498,65 +494,18 @@ disconnect_slot (NautilusWindow     *window,
     g_signal_handlers_disconnect_by_data (slot, window);
 }
 
-static NautilusWindowSlot *
-nautilus_window_create_slot (NautilusWindow *window,
-                             GFile          *location)
-{
-    NautilusFile *file = NULL;
-    NautilusWindowSlot *slot;
-
-    if (location)
-    {
-        file = nautilus_file_get (location);
-    }
-    /* If not file, assume we open the home directory. We will switch eventually
-     * to a different location if not.
-     */
-    if (file && nautilus_file_is_other_locations (file))
-    {
-        slot = NAUTILUS_WINDOW_SLOT (nautilus_other_locations_window_slot_new (window));
-    }
-    else
-    {
-        slot = nautilus_window_slot_new (window);
-    }
-
-    nautilus_file_unref (file);
-
-    return slot;
-}
-
 static NautilusWindowSlot *
 nautilus_window_create_and_init_slot (NautilusWindow          *window,
-                                      GFile                   *location,
                                       NautilusWindowOpenFlags  flags)
 {
     NautilusWindowSlot *slot;
 
-    slot = nautilus_window_create_slot (window, location);
+    slot = nautilus_window_slot_new (window);
     nautilus_window_initialize_slot (window, slot, flags);
 
     return slot;
 }
 
-static NautilusWindowSlot *
-replace_active_slot (NautilusWindow          *window,
-                     GFile                   *location,
-                     NautilusWindowOpenFlags  flags)
-{
-    NautilusWindowSlot *new_slot;
-    NautilusWindowSlot *active_slot;
-
-    new_slot = nautilus_window_create_and_init_slot (window, location, flags);
-    active_slot = nautilus_window_get_active_slot (window);
-    if (active_slot)
-    {
-        close_slot (window, active_slot, TRUE);
-    }
-
-    return new_slot;
-}
-
 void
 nautilus_window_initialize_slot (NautilusWindow          *window,
                                  NautilusWindowSlot      *slot,
@@ -594,12 +543,6 @@ nautilus_window_open_location_full (NautilusWindow          *window,
     NautilusWindowSlot *active_slot;
     gboolean new_tab_at_end;
 
-    /* The location owner can be one of the slots requesting to handle an
-     * unhandled location. But this slot can be destroyed when switching to
-     * a new slot. So keep the location alive.
-     */
-    g_object_ref (location);
-
     /* Assert that we are not managing new windows */
     g_assert (!(flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW));
     /* if the flags say we want a new tab, open a slot in the current window */
@@ -620,11 +563,7 @@ nautilus_window_open_location_full (NautilusWindow          *window,
 
     if (target_slot == NULL || (flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) != 0)
     {
-        target_slot = nautilus_window_create_and_init_slot (window, location, flags);
-    }
-    else if (!nautilus_window_slot_handles_location (target_slot, location))
-    {
-        target_slot = replace_active_slot (window, location, flags);
+        target_slot = nautilus_window_create_and_init_slot (window, flags);
     }
 
     /* Make the opened location the one active if we weren't ask for the
@@ -636,8 +575,6 @@ nautilus_window_open_location_full (NautilusWindow          *window,
     }
 
     nautilus_window_slot_open_location_full (target_slot, location, flags, selection);
-
-    g_object_unref (location);
 }
 
 static void
@@ -1212,7 +1149,7 @@ action_restore_tab (GSimpleAction *action,
 
     location = nautilus_file_get_location (data->file);
 
-    slot = nautilus_window_create_and_init_slot (window, location, flags);
+    slot = nautilus_window_create_and_init_slot (window, flags);
 
     nautilus_window_slot_open_location_full (slot, location, flags, NULL);
     nautilus_window_slot_restore_navigation_state (slot, data);
@@ -2203,7 +2140,7 @@ nautilus_window_constructed (GObject *self)
      * some actions trigger UI widgets to show/hide. */
     nautilus_window_initialize_actions (window);
 
-    slot = nautilus_window_create_and_init_slot (window, NULL, 0);
+    slot = nautilus_window_create_and_init_slot (window, 0);
     nautilus_window_set_active_slot (window, slot);
 
     window->bookmarks_id =


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