+2005-09-02 Marco Pesenti Gritti <mpg@redhat.com>
+
+ * 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 <mpg@redhat.com>
* data/evince.schemas.in:
#include "ev-sidebar.h"
#include "ev-sidebar-page.h"
+enum
+{
+ PROP_0,
+ PROP_CURRENT_PAGE
+};
+
enum
{
PAGE_COLUMN_TITLE,
(* 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)
{
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
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
GtkWidget *password_view;
GtkWidget *statusbar;
GtkWidget *sidebar_thumbs;
+ GtkWidget *sidebar_links;
/* Dialogs */
GtkWidget *properties;
#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"
GValue fullscreen = { 0, };
GValue rotation = { 0, };
GValue sidebar_size = { 0, };
+ GValue sidebar_page = { 0, };
/* Window size */
if (!GTK_WIDGET_VISIBLE (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);
}
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)
/* 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),
"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",