From d87812b63f78717e5b82c9a2170769a89b91eefd Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Mon, 12 Jul 2010 17:08:10 +0000 Subject: [shell] Focus the selected annotation in the sidebar --- (limited to 'shell') diff --git a/shell/ev-sidebar-annotations.c b/shell/ev-sidebar-annotations.c index 67a49f1..b1f0848 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 * @@ -182,11 +203,30 @@ ev_sidebar_annotations_new (void) } 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 72c5cc3..8762d78 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 9228f4a..168ed67 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -5376,6 +5376,14 @@ sidebar_layers_visibility_changed (EvSidebarLayers *layers, } 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) { GtkAction *action; @@ -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); -- cgit v0.9.1