]> www.fi.muni.cz Git - evince.git/commitdiff
initial sidebar document setting code.
authorJonathan Blandford <jrb@redhat.com>
Wed, 22 Dec 2004 18:41:31 +0000 (18:41 +0000)
committerJonathan Blandford <jrb@src.gnome.org>
Wed, 22 Dec 2004 18:41:31 +0000 (18:41 +0000)
Wed Dec 22 13:41:01 2004  Jonathan Blandford  <jrb@redhat.com>

        * shell/ev-sidebar.c (ev_sidebar_set_document): initial sidebar
        document setting code.

ChangeLog
shell/ev-sidebar-bookmarks.c
shell/ev-sidebar-bookmarks.h
shell/ev-sidebar.c
shell/ev-sidebar.h
shell/ev-window.c

index 3d95437d82ed9ba80886229a8f23eefd7d8e0a2d..1f70b1a98de4aa3d955c3314ae245dff041c36fb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Dec 22 13:41:01 2004  Jonathan Blandford  <jrb@redhat.com>
+
+       * shell/ev-sidebar.c (ev_sidebar_set_document): initial sidebar
+       document setting code.
+
 2004-12-22  Anders Carlsson  <andersca@gnome.org>
 
        * shell/eggfindbar.c: (entry_activate_callback):
index b7e060f54cb2cb4b96d3a398d307224d75821afa..e29975a680d0818f5e3fc97d79a059e27daa5fc4 100644 (file)
@@ -31,6 +31,8 @@
 
 struct _EvSidebarBookmarksPrivate {
        GtkWidget *tree_view;
+       GtkTreeModel *model;
+       EvDocument *current_document;
 };
 
 enum {
@@ -38,9 +40,15 @@ enum {
        BOOKMARKS_COLUMN_OUTLINE,
        BOOKMARKS_COLUMN_PAGE_NUM,
        BOOKMARKS_COLUMN_PAGE_VALID,
-       NUM_COLUMNS
+       BOOKMARKS_COLUMN_NUM_COLUMNS
 };
 
+static void bookmarks_page_num_func (GtkTreeViewColumn *tree_column,
+                                    GtkCellRenderer   *cell,
+                                    GtkTreeModel      *tree_model,
+                                    GtkTreeIter       *iter,
+                                    gpointer           data);
+
 G_DEFINE_TYPE (EvSidebarBookmarks, ev_sidebar_bookmarks, GTK_TYPE_VBOX)
 
 #define EV_SIDEBAR_BOOKMARKS_GET_PRIVATE(object) \
@@ -63,8 +71,16 @@ ev_sidebar_bookmarks_construct (EvSidebarBookmarks *ev_sidebar_bookmarks)
 {
        EvSidebarBookmarksPrivate *priv;
        GtkWidget *swindow;
+       GtkTreeViewColumn *column;
+       GtkCellRenderer *renderer;
 
        priv = ev_sidebar_bookmarks->priv;
+       priv->model = (GtkTreeModel *) gtk_tree_store_new (BOOKMARKS_COLUMN_NUM_COLUMNS,
+                                                          G_TYPE_STRING,
+                                                          G_TYPE_POINTER,
+                                                          G_TYPE_INT,
+                                                          G_TYPE_BOOLEAN);
+
        swindow = gtk_scrolled_window_new (NULL, NULL);
 
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
@@ -76,9 +92,30 @@ ev_sidebar_bookmarks_construct (EvSidebarBookmarks *ev_sidebar_bookmarks)
        priv->tree_view = gtk_tree_view_new ();
        gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->tree_view), FALSE);
        gtk_container_add (GTK_CONTAINER (swindow), priv->tree_view);
+       gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (priv->tree_view), TRUE);
 
        gtk_box_pack_start (GTK_BOX (ev_sidebar_bookmarks), swindow, TRUE, TRUE, 0);
        gtk_widget_show_all (GTK_WIDGET (ev_sidebar_bookmarks));
