X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=shell%2Fev-sidebar-links.c;h=cbe19b1bce2e0a9a21f8981d71e058f8ba97a59c;hb=7172457c057ce9ec6011866e055f9c5ce6e284f2;hp=58dac08ca9f835ed39c9688dc128c00bf8a3f80d;hpb=6de49223c660b9233b7809e81f826cb99e6ecd5d;p=evince.git
diff --git a/shell/ev-sidebar-links.c b/shell/ev-sidebar-links.c
index 58dac08c..cbe19b1b 100644
--- a/shell/ev-sidebar-links.c
+++ b/shell/ev-sidebar-links.c
@@ -33,7 +33,6 @@
#include "ev-job-queue.h"
#include "ev-document-links.h"
#include "ev-window.h"
-#include "ev-gui.h"
struct _EvSidebarLinksPrivate {
GtkWidget *tree_view;
@@ -55,12 +54,11 @@ enum {
PROP_WIDGET,
};
+enum {
+ LINK_ACTIVATED,
+ 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);
@@ -77,6 +75,7 @@ static gboolean ev_sidebar_links_support_document (EvSidebarPage *sidebar_page,
EvDocument *document);
static const gchar* ev_sidebar_links_get_label (EvSidebarPage *sidebar_page);
+static guint signals[N_SIGNALS];
G_DEFINE_TYPE_EXTENDED (EvSidebarLinks,
ev_sidebar_links,
@@ -162,21 +161,48 @@ ev_sidebar_links_dispose (GObject *object)
sidebar->priv->page_cache = NULL;
}
-
G_OBJECT_CLASS (ev_sidebar_links_parent_class)->dispose (object);
}
+static void
+ev_sidebar_links_map (GtkWidget *widget)
+{
+ EvSidebarLinks *links;
+
+ links = EV_SIDEBAR_LINKS (widget);
+
+ GTK_WIDGET_CLASS (ev_sidebar_links_parent_class)->map (widget);
+
+ if (links->priv->model) {
+ update_page_callback (links->priv->page_cache,
+ ev_page_cache_get_current_page (links->priv->page_cache),
+ links);
+ }
+}
+
static void
ev_sidebar_links_class_init (EvSidebarLinksClass *ev_sidebar_links_class)
{
- GObjectClass *g_object_class;
+ GObjectClass *g_object_class;
+ GtkWidgetClass *widget_class;
g_object_class = G_OBJECT_CLASS (ev_sidebar_links_class);
+ widget_class = GTK_WIDGET_CLASS (ev_sidebar_links_class);
g_object_class->set_property = ev_sidebar_links_set_property;
g_object_class->get_property = ev_sidebar_links_get_property;
g_object_class->dispose = ev_sidebar_links_dispose;
+ widget_class->map = ev_sidebar_links_map;
+
+ signals[LINK_ACTIVATED] = g_signal_new ("link-activated",
+ G_TYPE_FROM_CLASS (g_object_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (EvSidebarLinksClass, link_activated),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1, G_TYPE_OBJECT);
+
g_object_class_install_property (g_object_class,
PROP_MODEL,
g_param_spec_object ("model",
@@ -199,8 +225,6 @@ selection_changed_callback (GtkTreeSelection *selection,
GtkTreeModel *model;
GtkTreeIter iter;
- g_return_if_fail (EV_IS_SIDEBAR_LINKS (ev_sidebar_links));
-
document = EV_DOCUMENT (ev_sidebar_links->priv->document);
g_return_if_fail (ev_sidebar_links->priv->document != NULL);
@@ -216,8 +240,7 @@ selection_changed_callback (GtkTreeSelection *selection,
g_signal_handler_block (ev_sidebar_links->priv->page_cache,
ev_sidebar_links->priv->page_changed_id);
- /* FIXME: we should handle this better. This breaks w/ URLs */
- ev_page_cache_set_link (ev_sidebar_links->priv->page_cache, link);
+ g_signal_emit (ev_sidebar_links, signals[LINK_ACTIVATED], 0, link);
g_signal_handler_unblock (ev_sidebar_links->priv->page_cache,
ev_sidebar_links->priv->page_changed_id);
@@ -236,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..."));
@@ -263,32 +287,46 @@ print_section_cb (GtkWidget *menuitem, EvSidebarLinks *sidebar)
if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
EvLink *link;
- int first_page, last_page;
+ int first_page, last_page = -1;
gtk_tree_model_get (model, &iter,
EV_DOCUMENT_LINKS_COLUMN_LINK, &link,
-1);
- first_page = ev_link_get_page (link) + 1;
- if (link)
+ if (!link)
+ return;
+
+ first_page = ev_link_get_page (link);
+ if (first_page == -1) {
g_object_unref (link);
+ return;
+ }
+
+ first_page++;
+ g_object_unref (link);
if (gtk_tree_model_iter_next (model, &iter)) {
gtk_tree_model_get (model, &iter,
EV_DOCUMENT_LINKS_COLUMN_LINK, &link,
-1);
- last_page = ev_link_get_page (link);
- if (link)
- g_object_unref (link);
+ if (link) {
+ last_page = ev_link_get_page (link);
+ g_object_unref (link);
+ }
} else {
- last_page = -1;
+ last_page = ev_page_cache_get_n_pages (sidebar->priv->page_cache);
}
+
+ if (last_page == -1)
+ last_page = ev_page_cache_get_n_pages (sidebar->priv->page_cache);
window = gtk_widget_get_toplevel (GTK_WIDGET (sidebar));
if (EV_IS_WINDOW (window)) {
+#ifdef WITH_PRINT
ev_window_print_range (EV_WINDOW (window),
first_page, last_page);
+#endif
}
}
}
@@ -373,7 +411,7 @@ ev_sidebar_links_construct (EvSidebarLinks *ev_sidebar_links)
loading_model = create_loading_model ();
priv->tree_view = gtk_tree_view_new_with_model (loading_model);
g_object_unref (loading_model);
-
+
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
gtk_tree_selection_set_mode (selection, GTK_SELECTION_NONE);
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->tree_view), FALSE);
@@ -398,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",
@@ -420,42 +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 != NULL &&
- ev_link_get_link_type (link) == EV_LINK_TYPE_PAGE) {
- gchar *page_label;
- gchar *page_string;
- page_label = ev_page_cache_get_page_label (sidebar_links->priv->page_cache, ev_link_get_page (link));
- page_string = g_markup_printf_escaped ("%s", page_label);
+ if (!link)
+ return FALSE;
- g_object_set (cell,
- "markup", page_string,
- "visible", TRUE,
- NULL);
+ page = ev_link_get_page (link);
- g_free (page_label);
- g_free (page_string);
- } else {
- g_object_set (cell,
- "visible", FALSE,
- 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);
- if (link)
- g_object_unref (link);
+ g_free (page_label);
+
+ g_object_unref (link);
+ return FALSE;
}
/* Public Functions */
@@ -483,25 +518,25 @@ update_page_callback_foreach (GtkTreeModel *model,
EV_DOCUMENT_LINKS_COLUMN_LINK, &link,
-1);
- if (link && ev_link_get_link_type (link) == EV_LINK_TYPE_PAGE) {
+ if (link) {
int current_page;
+ int dest_page;
+ dest_page = ev_link_get_page (link);
+ g_object_unref (link);
+
current_page = ev_page_cache_get_current_page (sidebar_links->priv->page_cache);
- if (ev_link_get_page (link) == current_page) {
- GtkTreeSelection *selection;
-
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (sidebar_links->priv->tree_view));
-
- gtk_tree_selection_select_path (selection, path);
-
- g_object_unref (link);
+
+ if (dest_page == current_page) {
+ gtk_tree_view_expand_to_path (GTK_TREE_VIEW (sidebar_links->priv->tree_view),
+ path);
+ gtk_tree_view_set_cursor (GTK_TREE_VIEW (sidebar_links->priv->tree_view),
+ path, NULL, FALSE);
+
return TRUE;
}
}
- if (link)
- g_object_unref (link);
-
return FALSE;
}
@@ -511,39 +546,59 @@ update_page_callback (EvPageCache *page_cache,
EvSidebarLinks *sidebar_links)
{
GtkTreeSelection *selection;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+
+ /* Widget is not currently visible */
+ if (!GTK_WIDGET_MAPPED (sidebar_links))
+ return;
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (sidebar_links->priv->tree_view));
+
+ if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
+ EvLink *link;
+
+ gtk_tree_model_get (model, &iter,
+ EV_DOCUMENT_LINKS_COLUMN_LINK, &link,
+ -1);
+ if (link) {
+ gint dest_page;
+
+ dest_page = ev_link_get_page (link);
+ g_object_unref (link);
+
+ if (dest_page == current_page)
+ return;
+ }
+ }
+
/* We go through the tree linearly looking for the first page that
* matches. This is pretty inefficient. We can do something neat with
* a GtkTreeModelSort here to make it faster, if it turns out to be
* slow.
*/
-
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (sidebar_links->priv->tree_view));
-
g_signal_handler_block (selection, sidebar_links->priv->selection_id);
g_signal_handler_block (sidebar_links->priv->tree_view, sidebar_links->priv->row_activated_id);
- gtk_tree_selection_unselect_all (selection);
- gtk_tree_model_foreach (sidebar_links->priv->model,
+ gtk_tree_model_foreach (model,
update_page_callback_foreach,
sidebar_links);
-
+
g_signal_handler_unblock (selection, sidebar_links->priv->selection_id);
g_signal_handler_unblock (sidebar_links->priv->tree_view, sidebar_links->priv->row_activated_id);
}
static void
-row_activated_callback (GtkTreeView *treeview,
- GtkTreePath *arg1,
- GtkTreeViewColumn *arg2,
- gpointer user_data)
-{
+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);
+ gtk_tree_view_collapse_row (GTK_TREE_VIEW (treeview), arg1);
} else {
- gtk_tree_view_expand_row (GTK_TREE_VIEW (treeview), arg1, FALSE);
+ gtk_tree_view_expand_row (GTK_TREE_VIEW (treeview), arg1, FALSE);
}
-
- return;
}
static void
@@ -559,7 +614,7 @@ expand_open_links (GtkTreeView *tree_view, GtkTreeModel *model, GtkTreeIter *par
-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);
@@ -581,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);
@@ -591,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