struct _EvSidebarBookmarksPrivate {
GtkWidget *tree_view;
+ GtkTreeModel *model;
+ EvDocument *current_document;
};
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) \
{
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),
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
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)
{
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);
+
+}
+
#include <gtk/gtk.h>
#include "ev-sidebar.h"
+#include "ev-sidebar-bookmarks.h"
typedef struct
{
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,
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,
-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)
{
#define __EV_SIDEBAR_H__
#include <gtk/gtkvbox.h>
+#include "ev-document.h"
G_BEGIN_DECLS
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