+               
+       column = gtk_tree_view_column_new ();
+       gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE);
+       gtk_tree_view_append_column (GTK_TREE_VIEW (priv->tree_view), column);
+
+       renderer = (GtkCellRenderer*)
+               g_object_new (GTK_TYPE_CELL_RENDERER_TEXT,
+                             "ellipsize", PANGO_ELLIPSIZE_END,
+                             NULL);
+       gtk_tree_view_column_pack_start (GTK_TREE_VIEW_COLUMN (column), renderer, TRUE);
+       gtk_tree_view_column_set_attributes (GTK_TREE_VIEW_COLUMN (column), renderer,
+                                            "markup", BOOKMARKS_COLUMN_MARKUP,
+                                            NULL);
+               
+       renderer = gtk_cell_renderer_text_new ();
+       gtk_tree_view_column_pack_end (GTK_TREE_VIEW_COLUMN (column), renderer, FALSE);
+       gtk_tree_view_column_set_cell_data_func (GTK_TREE_VIEW_COLUMN (column), renderer,
+                                                (GtkTreeCellDataFunc) bookmarks_page_num_func,
+                                                NULL, NULL);
+
 }
 
 static void
@@ -89,6 +126,37 @@ ev_sidebar_bookmarks_init (EvSidebarBookmarks *ev_sidebar_bookmarks)
        ev_sidebar_bookmarks_construct (ev_sidebar_bookmarks);
 }
 
+static void
+bookmarks_page_num_func (GtkTreeViewColumn *tree_column,
+                        GtkCellRenderer   *cell,
+                        GtkTreeModel      *tree_model,
+                        GtkTreeIter       *iter,
+                        gpointer           data)
+{
+       int page_num;
+       gboolean page_valid;
+
+       gtk_tree_model_get (tree_model, iter,
+                           BOOKMARKS_COLUMN_PAGE_NUM, &page_num,
+                           BOOKMARKS_COLUMN_PAGE_VALID, &page_valid,
+                           -1);
+
+       if (page_valid) {
+               gchar *markup = g_strdup_printf ("<i>%d</i>", page_num);
+               g_object_set (cell,
+                             "markup", markup,
+                             "visible", TRUE,
+                             NULL);
+               g_free (markup);
+       } else {
+               g_object_set (cell,
+                             "visible", FALSE,
+                             NULL);
+       }
+}
+
+/* Public Functions */
+
 GtkWidget *
 ev_sidebar_bookmarks_new (void)
 {
@@ -98,3 +166,19 @@ ev_sidebar_bookmarks_new (void)
 
        return ev_sidebar_bookmarks;
 }
+
+void
+ev_sidebar_bookmarks_set_document (EvSidebarBookmarks *sidebar_bookmarks,
+                                  EvDocument         *document)
+{
+       EvSidebarBookmarksPrivate *priv;
+
+       g_return_if_fail (EV_IS_SIDEBAR_BOOKMARKS (sidebar_bookmarks));
+       g_return_if_fail (EV_IS_DOCUMENT (document));
+
+       priv = sidebar_bookmarks->priv;
+
+       g_assert (priv->current_document == NULL);
+
+}
+
index 86902c78822a52ca6fe27c8c56ab43e3ae8ce14c..92c5d41ad009b8f6d9c6451808c361c28780e052 100644 (file)
@@ -25,6 +25,7 @@
 #define __EV_SIDEBAR_BOOKMARKS_H__
 
 #include <gtk/gtkvbox.h>
+#include "ev-document.h"
 
 G_BEGIN_DECLS
 
