From: Jonathan Blandford Date: Wed, 22 Dec 2004 18:41:31 +0000 (+0000) Subject: initial sidebar document setting code. X-Git-Tag: EVINCE_0_1_0~77 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=37ca059dda89fecb22f6297d337ea393b2069605;p=evince.git initial sidebar document setting code. Wed Dec 22 13:41:01 2004 Jonathan Blandford * shell/ev-sidebar.c (ev_sidebar_set_document): initial sidebar document setting code. --- diff --git a/ChangeLog b/ChangeLog index 3d95437d..1f70b1a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Dec 22 13:41:01 2004 Jonathan Blandford + + * shell/ev-sidebar.c (ev_sidebar_set_document): initial sidebar + document setting code. + 2004-12-22 Anders Carlsson * shell/eggfindbar.c: (entry_activate_callback): diff --git a/shell/ev-sidebar-bookmarks.c b/shell/ev-sidebar-bookmarks.c index b7e060f5..e29975a6 100644 --- a/shell/ev-sidebar-bookmarks.c +++ b/shell/ev-sidebar-bookmarks.c @@ -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 ("%d", 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); + +} + diff --git a/shell/ev-sidebar-bookmarks.h b/shell/ev-sidebar-bookmarks.h index 86902c78..92c5d41a 100644 --- a/shell/ev-sidebar-bookmarks.h +++ b/shell/ev-sidebar-bookmarks.h @@ -25,6 +25,7 @@ #define __EV_SIDEBAR_BOOKMARKS_H__ #include +#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 diff --git a/shell/ev-sidebar.c b/shell/ev-sidebar.c index 4ff84052..780f9f6a 100644 --- a/shell/ev-sidebar.c +++ b/shell/ev-sidebar.c @@ -28,6 +28,7 @@ #include #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) { diff --git a/shell/ev-sidebar.h b/shell/ev-sidebar.h index ea97f5f8..ec028ffb 100644 --- a/shell/ev-sidebar.h +++ b/shell/ev-sidebar.h @@ -25,6 +25,7 @@ #define __EV_SIDEBAR_H__ #include +#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 diff --git a/shell/ev-window.c b/shell/ev-window.c index 870af0ba..4e1cc650 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -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);