From: Carlos Garcia Campos Date: Mon, 12 Jul 2010 17:08:10 +0000 (+0200) Subject: [shell] Focus the selected annotation in the sidebar X-Git-Tag: EVINCE_2_31_5~9 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=d87812b63f78717e5b82c9a2170769a89b91eefd;p=evince.git [shell] Focus the selected annotation in the sidebar --- diff --git a/shell/ev-sidebar-annotations.c b/shell/ev-sidebar-annotations.c index 67a49f1f..b1f08482 100644 --- a/shell/ev-sidebar-annotations.c +++ b/shell/ev-sidebar-annotations.c @@ -41,15 +41,23 @@ enum { N_COLUMNS }; +enum { + ANNOT_ACTIVATED, + N_SIGNALS +}; + struct _EvSidebarAnnotationsPrivate { GtkWidget *notebook; GtkWidget *tree_view; EvJob *job; + guint selection_changed_id; }; static void ev_sidebar_annotations_page_iface_init (EvSidebarPageInterface *iface); +static guint signals[N_SIGNALS]; + G_DEFINE_TYPE_EXTENDED (EvSidebarAnnotations, ev_sidebar_annotations, GTK_TYPE_VBOX, @@ -91,6 +99,7 @@ ev_sidebar_annotations_add_annots_list (EvSidebarAnnotations *ev_annots) GtkTreeModel *loading_model; GtkCellRenderer *renderer; GtkTreeViewColumn *column; + GtkTreeSelection *selection; swindow = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow), @@ -105,6 +114,8 @@ ev_sidebar_annotations_add_annots_list (EvSidebarAnnotations *ev_annots) gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (ev_annots->priv->tree_view), FALSE); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (ev_annots->priv->tree_view)); + gtk_tree_selection_set_mode (selection, GTK_SELECTION_NONE); column = gtk_tree_view_column_new (); @@ -173,6 +184,16 @@ ev_sidebar_annotations_class_init (EvSidebarAnnotationsClass *klass) g_type_class_add_private (g_object_class, sizeof (EvSidebarAnnotationsPrivate)); g_object_class_override_property (g_object_class, PROP_WIDGET, "main-widget"); + + signals[ANNOT_ACTIVATED] = + g_signal_new ("annot-activated", + G_TYPE_FROM_CLASS (g_object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (EvSidebarAnnotationsClass, annot_activated), + NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, + G_TYPE_POINTER); } GtkWidget * @@ -181,12 +202,31 @@ ev_sidebar_annotations_new (void) return GTK_WIDGET (g_object_new (EV_TYPE_SIDEBAR_ANNOTATIONS, NULL)); } +static void +selection_changed_cb (GtkTreeSelection *selection, + EvSidebarAnnotations *sidebar_annots) +{ + GtkTreeModel *model; + GtkTreeIter iter; + + if (gtk_tree_selection_get_selected (selection, &model, &iter)) { + EvMapping *mapping = NULL; + + gtk_tree_model_get (model, &iter, + COLUMN_ANNOT_MAPPING, &mapping, + -1); + if (mapping) + g_signal_emit (sidebar_annots, signals[ANNOT_ACTIVATED], 0, mapping); + } +} + static void job_finished_callback (EvJobAnnots *job, EvSidebarAnnotations *sidebar_annots) { EvSidebarAnnotationsPrivate *priv; GtkTreeStore *model; + GtkTreeSelection *selection; GList *l; GdkPixbuf *text_icon = NULL; GdkPixbuf *attachment_icon = NULL; @@ -206,6 +246,15 @@ job_finished_callback (EvJobAnnots *job, return; } + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view)); + gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); + if (priv->selection_changed_id == 0) { + priv->selection_changed_id = + g_signal_connect (selection, "changed", + G_CALLBACK (selection_changed_cb), + sidebar_annots); + } + model = gtk_tree_store_new (N_COLUMNS, G_TYPE_STRING, GDK_TYPE_PIXBUF, diff --git a/shell/ev-sidebar-annotations.h b/shell/ev-sidebar-annotations.h index 72c5cc35..8762d787 100644 --- a/shell/ev-sidebar-annotations.h +++ b/shell/ev-sidebar-annotations.h @@ -46,6 +46,8 @@ struct _EvSidebarAnnotations { struct _EvSidebarAnnotationsClass { GtkVBoxClass base_class; + void (* annot_activated) (EvSidebarAnnotations *sidebar_annots, + EvMapping *mapping); }; GType ev_sidebar_annotations_get_type (void) G_GNUC_CONST; diff --git a/shell/ev-window.c b/shell/ev-window.c index 9228f4a3..168ed67d 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -5375,6 +5375,14 @@ sidebar_layers_visibility_changed (EvSidebarLayers *layers, ev_view_reload (EV_VIEW (window->priv->view)); } +static void +sidebar_annots_annot_activated_cb (EvSidebarAnnotations *sidebar_annots, + EvMapping *annot_mapping, + EvWindow *window) +{ + ev_view_focus_annotation (EV_VIEW (window->priv->view), annot_mapping); +} + static void register_custom_actions (EvWindow *window, GtkActionGroup *group) { @@ -6537,6 +6545,10 @@ ev_window_init (EvWindow *ev_window) sidebar_widget = ev_sidebar_annotations_new (); ev_window->priv->sidebar_annots = sidebar_widget; + g_signal_connect (sidebar_widget, + "annot_activated", + G_CALLBACK (sidebar_annots_annot_activated_cb), + ev_window); gtk_widget_show (sidebar_widget); ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar), sidebar_widget);