From 56b849d72779ad2812dff99426bacebd0944e336 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 2 Sep 2005 10:41:11 +0000 Subject: [PATCH] Add a current page property and allow to get/set it 2005-09-02 Marco Pesenti Gritti * shell/ev-sidebar.h: * shell/ev-sidebar.c: (ev_sidebar_set_property), (ev_sidebar_get_current_page), (ev_sidebar_get_property), (ev_sidebar_class_init), (ev_sidebar_select_page), (ev_sidebar_menu_item_activate_cb), (ev_sidebar_new), (ev_sidebar_set_page): Add a current page property and allow to get/set it * shell/ev-window.c: (setup_view_from_metadata), (ev_window_sidebar_current_page_changed_cb), (ev_window_init): Persist current sidebar page per document --- ChangeLog | 16 ++++++ shell/ev-sidebar.c | 120 +++++++++++++++++++++++++++++++++++++++++---- shell/ev-sidebar.h | 2 + shell/ev-window.c | 46 ++++++++++++++++- 4 files changed, 173 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 52207117..d6d70be0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2005-09-02 Marco Pesenti Gritti + + * shell/ev-sidebar.h: + * shell/ev-sidebar.c: (ev_sidebar_set_property), + (ev_sidebar_get_current_page), (ev_sidebar_get_property), + (ev_sidebar_class_init), (ev_sidebar_select_page), + (ev_sidebar_menu_item_activate_cb), (ev_sidebar_new), + (ev_sidebar_set_page): + + Add a current page property and allow to get/set it + + * shell/ev-window.c: (setup_view_from_metadata), + (ev_window_sidebar_current_page_changed_cb), (ev_window_init): + + Persist current sidebar page per document + 2005-09-02 Marco Pesenti Gritti * data/evince.schemas.in: diff --git a/shell/ev-sidebar.c b/shell/ev-sidebar.c index f23a45f3..509a90b3 100644 --- a/shell/ev-sidebar.c +++ b/shell/ev-sidebar.c @@ -31,6 +31,12 @@ #include "ev-sidebar.h" #include "ev-sidebar-page.h" +enum +{ + PROP_0, + PROP_CURRENT_PAGE +}; + enum { PAGE_COLUMN_TITLE, @@ -73,6 +79,96 @@ ev_sidebar_destroy (GtkObject *object) (* GTK_OBJECT_CLASS (ev_sidebar_parent_class)->destroy) (object); } +static void +ev_sidebar_select_page (EvSidebar *ev_sidebar, GtkTreeIter *iter) +{ + char *title; + int index; + + gtk_tree_model_get (ev_sidebar->priv->page_model, iter, + PAGE_COLUMN_TITLE, &title, + PAGE_COLUMN_NOTEBOOK_INDEX, &index, + -1); + + gtk_notebook_set_current_page (GTK_NOTEBOOK (ev_sidebar->priv->notebook), index); + gtk_label_set_text (GTK_LABEL (ev_sidebar->priv->label), title); + + g_free (title); +} + +void +ev_sidebar_set_page (EvSidebar *ev_sidebar, + GtkWidget *main_widget) +{ + GtkTreeIter iter; + gboolean valid; + + valid = gtk_tree_model_get_iter_first (ev_sidebar->priv->page_model, &iter); + + while (valid) { + GtkWidget *widget; + + gtk_tree_model_get (ev_sidebar->priv->page_model, &iter, + PAGE_COLUMN_MAIN_WIDGET, &widget, + -1); + + if (widget == main_widget) { + ev_sidebar_select_page (ev_sidebar, &iter); + valid = FALSE; + } else { + valid = gtk_tree_model_iter_next (ev_sidebar->priv->page_model, &iter); + } + g_object_unref (widget); + } + + g_object_notify (G_OBJECT (ev_sidebar), "current-page"); +} + +static void +ev_sidebar_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + EvSidebar *sidebar = EV_SIDEBAR (object); + + switch (prop_id) + { + case PROP_CURRENT_PAGE: + ev_sidebar_set_page (sidebar, g_value_get_object (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static GtkWidget * +ev_sidebar_get_current_page (EvSidebar *sidebar) +{ + GtkNotebook *notebook = GTK_NOTEBOOK (sidebar->priv->notebook); + + return gtk_notebook_get_nth_page + (notebook, gtk_notebook_get_current_page (notebook)); +} + +static void +ev_sidebar_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + EvSidebar *sidebar = EV_SIDEBAR (object); + + switch (prop_id) + { + case PROP_CURRENT_PAGE: + g_value_set_object (value, ev_sidebar_get_current_page (sidebar)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + static void ev_sidebar_class_init (EvSidebarClass *ev_sidebar_class) { @@ -87,6 +183,16 @@ ev_sidebar_class_init (EvSidebarClass *ev_sidebar_class) g_type_class_add_private (g_object_class, sizeof (EvSidebarPrivate)); gtk_object_klass->destroy = ev_sidebar_destroy; + g_object_class->get_property = ev_sidebar_get_property; + g_object_class->set_property = ev_sidebar_set_property; + + g_object_class_install_property (g_object_class, + PROP_CURRENT_PAGE, + g_param_spec_object ("current-page", + "Current page", + "The currently visible page", + GTK_TYPE_WIDGET, + G_PARAM_READWRITE)); } static void @@ -198,32 +304,26 @@ ev_sidebar_menu_item_activate_cb (GtkWidget *widget, EvSidebar *ev_sidebar = EV_SIDEBAR (user_data); GtkTreeIter iter; GtkWidget *menu_item, *item; - gchar *title; gboolean valid; - gint index; menu_item = gtk_menu_get_active (GTK_MENU (ev_sidebar->priv->menu)); valid = gtk_tree_model_get_iter_first (ev_sidebar->priv->page_model, &iter); while (valid) { - gtk_tree_model_get (ev_sidebar->priv->page_model, - &iter, - PAGE_COLUMN_TITLE, &title, + gtk_tree_model_get (ev_sidebar->priv->page_model, &iter, PAGE_COLUMN_MENU_ITEM, &item, - PAGE_COLUMN_NOTEBOOK_INDEX, &index, -1); if (item == menu_item) { - gtk_notebook_set_current_page - (GTK_NOTEBOOK (ev_sidebar->priv->notebook), index); - gtk_label_set_text (GTK_LABEL (ev_sidebar->priv->label), title); + ev_sidebar_select_page (ev_sidebar, &iter); valid = FALSE; } else { valid = gtk_tree_model_iter_next (ev_sidebar->priv->page_model, &iter); } g_object_unref (item); - g_free (title); } + + g_object_notify (G_OBJECT (ev_sidebar), "current-page"); } static void diff --git a/shell/ev-sidebar.h b/shell/ev-sidebar.h index d599fff6..c0e99f09 100644 --- a/shell/ev-sidebar.h +++ b/shell/ev-sidebar.h @@ -54,6 +54,8 @@ GType ev_sidebar_get_type (void); GtkWidget *ev_sidebar_new (void); void ev_sidebar_add_page (EvSidebar *ev_sidebar, GtkWidget *main_widget); +void ev_sidebar_set_page (EvSidebar *ev_sidebar, + GtkWidget *main_widget); void ev_sidebar_set_document (EvSidebar *ev_sidebar, EvDocument *document); diff --git a/shell/ev-window.c b/shell/ev-window.c index 93a3f2a0..32d6c030 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -106,6 +106,7 @@ struct _EvWindowPrivate { GtkWidget *password_view; GtkWidget *statusbar; GtkWidget *sidebar_thumbs; + GtkWidget *sidebar_links; /* Dialogs */ GtkWidget *properties; @@ -156,6 +157,8 @@ static const GtkTargetEntry ev_drop_types[] = { #define GCONF_LOCKDOWN_PRINT "/desktop/gnome/lockdown/disable_printing" #define SIDEBAR_DEFAULT_SIZE 132 +#define LINKS_SIDEBAR_ID "links" +#define THUMBNAILS_SIDEBAR_ID "thumbnails" #define PRINT_CONFIG_FILENAME "ev-print-config.xml" @@ -965,6 +968,7 @@ setup_view_from_metadata (EvWindow *window) GValue fullscreen = { 0, }; GValue rotation = { 0, }; GValue sidebar_size = { 0, }; + GValue sidebar_page = { 0, }; /* Window size */ if (!GTK_WIDGET_VISIBLE (window)) { @@ -1053,6 +1057,18 @@ setup_view_from_metadata (EvWindow *window) 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); } @@ -2559,6 +2575,29 @@ ev_window_view_sidebar_cb (GtkAction *action, EvWindow *ev_window) gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))); } +static void +ev_window_sidebar_current_page_changed_cb (EvSidebar *ev_sidebar, + GParamSpec *pspec, + EvWindow *ev_window) +{ + GtkWidget *current_page; + const char *id; + + g_object_get (G_OBJECT (ev_sidebar), "current_page", ¤t_page, NULL); + + if (current_page == ev_window->priv->sidebar_links) { + id = LINKS_SIDEBAR_ID; + } else if (current_page == ev_window->priv->sidebar_thumbs) { + id = THUMBNAILS_SIDEBAR_ID; + } else { + g_assert_not_reached(); + } + + g_object_unref (current_page); + + ev_metadata_manager_set_string (ev_window->priv->uri, "sidebar_page", id); +} + static void ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar, GParamSpec *pspec, EvWindow *ev_window) @@ -3425,6 +3464,7 @@ ev_window_init (EvWindow *ev_window) /* Stub sidebar, for now */ sidebar_widget = ev_sidebar_links_new (); + ev_window->priv->sidebar_links = sidebar_widget; g_signal_connect (sidebar_widget, "notify::model", G_CALLBACK (sidebar_widget_model_set), @@ -3528,7 +3568,11 @@ ev_window_init (EvWindow *ev_window) "notify::visible", G_CALLBACK (ev_window_sidebar_visibility_changed_cb), ev_window); - + g_signal_connect (ev_window->priv->sidebar, + "notify::current-page", + G_CALLBACK (ev_window_sidebar_current_page_changed_cb), + ev_window); + /* Connect to find bar signals */ g_signal_connect (ev_window->priv->find_bar, "previous", -- 2.43.5