@@ -51,6 +52,8 @@ struct _EvSidebarBookmarksClass {
 
 GType      ev_sidebar_bookmarks_get_type (void);
 GtkWidget *ev_sidebar_bookmarks_new      (void);
+void       ev_sidebar_bookmarks_set_document (EvSidebarBookmarks *ev_sidebar_bookmarks,
+                                             EvDocument         *document);
 
 G_END_DECLS
 
index 4ff8405293fa5fe49d6138c3fff21b70a59c940d..780f9f6a73811371777b39450d5b483c4e116411 100644 (file)
@@ -28,6 +28,7 @@
 #include <gtk/gtk.h>
 
 #include "ev-sidebar.h"
+#include "ev-sidebar-bookmarks.h"
 
 typedef struct
 {
@@ -78,8 +79,8 @@ ev_sidebar_init (EvSidebar *ev_sidebar)
        GtkCellRenderer *renderer;
 
        ev_sidebar->priv = EV_SIDEBAR_GET_PRIVATE (ev_sidebar);
-
        gtk_box_set_spacing (GTK_BOX (ev_sidebar), 6);
+
        /* data model */
        ev_sidebar->priv->page_model = (GtkTreeModel *)
                gtk_list_store_new (PAGE_COLUMN_NUM_COLS,
@@ -87,6 +88,7 @@ ev_sidebar_init (EvSidebar *ev_sidebar)
                                    G_TYPE_STRING,
                                    GTK_TYPE_WIDGET,
                                    G_TYPE_INT);
+
        /* top option menu */
        hbox = gtk_hbox_new (FALSE, 6);
        gtk_box_pack_start (GTK_BOX (ev_sidebar), hbox,
@@ -172,6 +174,42 @@ ev_sidebar_add_page (EvSidebar   *ev_sidebar,
                                           -1);
 }
 
+void
+ev_sidebar_set_document (EvSidebar   *sidebar,
+                        EvDocument  *document)
+{
+       EvSidebarPrivate *priv;
+       GtkTreeIter iter;
+       gboolean result;
+
+       g_return_if_fail (EV_IS_SIDEBAR (sidebar));
+       g_return_if_fail (EV_IS_DOCUMENT (document));
+
+       priv = sidebar->priv;
+       
+       /* FIXME: We should prolly make sidebars have an interface.  For now, we
+        * do this bad hack (TM)
+        */
+       for (result = gtk_tree_model_get_iter_first (priv->page_model, &iter);
+            result;
+            result = gtk_tree_model_iter_next (priv->page_model, &iter)) {
+               GtkWidget *widget;
+
+               gtk_tree_model_get (priv->page_model, &iter,
+                                   PAGE_COLUMN_MAIN_WIDGET, &widget,
+                                   -1);
+
+               if (EV_IS_SIDEBAR_BOOKMARKS (widget))
+                       /* && EV_IS_BOOKMARKS (document)
+                          && ev_bookmarks_has_bookmarks (document)... */
+                       ev_sidebar_bookmarks_set_document (EV_SIDEBAR_BOOKMARKS (widget),
+                                                          document);
+               /* else if EV_IS_SIDEBAR_THUMBNAILS... */
+       }
+       
+
+}
+
 void
 ev_sidebar_clear (EvSidebar *ev_sidebar)
 {
index ea97f5f82368e9b3db771b63bff0799db39b4143..ec028ffb462e5bbc293c7f58e059d3e1becfa902 100644 (file)
@@ -25,6 +25,7 @@
 #define __EV_SIDEBAR_H__
 
 #include <gtk/gtkvbox.h>
+#include "ev-document.h"
 
 G_BEGIN_DECLS
 
@@ -49,13 +50,15 @@ struct _EvSidebarClass {
        GtkVBoxClass base_class;
 };
 
-GType      ev_sidebar_get_type (void);
-GtkWidget *ev_sidebar_new      (void);
-void       ev_sidebar_add_page (EvSidebar   *ev_sidebar,
-                               const gchar *page_id,
-                               const gchar *title,
-                               GtkWidget   *main_widget);
-void       ev_sidebar_clear    (EvSidebar   *ev_sidebar);
+GType      ev_sidebar_get_type     (void);
+GtkWidget *ev_sidebar_new          (void);
+void       ev_sidebar_add_page     (EvSidebar   *ev_sidebar,
+                                   const gchar *page_id,
+                                   const gchar *title,
+                                   GtkWidget   *main_widget);
+void       ev_sidebar_set_document (EvSidebar   *ev_sidebar,
+                                   EvDocument  *document);
+void       ev_sidebar_clear        (EvSidebar   *ev_sidebar);
 
 G_END_DECLS
 
index 870af0ba4abcd0e7a7c9d30c6fa8605730256553..4e1cc65008d6a503f58a4e411971fff9e3ca90b6 100644 (file)
@@ -271,6 +271,8 @@ ev_window_open (EvWindow *ev_window, const char *uri)
 
                        ev_view_set_document (EV_VIEW (ev_window->priv->view),
                                              document);
+                       ev_sidebar_set_document (EV_SIDEBAR (ev_window->priv->sidebar),
+                                                document);
 
                        update_action_sensitivity (ev_window);