[nautilus] Clean up sync_location_widgets by using vtable calls instead of type checks



commit d40b44e5f54a16bdf91ebf2d291732941717fdc6
Author: Alexander Larsson <alexl redhat com>
Date:   Wed Dec 16 15:41:00 2009 +0100

    Clean up sync_location_widgets by using vtable calls instead of type checks

 src/nautilus-navigation-window-pane.c |   27 ++++++++++++++++++++----
 src/nautilus-navigation-window-pane.h |    1 -
 src/nautilus-window-pane.c            |   36 ++++++++++++++------------------
 src/nautilus-window-pane.h            |    1 +
 4 files changed, 39 insertions(+), 26 deletions(-)
---
diff --git a/src/nautilus-navigation-window-pane.c b/src/nautilus-navigation-window-pane.c
index 75b1cf7..ddb3c0b 100644
--- a/src/nautilus-navigation-window-pane.c
+++ b/src/nautilus-navigation-window-pane.c
@@ -24,6 +24,7 @@
 
 #include "nautilus-navigation-window-pane.h"
 #include "nautilus-window-private.h"
+#include "nautilus-window-manage-views.h"
 #include "nautilus-navigation-bar.h"
 #include "nautilus-pathbar.h"
 #include "nautilus-location-bar.h"
@@ -514,12 +515,15 @@ nautilus_navigation_window_pane_add_slot_in_tab (NautilusNavigationWindowPane *p
 					   pane);
 }
 
