[evince] Add a toolbar for adding annotations
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince] Add a toolbar for adding annotations
- Date: Sun, 28 Jun 2015 10:49:00 +0000 (UTC)
commit 65aacea6eea6359da042e693846859e76ab2a1ed
Author: Carlos Garcia Campos <carlosgc gnome org>
Date: Sun Jun 28 12:39:21 2015 +0200
Add a toolbar for adding annotations
And remove the tool palette used in the sidebar. This makes easier to
add annotations and improves the discoverability of the feature.
https://bugzilla.gnome.org/show_bug.cgi?id=649045
po/POTFILES.in | 1 +
shell/Makefile.am | 2 +
shell/ev-annotations-toolbar.c | 173 ++++++++++++++++++++++++++++++++++++++++
shell/ev-annotations-toolbar.h | 44 ++++++++++
shell/ev-sidebar-annotations.c | 170 ++-------------------------------------
shell/ev-sidebar-annotations.h | 3 -
shell/ev-toolbar.c | 12 +++
shell/ev-window.c | 56 ++++++++++---
8 files changed, 283 insertions(+), 178 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 2ad581e..2b148c9 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -41,6 +41,7 @@ previewer/ev-previewer-window.c
properties/ev-properties-main.c
properties/ev-properties-view.c
shell/ev-annotation-properties-dialog.c
+shell/ev-annotations-toolbar.c
shell/ev-application.c
shell/ev-history.c
shell/ev-history-action.c
diff --git a/shell/Makefile.am b/shell/Makefile.am
index 0c7e5b8..96075c3 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -9,6 +9,8 @@ endif
evince_SOURCES= \
ev-annotation-properties-dialog.h \
ev-annotation-properties-dialog.c \
+ ev-annotations-toolbar.h \
+ ev-annotations-toolbar.c \
ev-bookmarks.h \
ev-bookmarks.c \
ev-bookmark-action.h \
diff --git a/shell/ev-annotations-toolbar.c b/shell/ev-annotations-toolbar.c
new file mode 100644
index 0000000..e973c72
--- /dev/null
+++ b/shell/ev-annotations-toolbar.c
@@ -0,0 +1,173 @@
+/* ev-annotations-toolbar.c
+ * this file is part of evince, a gnome document viewer
+ *
+ * Copyright (C) 2015 Carlos Garcia Campos <carlosgc gnome org>
+ *
+ * Evince is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Evince is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include "ev-annotations-toolbar.h"
+#include <evince-document.h>
+#include <glib/gi18n.h>
+
+enum {
+ BEGIN_ADD_ANNOT,
+ CANCEL_ADD_ANNOT,
+ N_SIGNALS
+};
+
+struct _EvAnnotationsToolbar {
+ GtkToolbar base_instance;
+
+ GtkWidget *text_button;
+ GtkWidget *highlight_button;
+};
+
+struct _EvAnnotationsToolbarClass {
+ GtkToolbarClass base_class;
+
+};
+
+static guint signals[N_SIGNALS];
+
+G_DEFINE_TYPE (EvAnnotationsToolbar, ev_annotations_toolbar, GTK_TYPE_TOOLBAR)
+
+static void
+ev_annotations_toolbar_annot_button_toggled (GtkWidget *button,
+ EvAnnotationsToolbar *toolbar)
+{
+ EvAnnotationType annot_type;
+
+ if (!gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (button))) {
+ g_signal_emit (toolbar, signals[CANCEL_ADD_ANNOT], 0, NULL);
+ return;
+ }
+
+ if (button == toolbar->text_button) {
+ annot_type = EV_ANNOTATION_TYPE_TEXT;
+ gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (toolbar->highlight_button),
FALSE);
+ } else if (button == toolbar->highlight_button) {
+ annot_type = EV_ANNOTATION_TYPE_TEXT_MARKUP;
+ gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (toolbar->text_button), FALSE);
+ } else {
+ g_assert_not_reached ();
+ }
+
+ g_signal_emit (toolbar, signals[BEGIN_ADD_ANNOT], 0, annot_type);
+}
+
+static gboolean
+ev_annotations_toolbar_toggle_button_if_active (EvAnnotationsToolbar *toolbar,
+ GtkToggleToolButton *button)
+{
+ if (!gtk_toggle_tool_button_get_active (button))
+ return FALSE;
+
+ g_signal_handlers_block_by_func (button,
+ ev_annotations_toolbar_annot_button_toggled,
+ toolbar);
+ gtk_toggle_tool_button_set_active (button, FALSE);
+ g_signal_handlers_unblock_by_func (button,
+ ev_annotations_toolbar_annot_button_toggled,
+ toolbar);
+
+ return TRUE;
+}
+
+static GtkWidget *
+ev_annotations_toolbar_create_toggle_button (EvAnnotationsToolbar *toolbar,
+ const gchar *icon_name,
+ const gchar *tooltip)
+{
+ GtkWidget *button = GTK_WIDGET (gtk_toggle_tool_button_new ());
+
+ gtk_widget_set_tooltip_text (button, tooltip);
+ gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (button), icon_name);
+ /* For some reason adding text-button class to the GtkToogleButton makes the button smaller */
+ gtk_style_context_add_class (gtk_widget_get_style_context (gtk_bin_get_child (GTK_BIN (button))),
"text-button");
+ g_signal_connect (button, "toggled",
+ G_CALLBACK (ev_annotations_toolbar_annot_button_toggled),
+ toolbar);
+
+ return button;
+}
+
+static void
+ev_annotations_toolbar_init (EvAnnotationsToolbar *toolbar)
+{
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (toolbar), GTK_ORIENTATION_HORIZONTAL);
+
+ gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_MENU);
+ gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (toolbar)),
+ GTK_STYLE_CLASS_INLINE_TOOLBAR);
+
+ toolbar->text_button = ev_annotations_toolbar_create_toggle_button (toolbar,
+ "document-new-symbolic",
+ _("Add text annotation"));
+ gtk_container_add (GTK_CONTAINER(toolbar), toolbar->text_button);
+ gtk_widget_show (toolbar->text_button);
+
+ /* FIXME: use a better icon than select-all */
+ toolbar->highlight_button = ev_annotations_toolbar_create_toggle_button (toolbar,
+ "edit-select-all-symbolic",
+ _("Add highlight
annotation"));
+ gtk_container_add (GTK_CONTAINER (toolbar), toolbar->highlight_button);
+ gtk_widget_show (toolbar->highlight_button);
+}
+
+static void
+ev_annotations_toolbar_class_init (EvAnnotationsToolbarClass *klass)
+{
+ GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
+
+ signals[BEGIN_ADD_ANNOT] =
+ g_signal_new ("begin-add-annot",
+ G_TYPE_FROM_CLASS (g_object_class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__ENUM,
+ G_TYPE_NONE, 1,
+ EV_TYPE_ANNOTATION_TYPE);
+
+ signals[CANCEL_ADD_ANNOT] =
+ g_signal_new ("cancel-add-annot",
+ G_TYPE_FROM_CLASS (g_object_class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0,
+ G_TYPE_NONE);
+}
+
+GtkWidget *
+ev_annotations_toolbar_new (void)
+{
+ return GTK_WIDGET (g_object_new (EV_TYPE_ANNOTATIONS_TOOLBAR, NULL));
+}
+
+void
+ev_annotations_toolbar_add_annot_finished (EvAnnotationsToolbar *toolbar)
+{
+ g_return_if_fail (EV_IS_ANNOTATIONS_TOOLBAR (toolbar));
+
+ if (ev_annotations_toolbar_toggle_button_if_active (toolbar, GTK_TOGGLE_TOOL_BUTTON
(toolbar->text_button)))
+ return;
+
+ ev_annotations_toolbar_toggle_button_if_active (toolbar, GTK_TOGGLE_TOOL_BUTTON
(toolbar->highlight_button));
+}
diff --git a/shell/ev-annotations-toolbar.h b/shell/ev-annotations-toolbar.h
new file mode 100644
index 0000000..7690ac3
--- /dev/null
+++ b/shell/ev-annotations-toolbar.h
@@ -0,0 +1,44 @@
+/* ev-annotations-toolbar.h
+ * this file is part of evince, a gnome document viewer
+ *
+ * Copyright (C) 2015 Carlos Garcia Campos <carlosgc gnome org>
+ *
+ * Evince is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Evince is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __EV_ANNOTATIONS_TOOLBAR_H__
+#define __EV_ANNOTATIONS_TOOLBAR_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define EV_TYPE_ANNOTATIONS_TOOLBAR (ev_annotations_toolbar_get_type())
+#define EV_ANNOTATIONS_TOOLBAR(object) (G_TYPE_CHECK_INSTANCE_CAST((object),
EV_TYPE_ANNOTATIONS_TOOLBAR, EvAnnotationsToolbar))
+#define EV_IS_ANNOTATIONS_TOOLBAR(object) (G_TYPE_CHECK_INSTANCE_TYPE((object),
EV_TYPE_ANNOTATIONS_TOOLBAR))
+#define EV_ANNOTATIONS_TOOLBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),
EV_TYPE_ANNOTATIONS_TOOLBAR, EvAnnotationsToolbarClass))
+#define EV_IS_ANNOTATIONS_TOOLBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),
EV_TYPE_ANNOTATIONS_TOOLBAR))
+#define EV_ANNOTATIONS_TOOLBAR_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object),
EV_TYPE_ANNOTATIONS_TOOLBAR, EvAnnotationsToolbarClass))
+
+typedef struct _EvAnnotationsToolbar EvAnnotationsToolbar;
+typedef struct _EvAnnotationsToolbarClass EvAnnotationsToolbarClass;
+
+GType ev_annotations_toolbar_get_type (void) G_GNUC_CONST;
+GtkWidget *ev_annotations_toolbar_new (void);
+void ev_annotations_toolbar_add_annot_finished (EvAnnotationsToolbar *toolbar);
+
+G_END_DECLS
+
+#endif /* __EV_ANNOTATIONS_TOOLBAR_H__ */
diff --git a/shell/ev-sidebar-annotations.c b/shell/ev-sidebar-annotations.c
index d99a9f2..013dec1 100644
--- a/shell/ev-sidebar-annotations.c
+++ b/shell/ev-sidebar-annotations.c
@@ -43,19 +43,14 @@ enum {
enum {
ANNOT_ACTIVATED,
- BEGIN_ANNOT_ADD,
- ANNOT_ADD_CANCELLED,
N_SIGNALS
};
struct _EvSidebarAnnotationsPrivate {
EvDocument *document;
- GtkWidget *notebook;
+ GtkWidget *swindow;
GtkWidget *tree_view;
- GtkWidget *palette;
- GtkToolItem *annot_text_item;
- GtkToolItem *annot_highlight_item;
EvJob *job;
guint selection_changed_id;
@@ -115,16 +110,16 @@ ev_sidebar_annotations_create_simple_model (const gchar *message)
}
static void
-ev_sidebar_annotations_add_annots_list (EvSidebarAnnotations *ev_annots)
+ev_sidebar_annotations_init (EvSidebarAnnotations *ev_annots)
{
- GtkWidget *swindow;
GtkTreeModel *loading_model;
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
GtkTreeSelection *selection;
- GtkWidget *label;
- swindow = gtk_scrolled_window_new (NULL, NULL);
+ ev_annots->priv = EV_SIDEBAR_ANNOTATIONS_GET_PRIVATE (ev_annots);
+
+ ev_annots->priv->swindow = gtk_scrolled_window_new (NULL, NULL);
/* Create tree view */
loading_model = ev_sidebar_annotations_create_simple_model (_("Loading…"));
@@ -153,106 +148,11 @@ ev_sidebar_annotations_add_annots_list (EvSidebarAnnotations *ev_annots)
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_container_add (GTK_CONTAINER (ev_annots->priv->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);
-
- gtk_widget_show (swindow);
-}
-
-static void
-ev_sidebar_annotations_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) {
- gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON
(sidebar_annots->priv->annot_highlight_item), FALSE);
- annot_type = EV_ANNOTATION_TYPE_TEXT;
- } else if (GTK_TOOL_ITEM (toolbutton) == sidebar_annots->priv->annot_highlight_item) {
- gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON
(sidebar_annots->priv->annot_text_item), FALSE);
- annot_type = EV_ANNOTATION_TYPE_TEXT_MARKUP;
- } else
- g_assert_not_reached ();
-
- 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);
-
- ev_annots->priv->palette = gtk_tool_palette_new ();
- gtk_widget_set_margin_top (ev_annots->priv->palette, 2);
- gtk_widget_set_margin_bottom (ev_annots->priv->palette, 2);
- gtk_widget_set_margin_start (ev_annots->priv->palette, 2);
- gtk_widget_set_margin_end (ev_annots->priv->palette, 2);
-
- group = gtk_tool_item_group_new (_("Annotations"));
- gtk_tool_item_group_set_header_relief (GTK_TOOL_ITEM_GROUP (group), GTK_RELIEF_NONE);
- gtk_container_add (GTK_CONTAINER (ev_annots->priv->palette), group);
-
- item = gtk_toggle_tool_button_new ();
- gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "document-new-symbolic");
- 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_annot_button_toggled),
- ev_annots);
- gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
- gtk_widget_show (GTK_WIDGET (item));
-
- /* FIXME: use a better icon than INDEX */
- item = gtk_toggle_tool_button_new ();
- gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), GTK_STOCK_INDEX);
- gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), _("Highlight"));
- gtk_widget_set_tooltip_text (GTK_WIDGET (item), _("Add highlight annotation"));
- ev_annots->priv->annot_highlight_item = item;
- g_signal_connect (item, "toggled",
- G_CALLBACK (ev_sidebar_annotations_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);
-
- 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_box_pack_start (GTK_BOX (ev_annots), ev_annots->priv->notebook, TRUE, TRUE, 0);
- gtk_widget_show (ev_annots->priv->notebook);
+ gtk_box_pack_start (GTK_BOX (ev_annots), ev_annots->priv->swindow, TRUE, TRUE, 0);
+ gtk_widget_show (ev_annots->priv->swindow);
}
static void
@@ -267,7 +167,7 @@ ev_sidebar_annotations_get_property (GObject *object,
switch (prop_id) {
case PROP_WIDGET:
- g_value_set_object (value, ev_sidebar_annots->priv->notebook);
+ g_value_set_object (value, ev_sidebar_annots->priv->swindow);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -296,24 +196,6 @@ ev_sidebar_annotations_class_init (EvSidebarAnnotationsClass *klass)
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
- signals[BEGIN_ANNOT_ADD] =
- g_signal_new ("begin-annot-add",
- G_TYPE_FROM_CLASS (g_object_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET (EvSidebarAnnotationsClass, begin_annot_add),
- NULL, NULL,
- g_cclosure_marshal_VOID__ENUM,
- G_TYPE_NONE, 1,
- EV_TYPE_ANNOTATION_TYPE);
- signals[ANNOT_ADD_CANCELLED] =
- g_signal_new ("annot-add-cancelled",
- G_TYPE_FROM_CLASS (g_object_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET (EvSidebarAnnotationsClass, annot_add_cancelled),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0,
- G_TYPE_NONE);
}
GtkWidget *
@@ -328,36 +210,6 @@ void
ev_sidebar_annotations_annot_added (EvSidebarAnnotations *sidebar_annots,
EvAnnotation *annot)
{
- GtkToggleToolButton *toolbutton;
-
- if (EV_IS_ANNOTATION (annot)) {
- switch (ev_annotation_get_annotation_type (annot)) {
- case EV_ANNOTATION_TYPE_TEXT:
- toolbutton = GTK_TOGGLE_TOOL_BUTTON (sidebar_annots->priv->annot_text_item);
- break;
- case EV_ANNOTATION_TYPE_TEXT_MARKUP:
- switch (ev_annotation_text_markup_get_markup_type (EV_ANNOTATION_TEXT_MARKUP
(annot))) {
- case EV_ANNOTATION_TEXT_MARKUP_HIGHLIGHT: {
- toolbutton = GTK_TOGGLE_TOOL_BUTTON
(sidebar_annots->priv->annot_highlight_item);
- break;
- }
- default:
- g_assert_not_reached ();
- }
- break;
- default:
- g_assert_not_reached ();
- }
-
- g_signal_handlers_block_by_func (toolbutton,
- ev_sidebar_annotations_annot_button_toggled,
- sidebar_annots);
- gtk_toggle_tool_button_set_active (toolbutton, FALSE);
- g_signal_handlers_unblock_by_func (toolbutton,
- ev_sidebar_annotations_annot_button_toggled,
- sidebar_annots);
- }
-
ev_sidebar_annotations_load (sidebar_annots);
}
@@ -582,7 +434,6 @@ ev_sidebar_annotations_document_changed_cb (EvDocumentModel *model,
{
EvDocument *document = ev_document_model_get_document (model);
EvSidebarAnnotationsPrivate *priv = sidebar_annots->priv;
- gboolean show_tabs;
if (!EV_IS_DOCUMENT_ANNOTATIONS (document))
return;
@@ -591,9 +442,6 @@ 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);
-
ev_sidebar_annotations_load (sidebar_annots);
}
diff --git a/shell/ev-sidebar-annotations.h b/shell/ev-sidebar-annotations.h
index a78e89a..6f9e6ae 100644
--- a/shell/ev-sidebar-annotations.h
+++ b/shell/ev-sidebar-annotations.h
@@ -48,9 +48,6 @@ struct _EvSidebarAnnotationsClass {
void (* annot_activated) (EvSidebarAnnotations *sidebar_annots,
EvMapping *mapping);
- void (* begin_annot_add) (EvSidebarAnnotations *sidebar_annots,
- EvAnnotationType annot_type);
- void (* annot_add_cancelled) (EvSidebarAnnotations *sidebar_annots);
};
GType ev_sidebar_annotations_get_type (void) G_GNUC_CONST;
diff --git a/shell/ev-toolbar.c b/shell/ev-toolbar.c
index 1f771a5..6bac02f 100644
--- a/shell/ev-toolbar.c
+++ b/shell/ev-toolbar.c
@@ -51,6 +51,7 @@ struct _EvToolbarPrivate {
GtkWidget *navigation_action;
GtkWidget *find_button;
GtkWidget *open_button;
+ GtkWidget *annots_button;
GMenu *bookmarks_section;
EvToolbarMode toolbar_mode;
@@ -225,6 +226,14 @@ ev_toolbar_constructed (GObject *object)
gtk_widget_set_margin_end (button, 6);
gtk_header_bar_pack_start (GTK_HEADER_BAR (ev_toolbar), button);
+ /* Edit Annots */
+ /* FIXME: Use a better icon for edit than text editor */
+ button = ev_toolbar_create_toggle_button (ev_toolbar, "win.toggle-edit-annots",
"accessories-text-editor-symbolic",
+ _("Annotate the document"));
+ ev_toolbar->priv->annots_button = button;
+ gtk_widget_set_margin_end (button, 6);
+ gtk_header_bar_pack_start (GTK_HEADER_BAR (ev_toolbar), button);
+
/* Action Menu */
menu = G_MENU_MODEL (gtk_builder_get_object (builder, "action-menu"));
button = ev_toolbar_create_menu_button (ev_toolbar, "open-menu-symbolic",
@@ -365,6 +374,7 @@ ev_toolbar_set_mode (EvToolbar *ev_toolbar,
gtk_widget_show (priv->zoom_action);
gtk_widget_show (priv->page_selector);
gtk_widget_show (priv->find_button);
+ gtk_widget_show (priv->annots_button);
gtk_widget_hide (priv->open_button);
break;
case EV_TOOLBAR_MODE_FULLSCREEN:
@@ -374,6 +384,7 @@ ev_toolbar_set_mode (EvToolbar *ev_toolbar,
gtk_widget_show (priv->zoom_action);
gtk_widget_show (priv->page_selector);
gtk_widget_show (priv->find_button);
+ gtk_widget_show (priv->annots_button);
gtk_widget_hide (priv->open_button);
break;
case EV_TOOLBAR_MODE_RECENT_VIEW:
@@ -383,6 +394,7 @@ ev_toolbar_set_mode (EvToolbar *ev_toolbar,
gtk_widget_hide (priv->zoom_action);
gtk_widget_hide (priv->page_selector);
gtk_widget_hide (priv->find_button);
+ gtk_widget_hide (priv->annots_button);
gtk_widget_show (priv->open_button);
break;
}
diff --git a/shell/ev-window.c b/shell/ev-window.c
index ea61de7..5b8fd5c 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -42,7 +42,7 @@
#include <gtk/gtk.h>
#include "ev-find-sidebar.h"
-
+#include "ev-annotations-toolbar.h"
#include "ev-application.h"
#include "ev-document-factory.h"
#include "ev-document-find.h"
@@ -144,6 +144,7 @@ struct _EvWindowPrivate {
GtkWidget *sidebar_layers;
GtkWidget *sidebar_annots;
GtkWidget *sidebar_bookmarks;
+ GtkWidget *annots_toolbar;
/* Settings */
GSettings *settings;
@@ -415,6 +416,7 @@ ev_window_update_actions_sensitivity (EvWindow *ev_window)
gboolean can_get_text = FALSE;
gboolean can_find = FALSE;
gboolean can_find_in_page;
+ gboolean can_annotate = FALSE;
gboolean presentation_mode;
gboolean recent_view_mode;
gboolean dual_mode = FALSE;
@@ -442,6 +444,10 @@ ev_window_update_actions_sensitivity (EvWindow *ev_window)
can_find = TRUE;
}
+ if (has_document && EV_IS_DOCUMENT_ANNOTATIONS (document)) {
+ can_annotate = ev_document_annotations_can_add_annotation (EV_DOCUMENT_ANNOTATIONS
(document));
+ }
+
if (has_document && ev_window->priv->settings) {
override_restrictions =
g_settings_get_boolean (ev_window->priv->settings,
@@ -497,6 +503,8 @@ ev_window_update_actions_sensitivity (EvWindow *ev_window)
!recent_view_mode);
ev_window_set_action_enabled (ev_window, "toggle-find", can_find &&
!recent_view_mode);
+ ev_window_set_action_enabled (ev_window, "toggle-edit-annots", can_annotate &&
+ !recent_view_mode);
ev_window_set_action_enabled (ev_window, "rotate-left", has_pages &&
!recent_view_mode);
ev_window_set_action_enabled (ev_window, "rotate-right", has_pages &&
@@ -5405,6 +5413,21 @@ ev_window_cmd_view_toggle_caret_navigation (GSimpleAction *action,
}
static void
+ev_window_cmd_toggle_edit_annots (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data)
+{
+ EvWindow *ev_window = user_data;
+
+ if (g_variant_get_boolean (state))
+ gtk_widget_show (ev_window->priv->annots_toolbar);
+ else
+ gtk_widget_hide (ev_window->priv->annots_toolbar);
+
+ g_simple_action_set_state (action, state);
+}
+
+static void
ev_window_dispose (GObject *object)
{
EvWindow *window = EV_WINDOW (object);
@@ -5691,6 +5714,7 @@ static const GActionEntry actions[] = {
{ "escape", ev_window_cmd_escape },
{ "open-menu", ev_window_cmd_action_menu },
{ "caret-navigation", NULL, NULL, "false", ev_window_cmd_view_toggle_caret_navigation },
+ { "toggle-edit-annots", NULL, NULL, "false", ev_window_cmd_toggle_edit_annots },
/* Popups specific items */
{ "open-link", ev_window_popup_cmd_open_link },
{ "open-link-new-window", ev_window_popup_cmd_open_link_new_window },
@@ -5743,9 +5767,8 @@ sidebar_annots_annot_activated_cb (EvSidebarAnnotations *sidebar_annots,
}
static void
-sidebar_annots_begin_annot_add (EvSidebarAnnotations *sidebar_annots,
- EvAnnotationType annot_type,
- EvWindow *window)
+ev_window_begin_add_annot (EvWindow *window,
+ EvAnnotationType annot_type)
{
ev_view_begin_add_annotation (EV_VIEW (window->priv->view), annot_type);
}
@@ -5757,6 +5780,7 @@ view_annot_added (EvView *view,
{
ev_sidebar_annotations_annot_added (EV_SIDEBAR_ANNOTATIONS (window->priv->sidebar_annots),
annot);
+ ev_annotations_toolbar_add_annot_finished (EV_ANNOTATIONS_TOOLBAR (window->priv->annots_toolbar));
}
static void
@@ -5768,8 +5792,7 @@ view_annot_removed (EvView *view,
}
static void
-sidebar_annots_annot_add_cancelled (EvSidebarAnnotations *sidebar_annots,
- EvWindow *window)
+ev_window_cancel_add_annot(EvWindow *window)
{
ev_view_cancel_add_annotation (EV_VIEW (window->priv->view));
}
@@ -6782,6 +6805,19 @@ ev_window_init (EvWindow *ev_window)
G_CALLBACK (activate_link_cb),
ev_window);
+ /* Annotations toolbar */
+ ev_window->priv->annots_toolbar = ev_annotations_toolbar_new ();
+ g_signal_connect_swapped (ev_window->priv->annots_toolbar,
+ "begin-add-annot",
+ G_CALLBACK (ev_window_begin_add_annot),
+ ev_window);
+ g_signal_connect_swapped (ev_window->priv->annots_toolbar,
+ "cancel-add-annot",
+ G_CALLBACK (ev_window_cancel_add_annot),
+ ev_window);
+ gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box),
+ ev_window->priv->annots_toolbar, FALSE, TRUE, 0);
+
/* Search Bar */
ev_window->priv->search_bar = gtk_search_bar_new ();
gtk_search_bar_set_show_close_button (GTK_SEARCH_BAR (ev_window->priv->search_bar), TRUE);
@@ -6874,14 +6910,6 @@ ev_window_init (EvWindow *ev_window)
"annot_activated",
G_CALLBACK (sidebar_annots_annot_activated_cb),
ev_window);
- g_signal_connect (sidebar_widget,
- "begin_annot_add",
- G_CALLBACK (sidebar_annots_begin_annot_add),
- ev_window);
- g_signal_connect (sidebar_widget,
- "annot_add_cancelled",
- G_CALLBACK (sidebar_annots_annot_add_cancelled),
- ev_window);
gtk_widget_show (sidebar_widget);
ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
sidebar_widget);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]