]> www.fi.muni.cz Git - evince.git/commitdiff
Expand links when specified by the document. Depend on a poppler api
authorMarco Pesenti Gritti <mpg@redhat.com>
Wed, 15 Jun 2005 14:06:40 +0000 (14:06 +0000)
committerMarco Pesenti Gritti <marco@src.gnome.org>
Wed, 15 Jun 2005 14:06:40 +0000 (14:06 +0000)
2005-06-15  Marco Pesenti Gritti <mpg@redhat.com>

        * backend/ev-document-links.h:
        * pdf/ev-poppler.cc:
        * shell/ev-sidebar-links.c: (create_loading_model),
        (expand_open_links), (job_finished_callback):

        Expand links when specified by the document.
        Depend on a poppler api (defined out for now)

ChangeLog
backend/ev-document-links.h
pdf/ev-poppler.cc
shell/ev-sidebar-links.c

index 794db778a1b23287127d61171447c2e8cae099ee..d1609993c97e8eaae97e8fac05b23ecc5e7485b7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2005-06-15  Marco Pesenti Gritti <mpg@redhat.com>
+
+       * backend/ev-document-links.h:
+       * pdf/ev-poppler.cc:
+       * shell/ev-sidebar-links.c: (create_loading_model),
+       (expand_open_links), (job_finished_callback):
+
+       Expand links when specified by the document.
+       Depend on a poppler api (defined out for now)
+
 2005-06-15  Marco Pesenti Gritti <mpg@redhat.com>
 
        * shell/ev-properties.c: (ev_properties_dispose),
index 6105a704ab79c7c760e79768426afc21c196d230..1f9459647f3f92ff8fc3fdad57d00701fba2f07b 100644 (file)
@@ -47,6 +47,7 @@ typedef struct _EvDocumentLinksIface EvDocumentLinksIface;
 enum {
        EV_DOCUMENT_LINKS_COLUMN_MARKUP,
        EV_DOCUMENT_LINKS_COLUMN_LINK,
+       EV_DOCUMENT_LINKS_COLUMN_EXPAND,
        EV_DOCUMENT_LINKS_COLUMN_NUM_COLUMNS
 };
 
index 9989d827674d6d9e17fb55f7ef34cb8930653d79..aebe7ce5dbceaeba0274aff9e252e2c25b24a7b4 100644 (file)
@@ -658,8 +658,14 @@ build_tree (PdfDocument      *pdf_document,
                PopplerIndexIter *child;
                PopplerAction *action;
                EvLink *link;
+               gboolean expand;
                
                action = poppler_index_iter_get_action (iter);
+#ifdef POPPLER_LINK_IS_OPEN
+               expand = poppler_index_iter_is_open (iter);
+#else
+               expand = TRUE;
+#endif
                if (action) {
                        gtk_tree_store_append (GTK_TREE_STORE (model), &tree_iter, parent);
                        link = ev_link_from_action (action);
@@ -668,6 +674,7 @@ build_tree (PdfDocument      *pdf_document,
                        gtk_tree_store_set (GTK_TREE_STORE (model), &tree_iter,
                                            EV_DOCUMENT_LINKS_COLUMN_MARKUP, ev_link_get_title (link),
                                            EV_DOCUMENT_LINKS_COLUMN_LINK, link,
+                                           EV_DOCUMENT_LINKS_COLUMN_EXPAND, expand,
                                            -1);
                        child = poppler_index_iter_get_child (iter);
                        if (child)
@@ -688,16 +695,16 @@ pdf_document_links_get_links_model (EvDocumentLinks *document_links)
        g_return_val_if_fail (PDF_IS_DOCUMENT (document_links), NULL);
 
        iter = poppler_index_iter_new (pdf_document->document);
-       /* Create the model iff we have items*/
+       /* Create the model if we have items*/
        if (iter != NULL) {
                model = (GtkTreeModel *) gtk_tree_store_new (EV_DOCUMENT_LINKS_COLUMN_NUM_COLUMNS,
                                                             G_TYPE_STRING,
-                                                            G_TYPE_POINTER);
+                                                            G_TYPE_POINTER,
+                                                            G_TYPE_BOOLEAN);
                build_tree (pdf_document, model, NULL, iter);
                poppler_index_iter_free (iter);
        }
        
-
        return model;
 }
 
index ced98c8c7aef510ee5a8dc5c3cd9e7f1d7ced90e..45719114a615d1c52de54dd019a20bf9f9466d8c 100644 (file)
@@ -220,12 +220,14 @@ create_loading_model (void)
        /* Creates a fake model to indicate that we're loading */
        retval = (GtkTreeModel *)gtk_list_store_new (EV_DOCUMENT_LINKS_COLUMN_NUM_COLUMNS,
                                                     G_TYPE_STRING,
-                                                    G_TYPE_OBJECT);
+                                                    G_TYPE_OBJECT,
+                                                    G_TYPE_BOOLEAN);
 
        gtk_list_store_append (GTK_LIST_STORE (retval), &iter);
        markup = g_strdup_printf ("<span size=\"larger\" style=\"italic\">%s</span>", _("Loading..."));
        gtk_list_store_set (GTK_LIST_STORE (retval), &iter,
                            EV_DOCUMENT_LINKS_COLUMN_MARKUP, markup,
+                           EV_DOCUMENT_LINKS_COLUMN_EXPAND, FALSE,
                            EV_DOCUMENT_LINKS_COLUMN_LINK, NULL,
                            -1);
        g_free (markup);
@@ -515,16 +517,39 @@ row_activated_callback                    (GtkTreeView *treeview,
        
         return;
 }
-                               
+
+static void
+expand_open_links (GtkTreeView *tree_view, GtkTreeModel *model, GtkTreeIter *parent)
+{
+       GtkTreeIter iter;
+       EvLink *link;
+       gboolean expand;
+
+       if (gtk_tree_model_iter_children (model, &iter, parent)) {
+               do {
+                       gtk_tree_model_get (model, &iter,
+                                           EV_DOCUMENT_LINKS_COLUMN_LINK, &link,
+                                           EV_DOCUMENT_LINKS_COLUMN_EXPAND, &expand,
+                                           -1);
+                       if (expand) {
+                               GtkTreePath *path;
+
+                               path = gtk_tree_model_get_path (model, &iter);
+                               gtk_tree_view_expand_row (tree_view, path, FALSE);
+                               gtk_tree_path_free (path);
+                       }
+
+                       expand_open_links (tree_view, model, &iter);
+               } while (gtk_tree_model_iter_next (model, &iter));
+       }
+}
+       
 static void
 job_finished_callback (EvJobLinks     *job,
                       EvSidebarLinks *sidebar_links)
 {
        EvSidebarLinksPrivate *priv;
        GtkTreeSelection *selection;
-       GtkTreeIter iter;
-       GtkTreePath *path;
-       gboolean result;
 
        priv = sidebar_links->priv;
 
@@ -535,16 +560,8 @@ job_finished_callback (EvJobLinks     *job,
        g_object_unref (job);
        priv->job = NULL;
 
-       /* Expand one level of the tree */
-       path = gtk_tree_path_new_first ();
-       for (result = gtk_tree_model_get_iter_first (priv->model, &iter);
-            result;
-            result = gtk_tree_model_iter_next (priv->model, &iter)) {
-               gtk_tree_view_expand_row (GTK_TREE_VIEW (priv->tree_view), path, FALSE);
-               gtk_tree_path_next (path);
-       }
-       gtk_tree_path_free (path);
-       
+       expand_open_links (GTK_TREE_VIEW (priv->tree_view), priv->model, NULL);
+
        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",