]> www.fi.muni.cz Git - evince.git/commitdiff
[shell] Focus the selected annotation in the sidebar
authorCarlos Garcia Campos <carlosgc@gnome.org>
Mon, 12 Jul 2010 17:08:10 +0000 (19:08 +0200)
committerCarlos Garcia Campos <carlosgc@gnome.org>
Mon, 12 Jul 2010 17:12:02 +0000 (19:12 +0200)
shell/ev-sidebar-annotations.c
shell/ev-sidebar-annotations.h
shell/ev-window.c

index 67a49f1f2f38dc0dc90438fcae763f3633077ba0..b1f084821851b12265fc9b723b00f1d7cedfbf05 100644 (file)
@@ -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,
index 72c5cc355e611c657fdef0ed13bf69a387216891..8762d78744951ff9dd10be76643328126d7f4f2b 100644 (file)
@@ -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;
index 9228f4a348eede8aed01077017a0ebfeb6057088..168ed67d4aeb24e79c0dd52df8e89e2bf9f2530b 100644 (file)
@@ -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);