diff options
author | Xan Lopez <xan@igalia.com> | 2012-01-17 00:35:36 +0800 |
---|---|---|
committer | Xan Lopez <xan@igalia.com> | 2012-01-17 01:49:35 +0800 |
commit | 64d06cecbf24c4731acc5f6c0b6dde60a5938027 (patch) | |
tree | c703252f673cc8e131867553209f2668002818b0 /src | |
parent | 3d7377cb22125311566c3699124005cd59181171 (diff) | |
download | gsoc2013-epiphany-64d06cecbf24c4731acc5f6c0b6dde60a5938027.tar gsoc2013-epiphany-64d06cecbf24c4731acc5f6c0b6dde60a5938027.tar.gz gsoc2013-epiphany-64d06cecbf24c4731acc5f6c0b6dde60a5938027.tar.bz2 gsoc2013-epiphany-64d06cecbf24c4731acc5f6c0b6dde60a5938027.tar.lz gsoc2013-epiphany-64d06cecbf24c4731acc5f6c0b6dde60a5938027.tar.xz gsoc2013-epiphany-64d06cecbf24c4731acc5f6c0b6dde60a5938027.tar.zst gsoc2013-epiphany-64d06cecbf24c4731acc5f6c0b6dde60a5938027.zip |
Stop using GtkUIManager to create the toolbar
Otherwise it's difficult to get the right layout for theming.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/ephy-combined-stop-reload-action.c | 1 | ||||
-rw-r--r-- | src/ephy-page-menu-action.c | 6 | ||||
-rw-r--r-- | src/ephy-toolbar.c | 199 | ||||
-rw-r--r-- | src/ephy-toolbar.h | 62 | ||||
-rw-r--r-- | src/ephy-window.c | 30 | ||||
-rw-r--r-- | src/ephy-window.h | 2 |
7 files changed, 289 insertions, 13 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index d916499be..f89a0219f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -29,6 +29,7 @@ NOINST_H_FILES = \ ephy-navigation-history-action.h \ ephy-page-menu-action.h \ ephy-password-info.h \ + ephy-toolbar.h \ languages.h \ pdm-dialog.h \ popup-commands.h \ @@ -70,6 +71,7 @@ libephymain_la_SOURCES = \ ephy-password-info.c \ ephy-session.c \ ephy-shell.c \ + ephy-toolbar.c \ ephy-window.c \ pdm-dialog.c \ popup-commands.c \ diff --git a/src/ephy-combined-stop-reload-action.c b/src/ephy-combined-stop-reload-action.c index 0b43d8f63..0789a2822 100644 --- a/src/ephy-combined-stop-reload-action.c +++ b/src/ephy-combined-stop-reload-action.c @@ -77,7 +77,6 @@ ephy_combined_stop_reload_action_set_loading (EphyCombinedStopReloadAction *acti EPHY_COMBINED_STOP_RELOAD_ACTION_STOP : EPHY_COMBINED_STOP_RELOAD_ACTION_REFRESH; g_object_set (action, - "label", combined_stop_reload_action_entries[action_enum].label, "icon-name", combined_stop_reload_action_entries[action_enum].stock_id, "tooltip", combined_stop_reload_action_entries[action_enum].tooltip, NULL); diff --git a/src/ephy-page-menu-action.c b/src/ephy-page-menu-action.c index 308d6c1b0..0a7c83d51 100644 --- a/src/ephy-page-menu-action.c +++ b/src/ephy-page-menu-action.c @@ -28,7 +28,7 @@ menu_position_func (GtkMenu *menu, int *x, int *y, gboolean *push_in, - GtkMenuToolButton *button) + GtkToolButton *button) { GtkAllocation allocation; GtkWidget *widget = GTK_WIDGET (button); @@ -68,12 +68,14 @@ ephy_page_menu_action_activate (GtkAction *action) window = _ephy_navigation_action_get_window (EPHY_NAVIGATION_ACTION (action)); manager = GTK_UI_MANAGER (ephy_window_get_ui_manager (window)); - menu = gtk_ui_manager_get_widget (manager, "/PagePopup"); + menu = gtk_ui_manager_get_widget (manager, "/ui/PagePopup"); list = gtk_action_get_proxies (action); if (GTK_IS_TOOL_BUTTON (list->data)) button = GTK_WIDGET (list->data); + g_return_if_fail (GTK_IS_TOOL_BUTTON (button)); + event = gtk_get_current_event (); if (event && event->type == GDK_BUTTON_PRESS) { activate_button = event->button.button; diff --git a/src/ephy-toolbar.c b/src/ephy-toolbar.c new file mode 100644 index 000000000..d3d8c3f1f --- /dev/null +++ b/src/ephy-toolbar.c @@ -0,0 +1,199 @@ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * Copyright © 2012 Igalia S.L. + * + * This program 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, or (at your option) + * any later version. + * + * This program 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. + * + */ + +#include "config.h" +#include "ephy-toolbar.h" + +G_DEFINE_TYPE (EphyToolbar, ephy_toolbar, GTK_TYPE_TOOLBAR) + +#define EPHY_TOOLBAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), EPHY_TYPE_TOOLBAR, EphyToolbarPrivate)) + +enum { + PROP_0, + PROP_WINDOW, + N_PROPERTIES +}; + +static GParamSpec *object_properties[N_PROPERTIES] = { NULL, }; + +struct _EphyToolbarPrivate { + EphyWindow *window; +}; + +static void +ephy_toolbar_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + EphyToolbarPrivate *priv = EPHY_TOOLBAR (object)->priv; + + switch (property_id) { + case PROP_WINDOW: + priv->window = EPHY_WINDOW (g_value_get_object (value)); + g_object_notify_by_pspec (object, object_properties[PROP_WINDOW]); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +ephy_toolbar_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + EphyToolbarPrivate *priv = EPHY_TOOLBAR (object)->priv; + + switch (property_id) { + case PROP_WINDOW: + g_value_set_object (value, priv->window); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static gboolean +create_menu_proxy_cb (GtkToolItem *item, gpointer user_data) +{ + return TRUE; +} + +static void +ephy_toolbar_constructed (GObject *object) +{ + EphyToolbarPrivate *priv = EPHY_TOOLBAR (object)->priv; + GtkActionGroup *action_group; + GtkAction *action; + GtkToolItem *tool_button, *back_forward, *location_stop_reload; + GtkWidget *box, *location, *toolbar; + + G_OBJECT_CLASS (ephy_toolbar_parent_class)->constructed (object); + + toolbar = GTK_WIDGET (object); + + /* Back and Forward */ + back_forward = gtk_tool_item_new (); + box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + + /* Back */ + tool_button = gtk_tool_button_new (NULL, NULL); + action_group = ephy_window_get_toolbar_action_group (priv->window); + action = gtk_action_group_get_action (action_group, "NavigationBack"); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (tool_button), + action); + gtk_container_add (GTK_CONTAINER (box), GTK_WIDGET (tool_button)); + + /* Forward */ + tool_button = gtk_tool_button_new (NULL, NULL); + action = gtk_action_group_get_action (action_group, "NavigationForward"); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (tool_button), + action); + gtk_container_add (GTK_CONTAINER (box), GTK_WIDGET (tool_button)); + + gtk_style_context_add_class (gtk_widget_get_style_context (box), + "raised"); + gtk_style_context_add_class (gtk_widget_get_style_context (box), + "linked"); + + gtk_container_add (GTK_CONTAINER (back_forward), box); + gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET (back_forward)); + gtk_widget_show_all (GTK_WIDGET (back_forward)); + gtk_widget_set_margin_right (GTK_WIDGET (back_forward), 12); + + /* Location and Reload/Stop */ + location_stop_reload = gtk_tool_item_new (); + box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + + /* Location */ + action = gtk_action_group_get_action (action_group, "Location"); + location = gtk_action_create_tool_item (action); + gtk_box_pack_start (GTK_BOX (box), location, + TRUE, TRUE, 0); + + /* Reload/Stop */ + tool_button = gtk_tool_button_new (NULL, NULL); + action = gtk_action_group_get_action (action_group, "ViewCombinedStopReload"); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (tool_button), + action); + gtk_container_add (GTK_CONTAINER (box), GTK_WIDGET (tool_button)); + + gtk_container_add (GTK_CONTAINER (location_stop_reload), box); + gtk_container_child_set (GTK_CONTAINER (toolbar), + GTK_WIDGET (location_stop_reload), + "expand", TRUE, + NULL); + + gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET (location_stop_reload)); + gtk_widget_set_margin_right (GTK_WIDGET (location_stop_reload), 12); + gtk_widget_show_all (GTK_WIDGET (location_stop_reload)); + + /* Page Menu */ + tool_button = gtk_tool_button_new (NULL, NULL); + action = gtk_action_group_get_action (action_group, "PageMenu"); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (tool_button), + action); + gtk_container_add (GTK_CONTAINER (toolbar), GTK_WIDGET (tool_button)); + /* FIXME: why is this needed?! GTK+ wants to create an overflow menu + * for this, no idea why. Connect to the signal to cancel it. */ + g_signal_connect (tool_button, "create-menu-proxy", + G_CALLBACK (create_menu_proxy_cb), NULL); +} + +static void +ephy_toolbar_class_init (EphyToolbarClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->set_property = ephy_toolbar_set_property; + gobject_class->get_property = ephy_toolbar_get_property; + gobject_class->constructed = ephy_toolbar_constructed; + + object_properties[PROP_WINDOW] = + g_param_spec_object ("window", + "Window", + "The toolbar's EphyWindow", + EPHY_TYPE_WINDOW, + G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_CONSTRUCT_ONLY); + + g_object_class_install_properties (gobject_class, + N_PROPERTIES, + object_properties); + + g_type_class_add_private (klass, sizeof (EphyToolbarPrivate)); +} + +static void +ephy_toolbar_init (EphyToolbar *toolbar) +{ + toolbar->priv = EPHY_TOOLBAR_GET_PRIVATE (toolbar); +} + +GtkWidget* +ephy_toolbar_new (EphyWindow *window) +{ + g_return_val_if_fail (EPHY_IS_WINDOW (window), NULL); + + return GTK_WIDGET (g_object_new (EPHY_TYPE_TOOLBAR, + "window", window, + NULL)); +} diff --git a/src/ephy-toolbar.h b/src/ephy-toolbar.h new file mode 100644 index 000000000..2ecc97f4e --- /dev/null +++ b/src/ephy-toolbar.h @@ -0,0 +1,62 @@ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * Copyright © 2012 Igalia S.L. + * + * This program 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, or (at your option) + * any later version. + * + * This program 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. + * + */ + +#if !defined (__EPHY_EPIPHANY_H_INSIDE__) && !defined (EPIPHANY_COMPILATION) +#error "Only <epiphany/epiphany.h> can be included directly." +#endif + +#ifndef EPHY_TOOLBAR_H +#define EPHY_TOOLBAR_H + +#include <gtk/gtk.h> + +#include "ephy-window.h" + +G_BEGIN_DECLS + +#define EPHY_TYPE_TOOLBAR (ephy_toolbar_get_type()) +#define EPHY_TOOLBAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EPHY_TYPE_TOOLBAR, EphyToolbar)) +#define EPHY_TOOLBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EPHY_TYPE_TOOLBAR, EphyToolbarClass)) +#define EPHY_IS_TOOLBAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EPHY_TYPE_TOOLBAR)) +#define EPHY_IS_TOOLBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EPHY_TYPE_TOOLBAR)) +#define EPHY_TOOLBAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EPHY_TYPE_TOOLBAR, EphyToolbarClass)) + +typedef struct _EphyToolbar EphyToolbar; +typedef struct _EphyToolbarClass EphyToolbarClass; +typedef struct _EphyToolbarPrivate EphyToolbarPrivate; + +struct _EphyToolbar { + GtkToolbar parent; + + /*< private >*/ + EphyToolbarPrivate *priv; +}; + +struct _EphyToolbarClass { + GtkToolbarClass parent_class; +}; + +GType ephy_toolbar_get_type (void) G_GNUC_CONST; + +GtkWidget *ephy_toolbar_new (EphyWindow *window); + +G_END_DECLS + +#endif /* EPHY_TOOLBAR_H */ diff --git a/src/ephy-window.c b/src/ephy-window.c index ea6358920..f8e70313f 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -55,6 +55,7 @@ #include "ephy-state.h" #include "ephy-stock-icons.h" #include "ephy-topic-action.h" +#include "ephy-toolbar.h" #include "ephy-type-builtins.h" #include "ephy-web-view.h" #include "ephy-zoom-action.h" @@ -1480,7 +1481,6 @@ setup_ui_manager (EphyWindow *window) action = g_object_new (EPHY_TYPE_NAVIGATION_HISTORY_ACTION, "name", "NavigationBack", - "label", _("_Back"), "icon-name", "go-previous-symbolic", "tooltip", _("Go to the previous visited page"), "window", window, @@ -1493,7 +1493,6 @@ setup_ui_manager (EphyWindow *window) action = g_object_new (EPHY_TYPE_NAVIGATION_HISTORY_ACTION, "name", "NavigationForward", - "label", _("_Forward"), "icon-name", "go-next-symbolic", "tooltip", _("Go to the next visited page"), "window", window, @@ -3560,13 +3559,12 @@ static GtkWidget * setup_toolbar (EphyWindow *window) { GtkWidget *toolbar; - GtkUIManager *manager; GtkAction *action; EphyWindowPrivate *priv = window->priv; - manager = GTK_UI_MANAGER (ephy_window_get_ui_manager (window)); - - toolbar = gtk_ui_manager_get_widget (manager, "/DefaultToolbar"); + toolbar = ephy_toolbar_new (window); + gtk_box_pack_start (GTK_BOX (priv->menu_dock), + toolbar, FALSE, FALSE, 0); action = gtk_action_group_get_action (priv->toolbar_action_group, "NavigationBack"); @@ -3657,7 +3655,14 @@ ephy_window_constructor (GType type, /* Setup the UI manager and connect verbs */ setup_ui_manager (window); + /* Create the notebook. */ + /* FIXME: the notebook needs to exist before the toolbar, + * because EphyLocationEntry uses it... */ priv->notebook = setup_notebook (window); + + /* Setup the toolbar. */ + priv->toolbar = setup_toolbar (window); + g_signal_connect_swapped (priv->notebook, "open-link", G_CALLBACK (ephy_link_open), window); gtk_box_pack_start (GTK_BOX (priv->main_vbox), @@ -3713,9 +3718,6 @@ ephy_window_constructor (GType type, g_object_unref (css_provider); g_object_unref (css_file); - /* Setup the toolbar. */ - priv->toolbar = setup_toolbar (window); - /* Initialize the menus */ priv->enc_menu = ephy_encoding_menu_new (window); @@ -3769,7 +3771,7 @@ ephy_window_constructor (GType type, ephy_action_change_sensitivity_flags (action, SENS_FLAG_CHROME, TRUE); } } - + /* ensure the UI is updated */ gtk_ui_manager_ensure_update (priv->manager); @@ -4259,3 +4261,11 @@ ephy_window_set_location (EphyWindow *window, ephy_location_action_set_address (EPHY_LOCATION_ACTION (action), address); priv->updating_address = FALSE; } + +GtkActionGroup * +ephy_window_get_toolbar_action_group (EphyWindow *window) +{ + g_return_val_if_fail (EPHY_IS_WINDOW (window), NULL); + + return window->priv->toolbar_action_group; +} diff --git a/src/ephy-window.h b/src/ephy-window.h index c0f6747de..e9b443f21 100644 --- a/src/ephy-window.h +++ b/src/ephy-window.h @@ -85,6 +85,8 @@ EphyEmbedEvent *ephy_window_get_context_event (EphyWindow *window); void ephy_window_set_downloads_box_visibility (EphyWindow *window, gboolean show); +GtkActionGroup *ephy_window_get_toolbar_action_group (EphyWindow *window); + G_END_DECLS #endif |