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




commit 4f9eadfbdb28b4c383c74f41195cfa2191f6e548
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                 | 43 ++++++----------
 src/nautilus-window-slot.h                 |  8 ---
 src/nautilus-window.c                      | 71 ++-----------------------
 6 files changed, 21 insertions(+), 219 deletions(-)
---
diff --git a/src/meson.build b/src/meson.build
index a1b9bdbd2..03af7ff75 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 060893eab..94f14f6b9 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"
@@ -246,30 +247,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)
@@ -291,6 +268,11 @@ real_get_view_for_location (NautilusWindowSlot *self,
     view = NULL;
     view_id = NAUTILUS_VIEW_INVALID_ID;
 
+    if (nautilus_file_is_other_locations (file))
+    {
+        return NAUTILUS_VIEW (nautilus_places_view_new ());
+    }
+
     /* If we are in search, try to use by default list view. */
     if (nautilus_file_is_in_search (file))
     {
@@ -353,6 +335,11 @@ nautilus_window_slot_content_view_matches (NautilusWindowSlot *self,
         return FALSE;
     }
 
+    if (id == NAUTILUS_VIEW_OTHER_LOCATIONS_ID)
+    {
+        return NAUTILUS_IS_PLACES_VIEW (priv->content_view);
+    }
+
     if (id != NAUTILUS_VIEW_INVALID_ID && NAUTILUS_IS_FILES_VIEW (priv->content_view))
     {
         return nautilus_files_view_get_view_id (priv->content_view) == id;
@@ -406,6 +393,7 @@ nautilus_window_slot_sync_actions (NautilusWindowSlot *self)
 {
     NautilusWindowSlotPrivate *priv;
 
+    NautilusView *view;
     GAction *action;
     GVariant *variant;
 
@@ -426,12 +414,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
@@ -3188,7 +3180,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 c1e14c373..eabc2423b 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
@@ -513,65 +509,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,
@@ -609,12 +558,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 */
@@ -635,11 +578,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
@@ -651,8 +590,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
@@ -1227,7 +1164,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);
@@ -2212,7 +2149,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]