diff options
-rw-r--r-- | shell/ev-sidebar-annotations.c | 200 |
1 files changed, 86 insertions, 114 deletions
diff --git a/shell/ev-sidebar-annotations.c b/shell/ev-sidebar-annotations.c index ec10b9cc..6cb98fef 100644 --- a/shell/ev-sidebar-annotations.c +++ b/shell/ev-sidebar-annotations.c @@ -51,13 +51,12 @@ enum { struct _EvSidebarAnnotationsPrivate { EvDocument *document; - GtkWidget *notebook; - GtkWidget *tree_view; - GtkWidget *palette; - GtkToolItem *annot_text_item; + GtkWidget *notebook; + GtkWidget *tree_view; + GtkWidget *annot_text_item; - EvJob *job; - guint selection_changed_id; + EvJob *job; + guint selection_changed_id; }; static void ev_sidebar_annotations_page_iface_init (EvSidebarPageInterface *iface); @@ -114,30 +113,54 @@ ev_sidebar_annotations_create_simple_model (const gchar *message) } static void -ev_sidebar_annotations_add_annots_list (EvSidebarAnnotations *ev_annots) +ev_sidebar_annotations_text_annot_button_toggled (GtkWidget *button, + EvSidebarAnnotations *sidebar_annots) { - GtkWidget *swindow; - GtkTreeModel *loading_model; - GtkCellRenderer *renderer; + EvAnnotationType annot_type; + + if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) { + g_signal_emit (sidebar_annots, signals[ANNOT_ADD_CANCELLED], 0, NULL); + return; + } + + if (button == sidebar_annots->priv->annot_text_item) + annot_type = EV_ANNOTATION_TYPE_TEXT; + else + annot_type = EV_ANNOTATION_TYPE_UNKNOWN; + + g_signal_emit (sidebar_annots, signals[BEGIN_ANNOT_ADD], 0, annot_type); +} + +static void +ev_sidebar_annotations_init (EvSidebarAnnotations *ev_annots) +{ + GtkWidget *swindow; + GtkTreeModel *loading_model; + GtkCellRenderer *renderer; GtkTreeViewColumn *column; - GtkTreeSelection *selection; - GtkWidget *label; + GtkTreeSelection *selection; + GtkWidget *hbox; + GtkWidget *buttonarea; + GtkWidget *image; + GtkWidget *label; + + ev_annots->priv = EV_SIDEBAR_ANNOTATIONS_GET_PRIVATE (ev_annots); + + gtk_orientable_set_orientation (GTK_ORIENTABLE (ev_annots), GTK_ORIENTATION_VERTICAL); swindow = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swindow), - GTK_SHADOW_IN); - // Use as much vertical space as available - gtk_widget_set_vexpand (GTK_WIDGET (swindow), TRUE); + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swindow), GTK_SHADOW_IN); + gtk_box_pack_start (GTK_BOX (ev_annots), swindow, TRUE, TRUE, 0); + gtk_widget_show (swindow); /* Create tree view */ loading_model = ev_sidebar_annotations_create_simple_model (_("Loading…")); ev_annots->priv->tree_view = gtk_tree_view_new_with_model (loading_model); g_object_unref (loading_model); - gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (ev_annots->priv->tree_view), - FALSE); + 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); @@ -154,93 +177,43 @@ ev_sidebar_annotations_add_annots_list (EvSidebarAnnotations *ev_annots) gtk_tree_view_column_set_attributes (column, renderer, "markup", COLUMN_MARKUP, NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (ev_annots->priv->tree_view), - column); + gtk_tree_view_append_column (GTK_TREE_VIEW (ev_annots->priv->tree_view), column); gtk_container_add (GTK_CONTAINER (swindow), ev_annots->priv->tree_view); gtk_widget_show (ev_annots->priv->tree_view); - label = gtk_label_new (_("List")); - gtk_notebook_append_page (GTK_NOTEBOOK (ev_annots->priv->notebook), - swindow, label); - gtk_widget_show (label); + hbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL); + gtk_widget_set_halign (hbox, GTK_ALIGN_START); + gtk_widget_set_margin_top (hbox, 6); + gtk_widget_show (hbox); - gtk_widget_show (swindow); -} + ev_annots->priv->annot_text_item = gtk_toggle_button_new (); + gtk_widget_set_halign (ev_annots->priv->annot_text_item, GTK_ALIGN_START); + buttonarea = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_box_set_spacing (GTK_BOX (buttonarea), 2); + gtk_widget_set_margin_start (buttonarea, 4); + gtk_widget_set_margin_end (buttonarea, 4); + gtk_container_add (GTK_CONTAINER (ev_annots->priv->annot_text_item), buttonarea); + gtk_widget_show (buttonarea); -static void -ev_sidebar_annotations_text_annot_button_toggled (GtkToggleToolButton *toolbutton, - EvSidebarAnnotations *sidebar_annots) -{ - EvAnnotationType annot_type; - - if (!gtk_toggle_tool_button_get_active (toolbutton)) { - g_signal_emit (sidebar_annots, signals[ANNOT_ADD_CANCELLED], 0, NULL); - return; - } - - if (GTK_TOOL_ITEM (toolbutton) == sidebar_annots->priv->annot_text_item) - annot_type = EV_ANNOTATION_TYPE_TEXT; - else - annot_type = EV_ANNOTATION_TYPE_UNKNOWN; - - g_signal_emit (sidebar_annots, signals[BEGIN_ANNOT_ADD], 0, annot_type); -} - -static void -ev_sidebar_annotations_add_annots_palette (EvSidebarAnnotations *ev_annots) -{ - GtkWidget *swindow; - GtkWidget *group; - GtkToolItem *item; - GtkWidget *label; - - swindow = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swindow), - GTK_SHADOW_IN); - - ev_annots->priv->palette = gtk_tool_palette_new (); - group = gtk_tool_item_group_new (_("Annotations")); - gtk_container_add (GTK_CONTAINER (ev_annots->priv->palette), group); - - /* FIXME: use a better icon than EDIT */ - item = gtk_toggle_tool_button_new (); - gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "gtk-edit"); - gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), _("Text")); - gtk_widget_set_tooltip_text (GTK_WIDGET (item), _("Add text annotation")); - ev_annots->priv->annot_text_item = item; - g_signal_connect (item, "toggled", - G_CALLBACK (ev_sidebar_annotations_text_annot_button_toggled), - ev_annots); - gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1); - gtk_widget_show (GTK_WIDGET (item)); - - gtk_container_add (GTK_CONTAINER (swindow), ev_annots->priv->palette); - gtk_widget_show (ev_annots->priv->palette); + image = gtk_image_new_from_icon_name ("list-add", GTK_ICON_SIZE_BUTTON); + gtk_widget_show (image); + gtk_box_pack_start (GTK_BOX (buttonarea), image, TRUE, TRUE, 0); label = gtk_label_new (_("Add")); - gtk_notebook_append_page (GTK_NOTEBOOK (ev_annots->priv->notebook), - swindow, label); gtk_widget_show (label); - - gtk_widget_show (swindow); -} - -static void -ev_sidebar_annotations_init (EvSidebarAnnotations *ev_annots) -{ - ev_annots->priv = EV_SIDEBAR_ANNOTATIONS_GET_PRIVATE (ev_annots); - - ev_annots->priv->notebook = gtk_notebook_new (); - gtk_notebook_set_show_tabs (GTK_NOTEBOOK (ev_annots->priv->notebook), FALSE); - gtk_notebook_set_show_border (GTK_NOTEBOOK (ev_annots->priv->notebook), FALSE); - ev_sidebar_annotations_add_annots_list (ev_annots); - ev_sidebar_annotations_add_annots_palette (ev_annots); - gtk_orientable_set_orientation (GTK_ORIENTABLE (ev_annots), GTK_ORIENTATION_VERTICAL); - gtk_container_add (GTK_CONTAINER (ev_annots), ev_annots->priv->notebook); - gtk_widget_show (ev_annots->priv->notebook); + gtk_box_pack_start (GTK_BOX (buttonarea), label, TRUE, TRUE, 0); + + gtk_box_pack_start (GTK_BOX (hbox), ev_annots->priv->annot_text_item, TRUE, TRUE, 6); + gtk_widget_set_tooltip_text (GTK_WIDGET (ev_annots->priv->annot_text_item), + _("Add text annotation")); + g_signal_connect (ev_annots->priv->annot_text_item, "toggled", + G_CALLBACK (ev_sidebar_annotations_text_annot_button_toggled), + ev_annots); + gtk_widget_show (GTK_WIDGET (ev_annots->priv->annot_text_item)); + + gtk_box_pack_end (GTK_BOX (ev_annots), hbox, FALSE, TRUE, 0); + gtk_widget_show (GTK_WIDGET (ev_annots)); } static void @@ -314,15 +287,15 @@ void ev_sidebar_annotations_annot_added (EvSidebarAnnotations *sidebar_annots, EvAnnotation *annot) { - GtkToggleToolButton *toolbutton; + GtkWidget *toggle_button; if (EV_IS_ANNOTATION_TEXT (annot)) { - toolbutton = GTK_TOGGLE_TOOL_BUTTON (sidebar_annots->priv->annot_text_item); - g_signal_handlers_block_by_func (toolbutton, + toggle_button = sidebar_annots->priv->annot_text_item; + g_signal_handlers_block_by_func (toggle_button, ev_sidebar_annotations_text_annot_button_toggled, sidebar_annots); - gtk_toggle_tool_button_set_active (toolbutton, FALSE); - g_signal_handlers_unblock_by_func (toolbutton, + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle_button), FALSE); + g_signal_handlers_unblock_by_func (toggle_button, ev_sidebar_annotations_text_annot_button_toggled, sidebar_annots); } @@ -430,21 +403,20 @@ job_finished_callback (EvJobAnnots *job, if (EV_IS_ANNOTATION_TEXT (annot)) { if (!text_icon) { - /* FIXME: use a better icon than EDIT */ text_icon = gtk_icon_theme_load_icon (icon_theme, - "gtk-edit", - GTK_ICON_SIZE_BUTTON, - GTK_ICON_LOOKUP_FORCE_SVG | GTK_ICON_LOOKUP_USE_BUILTIN, - NULL); + "starred", + GTK_ICON_SIZE_BUTTON, + GTK_ICON_LOOKUP_FORCE_REGULAR, + NULL); } pixbuf = text_icon; } else if (EV_IS_ANNOTATION_ATTACHMENT (annot)) { if (!attachment_icon) { attachment_icon = gtk_icon_theme_load_icon (icon_theme, - EV_STOCK_ATTACHMENT, - GTK_ICON_SIZE_BUTTON, - GTK_ICON_LOOKUP_FORCE_SVG | GTK_ICON_LOOKUP_USE_BUILTIN, - NULL); + "mail-attachment", + GTK_ICON_SIZE_BUTTON, + GTK_ICON_LOOKUP_FORCE_REGULAR, + NULL); } pixbuf = attachment_icon; } @@ -503,7 +475,7 @@ ev_sidebar_annotations_document_changed_cb (EvDocumentModel *model, { EvDocument *document = ev_document_model_get_document (model); EvSidebarAnnotationsPrivate *priv = sidebar_annots->priv; - gboolean show_tabs; + gboolean enable_add; if (!EV_IS_DOCUMENT_ANNOTATIONS (document)) return; @@ -512,8 +484,8 @@ ev_sidebar_annotations_document_changed_cb (EvDocumentModel *model, g_object_unref (priv->document); priv->document = g_object_ref (document); - show_tabs = ev_document_annotations_can_add_annotation (EV_DOCUMENT_ANNOTATIONS (document)); - gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), show_tabs); + enable_add = ev_document_annotations_can_add_annotation (EV_DOCUMENT_ANNOTATIONS (document)); + gtk_widget_set_sensitive (priv->annot_text_item, enable_add); ev_sidebar_annotations_load (sidebar_annots); } |