[evince] ev-sidebar: Port to GtkStack
- From: Germán Poo-Caamaño <gpoo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince] ev-sidebar: Port to GtkStack
- Date: Tue, 10 Jul 2018 20:20:30 +0000 (UTC)
commit 43c402efcbda69dfc77b30d006f50162171b6358
Author: Germán Poo-Caamaño <gpoo gnome org>
Date: Wed Jul 4 01:30:50 2018 -0400
ev-sidebar: Port to GtkStack
* Use less space to "describe" each pane.
Follows design proposed in issue #475
https://gitlab.gnome.org/GNOME/evince/issues/475#note_259392
shell/ev-sidebar.c | 529 +++++++++++++++++------------------------------------
shell/ev-sidebar.h | 13 +-
shell/ev-window.c | 58 ++++--
3 files changed, 216 insertions(+), 384 deletions(-)
---
diff --git a/shell/ev-sidebar.c b/shell/ev-sidebar.c
index 8a9c0360..2ad0773e 100644
--- a/shell/ev-sidebar.c
+++ b/shell/ev-sidebar.c
@@ -1,9 +1,11 @@
/* this file is part of evince, a gnome document viewer
*
* Copyright (C) 2004 Red Hat, Inc.
+ * Copyright (C) 2018 Germán Poo-Caamaño <gpoo gnome org>
*
* Author:
* Jonathan Blandford <jrb alum mit edu>
+ * Germán Poo-Caamaño <gpoo gnome org>
*
* Evince is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
@@ -26,6 +28,8 @@
#include <string.h>
+#include <glib.h>
+#include <glib-object.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
@@ -35,24 +39,22 @@
enum
{
PROP_0,
- PROP_CURRENT_PAGE
+ PROP_CURRENT_PAGE,
+ PROP_ACTIVE_ICON_NAME
};
enum
{
- PAGE_COLUMN_TITLE,
- PAGE_COLUMN_MENU_ITEM,
+ PAGE_COLUMN_NAME,
PAGE_COLUMN_MAIN_WIDGET,
- PAGE_COLUMN_NOTEBOOK_INDEX,
+ PAGE_COLUMN_TITLE,
+ PAGE_COLUMN_ICON_NAME,
PAGE_COLUMN_NUM_COLS
};
struct _EvSidebarPrivate {
- GtkWidget *notebook;
- GtkWidget *select_button;
- GtkWidget *menu;
- GtkWidget *hbox;
- GtkWidget *label;
+ GtkWidget *stack;
+ GtkWidget *switcher;
EvDocumentModel *model;
GtkTreeModel *page_model;
@@ -68,63 +70,12 @@ ev_sidebar_dispose (GObject *object)
{
EvSidebar *ev_sidebar = EV_SIDEBAR (object);
- if (ev_sidebar->priv->menu) {
- gtk_menu_detach (GTK_MENU (ev_sidebar->priv->menu));
- ev_sidebar->priv->menu = NULL;
- }
-
if (ev_sidebar->priv->page_model) {
g_object_unref (ev_sidebar->priv->page_model);
ev_sidebar->priv->page_model = NULL;
}
-
-
- G_OBJECT_CLASS (ev_sidebar_parent_class)->dispose (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");
+ G_OBJECT_CLASS (ev_sidebar_parent_class)->dispose (object);
}
static void
@@ -138,7 +89,7 @@ ev_sidebar_set_property (GObject *object,
switch (prop_id)
{
case PROP_CURRENT_PAGE:
- ev_sidebar_set_page (sidebar, g_value_get_object (value));
+ ev_sidebar_set_page (sidebar, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -146,12 +97,25 @@ ev_sidebar_set_property (GObject *object,
}
static GtkWidget *
-ev_sidebar_get_current_page (EvSidebar *sidebar)
+ev_sidebar_get_current_page (EvSidebar *ev_sidebar)
{
- GtkNotebook *notebook = GTK_NOTEBOOK (sidebar->priv->notebook);
+ return gtk_stack_get_visible_child (GTK_STACK (ev_sidebar->priv->stack));
+}
+
+static gchar *
+ev_sidebar_get_visible_icon_name (EvSidebar *ev_sidebar)
+{
+ GtkStack *stack;
+ GtkWidget *widget;
+ gchar *icon_name;
- return gtk_notebook_get_nth_page
- (notebook, gtk_notebook_get_current_page (notebook));
+ stack = GTK_STACK (ev_sidebar->priv->stack);
+ widget = gtk_stack_get_visible_child (stack);
+ gtk_container_child_get (GTK_CONTAINER (stack), widget,
+ "icon-name", &icon_name,
+ NULL);
+
+ return icon_name;
}
static void
@@ -161,12 +125,18 @@ ev_sidebar_get_property (GObject *object,
GParamSpec *pspec)
{
EvSidebar *sidebar = EV_SIDEBAR (object);
+ gchar *icon_name;
switch (prop_id)
{
case PROP_CURRENT_PAGE:
g_value_set_object (value, ev_sidebar_get_current_page (sidebar));
break;
+ case PROP_ACTIVE_ICON_NAME:
+ icon_name = ev_sidebar_get_visible_icon_name (sidebar);
+ g_value_set_string (value, icon_name);
+ g_free (icon_name);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -191,151 +161,34 @@ ev_sidebar_class_init (EvSidebarClass *ev_sidebar_class)
GTK_TYPE_WIDGET,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (g_object_class,
+ PROP_ACTIVE_ICON_NAME,
+ g_param_spec_string ("active-icon-name",
+ "Current page",
+ "The icon name of the currently visible page",
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
}
static void
-ev_sidebar_menu_position_under (GtkMenu *menu,
- int *x,
- int *y,
- gboolean *push_in,
- gpointer user_data)
-{
- GtkWidget *widget;
- GtkAllocation allocation;
-
- g_return_if_fail (GTK_IS_BUTTON (user_data));
- g_return_if_fail (!gtk_widget_get_has_window (GTK_WIDGET (user_data)));
-
- widget = GTK_WIDGET (user_data);
-
- gdk_window_get_origin (gtk_widget_get_window (widget), x, y);
- gtk_widget_get_allocation (widget, &allocation);
-
- *x += allocation.x;
- *y += allocation.y + allocation.height;
-
- *push_in = FALSE;
-}
-
-static gboolean
-ev_sidebar_select_button_press_cb (GtkWidget *widget,
- GdkEventButton *event,
- gpointer user_data)
-{
- EvSidebar *ev_sidebar = EV_SIDEBAR (user_data);
-
- if (event->button == 1) {
- GtkRequisition requisition;
- GtkAllocation allocation;
- gint width;
-
- gtk_widget_get_allocation (widget, &allocation);
- width = allocation.width;
- gtk_widget_set_size_request (ev_sidebar->priv->menu, -1, -1);
- gtk_widget_get_preferred_size (ev_sidebar->priv->menu, &requisition, NULL);
- gtk_widget_set_size_request (ev_sidebar->priv->menu,
- MAX (width, requisition.width), -1);
-
- gtk_widget_grab_focus (widget);
-
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
- gtk_menu_popup (GTK_MENU (ev_sidebar->priv->menu),
- NULL, NULL, ev_sidebar_menu_position_under, widget,
- event->button, event->time);
-
- return TRUE;
- }
-
- return FALSE;
-}
-
-static gboolean
-ev_sidebar_select_button_key_press_cb (GtkWidget *widget,
- GdkEventKey *event,
- gpointer user_data)
-{
- EvSidebar *ev_sidebar = EV_SIDEBAR (user_data);
-
- if (event->keyval == GDK_KEY_space ||
- event->keyval == GDK_KEY_KP_Space ||
- event->keyval == GDK_KEY_Return ||
- event->keyval == GDK_KEY_KP_Enter) {
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
- gtk_menu_popup (GTK_MENU (ev_sidebar->priv->menu),
- NULL, NULL, ev_sidebar_menu_position_under, widget,
- 1, event->time);
- return TRUE;
- }
-
- return FALSE;
-}
-
-static void
-ev_sidebar_close_clicked_cb (GtkWidget *widget,
- gpointer user_data)
-{
- EvSidebar *ev_sidebar = EV_SIDEBAR (user_data);
-
- gtk_widget_hide (GTK_WIDGET (ev_sidebar));
-}
-
-static void
-ev_sidebar_menu_deactivate_cb (GtkWidget *widget,
- gpointer user_data)
-{
- GtkWidget *menu_button;
-
- menu_button = GTK_WIDGET (user_data);
-
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (menu_button), FALSE);
-}
-
-static void
-ev_sidebar_menu_detach_cb (GtkWidget *widget,
- GtkMenu *menu)
-{
- EvSidebar *ev_sidebar = EV_SIDEBAR (widget);
-
- ev_sidebar->priv->menu = NULL;
-}
-
-static void
-ev_sidebar_menu_item_activate_cb (GtkWidget *widget,
- gpointer user_data)
+ev_sidebar_child_change_cb (GObject *gobject,
+ GParamSpec *pspec,
+ EvSidebar *ev_sidebar)
{
- EvSidebar *ev_sidebar = EV_SIDEBAR (user_data);
- GtkTreeIter iter;
- GtkWidget *menu_item, *item;
- gboolean valid;
+ GtkStack *stack = GTK_STACK (ev_sidebar->priv->stack);
+ const gchar *name;
- 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_MENU_ITEM, &item,
- -1);
-
- if (item == menu_item) {
- 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_object_notify (G_OBJECT (ev_sidebar), "current-page");
+ name = gtk_stack_get_visible_child_name (stack);
+ if (name)
+ g_object_notify (G_OBJECT (ev_sidebar), "current-page");
}
static void
ev_sidebar_init (EvSidebar *ev_sidebar)
{
- GtkWidget *hbox;
- GtkWidget *close_button;
- GtkWidget *select_hbox;
- GtkWidget *separator;
- GtkWidget *arrow;
+ GtkWidget *switcher;
+ GtkWidget *stack;
ev_sidebar->priv = EV_SIDEBAR_GET_PRIVATE (ev_sidebar);
@@ -344,163 +197,46 @@ ev_sidebar_init (EvSidebar *ev_sidebar)
gtk_list_store_new (PAGE_COLUMN_NUM_COLS,
G_TYPE_STRING,
GTK_TYPE_WIDGET,
- GTK_TYPE_WIDGET,
- G_TYPE_INT);
-
- /* top option menu */
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
- gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
- ev_sidebar->priv->hbox = hbox;
- gtk_box_pack_start (GTK_BOX (ev_sidebar), hbox, FALSE, FALSE, 0);
- gtk_widget_show (hbox);
-
- /* separator */
- separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
- gtk_box_pack_start (GTK_BOX (ev_sidebar), separator, FALSE, FALSE, 0);
- gtk_widget_show (separator);
-
- ev_sidebar->priv->select_button = gtk_toggle_button_new ();
- gtk_button_set_relief (GTK_BUTTON (ev_sidebar->priv->select_button), GTK_RELIEF_NONE);
- g_signal_connect (ev_sidebar->priv->select_button, "button_press_event",
- G_CALLBACK (ev_sidebar_select_button_press_cb),
- ev_sidebar);
- g_signal_connect (ev_sidebar->priv->select_button, "key_press_event",
- G_CALLBACK (ev_sidebar_select_button_key_press_cb),
- ev_sidebar);
-
- select_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
-
- ev_sidebar->priv->label = gtk_label_new ("");
- gtk_label_set_ellipsize (GTK_LABEL (ev_sidebar->priv->label), PANGO_ELLIPSIZE_END);
- gtk_box_pack_start (GTK_BOX (select_hbox),
- ev_sidebar->priv->label,
- FALSE, FALSE, 0);
- gtk_widget_show (ev_sidebar->priv->label);
-
- arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
- gtk_box_pack_end (GTK_BOX (select_hbox), arrow, FALSE, FALSE, 0);
- gtk_widget_show (arrow);
-
- gtk_container_add (GTK_CONTAINER (ev_sidebar->priv->select_button), select_hbox);
- gtk_widget_show (select_hbox);
-
- gtk_box_set_center_widget (GTK_BOX (hbox), ev_sidebar->priv->select_button);
- gtk_widget_show (ev_sidebar->priv->select_button);
-
- close_button = gtk_button_new_from_icon_name ("window-close-symbolic", GTK_ICON_SIZE_BUTTON);
- gtk_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
- g_signal_connect (close_button, "clicked",
- G_CALLBACK (ev_sidebar_close_clicked_cb),
- ev_sidebar);
- gtk_box_pack_end (GTK_BOX (hbox), close_button, FALSE, FALSE, 0);
- gtk_widget_show (close_button);
-
- ev_sidebar->priv->menu = gtk_menu_new ();
- g_signal_connect (ev_sidebar->priv->menu, "deactivate",
- G_CALLBACK (ev_sidebar_menu_deactivate_cb),
- ev_sidebar->priv->select_button);
- gtk_menu_attach_to_widget (GTK_MENU (ev_sidebar->priv->menu),
- GTK_WIDGET (ev_sidebar),
- ev_sidebar_menu_detach_cb);
- gtk_widget_show (ev_sidebar->priv->menu);
-
- ev_sidebar->priv->notebook = gtk_notebook_new ();
- gtk_notebook_set_show_border (GTK_NOTEBOOK (ev_sidebar->priv->notebook), FALSE);
- gtk_notebook_set_show_tabs (GTK_NOTEBOOK (ev_sidebar->priv->notebook), FALSE);
- gtk_box_pack_start (GTK_BOX (ev_sidebar), ev_sidebar->priv->notebook,
- TRUE, TRUE, 0);
- gtk_widget_show (ev_sidebar->priv->notebook);
-
- gtk_widget_set_sensitive (GTK_WIDGET (ev_sidebar->priv->notebook), FALSE);
- gtk_widget_set_sensitive (GTK_WIDGET (ev_sidebar->priv->select_button), FALSE);
-}
-
-/* Public functions */
-
-GtkWidget *
-ev_sidebar_new (void)
-{
- GtkWidget *ev_sidebar;
-
- ev_sidebar = g_object_new (EV_TYPE_SIDEBAR,
- "orientation", GTK_ORIENTATION_VERTICAL,
- NULL);
-
- return ev_sidebar;
-}
-
-void
-ev_sidebar_add_page (EvSidebar *ev_sidebar,
- GtkWidget *main_widget)
-{
- GtkTreeIter iter;
- GtkWidget *menu_item;
- gchar *label_title;
- const gchar *title;
- int index;
-
- g_return_if_fail (EV_IS_SIDEBAR (ev_sidebar));
- g_return_if_fail (EV_IS_SIDEBAR_PAGE (main_widget));
- g_return_if_fail (GTK_IS_WIDGET (main_widget));
-
- ev_sidebar_page_set_model (EV_SIDEBAR_PAGE (main_widget),
- ev_sidebar->priv->model);
- title = ev_sidebar_page_get_label (EV_SIDEBAR_PAGE (main_widget));
-
- index = gtk_notebook_append_page (GTK_NOTEBOOK (ev_sidebar->priv->notebook),
- main_widget, NULL);
-
- menu_item = gtk_image_menu_item_new_with_label (title);
- g_signal_connect (menu_item, "activate",
- G_CALLBACK (ev_sidebar_menu_item_activate_cb),
+ G_TYPE_STRING,
+ G_TYPE_STRING);
+
+ switcher = gtk_stack_switcher_new ();
+ ev_sidebar->priv->switcher = switcher;
+ gtk_box_pack_start (GTK_BOX (ev_sidebar), switcher, FALSE, TRUE, 0);
+ g_object_set (switcher, "icon-size", 1, NULL);
+ gtk_container_set_border_width (GTK_CONTAINER (switcher), 6);
+ gtk_widget_set_halign (switcher, GTK_ALIGN_CENTER);
+ gtk_widget_show (ev_sidebar->priv->switcher);
+
+ stack = gtk_stack_new ();
+ ev_sidebar->priv->stack = stack;
+ gtk_stack_set_homogeneous (GTK_STACK (stack), TRUE);
+ gtk_stack_switcher_set_stack (GTK_STACK_SWITCHER (switcher),
+ GTK_STACK (stack));
+ gtk_box_pack_start (GTK_BOX (ev_sidebar), stack, TRUE, TRUE, 0);
+ gtk_widget_show (ev_sidebar->priv->stack);
+
+ g_signal_connect (stack, "notify::visible-child",
+ G_CALLBACK (ev_sidebar_child_change_cb),
ev_sidebar);
- gtk_widget_show (menu_item);
- gtk_menu_shell_append (GTK_MENU_SHELL (ev_sidebar->priv->menu),
- menu_item);
-
- /* Insert and move to end */
- gtk_list_store_insert_with_values (GTK_LIST_STORE (ev_sidebar->priv->page_model),
- &iter, 0,
- PAGE_COLUMN_TITLE, title,
- PAGE_COLUMN_MENU_ITEM, menu_item,
- PAGE_COLUMN_MAIN_WIDGET, main_widget,
- PAGE_COLUMN_NOTEBOOK_INDEX, index,
- -1);
- gtk_list_store_move_before(GTK_LIST_STORE(ev_sidebar->priv->page_model),
- &iter, NULL);
-
-
- /* Set the first item added as active */
- gtk_tree_model_get_iter_first (ev_sidebar->priv->page_model, &iter);
- gtk_tree_model_get (ev_sidebar->priv->page_model,
- &iter,
- PAGE_COLUMN_TITLE, &label_title,
- PAGE_COLUMN_NOTEBOOK_INDEX, &index,
- -1);
-
- gtk_menu_set_active (GTK_MENU (ev_sidebar->priv->menu), index);
- gtk_label_set_text (GTK_LABEL (ev_sidebar->priv->label), label_title);
- gtk_notebook_set_current_page (GTK_NOTEBOOK (ev_sidebar->priv->notebook),
- index);
- g_free (label_title);
}
static gboolean
-ev_sidebar_current_page_support_document (EvSidebar *sidebar,
+ev_sidebar_current_page_support_document (EvSidebar *ev_sidebar,
EvDocument *document)
{
- GtkWidget *current_page = ev_sidebar_get_current_page (sidebar);
+ GtkWidget *current_page = ev_sidebar_get_current_page (ev_sidebar);
- return ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (current_page), document);
+ return ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (current_page),
+ document);
}
-
static void
ev_sidebar_document_changed_cb (EvDocumentModel *model,
GParamSpec *pspec,
- EvSidebar *sidebar)
+ EvSidebar *ev_sidebar)
{
- EvSidebarPrivate *priv = sidebar->priv;
+ EvSidebarPrivate *priv = ev_sidebar->priv;
EvDocument *document = ev_document_model_get_document (model);
GtkTreeIter iter;
gboolean valid;
@@ -510,47 +246,120 @@ ev_sidebar_document_changed_cb (EvDocumentModel *model,
valid;
valid = gtk_tree_model_iter_next (priv->page_model, &iter)) {
GtkWidget *widget;
- GtkWidget *menu_widget;
+ gchar *title;
+ gchar *icon_name;
gtk_tree_model_get (priv->page_model, &iter,
PAGE_COLUMN_MAIN_WIDGET, &widget,
- PAGE_COLUMN_MENU_ITEM, &menu_widget,
+ PAGE_COLUMN_TITLE, &title,
+ PAGE_COLUMN_ICON_NAME, &icon_name,
-1);
if (ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (widget), document)) {
- gtk_widget_set_sensitive (menu_widget, TRUE);
+ gtk_container_child_set (GTK_CONTAINER (priv->stack),
+ widget,
+ "icon-name", icon_name,
+ "title", title,
+ NULL);
if (!first_supported_page)
first_supported_page = widget;
} else {
- gtk_widget_set_sensitive (menu_widget, FALSE);
+ /* Without icon and title, the page is not shown in
+ * the GtkStackSwitchter */
+ gtk_container_child_set (GTK_CONTAINER (priv->stack),
+ widget,
+ "icon-name", NULL,
+ "title", NULL,
+ NULL);
}
g_object_unref (widget);
- g_object_unref (menu_widget);
+ g_free (title);
+ g_free (icon_name);
}
if (first_supported_page != NULL) {
- if (!ev_sidebar_current_page_support_document (sidebar, document)) {
- ev_sidebar_set_page (sidebar, first_supported_page);
+ if (!ev_sidebar_current_page_support_document (ev_sidebar, document)) {
+ ev_sidebar_set_page (ev_sidebar, first_supported_page);
}
- gtk_widget_set_sensitive (GTK_WIDGET (sidebar->priv->notebook), TRUE);
- gtk_widget_set_sensitive (GTK_WIDGET (sidebar->priv->select_button), TRUE);
} else {
- gtk_widget_hide (GTK_WIDGET (sidebar));
+ gtk_widget_hide (GTK_WIDGET (ev_sidebar));
}
}
+/* Public functions */
+
+GtkWidget *
+ev_sidebar_new (void)
+{
+ GtkWidget *ev_sidebar;
+
+ ev_sidebar = g_object_new (EV_TYPE_SIDEBAR,
+ "orientation", GTK_ORIENTATION_VERTICAL,
+ NULL);
+
+ return ev_sidebar;
+}
+
+void
+ev_sidebar_add_page (EvSidebar *ev_sidebar,
+ GtkWidget *widget,
+ const gchar *name,
+ const gchar *title,
+ const gchar *icon_name)
+{
+ EvSidebarPrivate *priv;
+ GtkTreeIter iter;
+
+ g_return_if_fail (EV_IS_SIDEBAR (ev_sidebar));
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
+ priv = ev_sidebar->priv;
+
+ ev_sidebar_page_set_model (EV_SIDEBAR_PAGE (widget), priv->model);
+
+ gtk_stack_add_named (GTK_STACK (priv->stack), widget, name);
+ gtk_container_child_set (GTK_CONTAINER (priv->stack), widget,
+ "icon-name", icon_name,
+ "title", title,
+ NULL);
+
+ /* Insert and move to end */
+ gtk_list_store_insert_with_values (GTK_LIST_STORE (priv->page_model),
+ &iter, 0,
+ PAGE_COLUMN_NAME, name,
+ PAGE_COLUMN_MAIN_WIDGET, widget,
+ PAGE_COLUMN_TITLE, title,
+ PAGE_COLUMN_ICON_NAME, icon_name,
+ -1);
+ gtk_list_store_move_before (GTK_LIST_STORE (priv->page_model),
+ &iter, NULL);
+}
+
void
-ev_sidebar_set_model (EvSidebar *sidebar,
+ev_sidebar_set_model (EvSidebar *ev_sidebar,
EvDocumentModel *model)
{
- g_return_if_fail (EV_IS_SIDEBAR (sidebar));
+ g_return_if_fail (EV_IS_SIDEBAR (ev_sidebar));
g_return_if_fail (EV_IS_DOCUMENT_MODEL (model));
- if (model == sidebar->priv->model)
+ if (model == ev_sidebar->priv->model)
return;
- sidebar->priv->model = model;
+ ev_sidebar->priv->model = model;
+
g_signal_connect (model, "notify::document",
G_CALLBACK (ev_sidebar_document_changed_cb),
- sidebar);
+ ev_sidebar);
+}
+
+void
+ev_sidebar_set_page (EvSidebar *ev_sidebar,
+ GtkWidget *main_widget)
+{
+ g_return_if_fail (EV_IS_SIDEBAR (ev_sidebar));
+ g_return_if_fail (GTK_IS_WIDGET (main_widget));
+
+ gtk_stack_set_visible_child (GTK_STACK (ev_sidebar->priv->stack),
+ main_widget);
+ g_object_notify (G_OBJECT (ev_sidebar), "current-page");
}
diff --git a/shell/ev-sidebar.h b/shell/ev-sidebar.h
index 5cee4fd0..d4cda917 100644
--- a/shell/ev-sidebar.h
+++ b/shell/ev-sidebar.h
@@ -2,9 +2,11 @@
* this file is part of evince, a gnome document viewer
*
* Copyright (C) 2004 Red Hat, Inc.
+ * Copyright (C) 2018 Germán Poo-Caamaño <gpoo gnome org>
*
* Author:
* Jonathan Blandford <jrb alum mit edu>
+ * Germán Poo-Caamaño <gpoo gnome org>
*
* Evince is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
@@ -54,11 +56,14 @@ struct _EvSidebarClass {
GType ev_sidebar_get_type (void) G_GNUC_CONST;
GtkWidget *ev_sidebar_new (void);
void ev_sidebar_add_page (EvSidebar *ev_sidebar,
- GtkWidget *main_widget);
+ GtkWidget *widget,
+ const gchar *name,
+ const gchar *title,
+ const gchar *icon_name);
void ev_sidebar_set_page (EvSidebar *ev_sidebar,
- GtkWidget *main_widget);
-void ev_sidebar_set_model (EvSidebar *sidebar,
- EvDocumentModel *model);
+ GtkWidget *main_widget);
+void ev_sidebar_set_model (EvSidebar *ev_sidebar,
+ EvDocumentModel *model);
G_END_DECLS
diff --git a/shell/ev-window.c b/shell/ev-window.c
index ae5c5047..bc5d2fe2 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -274,6 +274,12 @@ struct _EvWindowPrivate {
#define LAYERS_SIDEBAR_ID "layers"
#define ANNOTS_SIDEBAR_ID "annotations"
#define BOOKMARKS_SIDEBAR_ID "bookmarks"
+#define LINKS_SIDEBAR_ICON "view-list-symbolic"
+#define THUMBNAILS_SIDEBAR_ICON "view-grid-symbolic"
+#define ATTACHMENTS_SIDEBAR_ICON "mail-attachment-symbolic"
+#define LAYERS_SIDEBAR_ICON "view-paged-symbolic"
+#define ANNOTS_SIDEBAR_ICON "accessories-text-editor-symbolic"
+#define BOOKMARKS_SIDEBAR_ICON "bookmark-new-symbolic"
#define EV_PRINT_SETTINGS_FILE "print-settings"
#define EV_PRINT_SETTINGS_GROUP "Print Settings"
@@ -7113,7 +7119,9 @@ ev_window_init (EvWindow *ev_window)
sidebar_page_main_widget_update_cb (G_OBJECT (sidebar_widget), NULL, ev_window);
gtk_widget_show (sidebar_widget);
ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
- sidebar_widget);
+ sidebar_widget,
+ THUMBNAILS_SIDEBAR_ID, _("Thumbnails"),
+ THUMBNAILS_SIDEBAR_ICON);
sidebar_widget = ev_sidebar_links_new ();
ev_window->priv->sidebar_links = sidebar_widget;
@@ -7128,7 +7136,29 @@ ev_window_init (EvWindow *ev_window)
sidebar_page_main_widget_update_cb (G_OBJECT (sidebar_widget), NULL, ev_window);
gtk_widget_show (sidebar_widget);
ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
- sidebar_widget);
+ sidebar_widget,
+ LINKS_SIDEBAR_ID, _("Outline"),
+ LINKS_SIDEBAR_ICON);
+
+ sidebar_widget = ev_sidebar_annotations_new ();
+ ev_window->priv->sidebar_annots = sidebar_widget;
+ g_signal_connect (sidebar_widget,
+ "annot_activated",
+ G_CALLBACK (sidebar_annots_annot_activated_cb),
+ ev_window);
+ gtk_widget_show (sidebar_widget);
+ ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
+ sidebar_widget,
+ ANNOTS_SIDEBAR_ID, _("Annotations"),
+ ANNOTS_SIDEBAR_ICON);
+
+ sidebar_widget = ev_sidebar_bookmarks_new ();
+ ev_window->priv->sidebar_bookmarks = sidebar_widget;
+ gtk_widget_show (sidebar_widget);
+ ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
+ sidebar_widget,
+ BOOKMARKS_SIDEBAR_ID, _("Bookmarks"),
+ BOOKMARKS_SIDEBAR_ICON);
sidebar_widget = ev_sidebar_attachments_new ();
ev_window->priv->sidebar_attachments = sidebar_widget;
@@ -7142,7 +7172,9 @@ ev_window_init (EvWindow *ev_window)
ev_window, 0);
gtk_widget_show (sidebar_widget);
ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
- sidebar_widget);
+ sidebar_widget,
+ ATTACHMENTS_SIDEBAR_ID, _("Attachments"),
+ ATTACHMENTS_SIDEBAR_ICON);
sidebar_widget = ev_sidebar_layers_new ();
ev_window->priv->sidebar_layers = sidebar_widget;
@@ -7152,23 +7184,9 @@ ev_window_init (EvWindow *ev_window)
ev_window);
gtk_widget_show (sidebar_widget);
ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
- sidebar_widget);
-
- sidebar_widget = ev_sidebar_annotations_new ();
- ev_window->priv->sidebar_annots = sidebar_widget;
- g_signal_connect (sidebar_widget,
- "annot_activated",
- G_CALLBACK (sidebar_annots_annot_activated_cb),
- ev_window);
- gtk_widget_show (sidebar_widget);
- ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
- sidebar_widget);
-
- sidebar_widget = ev_sidebar_bookmarks_new ();
- ev_window->priv->sidebar_bookmarks = sidebar_widget;
- gtk_widget_show (sidebar_widget);
- ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
- sidebar_widget);
+ sidebar_widget,
+ LAYERS_SIDEBAR_ID, _("Layers"),
+ LAYERS_SIDEBAR_ICON);
ev_window->priv->view_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]