29 #include <glib/gi18n.h>
70 GtkTreeViewColumn *arg2,
93 #define EV_SIDEBAR_LINKS_GET_PRIVATE(object) \
94 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_SIDEBAR_LINKS, EvSidebarLinksPrivate))
97 ev_sidebar_links_set_property (GObject *
object,
110 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
128 g_value_set_object (value, ev_sidebar_links->priv->model);
131 g_value_set_object (value, ev_sidebar_links->priv->tree_view);
134 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
144 if (sidebar->priv->job) {
145 g_signal_handlers_disconnect_by_func (sidebar->priv->job,
148 g_object_unref (sidebar->priv->job);
149 sidebar->priv->job = NULL;
152 if (sidebar->priv->model) {
153 g_object_unref (sidebar->priv->model);
154 sidebar->priv->model = NULL;
157 if (sidebar->priv->page_link_tree) {
158 g_tree_unref (sidebar->priv->page_link_tree);
159 sidebar->priv->page_link_tree = NULL;
162 if (sidebar->priv->document) {
163 g_object_unref (sidebar->priv->document);
164 sidebar->priv->document = NULL;
165 sidebar->priv->doc_model = NULL;
168 G_OBJECT_CLASS (ev_sidebar_links_parent_class)->dispose (
object);
178 GTK_WIDGET_CLASS (ev_sidebar_links_parent_class)->map (widget);
180 if (links->priv->model) {
189 GObjectClass *g_object_class;
190 GtkWidgetClass *widget_class;
192 g_object_class = G_OBJECT_CLASS (ev_sidebar_links_class);
193 widget_class = GTK_WIDGET_CLASS (ev_sidebar_links_class);
195 g_object_class->set_property = ev_sidebar_links_set_property;
202 G_TYPE_FROM_CLASS (g_object_class),
203 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
206 g_cclosure_marshal_VOID__OBJECT,
207 G_TYPE_NONE, 1, G_TYPE_OBJECT);
209 g_object_class_install_property (g_object_class,
211 g_param_spec_object (
"model",
216 G_PARAM_STATIC_STRINGS));
217 g_object_class_override_property (g_object_class,
231 g_return_if_fail (ev_sidebar_links->priv->document != NULL);
233 if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
236 gtk_tree_model_get (model, &iter,
243 g_signal_handler_block (ev_sidebar_links->priv->doc_model,
244 ev_sidebar_links->priv->page_changed_id);
246 g_signal_handler_unblock (ev_sidebar_links->priv->doc_model,
247 ev_sidebar_links->priv->page_changed_id);
249 g_object_unref (link);
253 static GtkTreeModel *
256 GtkTreeModel *retval;
267 gtk_list_store_append (GTK_LIST_STORE (retval), &iter);
268 markup = g_strdup_printf (
"<span size=\"larger\" style=\"italic\">%s</span>",
_(
"Loading…"));
269 gtk_list_store_set (GTK_LIST_STORE (retval), &iter,
283 GtkTreeSelection *selection;
287 selection = gtk_tree_view_get_selection
288 (GTK_TREE_VIEW (sidebar->priv->tree_view));
290 if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
292 int first_page, last_page = -1;
295 gtk_tree_model_get (model, &iter,
305 if (first_page == -1) {
306 g_object_unref (link);
311 g_object_unref (link);
313 if (gtk_tree_model_iter_next (model, &iter)) {
314 gtk_tree_model_get (model, &iter,
320 g_object_unref (link);
329 window = gtk_widget_get_toplevel (GTK_WIDGET (sidebar));
342 menu = gtk_menu_new ();
343 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_PRINT, NULL);
344 gtk_label_set_label (GTK_LABEL (gtk_bin_get_child (GTK_BIN (item))),
_(
"Print…"));
345 gtk_widget_show (item);
346 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
347 g_signal_connect (item,
"activate",
350 return GTK_MENU (menu);
358 gtk_menu_popup (menu, NULL, NULL,
360 sidebar->priv->tree_view, 0,
361 gtk_get_current_event_time ());
362 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu),
FALSE);
367 GdkEventButton *event,
370 GtkTreePath *path = NULL;
372 if (event->button == 3) {
373 if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (treeview),
378 gtk_tree_view_set_cursor (GTK_TREE_VIEW (treeview),
381 NULL, NULL, NULL, event->button,
382 gtk_get_current_event_time ());
383 gtk_tree_path_free (path);
398 GtkTreeViewColumn *column;
399 GtkCellRenderer *renderer;
400 GtkTreeSelection *selection;
401 GtkTreeModel *loading_model;
403 priv = ev_sidebar_links->priv;
405 swindow = gtk_scrolled_window_new (NULL, NULL);
409 priv->
tree_view = gtk_tree_view_new_with_model (loading_model);
410 g_object_unref (loading_model);
412 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->
tree_view));
413 gtk_tree_selection_set_mode (selection, GTK_SELECTION_NONE);
414 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->
tree_view),
FALSE);
415 gtk_container_add (GTK_CONTAINER (swindow), priv->
tree_view);
417 gtk_box_pack_start (GTK_BOX (ev_sidebar_links), swindow,
TRUE,
TRUE, 0);
418 gtk_widget_show_all (GTK_WIDGET (ev_sidebar_links));
420 column = gtk_tree_view_column_new ();
421 gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column),
TRUE);
422 gtk_tree_view_append_column (GTK_TREE_VIEW (priv->
tree_view), column);
424 renderer = gtk_cell_renderer_text_new ();
425 g_object_set (G_OBJECT (renderer),
426 "ellipsize", PANGO_ELLIPSIZE_END,
428 gtk_tree_view_column_pack_start (GTK_TREE_VIEW_COLUMN (column), renderer,
TRUE);
429 gtk_tree_view_column_set_attributes (GTK_TREE_VIEW_COLUMN (column), renderer,
433 column = gtk_tree_view_column_new ();
434 gtk_tree_view_append_column (GTK_TREE_VIEW (priv->
tree_view), column);
436 renderer = gtk_cell_renderer_text_new ();
437 g_object_set (G_OBJECT (renderer),
438 "ellipsize", PANGO_ELLIPSIZE_MIDDLE,
440 "style", PANGO_STYLE_ITALIC,
443 gtk_tree_view_column_pack_start (GTK_TREE_VIEW_COLUMN (column), renderer,
FALSE);
444 gtk_tree_view_column_set_attributes (GTK_TREE_VIEW_COLUMN (column), renderer,
449 "button_press_event",
471 GtkWidget *ev_sidebar_links;
474 "orientation", GTK_ORIENTATION_VERTICAL,
477 return ev_sidebar_links;
488 gint page = GPOINTER_TO_INT (page_ptr);
493 return data->
page - page;
500 GtkTreeSelection *selection;
505 if (!gtk_widget_is_visible (GTK_WIDGET (sidebar_links)))
508 search_data.
page = current_page;
514 path = g_tree_lookup (sidebar_links->priv->page_link_tree, GINT_TO_POINTER (search_data.
best_existing));
520 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (sidebar_links->priv->tree_view));
522 g_signal_handler_block (selection, sidebar_links->priv->selection_id);
523 g_signal_handler_block (sidebar_links->priv->tree_view, sidebar_links->priv->row_activated_id);
525 gtk_tree_view_expand_to_path (GTK_TREE_VIEW (sidebar_links->priv->tree_view),
527 gtk_tree_view_set_cursor (GTK_TREE_VIEW (sidebar_links->priv->tree_view),
530 g_signal_handler_unblock (selection, sidebar_links->priv->selection_id);
531 g_signal_handler_unblock (sidebar_links->priv->tree_view, sidebar_links->priv->row_activated_id);
545 GtkTreeViewColumn *arg2,
548 if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (treeview), arg1)) {
549 gtk_tree_view_collapse_row (GTK_TREE_VIEW (treeview), arg1);
551 gtk_tree_view_expand_row (GTK_TREE_VIEW (treeview), arg1,
FALSE);
561 if (gtk_tree_model_iter_children (model, &iter, parent)) {
563 gtk_tree_model_get (model, &iter,
569 path = gtk_tree_model_get_path (model, &iter);
570 gtk_tree_view_expand_row (tree_view, path,
FALSE);
571 gtk_tree_path_free (path);
575 }
while (gtk_tree_model_iter_next (model, &iter));
583 return GPOINTER_TO_INT (a) - GPOINTER_TO_INT (b);
598 gtk_tree_model_get (model, iter,
606 g_object_unref (link);
609 if (!g_tree_lookup (priv->
page_link_tree, GINT_TO_POINTER (page)))
610 g_tree_insert (priv->
page_link_tree, GINT_TO_POINTER (page), gtk_tree_path_copy (path));
621 if (priv->
model == model)
625 g_object_unref (priv->
model);
626 priv->
model = g_object_ref (model);
633 gtk_tree_model_foreach (model,
637 g_object_notify (G_OBJECT (sidebar_links),
"model");
645 GtkTreeSelection *selection;
649 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->
tree_view), job->
model);
651 g_object_unref (job);
656 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->
tree_view));
657 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
661 g_signal_connect (selection,
"changed",
666 g_signal_connect_swapped (priv->
doc_model,
"page-changed",
671 g_signal_connect (priv->
tree_view,
"row-activated",
695 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->
tree_view), NULL);
699 priv->
document = g_object_ref (document);
702 g_signal_handlers_disconnect_by_func (priv->
job,
705 g_object_unref (priv->
job);
709 g_signal_connect (priv->
job,
728 g_signal_connect (model,
"notify::document",