From c2f443161a3fe0e1415d9e9017c300f6adf52074 Mon Sep 17 00:00:00 2001
From: Marco Pesenti Gritti <mpg@redhat.com>
Date: Mon, 19 Sep 2005 12:15:02 +0000
Subject: [PATCH] Show the index by default when there is one

2005-09-19  Marco Pesenti Gritti  <mpg@redhat.com>

        * shell/ev-window.c: (update_sidebar_visibility),
        (setup_sidebar_from_metadata), (ev_window_setup_document),
        (setup_view_from_metadata):

        Show the index by default when there is one
---
 ChangeLog         |  8 +++++
 shell/ev-window.c | 81 +++++++++++++++++++++++++++--------------------
 2 files changed, 55 insertions(+), 34 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e3da7bdd..7f6f9961 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2005-09-19  Marco Pesenti Gritti  <mpg@redhat.com>
+
+	* shell/ev-window.c: (update_sidebar_visibility),
+	(setup_sidebar_from_metadata), (ev_window_setup_document),
+	(setup_view_from_metadata):
+
+	Show the index by default when there is one	
+
 2005-09-19  Marco Pesenti Gritti  <mpg@redhat.com>
 
 	* shell/ev-window-title.c: (ev_window_title_set_document):
diff --git a/shell/ev-window.c b/shell/ev-window.c
index fe3d6241..4c893f3b 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -602,6 +602,18 @@ update_document_mode (EvWindow *window, EvDocumentMode mode)
 	}
 }
 
+static void
+update_sidebar_visibility (EvWindow *window)
+{
+	char *uri = window->priv->uri;
+	GValue sidebar_visibility = { 0, };
+
+	if (uri && ev_metadata_manager_get (uri, "sidebar_visibility", &sidebar_visibility)) {
+		set_widget_visibility (window->priv->sidebar,
+				       g_value_get_boolean (&sidebar_visibility));
+	}
+}
+
 static void
 setup_document_from_metadata (EvWindow *window)
 {
@@ -615,6 +627,40 @@ setup_document_from_metadata (EvWindow *window)
 	}
 }
 
+static void
+setup_sidebar_from_metadata (EvWindow *window, EvDocument *document)
+{
+	char *uri = window->priv->uri;
+	GtkWidget *sidebar = window->priv->sidebar;
+	GtkWidget *links = window->priv->sidebar_links;
+	GtkWidget *thumbs = window->priv->sidebar_thumbs;
+	GValue sidebar_size = { 0, };
+	GValue sidebar_page = { 0, };
+
+	if (ev_metadata_manager_get (uri, "sidebar_size", &sidebar_size)) {
+		gtk_paned_set_position (GTK_PANED (window->priv->hpaned),
+					g_value_get_int (&sidebar_size));
+	}
+
+	if (ev_metadata_manager_get (uri, "sidebar_page", &sidebar_page)) {
+		const char *page_id = g_value_get_string (&sidebar_page);
+
+		if (strcmp (page_id, "links") == 0) {
+			ev_sidebar_set_page (EV_SIDEBAR (sidebar), links);
+		} else if (strcmp (page_id, "thumbnails")) {
+			ev_sidebar_set_page (EV_SIDEBAR (sidebar), thumbs);
+		}
+	} else {
+		if (ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (links), document)) {
+			ev_sidebar_set_page (EV_SIDEBAR (sidebar), links);
+		} else if (ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (thumbs), document)) {
+			ev_sidebar_set_page (EV_SIDEBAR (sidebar), thumbs);
+		}
+	}
+
+	update_sidebar_visibility (window);
+}
+
 static void
 ev_window_setup_document (EvWindow *ev_window)
 {
@@ -657,6 +703,7 @@ ev_window_setup_document (EvWindow *ev_window)
 	}
 
 	setup_document_from_metadata (ev_window);
+	setup_sidebar_from_metadata (ev_window, document);
 }
 
 static void
@@ -875,18 +922,6 @@ ev_window_xfer_job_cb  (EvJobXfer *job,
 	}		
 }
 
-static void
-update_sidebar_visibility (EvWindow *window)
-{
-	char *uri = window->priv->uri;
-	GValue sidebar_visibility = { 0, };
-
-	if (uri && ev_metadata_manager_get (uri, "sidebar_visibility", &sidebar_visibility)) {
-		set_widget_visibility (window->priv->sidebar,
-				       g_value_get_boolean (&sidebar_visibility));
-	}
-}
-
 static void
 setup_view_from_metadata (EvWindow *window)
 {
@@ -905,8 +940,6 @@ setup_view_from_metadata (EvWindow *window)
 	GValue presentation = { 0, };
 	GValue fullscreen = { 0, };
 	GValue rotation = { 0, };
-	GValue sidebar_size = { 0, };
-	GValue sidebar_page = { 0, };
 
 	if (window->priv->uri == NULL) {
 		return;
@@ -992,26 +1025,6 @@ setup_view_from_metadata (EvWindow *window)
 			}
 		}
 	}
-
-	/* Sidebar */
-	if (ev_metadata_manager_get (uri, "sidebar_size", &sidebar_size)) {
-		gtk_paned_set_position (GTK_PANED (window->priv->hpaned),
-					g_value_get_int (&sidebar_size));
-	}
-
-	if (ev_metadata_manager_get (uri, "sidebar_page", &sidebar_page)) {
-		const char *page_id = g_value_get_string (&sidebar_page);
-
-		if (strcmp (page_id, "links") == 0) {
-			ev_sidebar_set_page (EV_SIDEBAR (window->priv->sidebar),
-					     window->priv->sidebar_links);
-		} else if (strcmp (page_id, "thumbnails")) {
-			ev_sidebar_set_page (EV_SIDEBAR (window->priv->sidebar),
-					     window->priv->sidebar_thumbs);
-		}
-	}
-
-	update_sidebar_visibility (window);
 }
 
 void
-- 
2.43.5