void PdfBookmarks::createBookmarks(GtkTreeModel * model, GList * &data, GtkTreeIter * iter, int level, Document * doc) { XOJ_CHECK_TYPE(PdfBookmarks); XojLinkDest * link = NULL; LinkDestination * dest = NULL; do { gtk_tree_model_get(model, iter, DOCUMENT_LINKS_COLUMN_LINK, &link, -1); dest = link->dest; g_object_unref(link); int page = doc->findPdfPage(dest->getPdfPage()); if (page == -1) { continue; } data = g_list_append(data, new Bookmark(dest->getName(), level, page, dest->getTop())); GtkTreeIter children = { 0 }; if (gtk_tree_model_iter_children(model, &children, iter)) { createBookmarks(model, data, &children, level + 1, doc); } } while (gtk_tree_model_iter_next(model, iter)); }
bool SidebarIndexPage::treeBookmarkSelected(GtkWidget* treeview, SidebarIndexPage* sidebar) { XOJ_CHECK_TYPE_OBJ(sidebar, SidebarIndexPage); if (sidebar->searchTimeout) { return false; } gtk_widget_grab_focus(GTK_WIDGET(treeview)); GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); if (selection) { GtkTreeModel* model = NULL; GtkTreeIter iter = { 0 }; if (gtk_tree_selection_get_selected(selection, &model, &iter)) { XojLinkDest* link = NULL; gtk_tree_model_get(model, &iter, DOCUMENT_LINKS_COLUMN_LINK, &link, -1); if (link && link->dest) { LinkDestination* dest = link->dest; size_t pdfPage = dest->getPdfPage(); if (pdfPage != size_t_npos) { Document* doc = sidebar->control->getDocument(); doc->lock(); size_t page = doc->findPdfPage(pdfPage); doc->unlock(); if (page == size_t_npos) { sidebar->askInsertPdfPage(pdfPage); } else { if (dest->shouldChangeTop()) { sidebar->control->getScrollHandler()->scrollToPage(page, dest->getTop()); } else { if (sidebar->control->getCurrentPageNo() != page) { sidebar->control->getScrollHandler()->scrollToPage(page); } } } } } g_object_unref(link); return true; } } return false; }