[nautilus/wip/antoniof/make-window-slot-final: 198/200] window-slot: Make back_or_forward() a slot method




commit e8147de9b0143af2c795c8fe5ec6faf632f8308a
Author: António Fernandes <antoniof gnome org>
Date:   Wed Jan 13 13:31:05 2021 +0000

    window-slot: Make back_or_forward() a slot method
    
    We define a NautilusWindow method in nauitlus-window-slot.c. That's
    just wrong.
    
    Also, there is no reason for this to be a NautilusWindow method,
    rather than a slot one.
    
    The only consumers are NautilusWindow and NautilusToolbar, and both
    have a pointer to the current slot, so let's make this a slot method.
    
    For convenience, also add a private NautilusWindow wrapper method.

 src/nautilus-toolbar.c     | 12 ++++++------
 src/nautilus-window-slot.c |  8 +++-----
 src/nautilus-window-slot.h |  4 ++++
 src/nautilus-window.c      | 18 ++++++++++++++++++
 src/nautilus-window.h      |  3 ---
 5 files changed, 31 insertions(+), 14 deletions(-)
---
diff --git a/src/nautilus-toolbar.c b/src/nautilus-toolbar.c
index acc1ea485..dc5574a07 100644
--- a/src/nautilus-toolbar.c
+++ b/src/nautilus-toolbar.c
@@ -161,9 +161,9 @@ toolbar_update_appearance (NautilusToolbar *self)
 }
 
 static void
-activate_back_or_forward_menu_item (GtkMenuItem    *menu_item,
-                                    NautilusWindow *window,
-                                    gboolean        back)
+activate_back_or_forward_menu_item (GtkMenuItem        *menu_item,
+                                    NautilusWindowSlot *window_slot,
+                                    gboolean            back)
 {
     int index;
 
@@ -171,21 +171,21 @@ activate_back_or_forward_menu_item (GtkMenuItem    *menu_item,
 
     index = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menu_item), "user_data"));
 
-    nautilus_window_back_or_forward (window, back, index);
+    nautilus_window_slot_back_or_forward (window_slot, back, index);
 }
 
 static void
 activate_back_menu_item_callback (GtkMenuItem     *menu_item,
                                   NautilusToolbar *self)
 {
-    activate_back_or_forward_menu_item (menu_item, self->window, TRUE);
+    activate_back_or_forward_menu_item (menu_item, self->window_slot, TRUE);
 }
 
 static void
 activate_forward_menu_item_callback (GtkMenuItem     *menu_item,
                                      NautilusToolbar *self)
 {
-    activate_back_or_forward_menu_item (menu_item, self->window, FALSE);
+    activate_back_or_forward_menu_item (menu_item, self->window_slot, FALSE);
 }
 
 static void
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index bfe319ad6..155dbc089 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -2150,11 +2150,10 @@ nautilus_window_slot_set_content_view (NautilusWindowSlot *self,
 }
 
 void
-nautilus_window_back_or_forward (NautilusWindow *window,
-                                 gboolean        back,
-                                 guint           distance)
+nautilus_window_slot_back_or_forward (NautilusWindowSlot *self,
+                                      gboolean            back,
+                                      guint               distance)
 {
-    NautilusWindowSlot *self;
     GList *list;
     guint len;
     NautilusBookmark *bookmark;
@@ -2162,7 +2161,6 @@ nautilus_window_back_or_forward (NautilusWindow *window,
     GFile *old_location;
     g_autofree char *scroll_pos = NULL;
 
-    self = nautilus_window_get_active_slot (window);
     list = back ? self->back_list : self->forward_list;
     len = g_list_length (list);
 
diff --git a/src/nautilus-window-slot.h b/src/nautilus-window-slot.h
index b41545c66..268578789 100644
--- a/src/nautilus-window-slot.h
+++ b/src/nautilus-window-slot.h
@@ -111,4 +111,8 @@ NautilusQueryEditor *nautilus_window_slot_get_query_editor (NautilusWindowSlot *
 /* Only used by slot-dnd */
 NautilusView*  nautilus_window_slot_get_current_view       (NautilusWindowSlot *slot);
 
+void nautilus_window_slot_back_or_forward                  (NautilusWindowSlot *slot,
+                                                            gboolean            back,
+                                                            guint               distance);
+
 void free_navigation_state                                 (gpointer data);
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 62dc480d2..54566b94d 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -80,6 +80,9 @@ 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 nautilus_window_back_or_forward (NautilusWindow *window,
+                                             gboolean        back,
+                                             guint           distance);
 
 /* 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
@@ -2601,6 +2604,21 @@ nautilus_window_delete_event (GtkWidget   *widget,
     return FALSE;
 }
 
+static void
+nautilus_window_back_or_forward (NautilusWindow *window,
+                                 gboolean        back,
+                                 guint           distance)
+{
+    NautilusWindowSlot *slot;
+
+    slot = nautilus_window_get_active_slot (window);
+
+    if (slot != NULL)
+    {
+        nautilus_window_slot_back_or_forward (slot, back, distance);
+    }
+}
+
 static void
 on_multi_press_gesture_pressed (GtkGestureMultiPress *gesture,
                                 gint                  n_press,
diff --git a/src/nautilus-window.h b/src/nautilus-window.h
index 6f95fef64..5b9bf9133 100644
--- a/src/nautilus-window.h
+++ b/src/nautilus-window.h
@@ -78,9 +78,6 @@ void                 nautilus_window_sync_location_widgets (NautilusWindow *wind
 
 void     nautilus_window_hide_sidebar         (NautilusWindow *window);
 void     nautilus_window_show_sidebar         (NautilusWindow *window);
-void     nautilus_window_back_or_forward      (NautilusWindow *window,
-                                               gboolean        back,
-                                               guint           distance);
 void nautilus_window_reset_menus (NautilusWindow *window);
 
 GtkWidget *         nautilus_window_get_notebook (NautilusWindow *window);


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