-void
-nautilus_navigation_window_pane_sync_location_widgets (NautilusNavigationWindowPane *pane)
+static void
+real_sync_location_widgets (NautilusWindowPane *pane)
 {
+	NautilusNavigationWindowSlot *navigation_slot;
+	NautilusNavigationWindowPane *navigation_pane;
 	NautilusWindowSlot *slot;
 
-	slot = NAUTILUS_WINDOW_PANE (pane)->active_slot;
+	slot = pane->active_slot;
+	navigation_pane = NAUTILUS_NAVIGATION_WINDOW_PANE (pane);
 
 	/* Change the location bar and path bar to match the current location. */
 	if (slot->location != NULL) {
@@ -527,9 +531,21 @@ nautilus_navigation_window_pane_sync_location_widgets (NautilusNavigationWindowP
 
 		/* this may be NULL if we just created the slot */
 		uri = nautilus_window_slot_get_location_uri (slot);
-		nautilus_navigation_bar_set_location (NAUTILUS_NAVIGATION_BAR (pane->navigation_bar),uri);
+		nautilus_navigation_bar_set_location (NAUTILUS_NAVIGATION_BAR (navigation_pane->navigation_bar), uri);
 		g_free (uri);
-		nautilus_path_bar_set_path (NAUTILUS_PATH_BAR (pane->path_bar),slot->location);
+		nautilus_path_bar_set_path (NAUTILUS_PATH_BAR (navigation_pane->path_bar), slot->location);
+	}
+
+	/* Update window global UI if this is the active pane */
+	if (pane == pane->window->details->active_pane) {
+		nautilus_window_update_up_button (pane->window);
+
+		/* Check if the back and forward buttons need enabling or disabling. */
+		navigation_slot = NAUTILUS_NAVIGATION_WINDOW_SLOT (pane->window->details->active_pane->active_slot);
+		nautilus_navigation_window_allow_back (NAUTILUS_NAVIGATION_WINDOW (pane->window),
+						       navigation_slot->back_list != NULL);
+		nautilus_navigation_window_allow_forward (NAUTILUS_NAVIGATION_WINDOW (pane->window),
+							  navigation_slot->forward_list != NULL);
 	}
 }
 
@@ -846,6 +862,7 @@ nautilus_navigation_window_pane_class_init (NautilusNavigationWindowPaneClass *c
 	G_OBJECT_CLASS (class)->dispose = nautilus_navigation_window_pane_dispose;
 	NAUTILUS_WINDOW_PANE_CLASS (class)->show = nautilus_navigation_window_pane_show;
 	NAUTILUS_WINDOW_PANE_CLASS (class)->sync_search_widgets = real_sync_search_widgets;
+	NAUTILUS_WINDOW_PANE_CLASS (class)->sync_location_widgets = real_sync_location_widgets;
 }
 
 static void
diff --git a/src/nautilus-navigation-window-pane.h b/src/nautilus-navigation-window-pane.h
index 8a61148..e6aa65b 100644
--- a/src/nautilus-navigation-window-pane.h
+++ b/src/nautilus-navigation-window-pane.h
@@ -88,7 +88,6 @@ void     nautilus_navigation_window_pane_show_location_bar_temporarily (Nautilus
 void     nautilus_navigation_window_pane_show_navigation_bar_temporarily (NautilusNavigationWindowPane *pane);
 void     nautilus_navigation_window_pane_always_use_location_entry (NautilusNavigationWindowPane *pane, gboolean use_entry);
 gboolean nautilus_navigation_window_pane_hide_temporary_bars (NautilusNavigationWindowPane *pane);
-void     nautilus_navigation_window_pane_sync_location_widgets (NautilusNavigationWindowPane *pane);
 void     nautilus_navigation_window_pane_set_active (NautilusNavigationWindowPane *pane, gboolean is_active);
 /* notebook */
 void     nautilus_navigation_window_pane_add_slot_in_tab (NautilusNavigationWindowPane *pane, NautilusWindowSlot *slot, NautilusWindowOpenSlotFlags flags);
diff --git a/src/nautilus-window-pane.c b/src/nautilus-window-pane.c
index a38d2cf..b718ec4 100644
--- a/src/nautilus-window-pane.c
+++ b/src/nautilus-window-pane.c
@@ -152,32 +152,27 @@ nautilus_window_pane_slot_close (NautilusWindowPane *pane, NautilusWindowSlot *s
 	}
 }
 
-void
-nautilus_window_pane_sync_location_widgets (NautilusWindowPane *pane)
+static void
+real_sync_location_widgets (NautilusWindowPane *pane)
 {
-	if (NAUTILUS_IS_NAVIGATION_WINDOW_PANE (pane)) {
-		NautilusNavigationWindowSlot *navigation_slot;
+	NautilusWindowSlot *slot;
 
-		nautilus_navigation_window_pane_sync_location_widgets (NAUTILUS_NAVIGATION_WINDOW_PANE (pane));
-		nautilus_window_update_up_button (pane->window);
+	/* TODO: Would be nice with a real subclass for spatial panes */
+	g_assert (NAUTILUS_IS_SPATIAL_WINDOW (pane->window));
 
-		/* Check if the back and forward buttons need enabling or disabling. */
-		navigation_slot = NAUTILUS_NAVIGATION_WINDOW_SLOT (pane->window->details->active_pane->active_slot);
-		nautilus_navigation_window_allow_back (NAUTILUS_NAVIGATION_WINDOW (pane->window),
-						       navigation_slot->back_list != NULL);
-		nautilus_navigation_window_allow_forward (NAUTILUS_NAVIGATION_WINDOW (pane->window),
-							  navigation_slot->forward_list != NULL);
+	slot = pane->active_slot;
 
-	}
+	/* Change the location button to match the current location. */
+	nautilus_spatial_window_set_location_button (NAUTILUS_SPATIAL_WINDOW (pane->window),
+						     slot->location);
+}
 
-	if (NAUTILUS_IS_SPATIAL_WINDOW (pane->window)) {
-		NautilusWindowSlot *slot;
 
-		slot = pane->window->details->active_pane->active_slot;
-		/* Change the location button to match the current location. */
-		nautilus_spatial_window_set_location_button (NAUTILUS_SPATIAL_WINDOW (pane->window),
-							     slot->location);
-	}
+void
+nautilus_window_pane_sync_location_widgets (NautilusWindowPane *pane)
+{
+	EEL_CALL_METHOD (NAUTILUS_WINDOW_PANE_CLASS, pane,
+			 sync_location_widgets, (pane));
 }
 
 void
@@ -229,6 +224,7 @@ static void
 nautilus_window_pane_class_init (NautilusWindowPaneClass *class)
 {
 	G_OBJECT_CLASS (class)->dispose = nautilus_window_pane_dispose;
+	NAUTILUS_WINDOW_PANE_CLASS (class)->sync_location_widgets = real_sync_location_widgets;
 }
 
 static void
diff --git a/src/nautilus-window-pane.h b/src/nautilus-window-pane.h
index 64f4fbc..3fef33c 100644
--- a/src/nautilus-window-pane.h
+++ b/src/nautilus-window-pane.h
@@ -41,6 +41,7 @@ struct _NautilusWindowPaneClass {
 
 	void (*show) (NautilusWindowPane *pane);
 	void (*sync_search_widgets) (NautilusWindowPane *pane);
+	void (*sync_location_widgets) (NautilusWindowPane *pane);
 };
 
 /* A NautilusWindowPane is a layer between a slot and a window.



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