X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=sidebyside;f=shell%2Fev-sidebar-links.c;h=cbe19b1bce2e0a9a21f8981d71e058f8ba97a59c;hb=b712f364fbbc41c010613c3005befe66d6b8fe16;hp=50eb29f6b30157420985489dc3c01743a18c0ccc;hpb=738af006aeed38bb1cc0f002a8613a343f5c3706;p=evince.git
diff --git a/shell/ev-sidebar-links.c b/shell/ev-sidebar-links.c
index 50eb29f6..cbe19b1b 100644
--- a/shell/ev-sidebar-links.c
+++ b/shell/ev-sidebar-links.c
@@ -59,11 +59,6 @@ enum {
N_SIGNALS
};
-static void links_page_num_func (GtkTreeViewColumn *tree_column,
- GtkCellRenderer *cell,
- GtkTreeModel *tree_model,
- GtkTreeIter *iter,
- EvSidebarLinks *sidebar_links);
static void update_page_callback (EvPageCache *page_cache,
gint current_page,
EvSidebarLinks *sidebar_links);
@@ -178,7 +173,7 @@ ev_sidebar_links_map (GtkWidget *widget)
GTK_WIDGET_CLASS (ev_sidebar_links_parent_class)->map (widget);
- if (links->priv->page_cache) {
+ if (links->priv->model) {
update_page_callback (links->priv->page_cache,
ev_page_cache_get_current_page (links->priv->page_cache),
links);
@@ -264,7 +259,8 @@ create_loading_model (void)
retval = (GtkTreeModel *)gtk_list_store_new (EV_DOCUMENT_LINKS_COLUMN_NUM_COLUMNS,
G_TYPE_STRING,
G_TYPE_OBJECT,
- G_TYPE_BOOLEAN);
+ G_TYPE_BOOLEAN,
+ G_TYPE_STRING);
gtk_list_store_append (GTK_LIST_STORE (retval), &iter);
markup = g_strdup_printf ("%s", _("Loading..."));
@@ -278,27 +274,6 @@ create_loading_model (void)
return retval;
}
-static gint
-get_page_from_link (EvLink *link)
-{
- EvLinkAction *action;
- EvLinkDest *dest;
-
- action = ev_link_get_action (link);
- if (!action)
- return -1;
-
- if (ev_link_action_get_action_type (action) !=
- EV_LINK_ACTION_TYPE_GOTO_DEST)
- return -1;
-
- dest = ev_link_action_get_dest (action);
- if (dest)
- return ev_link_dest_get_page (dest);
-
- return -1;
-}
-
static void
print_section_cb (GtkWidget *menuitem, EvSidebarLinks *sidebar)
{
@@ -321,7 +296,7 @@ print_section_cb (GtkWidget *menuitem, EvSidebarLinks *sidebar)
if (!link)
return;
- first_page = get_page_from_link (link);
+ first_page = ev_link_get_page (link);
if (first_page == -1) {
g_object_unref (link);
return;
@@ -336,7 +311,7 @@ print_section_cb (GtkWidget *menuitem, EvSidebarLinks *sidebar)
-1);
if (link) {
- last_page = get_page_from_link (link);
+ last_page = ev_link_get_page (link);
g_object_unref (link);
}
} else {
@@ -461,9 +436,10 @@ ev_sidebar_links_construct (EvSidebarLinks *ev_sidebar_links)
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) links_page_num_func,
- ev_sidebar_links, NULL);
+ gtk_tree_view_column_set_attributes (GTK_TREE_VIEW_COLUMN (column), renderer,
+ "text", EV_DOCUMENT_LINKS_COLUMN_PAGE_LABEL,
+ NULL);
+ g_object_set (G_OBJECT (renderer), "style", PANGO_STYLE_ITALIC, NULL);
g_signal_connect (GTK_TREE_VIEW (priv->tree_view),
"button_press_event",
@@ -483,51 +459,38 @@ ev_sidebar_links_init (EvSidebarLinks *ev_sidebar_links)
ev_sidebar_links_construct (ev_sidebar_links);
}
-static void
-links_page_num_func (GtkTreeViewColumn *tree_column,
- GtkCellRenderer *cell,
- GtkTreeModel *tree_model,
- GtkTreeIter *iter,
- EvSidebarLinks *sidebar_links)
+static gboolean
+fill_page_labels (GtkTreeModel *tree_model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ EvSidebarLinks *sidebar_links)
{
EvLink *link;
gint page;
+ gchar *page_label;
gtk_tree_model_get (tree_model, iter,
EV_DOCUMENT_LINKS_COLUMN_LINK, &link,
-1);
- if (!link) {
- g_object_set (cell,
- "visible", FALSE,
- NULL);
- return;
- }
-
- page = get_page_from_link (link);
+ if (!link)
+ return FALSE;
- if (page >= 0) {
- gchar *page_label;
- gchar *page_string;
+ page = ev_link_get_page (link);
- page_label = ev_page_cache_get_page_label (sidebar_links->priv->page_cache,
- page);
- page_string = g_markup_printf_escaped ("%s", page_label);
-
- g_object_set (cell,
- "markup", page_string,
- "visible", TRUE,
- NULL);
+ if (page < 0)
+ return FALSE;
+
+ page_label = ev_page_cache_get_page_label (sidebar_links->priv->page_cache,
+ page);
+ gtk_tree_store_set (GTK_TREE_STORE (tree_model), iter,
+ EV_DOCUMENT_LINKS_COLUMN_PAGE_LABEL, page_label,
+ -1);
- g_free (page_label);
- g_free (page_string);
- } else {
- g_object_set (cell,
- "visible", FALSE,
- NULL);
- }
+ g_free (page_label);
g_object_unref (link);
+ return FALSE;
}
/* Public Functions */
@@ -559,7 +522,7 @@ update_page_callback_foreach (GtkTreeModel *model,
int current_page;
int dest_page;
- dest_page = get_page_from_link (link);
+ dest_page = ev_link_get_page (link);
g_object_unref (link);
current_page = ev_page_cache_get_current_page (sidebar_links->priv->page_cache);
@@ -601,7 +564,7 @@ update_page_callback (EvPageCache *page_cache,
if (link) {
gint dest_page;
- dest_page = get_page_from_link (link);
+ dest_page = ev_link_get_page (link);
g_object_unref (link);
if (dest_page == current_page)
@@ -630,7 +593,7 @@ row_activated_callback (GtkTreeView *treeview,
GtkTreePath *arg1,
GtkTreeViewColumn *arg2,
gpointer user_data)
-{
+{
if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (treeview), arg1)) {
gtk_tree_view_collapse_row (GTK_TREE_VIEW (treeview), arg1);
} else {
@@ -673,6 +636,8 @@ job_finished_callback (EvJobLinks *job,
priv->model = job->model;
g_object_notify (G_OBJECT (sidebar_links), "model");
+
+ gtk_tree_model_foreach (priv->model, (GtkTreeModelForeachFunc)fill_page_labels, sidebar_links);
gtk_tree_view_set_model (GTK_TREE_VIEW (priv->tree_view), job->model);
@@ -683,18 +648,26 @@ job_finished_callback (EvJobLinks *job,
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
- priv->selection_id = g_signal_connect (selection, "changed",
- G_CALLBACK (selection_changed_callback),
- sidebar_links);
- priv->page_changed_id = g_signal_connect (priv->page_cache, "page-changed",
+
+ if (priv->selection_id <= 0) {
+ priv->selection_id =
+ g_signal_connect (selection, "changed",
+ G_CALLBACK (selection_changed_callback),
+ sidebar_links);
+ }
+ priv->page_changed_id = g_signal_connect (priv->page_cache, "page-changed",
G_CALLBACK (update_page_callback),
sidebar_links);
- priv->row_activated_id = g_signal_connect (G_OBJECT (priv->tree_view), "row-activated",
- G_CALLBACK (row_activated_callback), sidebar_links);
+ if (priv->row_activated_id <= 0) {
+ priv->row_activated_id =
+ g_signal_connect (G_OBJECT (priv->tree_view), "row-activated",
+ G_CALLBACK (row_activated_callback),
+ sidebar_links);
+ }
+
update_page_callback (priv->page_cache,
ev_page_cache_get_current_page (priv->page_cache),
sidebar_links);
-
}
static void