[evince/wip/recent-view: 16/17] shell: Implement a different toolbar for bookshelf/recent view
- From: Germán Poó Caamaño <gpoo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince/wip/recent-view: 16/17] shell: Implement a different toolbar for bookshelf/recent view
- Date: Thu, 27 Feb 2014 22:49:17 +0000 (UTC)
commit 8182dcbe9b1336814d344dd19245a2ab870ef749
Author: Aakash Goenka <aakash goenka gmail com>
Date: Tue Jul 23 22:58:52 2013 +0530
shell: Implement a different toolbar for bookshelf/recent view
Added a new EvMinimalToolbar which is displayed while in
bookshelf/recent view, instead of the full regular toolbar.
shell/Makefile.am | 2 +
shell/ev-minimal-toolbar.c | 196 ++++++++++++++++++++++++++++++++++++++++++++
shell/ev-minimal-toolbar.h | 56 +++++++++++++
shell/ev-window.c | 74 ++++++++++++++---
shell/ev-window.h | 1 +
5 files changed, 315 insertions(+), 14 deletions(-)
---
diff --git a/shell/Makefile.am b/shell/Makefile.am
index a2d9d49..bda2f81 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -35,6 +35,8 @@ evince_SOURCES= \
ev-message-area.h \
ev-metadata.c \
ev-metadata.h \
+ ev-minimal-toolbar.c \
+ ev-minimal-toolbar.h \
ev-password-view.h \
ev-password-view.c \
ev-progress-message-area.h \
diff --git a/shell/ev-minimal-toolbar.c b/shell/ev-minimal-toolbar.c
new file mode 100644
index 0000000..7c2622b
--- /dev/null
+++ b/shell/ev-minimal-toolbar.c
@@ -0,0 +1,196 @@
+/* ev-minimal-toolbar.c
+ * this file is part of evince, a gnome document viewer
+ *
+ * Copyright (C) 2012 Carlos Garcia Campos <carlosgc gnome org>
+ * Copyright (C) 2013 Aakash Goenka <aakash goenka gmail com>
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "ev-minimal-toolbar.h"
+#include <math.h>
+
+enum
+{
+ PROP_0,
+ PROP_WINDOW
+};
+
+struct _EvMinimalToolbarPrivate {
+ EvWindow *window;
+};
+
+G_DEFINE_TYPE (EvMinimalToolbar, ev_minimal_toolbar, GTK_TYPE_TOOLBAR)
+
+static void
+ev_minimal_toolbar_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EvMinimalToolbar *ev_minimal_toolbar = EV_MINIMAL_TOOLBAR (object);
+
+ switch (prop_id) {
+ case PROP_WINDOW:
+ ev_minimal_toolbar->priv->window = g_value_get_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static gint
+get_icon_margin (EvMinimalToolbar *ev_minimal_toolbar)
+{
+ GtkIconSize toolbar_size;
+ gint toolbar_size_px, menu_size_px;
+ GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (ev_minimal_toolbar));
+
+ toolbar_size = gtk_toolbar_get_icon_size (GTK_TOOLBAR (ev_minimal_toolbar));
+
+ gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &menu_size_px, NULL);
+ gtk_icon_size_lookup_for_settings (settings, toolbar_size, &toolbar_size_px, NULL);
+
+ return (gint)floor ((toolbar_size_px - menu_size_px) / 2.0);
+}
+
+static void
+ev_minimal_toolbar_set_button_image (EvMinimalToolbar *ev_minimal_toolbar,
+ GtkButton *button)
+{
+ GtkWidget *image;
+
+ image = gtk_image_new ();
+ g_object_set (image, "margin", get_icon_margin (ev_minimal_toolbar), NULL);
+ gtk_button_set_image (button, image);
+}
+
+static void
+ev_minimal_toolbar_set_button_action (EvMinimalToolbar *ev_toolbar,
+ GtkButton *button,
+ GtkAction *action)
+{
+ gtk_activatable_set_related_action (GTK_ACTIVATABLE (button), action);
+ gtk_button_set_label (button, NULL);
+ gtk_button_set_focus_on_click (button, FALSE);
+}
+
+static GtkWidget *
+ev_minimal_toolbar_create_button (EvMinimalToolbar *ev_toolbar,
+ GtkAction *action)
+{
+ GtkWidget *button = gtk_button_new ();
+
+ ev_minimal_toolbar_set_button_image (ev_toolbar, GTK_BUTTON (button));
+ ev_minimal_toolbar_set_button_action (ev_toolbar, GTK_BUTTON (button), action);
+
+ return button;
+}
+
+static void
+ev_minimal_toolbar_constructed (GObject *object)
+{
+ EvMinimalToolbar *ev_minimal_toolbar = EV_MINIMAL_TOOLBAR (object);
+ GtkActionGroup *action_group;
+ GtkWidget *tool_item;
+ GtkAction *action;
+ GtkWidget *button;
+
+ G_OBJECT_CLASS (ev_minimal_toolbar_parent_class)->constructed (object);
+
+ /* Set the MENUBAR style class so it's possible to drag the app
+ * using the toolbar. */
+ gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (ev_minimal_toolbar)),
+ GTK_STYLE_CLASS_MENUBAR);
+
+ action_group = ev_window_get_minimal_toolbar_action_group (ev_minimal_toolbar->priv->window);
+
+ /* Button for file open dialog */
+ action = gtk_action_group_get_action (action_group, "ToolbarOpenDocument");
+ button = ev_minimal_toolbar_create_button (ev_minimal_toolbar, action);
+ tool_item = GTK_WIDGET (gtk_tool_item_new ());
+ gtk_container_add (GTK_CONTAINER (tool_item), button);
+ gtk_widget_show (button);
+ gtk_container_add (GTK_CONTAINER (ev_minimal_toolbar), tool_item);
+ gtk_widget_show (tool_item);
+
+ /* Separator */
+ tool_item = GTK_WIDGET (gtk_tool_item_new ());
+ gtk_tool_item_set_expand (GTK_TOOL_ITEM (tool_item), TRUE);
+ gtk_container_add (GTK_CONTAINER (ev_minimal_toolbar), tool_item);
+ gtk_widget_show (tool_item);
+
+ /* About Button */
+ action = gtk_action_group_get_action (action_group, "ToolbarAbout");
+ button = ev_minimal_toolbar_create_button (ev_minimal_toolbar, action);
+ gtk_widget_set_halign (button, GTK_ALIGN_END);
+ tool_item = GTK_WIDGET (gtk_tool_item_new ());
+ gtk_widget_set_margin_right (tool_item, 6);
+ gtk_container_add (GTK_CONTAINER (tool_item), button);
+ gtk_widget_show (button);
+ gtk_container_add (GTK_CONTAINER (ev_minimal_toolbar), tool_item);
+ gtk_widget_show (tool_item);
+
+ /* Close Button */
+ action = gtk_action_group_get_action (action_group, "ToolbarCloseWindow");
+ button = ev_minimal_toolbar_create_button (ev_minimal_toolbar, action);
+ gtk_widget_set_halign (button, GTK_ALIGN_END);
+ tool_item = GTK_WIDGET (gtk_tool_item_new ());
+ gtk_container_add (GTK_CONTAINER (tool_item), button);
+ gtk_widget_show (button);
+ gtk_container_add (GTK_CONTAINER (ev_minimal_toolbar), tool_item);
+ gtk_widget_show (tool_item);
+}
+
+static void
+ev_minimal_toolbar_class_init (EvMinimalToolbarClass *klass)
+{
+ GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
+
+ g_object_class->set_property = ev_minimal_toolbar_set_property;
+ g_object_class->constructed = ev_minimal_toolbar_constructed;
+
+ g_object_class_install_property (g_object_class,
+ PROP_WINDOW,
+ g_param_spec_object ("window",
+ "Window",
+ "The evince window",
+ EV_TYPE_WINDOW,
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ g_type_class_add_private (g_object_class, sizeof (EvMinimalToolbarPrivate));
+}
+
+static void
+ev_minimal_toolbar_init (EvMinimalToolbar *ev_minimal_toolbar)
+{
+ ev_minimal_toolbar->priv = G_TYPE_INSTANCE_GET_PRIVATE (ev_minimal_toolbar, EV_TYPE_MINIMAL_TOOLBAR,
EvMinimalToolbarPrivate);
+}
+
+GtkWidget *
+ev_minimal_toolbar_new (EvWindow *window)
+{
+ g_return_val_if_fail (EV_IS_WINDOW (window), NULL);
+
+ return GTK_WIDGET (g_object_new (EV_TYPE_MINIMAL_TOOLBAR,
+ "window", window,
+ NULL));
+}
diff --git a/shell/ev-minimal-toolbar.h b/shell/ev-minimal-toolbar.h
new file mode 100644
index 0000000..16dbbee
--- /dev/null
+++ b/shell/ev-minimal-toolbar.h
@@ -0,0 +1,56 @@
+/* ev-minimal-toolbar.h
+ * this file is part of evince, a gnome document viewer
+ *
+ * Copyright (C) 2012 Carlos Garcia Campos <carlosgc gnome org>
+ * Copyright (C) 2013 Aakash Goenka <aakash goenka gmail com>
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __EV_MINIMAL_TOOLBAR_H__
+#define __EV_MINIMAL_TOOLBAR_H__
+
+#include <gtk/gtk.h>
+#include "ev-window.h"
+
+G_BEGIN_DECLS
+
+#define EV_TYPE_MINIMAL_TOOLBAR (ev_minimal_toolbar_get_type())
+#define EV_MINIMAL_TOOLBAR(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_MINIMAL_TOOLBAR,
EvMinimalToolbar))
+#define EV_IS_MINIMAL_TOOLBAR(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_MINIMAL_TOOLBAR))
+#define EV_MINIMAL_TOOLBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_MINIMAL_TOOLBAR,
EvMinimalToolbarClass))
+#define EV_IS_MINIMAL_TOOLBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EV_TYPE_MINIMAL_TOOLBAR))
+#define EV_MINIMAL_TOOLBAR_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), EV_TYPE_MINIMAL_TOOLBAR,
EvMinimalToolbarClass))
+
+typedef struct _EvMinimalToolbar EvMinimalToolbar;
+typedef struct _EvMinimalToolbarClass EvMinimalToolbarClass;
+typedef struct _EvMinimalToolbarPrivate EvMinimalToolbarPrivate;
+
+struct _EvMinimalToolbar {
+ GtkToolbar base_instance;
+
+ EvMinimalToolbarPrivate *priv;
+};
+
+struct _EvMinimalToolbarClass {
+ GtkToolbarClass base_class;
+};
+
+GType ev_minimal_toolbar_get_type (void);
+GtkWidget *ev_minimal_toolbar_new (EvWindow *window);
+
+G_END_DECLS
+
+#endif /* __EV_MINIMAL_TOOLBAR_H__ */
diff --git a/shell/ev-window.c b/shell/ev-window.c
index 195073f..4866c64 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -92,6 +92,7 @@
#include "ev-zoom-action.h"
#include "ev-toolbar.h"
#include "ev-recent-view.h"
+#include "ev-minimal-toolbar.h"
#ifdef ENABLE_DBUS
#include "ev-gdbus-generated.h"
@@ -172,6 +173,7 @@ struct _EvWindowPrivate {
/* UI Builders */
GtkActionGroup *action_group;
+ GtkActionGroup *minimal_toolbar_action_group;
GtkActionGroup *view_popup_action_group;
GtkActionGroup *attachment_popup_action_group;
GtkActionGroup *zoom_selector_popup_action_group;
@@ -194,6 +196,7 @@ struct _EvWindowPrivate {
/* For bookshelf view of recent items*/
EvRecentView *recent_view;
+ GtkWidget *minimal_toolbar;
/* Document */
EvDocumentModel *model;
@@ -518,6 +521,7 @@ ev_window_update_actions_sensitivity (EvWindow *ev_window)
gboolean presentation_mode;
gboolean can_find_in_page = FALSE;
gboolean dual_mode = FALSE;
+ gboolean fullscreen_mode = FALSE;
if (ev_window->priv->document && !ev_window->priv->recent_view) {
page = ev_document_model_get_page (ev_window->priv->model);
@@ -526,9 +530,11 @@ ev_window_update_actions_sensitivity (EvWindow *ev_window)
dual_mode = ev_document_model_get_dual_page (ev_window->priv->model);
}
- ev_window_set_action_sensitive (ev_window, "RecentViewShow",
- ev_window->priv->document ||
- !ev_window->priv->recent_view);
+ fullscreen_mode = ev_document_model_get_fullscreen (ev_window->priv->model);
+ ev_window_set_action_sensitive (ev_window, "RecentViewShow",
+ ev_window->priv->document &&
+ !ev_window->priv->recent_view &&
+ !fullscreen_mode);
can_find_in_page = (ev_window->priv->find_job &&
ev_job_find_has_results (EV_JOB_FIND (ev_window->priv->find_job)));
@@ -4270,6 +4276,7 @@ ev_window_run_fullscreen (EvWindow *window)
if (window->priv->metadata && !ev_window_is_empty (window))
ev_metadata_set_boolean (window->priv->metadata, "fullscreen", TRUE);
+ ev_window_update_actions_sensitivity (window);
}
static void
@@ -4314,6 +4321,7 @@ ev_window_stop_fullscreen (EvWindow *window,
if (window->priv->metadata && !ev_window_is_empty (window))
ev_metadata_set_boolean (window->priv->metadata, "fullscreen", FALSE);
+ ev_window_update_actions_sensitivity (window);
}
static void
@@ -4721,15 +4729,10 @@ ev_window_cmd_bookmark_activate (GtkAction *action,
}
static void
-ev_window_cmd_toggle_recent_view (GtkAction *action,
+ev_window_cmd_show_recent_view (GtkAction *action,
EvWindow *ev_window)
{
- if (!ev_window->priv->recent_view)
- ev_window_show_recent_view (ev_window);
- else {
- ev_window_try_swap_out_recent_view (ev_window);
- ev_window_setup_action_sensitivity (ev_window);
- }
+ ev_window_show_recent_view (ev_window);
return;
}
@@ -5390,10 +5393,12 @@ ev_window_try_swap_out_recent_view (EvWindow *ev_window)
if (ev_window->priv->recent_view)
{
gtk_widget_hide (GTK_WIDGET (ev_window->priv->recent_view));
+ gtk_widget_hide (GTK_WIDGET (ev_window->priv->minimal_toolbar));
g_object_unref (ev_window->priv->recent_view);
ev_window->priv->recent_view = NULL;
}
gtk_widget_show (ev_window->priv->hpaned);
+ gtk_widget_show (ev_window->priv->toolbar);
}
static void
@@ -5864,6 +5869,10 @@ ev_window_dispose (GObject *object)
priv->action_group = NULL;
}
+ if (priv->minimal_toolbar_action_group) {
+ g_object_unref (priv->minimal_toolbar_action_group);
+ priv->minimal_toolbar_action_group = NULL;
+ }
if (priv->view_popup_action_group) {
g_object_unref (priv->view_popup_action_group);
priv->view_popup_action_group = NULL;
@@ -6139,10 +6148,10 @@ static const GtkActionEntry entries[] = {
{ "ViewAutoscroll", GTK_STOCK_MEDIA_PLAY, N_("Auto_scroll"), NULL, NULL,
G_CALLBACK (ev_window_cmd_view_autoscroll) },
- /* View of recent items */
- { "RecentViewShow", "view-grid-symbolic", N_("Recent Items"), NULL,
- N_("Toggle between view of recent items and open document"),
- G_CALLBACK (ev_window_cmd_toggle_recent_view) },
+ /* View of recent documents */
+ { "RecentViewShow", "view-grid-symbolic", N_("Recent Documents"), NULL,
+ N_("Show recent documents"),
+ G_CALLBACK (ev_window_cmd_show_recent_view) },
/* Go menu */
{ "GoPreviousPage", "go-up-symbolic", N_("_Previous Page"), "<control>Page_Up",
@@ -6299,6 +6308,19 @@ static const GtkToggleActionEntry zoom_selector_popup_actions[] = {
G_CALLBACK (ev_window_cmd_view_zoom_automatic) }
};
+/* Items for the minimal toolbar */
+static const GtkActionEntry minimal_toolbar_entries [] = {
+ { "ToolbarOpenDocument", "document-open-symbolic", N_("_Open…"), NULL,
+ N_("Open an existing document"),
+ G_CALLBACK (ev_window_cmd_file_open) },
+ { "ToolbarAbout", "dialog-information-symbolic", N_("_About"), NULL,
+ N_("About "),
+ G_CALLBACK (ev_window_cmd_help_about) },
+ { "ToolbarCloseWindow", "window-close-symbolic", N_("Close"), NULL,
+ N_("Close this window"),
+ G_CALLBACK (ev_window_cmd_file_close_window) },
+};
+
static void
sidebar_links_link_activated_cb (EvSidebarLinks *sidebar_links, EvLink *link, EvWindow *window)
{
@@ -7447,6 +7469,12 @@ ev_window_init (EvWindow *ev_window)
gtk_ui_manager_get_accel_group (ev_window->priv->ui_manager);
gtk_window_add_accel_group (GTK_WINDOW (ev_window), accel_group);
+ action_group = gtk_action_group_new ("MinimalToolbarActions");
+ ev_window->priv->minimal_toolbar_action_group = action_group;
+ gtk_action_group_set_translation_domain (action_group, NULL);
+ gtk_action_group_add_actions (action_group, minimal_toolbar_entries,
+ G_N_ELEMENTS (minimal_toolbar_entries), ev_window);
+
action_group = gtk_action_group_new ("ViewPopupActions");
ev_window->priv->view_popup_action_group = action_group;
gtk_action_group_set_translation_domain (action_group, NULL);
@@ -7515,6 +7543,13 @@ ev_window_init (EvWindow *ev_window)
gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box),
ev_window->priv->find_bar,
FALSE, TRUE, 0);
+
+ ev_window->priv->minimal_toolbar = ev_minimal_toolbar_new (ev_window);
+ gtk_widget_set_halign (ev_window->priv->minimal_toolbar, GTK_ALIGN_FILL);
+ gtk_widget_set_valign (ev_window->priv->minimal_toolbar, GTK_ALIGN_START);
+ gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box),
+ ev_window->priv->minimal_toolbar,
+ FALSE, TRUE, 0);
/* Add the main area */
ev_window->priv->hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
@@ -7847,6 +7882,8 @@ void
ev_window_show_recent_view (EvWindow *ev_window)
{
gtk_widget_hide (ev_window->priv->hpaned);
+ gtk_widget_hide (ev_window->priv->toolbar);
+ gtk_widget_hide (ev_window->priv->find_bar);
if (!ev_window->priv->recent_view) {
ev_window->priv->recent_view = ev_recent_view_new ();
g_object_ref (ev_window->priv->recent_view);
@@ -7859,6 +7896,7 @@ ev_window_show_recent_view (EvWindow *ev_window)
TRUE, TRUE, 0);
}
+ gtk_widget_show (ev_window->priv->minimal_toolbar);
gtk_widget_show (GTK_WIDGET (ev_window->priv->recent_view));
ev_window_setup_action_sensitivity (ev_window);
@@ -7898,3 +7936,11 @@ ev_window_get_zoom_selector_action_group (EvWindow *ev_window)
return ev_window->priv->zoom_selector_popup_action_group;
}
+
+GtkActionGroup *
+ev_window_get_minimal_toolbar_action_group (EvWindow *ev_window)
+{
+ g_return_val_if_fail (EV_WINDOW (ev_window), NULL);
+
+ return ev_window->priv->minimal_toolbar_action_group;
+}
diff --git a/shell/ev-window.h b/shell/ev-window.h
index 3dc1f2c..1876b30 100644
--- a/shell/ev-window.h
+++ b/shell/ev-window.h
@@ -90,6 +90,7 @@ GtkUIManager *ev_window_get_ui_manager (EvWindow *ev_win
GtkActionGroup *ev_window_get_main_action_group (EvWindow *ev_window);
GtkActionGroup *ev_window_get_zoom_selector_action_group (EvWindow *ev_window);
void ev_window_show_recent_view (EvWindow *ev_window);
+GtkActionGroup *ev_window_get_minimal_toolbar_action_group (EvWindow *ev_window);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]